Ejemplo n.º 1
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                //BUG: this will dispose ALL world's bodies.
                CJoint[] joints = new CJoint[CHashTables.Joint.Count];
                CHashTables.Joint.Values.CopyTo(joints, 0);

                foreach (CJoint joint in joints)
                    joint.Dispose();

                CBody[] bodies = new CBody[CHashTables.Body.Count];
                CHashTables.Body.Values.CopyTo(bodies, 0);

                foreach (CBody body in bodies)
                    body.Dispose();

                if (m_Handle != IntPtr.Zero)
                {
                    Newton.NewtonDestroy(m_Handle);
                    m_Handle = IntPtr.Zero;
                }

                // Stuff was left behind, so I'm clearing everything (there's likely only one world anyway)
                CHashTables.Clear();
            }
        }
Ejemplo n.º 2
0
		public void CreateUpVector(Vector3D pPinDir, CBody pBody)
		{
			m_Handle = Newton.NewtonConstraintCreateUpVector(m_World.Handle,
				new NewtonVector3(pPinDir).NWVector3,
				pBody.Handle);

			CHashTables.Joint.Add(m_Handle, this);
		}
Ejemplo n.º 3
0
        public void CreateVehicle(Vector3D pUpDir, CBody pNewtonBody)
        {
            m_Handle = Newton.NewtonConstraintCreateVehicle(m_World.Handle,
                new NewtonVector3(pUpDir).NWVector3,
                pNewtonBody.Handle);

            CHashTables.Joint.Add(m_Handle, this);
        }
Ejemplo n.º 4
0
 public CWorldRayPreFilterEventArgs(CBody pBody,
                                    object pUserData,
                                    CCollision pCollision)
 {
     m_Body      = pBody;
     m_UserData  = pUserData;
     m_Collision = pCollision;
 }
Ejemplo n.º 5
0
 public CWorldRayFilterEventArgs(CBody pBody,
                                 Vector3D pHitNormal,
                                 object pUserData,
                                 float pIntersetParam)
 {
     m_Body          = pBody;
     m_HitNormal     = pHitNormal;
     m_UserData      = pUserData;
     m_IntersetParam = pIntersetParam;
 }
Ejemplo n.º 6
0
        public void NewtonConstraintCreateBall(Vector3D pPivotPoint,
                                               CBody pChildBody,
                                               CBody pParentBody)
        {
            m_Handle = Newton.NewtonConstraintCreateBall(m_World.Handle,
                                                         new NewtonVector3(pPivotPoint).NWVector3,
                                                         pChildBody.Handle,
                                                         pParentBody.Handle);

            CHashTables.Joint.Add(m_Handle, this);
        }
Ejemplo n.º 7
0
		public void NewtonConstraintCreateBall(Vector3D pPivotPoint,
			CBody pChildBody,
			CBody pParentBody)
		{
			m_Handle = Newton.NewtonConstraintCreateBall(m_World.Handle,
			new NewtonVector3(pPivotPoint).NWVector3,
			pChildBody.Handle,
			pParentBody.Handle);

			CHashTables.Joint.Add(m_Handle, this);
		}
Ejemplo n.º 8
0
 public CTreeCollisionEventArgs(CBody pBody,
                                Vector3D pVertex,
                                int pVertexstrideInBytes,
                                int pIndexCount,
                                int[] pIndexArray)
 {
     m_Body   = pBody;
     m_Vertex = pVertex;
     m_VertexstrideInBytes = pVertexstrideInBytes;
     m_IndexCount          = pIndexCount;
     m_IndexArray          = pIndexArray;
 }
Ejemplo n.º 9
0
        public static Body GetBodyFromUserData(CBody body)
        {
            if (body.UserData is Body)
            {
                return (Body)body.UserData;
            }
            else if (body.UserData is IMapObject)
            {
                return (Body)((IMapObject)body.UserData).PhysicsBody;
            }

            return null;
        }
Ejemplo n.º 10
0
        public static ConvexBody3D GetConvexBodyFromUserData(CBody body)
        {
            if (body.UserData is ConvexBody3D)
            {
                return (ConvexBody3D)body.UserData;
            }
            else if (body.UserData is IMapObject)
            {
                return (ConvexBody3D)((IMapObject)body.UserData).PhysicsBody;
            }

            return null;
        }
