Example #1
0
 public unsafe static void ConvexSweepTest(this GhostObject obj, ConvexShape castShape, ref OpenTK.Matrix4 convexFromWorld, ref OpenTK.Matrix4 convexToWorld, ConvexResultCallback resultCallback, float allowedCcdPenetration)
 {
     fixed(OpenTK.Matrix4 *convexFromWorldPtr = &convexFromWorld)
     {
         fixed(OpenTK.Matrix4 *convexToWorldPtr = &convexToWorld)
         {
             obj.ConvexSweepTest(castShape, ref *(BulletSharp.Math.Matrix *)convexFromWorldPtr, ref *(BulletSharp.Math.Matrix *)convexToWorldPtr, resultCallback, allowedCcdPenetration);
         }
     }
 }
Example #2
0
 public unsafe static void RayTest(this GhostObject obj, ref OpenTK.Vector3 rayFromWorld, ref OpenTK.Vector3 rayToWorld, RayResultCallback resultCallback)
 {
     fixed(OpenTK.Vector3 *rayFromWorldPtr = &rayFromWorld)
     {
         fixed(OpenTK.Vector3 *rayToWorldPtr = &rayToWorld)
         {
             obj.RayTest(ref *(BulletSharp.Math.Vector3 *)rayFromWorldPtr, ref *(BulletSharp.Math.Vector3 *)rayToWorldPtr, resultCallback);
         }
     }
 }
Example #3
0
        internal override bool _BuildCollisionObject()
        {
            BPhysicsWorld world = BPhysicsWorld.Get();

            if (m_collisionObject != null)
            {
                if (isInWorld && world != null)
                {
                    world.RemoveCollisionObject(m_collisionObject);
                }
            }

            if (transform.localScale != UnityEngine.Vector3.one)
            {
                Debug.LogError("The local scale on this collision shape is not one. Bullet physics does not support scaling on a rigid body world transform. Instead alter the dimensions of the CollisionShape.");
            }

            m_collisionShape = GetComponent <BCollisionShape>();
            if (m_collisionShape == null)
            {
                Debug.LogError("There was no collision shape component attached to this BRigidBody. " + name);
                return(false);
            }

            CollisionShape cs = m_collisionShape.GetCollisionShape();

            //rigidbody is dynamic if and only if mass is non zero, otherwise static


            if (m_collisionObject == null)
            {
                m_collisionObject = new BulletSharp.GhostObject();
                m_collisionObject.CollisionShape = cs;
                BulletSharp.Math.Matrix     worldTrans;
                BulletSharp.Math.Quaternion q = transform.rotation.ToBullet();
                BulletSharp.Math.Matrix.RotationQuaternion(ref q, out worldTrans);
                worldTrans.Origin = transform.position.ToBullet();
                m_collisionObject.WorldTransform = worldTrans;
                m_collisionObject.UserObject     = this;
                m_collisionObject.CollisionFlags = m_collisionObject.CollisionFlags | BulletSharp.CollisionFlags.NoContactResponse;
            }
            else
            {
                BulletSharp.Math.Matrix     worldTrans;
                BulletSharp.Math.Quaternion q = transform.rotation.ToBullet();
                BulletSharp.Math.Matrix.RotationQuaternion(ref q, out worldTrans);
                worldTrans.Origin = transform.position.ToBullet();
                m_collisionObject.WorldTransform = worldTrans;
                m_collisionObject.CollisionShape = cs;
                m_collisionObject.CollisionFlags = m_collisionObject.CollisionFlags | BulletSharp.CollisionFlags.NoContactResponse;
            }
            return(true);
        }
        internal override bool _BuildCollisionObject()
        {
            BPhysicsWorld world = BPhysicsWorld.Get();
            if (m_collisionObject != null)
            {
                if (isInWorld && world != null)
                {
                    world.RemoveCollisionObject(m_collisionObject);
                }
            }

            if (transform.localScale != UnityEngine.Vector3.one)
            {
                Debug.LogError("The local scale on this collision shape is not one. Bullet physics does not support scaling on a rigid body world transform. Instead alter the dimensions of the CollisionShape.");
            }

            m_collisionShape = GetComponent<BCollisionShape>();
            if (m_collisionShape == null)
            {
                Debug.LogError("There was no collision shape component attached to this BRigidBody. " + name);
                return false;
            }

            CollisionShape cs = m_collisionShape.GetCollisionShape();
            //rigidbody is dynamic if and only if mass is non zero, otherwise static

            if (m_collisionObject == null)
            {
                m_collisionObject = new BulletSharp.GhostObject();
                m_collisionObject.CollisionShape = cs;
                BulletSharp.Math.Matrix worldTrans;
                BulletSharp.Math.Quaternion q = transform.rotation.ToBullet();
                BulletSharp.Math.Matrix.RotationQuaternion(ref q, out worldTrans);
                worldTrans.Origin = transform.position.ToBullet();
                m_collisionObject.WorldTransform = worldTrans;
                m_collisionObject.UserObject = this;
                m_collisionObject.CollisionFlags = m_collisionObject.CollisionFlags | BulletSharp.CollisionFlags.NoContactResponse;
            }
            else {
                BulletSharp.Math.Matrix worldTrans;
                BulletSharp.Math.Quaternion q = transform.rotation.ToBullet();
                BulletSharp.Math.Matrix.RotationQuaternion(ref q, out worldTrans);
                worldTrans.Origin = transform.position.ToBullet();
                m_collisionObject.WorldTransform = worldTrans;
                m_collisionObject.CollisionShape = cs;
                m_collisionObject.CollisionFlags = m_collisionObject.CollisionFlags | BulletSharp.CollisionFlags.NoContactResponse;
            }
            return true;
        }
