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);
}
}