Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BoxColliderShape"/> class.
        /// </summary>
        /// <param name="is2D">If this cube is a 2D quad</param>
        /// <param name="size">The size of the cube</param>
        public BoxColliderShape(bool is2D, Vector3 size)
        {
            Type    = ColliderShapeTypes.Box;
            Is2D    = is2D;
            BoxSize = size;

            //Box is not working properly when in a convex2dshape, Z cannot be 0

            cachedScaling = Is2D ? new Vector3(1, 1, 0.001f) : Vector3.One;

            if (is2D)
            {
                size.Z = 0.001f;
            }

            var shape = new BulletSharp.BoxShape(size / 2)
            {
                LocalScaling = cachedScaling,
            };

            if (Is2D)
            {
                InternalShape = new BulletSharp.Convex2DShape(shape)
                {
                    LocalScaling = cachedScaling
                };
            }
            else
            {
                InternalShape = shape;
            }

            DebugPrimitiveMatrix = Matrix.Scaling(size * DebugScaling);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BoxColliderShape"/> class.
        /// </summary>
        /// <param name="size">The size of the cube</param>
        public BoxColliderShape(Vector3 size)
        {
            Type = ColliderShapeTypes.Box;
            Is2D = false;

            InternalShape = new BulletSharp.BoxShape(size / 2);

            DebugPrimitiveMatrix = Matrix.Scaling(size * 1.01f);
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BoxColliderShape"/> class.
        /// </summary>
        /// <param name="halfExtents">The half extents.</param>
        public BoxColliderShape(Vector3 halfExtents)
        {
            Type = ColliderShapeTypes.Box;
            Is2D = false;

            InternalShape = new BulletSharp.BoxShape(halfExtents);

            DebugPrimitiveMatrix = Matrix.Scaling((halfExtents * 2.0f) * 1.01f);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BoxColliderShape"/> class.
        /// </summary>
        /// <param name="halfExtents">The half extents.</param>
        public BoxColliderShape(Vector3 halfExtents)
        {
            Type = ColliderShapeTypes.Box;
            Is2D = false;

            InternalShape = new BulletSharp.BoxShape(halfExtents);

            DebugPrimitiveMatrix = Matrix.Scaling((halfExtents * 2.0f) * 1.01f);
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BoxColliderShape"/> class.
        /// </summary>
        /// <param name="size">The size of the cube</param>
        public BoxColliderShape(Vector3 size)
        {
            Type = ColliderShapeTypes.Box;
            Is2D = false;

            InternalShape = new BulletSharp.BoxShape(size/2)
            {
                LocalScaling = Vector3.One
            };

            DebugPrimitiveMatrix = Matrix.Scaling(size * 1.01f);
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BoxColliderShape"/> class.
        /// </summary>
        /// <param name="size">The size of the cube</param>
        public BoxColliderShape(Vector3 size)
        {
            Type = ColliderShapeTypes.Box;
            Is2D = false;

            CachedScaling = Vector3.One;
            InternalShape = new BulletSharp.BoxShape(size / 2)
            {
                LocalScaling = CachedScaling
            };

            DebugPrimitiveMatrix = Matrix.Scaling(size * DebugScaling);
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BoxColliderShape"/> class.
        /// </summary>
        /// <param name="halfExtents">The half extents.</param>
        public BoxColliderShape(Vector3 halfExtents)
        {
            Type = ColliderShapeTypes.Box;
            Is2D = false;

            HalfExtents = halfExtents;

            InternalShape = new BulletSharp.BoxShape(halfExtents);

            if (!PhysicsEngine.Singleton.CreateDebugPrimitives)
            {
                return;
            }
            DebugPrimitive        = GeometricPrimitive.Cube.New(PhysicsEngine.Singleton.DebugGraphicsDevice);
            DebugPrimitiveScaling = Matrix.Scaling((halfExtents * 2.0f) * 1.01f);
        }
Esempio n. 8
0
        public void InitializeWorld()
        {
            mGameObjects = new List <NetGameObject>();
            //mWorldMap = new WorldMap();

#if _USE_BEPU_PHYSICS
            space = new BEPUphysics.Space();
            space.ForceUpdater.Gravity = new BEPUutilities.Vector3(0, -9.81f, 0);
#elif _USE_BULLET_SHARP
            Broadphase = new BulletSharp.AxisSweep3(new BulletSharp.Math.Vector3(-1000, -1000, -1000), new BulletSharp.Math.Vector3(1000, 1000, 1000));

            var conf       = new BulletSharp.DefaultCollisionConfiguration();
            var dispatcher = new BulletSharp.CollisionDispatcher(conf);
            world         = new BulletSharp.MultiBodyDynamicsWorld(dispatcher, Broadphase, new BulletSharp.MultiBodyConstraintSolver(), conf);
            world.Gravity = new BulletSharp.Math.Vector3(0, -9.81f, 0);

            var box = new BulletSharp.BoxShape(50f, 1f, 50f);
            //box.Margin = 0f;
            floor = new BulletSharp.RigidBody(new BulletSharp.RigidBodyConstructionInfo(0f, new BulletSharp.DefaultMotionState(), box, new BulletSharp.Math.Vector3(0, -2f, 0)));
            floor.CollisionFlags = BulletSharp.CollisionFlags.KinematicObject;


            BulletSharp.Math.Matrix worldTrans = new BulletSharp.Math.Matrix();
            worldTrans.M41       = 0f;
            worldTrans.M42       = -2f;
            worldTrans.M43       = 0;
            floor.WorldTransform = worldTrans;
            //floor.Friction = 0.5f;


            world.AddRigidBody(floor, BulletSharp.CollisionFilterGroups.DefaultFilter, //BulletSharp.CollisionFilterGroups.Everything);
                               (BulletSharp.CollisionFilterGroups.DefaultFilter
                                | BulletSharp.CollisionFilterGroups.StaticFilter
                                | BulletSharp.CollisionFilterGroups.KinematicFilter
                                | BulletSharp.CollisionFilterGroups.DebrisFilter
                                | BulletSharp.CollisionFilterGroups.SensorTrigger
                                | BulletSharp.CollisionFilterGroups.CharacterFilter
                               )
                               );
#elif _USE_BEPU_PHYSICS_V2
            characters = new BepuPhysics.CharacterControllers(BufferPool);
            Simulation = Simulation.Create(BufferPool, new BepuPhysics.CharacterNarrowphaseCallbacks(characters), new DemoPoseIntegratorCallbacks(new System.Numerics.Vector3(0, -10, 0)));

            Simulation.Statics.Add(new StaticDescription(new System.Numerics.Vector3(0, 0, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(50, 1, 50)), 0.1f)));
#endif
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BoxColliderShape"/> class.
        /// </summary>
        /// <param name="is2D">If this cube is a 2D quad</param>
        /// <param name="size">The size of the cube</param>
        public BoxColliderShape(bool is2D, Vector3 size, Vector3?offset = null, Quaternion?localrot = null)
        {
            Type    = ColliderShapeTypes.Box;
            Is2D    = is2D;
            BoxSize = size;

            //Box is not working properly when in a convex2dshape, Z cannot be 0

            cachedScaling = Is2D ? new Vector3(1, 1, 0.001f) : Vector3.One;

            if (is2D)
            {
                size.Z = 0.001f;
            }

            var shape = new BulletSharp.BoxShape(size / 2)
            {
                LocalScaling = cachedScaling,
            };

            if (Is2D)
            {
                InternalShape = new BulletSharp.Convex2DShape(shape)
                {
                    LocalScaling = cachedScaling
                };
            }
            else
            {
                InternalShape = shape;
            }

            DebugPrimitiveMatrix = Matrix.Scaling(size * DebugScaling);

            if (offset.HasValue || localrot.HasValue)
            {
                LocalOffset   = offset ?? Vector3.Zero;
                LocalRotation = localrot ?? Quaternion.Identity;
                UpdateLocalTransformations();
            }
        }
Esempio n. 10
0
 public BoxShape(OpenTK.Vector3 halfExtents)
 {
     HalfExtent             = halfExtents;
     BulletShape            = new BulletSharp.BoxShape(halfExtents);
     BulletShape.UserObject = this;
 }
Esempio n. 11
0
 /// <summary>
 /// Create the collision box.
 /// </summary>
 /// <param name="width">Box base width (X axis).</param>
 /// <param name="height">Box base height (Y axis).</param>
 /// <param name="depth">Bow base depth (Z axis).</param>
 public CollisionBox(float width = 1f, float height = 1f, float depth = 1f)
 {
     _shape = new BulletSharp.BoxShape(width / 2f, height / 2f, depth / 2f);
 }