Example #5
0
        internal override bool _BuildCollisionObject()
        {
            BPhysicsWorld world = BPhysicsWorld.Get;

            if (m_collisionObject != null)
            {
                if (isInWorld && world != null)
                {
                    world.RemoveCollisionObject(this);
                }
            }
            m_collisionShape = this.GetParent <Unit>().GetComponent <BCollisionShape>();
            if (m_collisionShape == null)
            {
                Log.Warning("There was no collision shape component attached to this BRigidBody. ");
                return(false);
            }

            CollisionShape cs = m_collisionShape.GetCollisionShape;

            //rigidbody is dynamic if and only if mass is non zero, otherwise static


            if (m_collisionObject == null)
            {
                m_collisionObject = new BulletSharp.GhostObject();
                m_collisionObject.CollisionShape = cs;
                BulletSharp.Math.Matrix     worldTrans;
                BulletSharp.Math.Quaternion q = this.GetParent <Unit>().Quaternion.ToBullet();
                BulletSharp.Math.Matrix.RotationQuaternion(ref q, out worldTrans);
                worldTrans.Origin = this.GetParent <Unit>().Position.ToBullet();
                m_collisionObject.WorldTransform = worldTrans;
                m_collisionObject.UserObject     = this;
                m_collisionObject.CollisionFlags = m_collisionObject.CollisionFlags | BulletSharp.CollisionFlags.NoContactResponse;
            }
            else
            {
                BulletSharp.Math.Matrix     worldTrans;
                BulletSharp.Math.Quaternion q = this.GetParent <Unit>().Quaternion.ToBullet();
                BulletSharp.Math.Matrix.RotationQuaternion(ref q, out worldTrans);
                worldTrans.Origin = this.GetParent <Unit>().Position.ToBullet();
                m_collisionObject.WorldTransform = worldTrans;
                m_collisionObject.CollisionShape = cs;
                m_collisionObject.CollisionFlags = m_collisionObject.CollisionFlags | BulletSharp.CollisionFlags.NoContactResponse;
            }
            return(true);
        }
