How to view the AABB

Feb 20, 2010 at 4:16 PM
Edited Feb 20, 2010 at 5:03 PM

How do easy view the AABB?

I havn't found this anywhere as the AABB view doesn't work in the code.


EDIT: I now saw that the AABB drawing was only working in debug. But when I tries to use the same code nothing seems to happen. I set DrawAABBs = true; And calls physics.Draw() every time the game sould draw! But I can't seem to find anything like in the test game. The terrain doesn't show anything. And my tank doesn't collide with it, even thought it drops!

(Sorry for sounding like a noob, but I've had those problems since I first tried to use a physics engine (even PhysX, JigLibX, e.t.c.))

Feb 20, 2010 at 5:17 PM

Hey Mattan360,

You are correct that DrawAABBs is only possible in DEBUG.  It also requires that a IViewpointService service (via ViewpointComponent) exist in the Game.Services (or GameScreen.Services if you are using the GameStateComponent) and an active camera. You can take a look at ExampleScreen.cs for an example of setting up that.  If you already have a camera system, you can create a StaticCamera, set IsViewUpdated to false and update it's View property manually every Update.

As far as your tank not colliding with the terrain,  If you want to post some code here, I'd be happy to take a look.  You might try using a CollisionPlane instead of a CollisionMesh to see if the physics is indeed set up correctly.  There are a lot less things that could go wrong with plane collision detection. 

Let me know.  Good luck!

Feb 21, 2010 at 10:08 AM
Edited Feb 21, 2010 at 10:38 AM

OK, thanks for the reply.

The collisions works with a plane.

I'm going to try use the stuff with IViewpointService to get a better view over how it all looks :D

Can it be that easy that heightmap scale doesn't work?

EDIT: I wrote this code in the initialize.

cam = new StaticCamera(this, "Static");
cam.IsViewUpdated = false;
cam.Viewport = GraphicsDevice.Viewport;

view = new ViewpointComponent(this);
And this in the update:
cam.Projection = projectionMatrix;
cam.Position = cameraPosition;
cam.View = viewMatrix;

But it still doesn't work.
The game is devided into classes, one for the game part wich update calls are made from the main game.
There is a loader where I keep most of my variables. (I've removed all references to that in the code above)
Feb 25, 2010 at 2:44 PM

Hi again!

Do I need anything special like textures and such, or to call anyfunction or set any variable to draw the physics.

Also, do you set the size of a collision mesh trought the extents?

Feb 28, 2010 at 9:52 PM

Drawing the AABBs of the phyiscs engine should not require any extra content.  Maybe put a breakpoint in PhysicsComponent.Draw and/or PhysicsComponent.UpdateDebug and if its calling the code you would expect?

The size of the CollisionMesh is based on the ContentProcessor properties of the model and the bones that make up the model, if they were modified.  If I add a model (fbx or x) to my content projects, I can modify the Scale property of the Model - XNA Framework content processor.  The bones will reflect this scale as well, but you can modify the bones and with a call to model.CopyTransformsFrom.  So, first load the model:

Model model = this.Content.Load("some model");

Then create the CollisionMesh and associated CollisionGroup and add it the the physics component:

CollisionMesh mesh = new CollisionMesh(new ModelCollisionMeshProxy(model));
CollisionGroup group = new CollisionGroup();

To draw the mesh, make sure to use the same model as above and use it's bones:

this.transforms = new Matrix[this.model.Bones.Count];
foreach (ModelMesh mesh in this.model.Meshes)
	foreach (Effect effect in mesh.Effects)
		effect.Parameters["World"].SetValue(this.transforms[mesh.ParentBone.Index] * World);