Issue with mesh size and collision

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
julius
Posts: 1
Joined: Sun Jul 26, 2015 4:55 pm

Issue with mesh size and collision

Post by julius »

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 :D
Using half
Using half
using half.jpg (30.82 KiB) Viewed 3171 times
Without using half
Without using half
without half.jpg (29.16 KiB) Viewed 3171 times
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);
        }
    }

Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Issue with mesh size and collision

Post by Norbo »

Assuming nothing weird is happening like scaling factors in the bone/world transforms, the box model is probably 2 units wide in local space. That is, the vertices are +-(1, 1, 1) instead of +-(0.5, 0.5, 0.5). So, if the physics box is 2 wide, high, and long, using the full dimensions would make the box's visualization (1, 1, 1) * 2 - (-1, -1, -1) * 2 = (4, 4, 4) from min to max.
Post Reply