Ejemplo n.º 1
0
        public bool GetNearestPoint_HullToHull(out Point3D?contactPointThis, out Point3D?contactPointOther, out Vector3D?normal, CollisionHull otherHull, int threadIndex, Transform3D thisTransform, Transform3D otherTransform)
        {
            float[] finalOffsetThis  = thisTransform == null ? new NewtonMatrix(Matrix3D.Identity).Matrix : new NewtonMatrix(thisTransform.Value).Matrix;               // not including the member's offset, because newton is already accounting for it.
            float[] finalOffsetOther = thisTransform == null ? new NewtonMatrix(Matrix3D.Identity).Matrix : new NewtonMatrix(otherTransform.Value).Matrix;

            NewtonVector3 contactANewt = new NewtonVector3();
            NewtonVector3 contactBNewt = new NewtonVector3();
            NewtonVector3 normalNewt   = new NewtonVector3();

            int retVal = Newton.NewtonCollisionClosestPoint(_world.Handle, _handle, finalOffsetThis, otherHull.Handle, finalOffsetOther, contactANewt.Vector, contactBNewt.Vector, normalNewt.Vector, threadIndex);

            // Exit Function
            if (retVal == 1)
            {
                contactPointThis  = contactANewt.ToPointWPF();
                contactPointOther = contactBNewt.ToPointWPF();
                normal            = normalNewt.ToVectorWPF();
                return(true);
            }
            else
            {
                contactPointThis  = null;
                contactPointOther = null;
                normal            = null;
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is the axis aligned box in world coords
        /// </summary>
        public void GetAABB(out Point3D minPoint, out Point3D maxPoint)
        {
            NewtonVector3 newtMin = new NewtonVector3();
            NewtonVector3 newtMax = new NewtonVector3();

            Newton.NewtonBodyGetAABB(_handle, newtMin.Vector, newtMax.Vector);

            minPoint = newtMin.ToPointWPF();
            maxPoint = newtMax.ToPointWPF();
        }
Ejemplo n.º 3
0
        public Point3D GetFarthestVertex(Vector3D direction)
        {
            // Look this up on the web page, it explains it pretty well (this method is useful for calculating custom bounding surfaces)

            NewtonVector3 retVal = new NewtonVector3();

            Newton.NewtonCollisionSupportVertex(_handle, new NewtonVector3(direction).Vector, retVal.Vector);

            return(retVal.ToPointWPF());
        }
Ejemplo n.º 4
0
        public void CalculateAproximateAABB(out Point3D minPoint, out Point3D maxPoint, Transform3D transform)
        {
            float[] finalOffset = transform == null ? new NewtonMatrix(Matrix3D.Identity).Matrix : new NewtonMatrix(transform.Value).Matrix;            // not including _offsetMatrix, because newton is already accounting for it.

            NewtonVector3 minNewt = new NewtonVector3();
            NewtonVector3 maxNewt = new NewtonVector3();

            Newton.NewtonCollisionCalculateAABB(_handle, finalOffset, minNewt.Vector, maxNewt.Vector);

            minPoint = minNewt.ToPointWPF();
            maxPoint = maxNewt.ToPointWPF();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Vectors are in world coords
        /// </summary>
        public void GetContactPositionAndNormalWorld(out Point3D position, out Vector3D normal, out double normalSpeed, Body body)
        {
            NewtonVector3 newtPos    = new NewtonVector3();
            NewtonVector3 newtNormal = new NewtonVector3();

            Newton.NewtonMaterialGetContactPositionAndNormal(_handle, body.Handle, newtPos.Vector, newtNormal.Vector);

            position = newtPos.ToPointWPF();

            normal = newtNormal.ToVectorWPF();
            normal.Normalize();
            normalSpeed = this.ContactNormalSpeed;
            normal     *= normalSpeed;
        }
Ejemplo n.º 6
0
        public bool GetNearestPoint_PointToHull(out Point3D?contactPoint, Vector3D?normal, Vector3D point, int threadIndex, Transform3D transform)
        {
            float[] finalOffset = transform == null ? new NewtonMatrix(Matrix3D.Identity).Matrix : new NewtonMatrix(transform.Value).Matrix;            // not including _offsetMatrix, because newton is already accounting for it.

            NewtonVector3 contactNewt = new NewtonVector3();
            NewtonVector3 normalNewt  = new NewtonVector3();

            int retVal = Newton.NewtonCollisionPointDistance(_world.Handle, new NewtonVector3(point).Vector, _handle, finalOffset, contactNewt.Vector, normalNewt.Vector, threadIndex);

            // Exit Function
            if (retVal == 1)
            {
                contactPoint = contactNewt.ToPointWPF();
                normal       = normalNewt.ToVectorWPF();
                return(true);
            }
            else
            {
                contactPoint = null;
                normal       = null;
                return(false);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Vectors are in world coords
        /// </summary>
        public void GetContactPositionAndNormalWorld(out Point3D position, out Vector3D normal, out double normalSpeed, Body body)
        {
            NewtonVector3 newtPos = new NewtonVector3();
            NewtonVector3 newtNormal = new NewtonVector3();

            Newton.NewtonMaterialGetContactPositionAndNormal(_handle, body.Handle, newtPos.Vector, newtNormal.Vector);

            position = newtPos.ToPointWPF();

            normal = newtNormal.ToVectorWPF();
            normal.Normalize();
            normalSpeed = this.ContactNormalSpeed;
            normal *= normalSpeed;
        }
Ejemplo n.º 8
0
        public void CalculateAproximateAABB(out Point3D minPoint, out Point3D maxPoint, Transform3D transform)
        {
            float[] finalOffset = transform == null ? new NewtonMatrix(Matrix3D.Identity).Matrix : new NewtonMatrix(transform.Value).Matrix;		// not including _offsetMatrix, because newton is already accounting for it.

            NewtonVector3 minNewt = new NewtonVector3();
            NewtonVector3 maxNewt = new NewtonVector3();

            Newton.NewtonCollisionCalculateAABB(_handle, finalOffset, minNewt.Vector, maxNewt.Vector);

            minPoint = minNewt.ToPointWPF();
            maxPoint = maxNewt.ToPointWPF();
        }
Ejemplo n.º 9
0
        public Point3D GetFarthestVertex(Vector3D direction)
        {
            // Look this up on the web page, it explains it pretty well (this method is useful for calculating custom bounding surfaces)

            NewtonVector3 retVal = new NewtonVector3();

            Newton.NewtonCollisionSupportVertex(_handle, new NewtonVector3(direction).Vector, retVal.Vector);

            return retVal.ToPointWPF();
        }
Ejemplo n.º 10
0
        public bool GetNearestPoint_HullToHull(out Point3D? contactPointThis, out Point3D? contactPointOther, out Vector3D? normal, CollisionHull otherHull, int threadIndex, Transform3D thisTransform, Transform3D otherTransform)
        {
            float[] finalOffsetThis = thisTransform == null ? new NewtonMatrix(Matrix3D.Identity).Matrix : new NewtonMatrix(thisTransform.Value).Matrix;		// not including the member's offset, because newton is already accounting for it.
            float[] finalOffsetOther = thisTransform == null ? new NewtonMatrix(Matrix3D.Identity).Matrix : new NewtonMatrix(otherTransform.Value).Matrix;

            NewtonVector3 contactANewt = new NewtonVector3();
            NewtonVector3 contactBNewt = new NewtonVector3();
            NewtonVector3 normalNewt = new NewtonVector3();

            int retVal = Newton.NewtonCollisionClosestPoint(_world.Handle, _handle, finalOffsetThis, otherHull.Handle, finalOffsetOther, contactANewt.Vector, contactBNewt.Vector, normalNewt.Vector, threadIndex);

            // Exit Function
            if (retVal == 1)
            {
                contactPointThis = contactANewt.ToPointWPF();
                contactPointOther = contactBNewt.ToPointWPF();
                normal = normalNewt.ToVectorWPF();
                return true;
            }
            else
            {
                contactPointThis = null;
                contactPointOther = null;
                normal = null;
                return false;
            }
        }
Ejemplo n.º 11
0
        public bool GetNearestPoint_PointToHull(out Point3D? contactPoint, Vector3D? normal, Vector3D point, int threadIndex, Transform3D transform)
        {
            float[] finalOffset = transform == null ? new NewtonMatrix(Matrix3D.Identity).Matrix : new NewtonMatrix(transform.Value).Matrix;		// not including _offsetMatrix, because newton is already accounting for it.

            NewtonVector3 contactNewt = new NewtonVector3();
            NewtonVector3 normalNewt = new NewtonVector3();

            int retVal = Newton.NewtonCollisionPointDistance(_world.Handle, new NewtonVector3(point).Vector, _handle, finalOffset, contactNewt.Vector, normalNewt.Vector, threadIndex);

            // Exit Function
            if (retVal == 1)
            {
                contactPoint = contactNewt.ToPointWPF();
                normal = normalNewt.ToVectorWPF();
                return true;
            }
            else
            {
                contactPoint = null;
                normal = null;
                return false;
            }
        }