Example #6
0
        public void SetUp()
        {
            conf = new DefaultCollisionConfiguration();
            dispatcher = new CollisionDispatcher(conf);
            broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));
            world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, conf);

            broadphase.OverlappingPairUserCallback = new AxisSweepUserCallback();

            boxShape = new BoxShape(1);

            body1 = CreateBody(10.0f, new SphereShape(1.0f), new Vector3(2, 2, 0));
            body2 = CreateBody(1.0f, new SphereShape(1.0f), new Vector3(0, 2, 0));

            ghostObject = new PairCachingGhostObject();
            ghostObject.WorldTransform = Matrix.Translation(-1, 2, 0);
            ghostObject.CollisionShape = boxShape;
            broadphase.OverlappingPairCache.SetInternalGhostPairCallback(new GhostPairCallback());
        }
Example #7
0
        /// <summary>
        /// Creates a new trigger region. It automatically adds itself to the TriggerReporter's dictionary, so you don't have to do that.
        /// </summary>
        /// <param name="orientation">a degree vector</param>
        public TriggerRegion(string name, Vector3 position, Quaternion orientation, CollisionShape shape)
        {
            Name = name;
            CurrentlyCollidingWith = new HashSet<RigidBody>();

            // mogre
            var sceneMgr = LKernel.GetG<SceneManager>();

            Node = sceneMgr.RootSceneNode.CreateChildSceneNode(name);
            if (Settings.Default.EnableGlowyRegions) {
                // make a mesh for the region depending on what its type is
                switch (shape.ShapeType) {
                    case BroadphaseNativeType.BoxShape:
                        Entity = sceneMgr.CreateEntity(name, "primitives/box.mesh");
                        Node.SetScale((shape as BoxShape).HalfExtentsWithoutMargin * 2);
                        break;
                    case BroadphaseNativeType.CapsuleShape:
                        Entity = sceneMgr.CreateEntity(name, "primitives/cylinder.mesh");
                        Vector3 vec = new Vector3();
                        vec.y = (shape as CapsuleShape).HalfHeight * 2;
                        vec.x = vec.z = (shape as CapsuleShape).Radius * 2;
                        Node.SetScale(vec);
                        break;
                    case BroadphaseNativeType.CylinderShape:
                        Entity = sceneMgr.CreateEntity(name, "primitives/cylinder.mesh");
                        Vector3 vec2 = new Vector3();
                        vec2.y = (shape as CylinderShape).HalfExtentsWithoutMargin.y;
                        vec2.x = vec2.z = (shape as CylinderShape).Radius * 2;
                        Node.SetScale(vec2);
                        break;
                    case BroadphaseNativeType.SphereShape:
                        Entity = sceneMgr.CreateEntity(name, "primitives/sphere.mesh");
                        float dim = (shape as SphereShape).Radius * 2;
                        Node.SetScale(dim, dim, dim);
                        break;
                    default:
                        // for things like meshes, convex hulls, etc
                        Entity = sceneMgr.CreateEntity(name, "primitives/box.mesh");
                        break;
                }
                GlowColor = BalloonGlowColour.red;
                Entity.CastShadows = false;

                Node.AttachObject(Entity);
            }
            Node.Position = position;
            Node.Orientation = orientation;

            // physics
            Matrix4 transform = new Matrix4();
            transform.MakeTransform(position, Vector3.UNIT_SCALE, orientation);

            var motionState = new DefaultMotionState();
            motionState.WorldTransform = transform;

            // thanks to kloplop321 in #ogre3d for his help with this
             	Ghost = new GhostObject();
            Ghost.CollisionShape = shape;
            Ghost.WorldTransform = transform;
            Ghost.UserObject = new CollisionObjectDataHolder(Ghost, PonykartCollisionGroups.Triggers, name);

            Ghost.CollisionFlags |= CollisionFlags.NoContactResponse | CollisionFlags.CustomMaterialCallback;
            LKernel.GetG<PhysicsMain>().World.AddCollisionObject(Ghost, PonykartCollisionGroups.Triggers, PonykartCollidesWithGroups.Triggers);

            // then add this to the trigger reporter
            LKernel.GetG<TriggerReporter>().Regions.Add(name, this);
        }