| JigLibX |
| Discuss any JigLibX related stuff here. |
| ProxyProdigy - January 24, 2009 03:05pm |
| Hiding Unseen Objects |
| Whenever you add a lot of objects (especially high poly models) to your world, your FPS begins to drop. So, instead of rendering everything in the world, I decided to only render and draw what is in my FOV. To do this, I created a quick method to check if objects are within my FOV. I also have to change my camera's FOV to 50 instead of the default 45. Otherwise, some objects would "disappear" when I turn and have a widescreen monitor. Lower width screens weren't affected. But, on my 24 inch widescreen monitor, I try to use up as much realestate as possible. Anyways, I added the following method to my PhysicObject.
public static bool IsInsideCone(Vector3 point, Vector3 coneOrigin, Vector3 coneDirection, double coneAngle) { Vector3 tempVect = Vector3.Normalize(point - coneOrigin); return Vector3.Dot(coneDirection, tempVect) >= Math.Cos(coneAngle); } After that, I do a check in my PhysicObject.Draw method before drawing any meshes. My code for this looks like: if (IsInsideCone(body.Position, camera.cameraPosition, camera.cameraDirection, FOVPlusPadding)){ } My PhysicObject.Draw method now looks like this: public override void Draw(GameTime gameTime) { Camera camera = ((GameCore)this.Game).Camera; float FOVPlusPadding = camera.FOV * 1.1f; if (model != null && IsInsideCone(body.Position, camera.cameraPosition, camera.cameraDirection, FOVPlusPadding)) { if (boneTransforms == null || boneCount != model.Bones.Count) { boneTransforms = new Matrix[model.Bones.Count]; boneCount = model.Bones.Count; } model.CopyAbsoluteBoneTransformsTo(boneTransforms); foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { if (body.CollisionSkin != null) effect.World = boneTransforms[mesh.ParentBone.Index] * Matrix.CreateScale(scale) * body.CollisionSkin.GetPrimitiveLocal(0).Transform.Orientation * body.Orientation * Matrix.CreateTranslation(body.Position); else effect.World = boneTransforms[mesh.ParentBone.Index] * Matrix.CreateScale(scale) * body.Orientation * Matrix.CreateTranslation(body.Position); effect.View = camera.viewMatrix; effect.Projection = camera.projectionMatrix; ApplyEffects(effect); effect.EnableDefaultLighting(); effect.PreferPerPixelLighting = true; } mesh.Draw(); } } if (this.collision != null) { int count = collision.NumPrimitives; for (int i = 0; i < count; i++) { BoundingBox box = new BoundingBox(); BoundingBoxHelper.AddPrimitive(collision.GetPrimitiveOldWorld(i), ref box); } } base.Draw(gameTime); } |
| ProxyProdigy - January 24, 2009 07:13pm |
| Car Begins to Wobble |
| I came across a problem where, when my car accelerated to a certain speed, it would begin to wobble from side to side. It caused the car to look like it was driving on a bumpy road. Eventually, the car would wobble so much that it would lose traction and slow down which in return allowed the car to gain traction and begin driving again.
The cause for this was the first tire in the list would lose traction and come up off the ground. Then the second tire in the list would do the same and so on. Since the tires operate in the order they're listed in the code, one wheel would start a chain reaction that fell thru to the others. To fix the problem, I simply tightened the suspension on the car and the problem was solved. However, this causes my car to have a larger turning radius than before. So, I'm still looking into alternatives. But, hopefully, this will help any of you that run into the same problem. |
| ProxyProdigy - February 8, 2009 01:08am |
| Car Spins Out of Control |
| Recently, I encountered a problem where my car would spin out of control when driving over a TriangleMeshObject. I posted a video of this occurring in the JiggleGame demo at http://www.yourmercials.com/video/460/. You can also see the action happen in my game in a video at http://www.yourmercials.com/video/461/. noone88 worked out the problem and got me back on track (so to speak). You can follow the discussion and see the fix over at the JigLibX site. The code / fix is at http://www.codeplex.com/JigLibX/Thread/View.aspx?ThreadId=46769 |
| ProxyProdigy - February 20, 2009 08:09am |
|
You must be logged in to post comments. Not a member? SIGN-UP NOW Registration is free and easy! |
Log In Already a member? Login here. |
