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); } }
/// <summary> /// Vector is in world coords /// </summary> public Vector3D GetContactForceWorld(Body body) { NewtonVector3 retVal = new NewtonVector3(); Newton.NewtonMaterialGetContactForce(_handle, body.Handle, retVal.Vector); return(retVal.ToVectorWPF()); }
/// <summary> /// Tells you how much force to apply to get the desired velocity (doesn't consider rotation) /// </summary> /// <remarks> /// From newton.cpp: /// /// Calculate the next force that needs to be applied to the body to archive the desired velocity in the current time step. /// /// Parameters: /// *const NewtonBody* *bodyPtr - pointer to the body. /// *dFloat* timestep - time step that the force will be applyed. /// *const dFloat* *desiredVeloc - pointer to an array of 3 floats containing the desired velocity. /// *dFloat* *forceOut - pointer to an array of 3 floats to hold the calculated net force. /// /// Remark: this function can be useful when creating object for game play. /// /// remark: this treat the body as a point mass and is uses the solver to calculates the net force that need to be applied to the body /// such that is reach the desired velocity in the next time step. /// In general the force should be calculated by the expression f = M * (dsiredVeloc - bodyVeloc) / timestep /// however due to algorithmic optimization and limitations if such equation is used then the solver will generate a different desired velocity. /// </remarks> public Vector3D GetForceForDesiredVelocity(Vector3D desiredVelocity, double timestep) { NewtonVector3 retVal = new NewtonVector3(); Newton.NewtonBodyCalculateInverseDynamicsForce(_handle, Convert.ToSingle(timestep), new NewtonVector3(desiredVelocity).Vector, retVal.Vector); return(retVal.ToVectorWPF()); }
public void GetBodyAABB(out Point3D minPoint, out Point3D maxPoint, int bodyIndex) { float[] p0 = new float[3]; float[] p1 = new float[3]; Newton.NewtonIslandGetBodyAABB(_handle, bodyIndex, p0, p1); minPoint = new NewtonVector3(p0).ToPointWPF(); maxPoint = new NewtonVector3(p1).ToPointWPF(); }
/// <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(); }
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()); }
public InertialMatrix CalculateInertialMatrix() { //NOTE: The generated inertia values should be multiplied by the object mass before calling NewtonBodySetMassMatrix NewtonVector3 inertia = new NewtonVector3(); NewtonVector3 origin = new NewtonVector3(); Newton.NewtonConvexCollisionCalculateInertialMatrix(_handle, inertia.Vector, origin.Vector); return(new InertialMatrix(inertia.ToVectorWPF(), origin.ToVectorWPF())); }
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(); }
/// <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; }
/// <summary> /// The vectors are sized according to their speed (returning the speeds explicitely so the caller doesn't have to go to the expense of /// calling .Length) /// </summary> /// <remarks> /// Not sure if the vectors are local or world coords. Documentation is nearly non existent for this one. I'm guessing it's world if /// the contact normal is in world coords /// /// The contact normal is perpendicular to the face (the particular triangle of the collision hull that is currently colliding) /// /// The primary and secondary tangents are parallel to that face? I know the primary and secondary are perpendicular to each other, /// but not sure what drives which is which - is it just the order of the verticies when the triangle was created? Maybe they should just /// be considered arbitraray until you call this.RotateTangentDirections (which you would probably only do if you were then going to /// overide accel/friction) /// </remarks> public void GetContactTangentDirections(out Vector3D primaryTangent, out double primaryTangentSpeed, out Vector3D secondaryTangent, out double secondaryTangentSpeed, Body body) { NewtonVector3 newtPrim = new NewtonVector3(); NewtonVector3 newtSec = new NewtonVector3(); Newton.NewtonMaterialGetContactTangentDirections(_handle, body.Handle, newtPrim.Vector, newtSec.Vector); primaryTangent = newtPrim.ToVectorWPF(); primaryTangent.Normalize(); primaryTangentSpeed = Newton.NewtonMaterialGetContactTangentSpeed(_handle, 0); primaryTangent *= primaryTangentSpeed; secondaryTangent = newtSec.ToVectorWPF(); secondaryTangent.Normalize(); secondaryTangentSpeed = Newton.NewtonMaterialGetContactTangentSpeed(_handle, 1); secondaryTangent *= secondaryTangentSpeed; }
public bool RayCast(out double percentAlongLine, out Point3D?contactPoint, out Vector3D?contactNormal, out int faceID, Point3D startPoint, Point3D endPoint) { NewtonVector3 normalNewt = new NewtonVector3(); int faceIDNewt = -1; percentAlongLine = Newton.NewtonCollisionRayCast(_handle, new NewtonVector3(startPoint).Vector, new NewtonVector3(endPoint).Vector, normalNewt.Vector, ref faceIDNewt); if (percentAlongLine < 0d || percentAlongLine > 1d) { contactPoint = null; contactNormal = null; faceID = -1; return(false); } else { contactPoint = startPoint + ((endPoint - startPoint) * percentAlongLine); contactNormal = normalNewt.ToVectorWPF(); faceID = faceIDNewt; return(true); } }
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); } }
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(); }
public InertialMatrix CalculateInertialMatrix() { //NOTE: The generated inertia values should be multiplied by the object mass before calling NewtonBodySetMassMatrix NewtonVector3 inertia = new NewtonVector3(); NewtonVector3 origin = new NewtonVector3(); Newton.NewtonConvexCollisionCalculateInertialMatrix(_handle, inertia.Vector, origin.Vector); return new InertialMatrix(inertia.ToVectorWPF(), origin.ToVectorWPF()); }
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; } }
/// <summary> /// Vector is in world coords /// </summary> public Vector3D GetContactForceWorld(Body body) { NewtonVector3 retVal = new NewtonVector3(); Newton.NewtonMaterialGetContactForce(_handle, body.Handle, retVal.Vector); return retVal.ToVectorWPF(); }
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; } }
public bool RayCast(out double percentAlongLine, out Point3D? contactPoint, out Vector3D? contactNormal, out int faceID, Point3D startPoint, Point3D endPoint) { NewtonVector3 normalNewt = new NewtonVector3(); int faceIDNewt = -1; percentAlongLine = Newton.NewtonCollisionRayCast(_handle, new NewtonVector3(startPoint).Vector, new NewtonVector3(endPoint).Vector, normalNewt.Vector, ref faceIDNewt); if (percentAlongLine < 0d || percentAlongLine > 1d) { contactPoint = null; contactNormal = null; faceID = -1; return false; } else { contactPoint = startPoint + ((endPoint - startPoint) * percentAlongLine); contactNormal = normalNewt.ToVectorWPF(); faceID = faceIDNewt; return true; } }