Ejemplo n.º 11
0
        public CBody   m_PolySoupBody;                  // pointer to the rigid body owner of this collision tree

        internal UserMeshCollisionCollideDesc(Newton.NewtonUserMeshCollisionCollideDesc pDesc)
        {
            m_BoxP0               = new NewtonVector4(pDesc.m_BoxP0).ToDirectX();
            m_BoxP1               = new NewtonVector4(pDesc.m_BoxP1).ToDirectX();
            m_UserData            = pDesc.m_UserData;
            m_FaceCount           = pDesc.m_FaceCount;
            m_Vertex              = pDesc.m_Vertex;
            m_VertexStrideInBytes = pDesc.m_VertexStrideInBytes;
            m_UserAttribute       = pDesc.m_UserAttribute;
            m_FaceIndexCount      = pDesc.m_FaceIndexCount;
            m_FaceVertexIndex     = pDesc.m_FaceVertexIndex;
            m_ObjBody             = (CBody)CHashTables.Body[pDesc.m_ObjBody];
            m_PolySoupBody        = (CBody)CHashTables.Body[pDesc.m_PolySoupBody];
        }
Ejemplo n.º 12
0
		public CBody m_PolySoupBody;          	// pointer to the rigid body owner of this collision tree 

		internal UserMeshCollisionCollideDesc(Newton.NewtonUserMeshCollisionCollideDesc pDesc)
		{
			m_BoxP0 = new NewtonVector4(pDesc.m_BoxP0).ToDirectX();
			m_BoxP1 = new NewtonVector4(pDesc.m_BoxP1).ToDirectX();
			m_UserData = pDesc.m_UserData;
			m_FaceCount = pDesc.m_FaceCount;
			m_Vertex = pDesc.m_Vertex;
			m_VertexStrideInBytes = pDesc.m_VertexStrideInBytes;
			m_UserAttribute = pDesc.m_UserAttribute;
			m_FaceIndexCount = pDesc.m_FaceIndexCount;
			m_FaceVertexIndex = pDesc.m_FaceVertexIndex;
			m_ObjBody =  (CBody)CHashTables.Body[pDesc.m_ObjBody];
			m_PolySoupBody = (CBody)CHashTables.Body[pDesc.m_PolySoupBody];
		}
		public void CreateUserBilateral(int pMaxDOF,
			EventHandler<CUserBilateralEventArgs> pCallback,
			CBody pChildBody,
			CBody pParentBody)
		{
			m_UserBilateral = pCallback;
			m_NewtonUserBilateral = new Newton.NewtonUserBilateral(InvokeUserBilateral);

            m_Handle = Newton.NewtonConstraintCreateUserJoint(m_World.Handle,
				pMaxDOF,
				m_NewtonUserBilateral,
				pChildBody.Handle,
				pParentBody.Handle);

			CHashTables.Joint.Add(m_Handle, this);
		}
Ejemplo n.º 14
0
 public CContactBeginEventArgs(IntPtr pMaterial, CBody pBody0, CBody pBody1)
 {
     m_Material = pMaterial;
     m_Body0    = pBody0;
     m_Body1    = pBody1;
 }
Ejemplo n.º 15
0
 public CBodyIteratorEventArgs(CBody pBody)
 {
     m_Body = pBody;
 }
Ejemplo n.º 16
0
		public CWorldRayFilterEventArgs(CBody pBody,
			Vector3D pHitNormal,
			object pUserData,
			float pIntersetParam)
		{
			m_Body = pBody;
			m_HitNormal = pHitNormal;
			m_UserData = pUserData;
			m_IntersetParam = pIntersetParam;
		}
Ejemplo n.º 17
0
 public CBodyLeaveWorldEventArgs(CBody pBody)
 {
     m_Body = pBody;
 }
Ejemplo n.º 18
0
		public CContactBeginEventArgs(IntPtr pMaterial, CBody pBody0, CBody pBody1)
		{
			m_Material = pMaterial;
			m_Body0 = pBody0;
			m_Body1 = pBody1;
		}
Ejemplo n.º 19
0
		public CBodyLeaveWorldEventArgs(CBody pBody)
		{
			m_Body = pBody;
		}
Ejemplo n.º 20
0
 public uint GetBodyCollisionID(CBody pNewtonBody)
 {
     return(Newton.NewtonMaterialGetBodyCollisionID(m_Handle, pNewtonBody.Handle));
 }
Ejemplo n.º 21
0
        public CWorldRayPreFilterEventArgs(CBody pBody,
			object pUserData,
			CCollision pCollision)
		{
			m_Body = pBody;
			m_UserData = pUserData;
			m_Collision = pCollision;
		}
Ejemplo n.º 22
0
 public void UnfreezeBody(CBody pBody)
 {
     Newton.NewtonWorldUnfreezeBody(m_Handle, pBody.Handle);
 }
Ejemplo n.º 23
0
		public CBodyIteratorEventArgs(CBody pBody)
		{
			m_Body = pBody;
		}
Ejemplo n.º 24
0
		public uint GetBodyCollisionID(CBody pNewtonBody)
		{
			return Newton.NewtonMaterialGetBodyCollisionID(m_Handle, pNewtonBody.Handle);
		}
Ejemplo n.º 25
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_body != null)
                {
                    _body.Destructor -= _body_Destructor;

                    if (_isInitialised)
                    {
                        _body.Dispose();

                        _isInitialised = false;
                    }
                    _body = null;
                }
            }
        }
