Problems with graphic matching complex objects
Posted: Sun Mar 10, 2013 8:58 am
Hi Norbo, I recently came back to my hobby of making a game in XNA. I had a few problems with the graphics not matching the collision, I implemented the code you have in your graphics matching demo. It works for semi-complex models such as guns, sorta. But more complex models such as vehicles or buildings (actually those are fairly simple) don't match up at all. I am using the Character controller, loading the model as a convex hull, offsetting the graphics transform, then drawing it.
Here is a photo to let you know exactly what is happening, the character floats slightly above the truck bed:

I can also walk through the cab:

Here is the code where I construct the object:
Here is where the localGraphicsTransform comes into play:
Anything helps, thanks.
Here is a photo to let you know exactly what is happening, the character floats slightly above the truck bed:

I can also walk through the cab:

Here is the code where I construct the object:
Code: Select all
BepuEntity creatBarrel(Vector3 position, float mass)
{
BepuEntity bar = new BepuEntity();
bar.modelName = "Levels\\Test\\untitled"; //The truck model
bar.diffName = "Levels\\Test\\TruckR"; //Diffuse texture
bar.normName = "Levels\\Test\\TruckRNrml"; //Normal texture
bar.specName = "Levels\\Test\\TruckRNrml"; //Specular
bar.LoadContent(); //Loads the model and textues
TriangleMesh.GetVerticesAndIndicesFromModel(bar.model, out vertices, out indices);
//for (int i = 0; i < vertices.Length; i++)
// vertices[i] = Vector3.Transform(vertices[i], Matrix.CreateScale(1 - 0.01f)); //I tried the graphics matching solution I found on the forums, didn't work.
bar.body = new ConvexHull(vertices, 10);
bar.localGraphicsTransform = Matrix.CreateTranslation(-bar.body.Position);//.body.Position
bar.body.Position = position;
bar.Position = position;// position;
bar.configureEvents();
space.Add(bar.body);
bar.body.BecomeKinematic();
children.Add(bar);
return bar;
}
Code: Select all
public override void Update(GameTime gameTime) //This is called for all BEPU objects in the game.
{
//Console.WriteLine(body.WorldTransform.Translation.ToString());
worldTransform = localGraphicsTransform * body.WorldTransform;
}