Issue with mesh size and collision
Posted: Sun Jul 26, 2015 5:09 pm
I keep having an issue where my collision area seems to be half the size of what my rendered mesh is. I am just using a box that I created in blender exported to fbx and ran through the fbx converter. The only way I can get it to correctly size up is if I use HalfWidth, HalfHeight, and HalfLength of the box. I have a feeling it has something to do with this (viewtopic.php?t=1517). Instead of using calculations is it bad practice to just use the halfs of the length width and height?
Thanks ahead of time for any help on this! By the way, I am pretty new to BepuPhysics and MonoGame/XNA if it isn't obvious
My class:
Thanks ahead of time for any help on this! By the way, I am pretty new to BepuPhysics and MonoGame/XNA if it isn't obvious
My class:
Code: Select all
public class EntityModelTest : DrawableGameComponent
{
public Entity _entity {get; set;}
Model _model;
Vector3 _location;
Matrix[] _boneTransforms;
Box _box;
Matrix _transform;
Game1 _game;
public EntityModelTest(Model model, Vector3 location, int width, int height, int length, int mass, Game1 game)
: base(game)
{
this._box = new Box(MathConverter.Convert(location), width, height, length, mass);
this._model = model;
this._location = location;
this._entity = (Entity)_box;
this._transform = Matrix.CreateScale(_box.HalfWidth, _box.HalfHeight, _box.HalfLength);
this._game = game;
this._entity.Tag = this;
this._boneTransforms = new Matrix[model.Bones.Count];
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
}
}
_game.space.Add(_box);
_game.Components.Add(this);
}
public override void Draw(GameTime gameTime)
{
Matrix worldMatrix = _transform * MathConverter.Convert(_entity.WorldTransform);
_model.CopyAbsoluteBoneTransformsTo(_boneTransforms);
foreach (ModelMesh mesh in _model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = _boneTransforms[mesh.ParentBone.Index] * worldMatrix;
effect.View = (Game as Game1).Camera.ViewMatrix;
effect.Projection = (Game as Game1).Camera.ProjectionMatrix;
}
mesh.Draw();
}
base.Draw(gameTime);
}
public void addLinearVelocity(Vector3 direction, int velocity)
{
_entity.LinearVelocity = MathConverter.Convert(direction * velocity);
}
}