Ejemplo n.º 26
0
        public RayCastResult CastRay(Point3D position, Vector3D direction, double rayLength, BodyFilterType filterType, params Body[] bodies)
        {

            //TODO:  If the ray starts outside the boundries, then this method will fail.  Fix that here, so the user doesn't
            // have to worry about it.  Also, if the ray length would cause an endpoint outside the bounds
            //
            // Also, if I fixed the start distance, then I need to add that back into the result, so it's transparent to the caller


            CBody[] bodyHandles = null;
            if (bodies.Length > 0)
            {
                // make a list of newton handles
                bodyHandles = new CBody[bodies.Length];
                for (int i = 0; i < bodies.Length; i++)
                {
                    bodyHandles[i] = bodies[i].NewtonBody;
                }
            }

            //TODO:  Always skip the boundry terrains

            EventHandler<CWorldRayPreFilterEventArgs> preFilterHandler = null;
            if (bodyHandles != null)
            {
                // This artificial method gets called from within NewtonWorld.WorldRayCast
                preFilterHandler = delegate(object sender, CWorldRayPreFilterEventArgs preFilterArgs)
                {
                    switch (filterType)
                    {
                        case BodyFilterType.ExcludeBodies:
                            preFilterArgs.Skip = (Array.IndexOf(bodyHandles, preFilterArgs.Body)) >= 0;
                            break;
                        case BodyFilterType.IncludeBodies:
                            preFilterArgs.Skip = (Array.IndexOf(bodyHandles, preFilterArgs.Body)) < 0;
                            break;
                    }
                };
            }

            List<CWorldRayFilterEventArgs> hitTestResults = new List<CWorldRayFilterEventArgs>();

            Vector3D posAsVector = position.ToVector();		// newt wants a vector instead of a point3d

            // Ask newton to do the hit test (it will invoke the filter delegate, whose implementation is above)
            this.NewtonWorld.WorldRayCast(posAsVector, posAsVector + (direction * rayLength),
                delegate(object sender, CWorldRayFilterEventArgs filterArgs)
                {
                    hitTestResults.Add(filterArgs);
                },
                null, preFilterHandler);

            if (hitTestResults.Count > 0)
            {
                // Find the closest one
                CWorldRayFilterEventArgs hitTestResult = null;
                double distance = double.MaxValue;
                for (int i = 0; i < hitTestResults.Count; i++)
                {
                    double d = (hitTestResults[i].IntersetParam * rayLength);
                    if (d < distance)
                    {
                        distance = d;
                        hitTestResult = hitTestResults[i];
                    }
                }

                Body resultBody = UtilityNewt.GetBodyFromUserData(hitTestResult.Body);
                if (resultBody == null)
                {
                    throw new ApplicationException("Couldn't get the Body from the CBody.UserData");
                }

                // Exit Function
                return new RayCastResult(resultBody, distance, hitTestResult.HitNormal, hitTestResult.IntersetParam);
            }
            else
            {
                // Nothing found
                return null;
            }
        }
Ejemplo n.º 27
0
 public void UnfreezeBody(CBody pBody)
 {
     Newton.NewtonWorldUnfreezeBody(m_Handle, pBody.Handle);
 }
Ejemplo n.º 28
0
 private void _body_Destructor(object sender, CBodyDestructorEventArgs e)
 {
     _body.Destructor -= _body_Destructor;
     _body = null;
 }
Ejemplo n.º 29
0
        public void Initialise(World world)
        {
            if (_isInitialised)
                return;

            if (world == null) throw new ArgumentNullException("world");

            _world = world;

            _collision = OnInitialise(world);

            if (_collision == null)
            {
                _collision = new NullCollision(_world);
            }

            _body = new CBody(_collision.NewtonCollision);
            _body.Destructor += _body_Destructor;
            _body.AutoFreeze = this.AutoPause;
            _body.UserData = this;
            _body.Matrix = _visualMatrix.Matrix;

            OnInitialiseEnd();  // this might adjust the _body.Matrix property

            // not initialised yet, nothing should be called on property changed event
            this.Transform = new MatrixTransform3D(_body.Matrix);

            _body.SetTransform += body_setTransform;
            _body.ApplyForceAndTorque += body_ApplyForceAndTorque;

            CalculateMass(this.Mass);

            world.AddBody(this);
            _isInitialised = true;
        }
Ejemplo n.º 30
0
		public CTreeCollisionEventArgs(CBody pBody,
			Vector3D pVertex,
			int pVertexstrideInBytes,
			int pIndexCount,
			int[] pIndexArray)
		{
			m_Body = pBody;
			m_Vertex = pVertex;
			m_VertexstrideInBytes = pVertexstrideInBytes;
			m_IndexCount = pIndexCount;
			m_IndexArray = pIndexArray;
		}