public override void InitJoint() { NewtonBody child = GetComponent <NewtonBody>(); dMatrix matrix = Utils.ToMatrix(m_Pivot, m_Pin); IntPtr otherBody = (m_OtherBody != null) ? m_OtherBody.GetBody().GetBody() : IntPtr.Zero; m_Joint = new dNewtonJointBallAndSocket(matrix, child.GetBody().GetBody(), otherBody); Stiffness = m_Stiffness; }
public override void InitJoint() { NewtonBody child = GetComponent <NewtonBody>(); dMatrix matrix = Utils.ToMatrix(m_Pivot, m_Pin); IntPtr otherBody = (m_OtherBody != null) ? m_OtherBody.GetBody().GetBody() : IntPtr.Zero; m_Joint = new dNewtonJointSlider(matrix, child.GetBody().GetBody(), otherBody); Stiffness = m_Stiffness; EnableCollision = m_EnableCollision; EnableLimits = m_EnableLimits; SetSpringDamper = m_SetSpringDamper; }
public override void InitJoint() { NewtonBody child = GetComponent <NewtonBody>(); dMatrix matrix = Utils.ToMatrix(m_Pivot, m_Pin); IntPtr otherBody = (m_OtherBody != null) ? m_OtherBody.GetBody().GetBody() : IntPtr.Zero; m_Joint = new dNewtonJointSliderActuator(matrix, child.GetBody().GetBody(), otherBody); EnableCollision = m_EnableCollision; Speed = m_Speed; MaxForce = m_MaxForce; TargetPosition = m_TargetPosition; }
public override void InitJoint() { NewtonBody child = GetComponent <NewtonBody>(); dMatrix matrix = Utils.ToMatrix(m_Pivot, m_Pin0, m_Pin1); IntPtr otherBody = (m_OtherBody != null) ? m_OtherBody.GetBody().GetBody() : IntPtr.Zero; m_Joint = new dNewtonJointDoubleHinge(matrix, child.GetBody().GetBody(), otherBody); Stiffness = m_Stiffness; EnableCollision = m_EnableCollision; EnableLimits_0 = m_EnableLimits_0; EnableLimits_1 = m_EnableLimits_1; }
public override void InitJoint() { NewtonBody child = GetComponent <NewtonBody>(); dMatrix matrix = Utils.ToMatrix(m_Pivot, m_Pin); IntPtr otherBody = (m_OtherBody != null) ? m_OtherBody.GetBody().GetBody() : IntPtr.Zero; m_Joint = new dNewtonJointHingeActuator(matrix, child.GetBody().GetBody(), otherBody); TargetAngle = m_TargetAngle; AngularRate = m_AngularRate; MaxTorque = m_MaxTorque; EnableCollision = m_EnableCollision; }
private void ValidateEditorShape() { if (m_EditorShape == null) { NewtonBody body = GetBodyInParent(); if (body != null) { if (body.World != null) { m_EditorShape = Create(body.World); } } } }
public override void InitJoint() { Vector3 childPin = m_Pin.normalized; Vector3 parentPin = m_ParentPin.normalized; NewtonBody child = GetComponent <NewtonBody>(); IntPtr otherBody = (m_OtherBody != null) ? m_OtherBody.GetBody().GetBody() : IntPtr.Zero; dVector childPin_ = new dVector(childPin.x, childPin.y, childPin.z, 0.0f); dVector parentPin_ = new dVector(parentPin.x, parentPin.y, parentPin.z, 0.0f); m_Joint = new dNewtonJointGear(m_GearRatio, childPin_, parentPin_, child.GetBody().GetBody(), otherBody); EnableCollision = m_EnableCollision; }
public override void InitJoint() { NewtonBody child = GetComponent <NewtonBody>(); IntPtr otherBody = (m_OtherBody != null) ? m_OtherBody.GetBody().GetBody() : IntPtr.Zero; var gearPinNorm = m_GearPin.normalized; var slidePinNorm = m_SlidePin.normalized; dVector childPin = new dVector(gearPinNorm.x, gearPinNorm.y, gearPinNorm.z, 0.0f); dVector parentPin = new dVector(slidePinNorm.x, slidePinNorm.y, slidePinNorm.z, 0.0f); m_Joint = new dNewtonJointRackAndPinion(m_GearRatio, childPin, parentPin, child.GetBody().GetBody(), otherBody); EnableCollision = m_EnableCollision; }
private NewtonBody GetBodyInParent() { NewtonBody body = null; Transform gameTransform = transform; while (gameTransform != null) { // this is a child body we need to find the root rigid body owning the shape if (body == null) { body = gameTransform.gameObject.GetComponent <NewtonBody>(); } gameTransform = gameTransform.parent; } return(body); }
public override void InitJoint() { var childPinNorm = m_Pin.normalized; var parentPinNorm = m_ParentPin.normalized; var refPinNorm = m_ReferencePin.normalized; NewtonBody child = GetComponent <NewtonBody>(); IntPtr otherBody = (m_OtherBody != null) ? m_OtherBody.GetBody().GetBody() : IntPtr.Zero; IntPtr referenceBody = (m_ReferenceBody != null) ? m_ReferenceBody.GetBody().GetBody() : IntPtr.Zero; dVector dChildPin = new dVector(childPinNorm.x, childPinNorm.y, childPinNorm.z, 0.0f); dVector dParentPin = new dVector(parentPinNorm.x, parentPinNorm.y, parentPinNorm.z, 0.0f); dVector dReferencePin = new dVector(refPinNorm.x, refPinNorm.y, refPinNorm.z, 0.0f); m_Joint = new dNewtonJointDifferentialGear(m_GearRatio, dChildPin, dParentPin, dReferencePin, child.GetBody().GetBody(), otherBody, referenceBody); EnableCollision = m_EnableCollision; }
public virtual void OnPostCollision(NewtonBody otherBody) { // do nothing //Debug.Log("do nothing"); }
public virtual void OnContact(NewtonBody otherBody, float normalImpact) { // do nothing //Debug.Log("do nothing"); }
public NewtonBodyCollision(NewtonBody body) { if (body.World.GetWorld() == null) { throw new NullReferenceException("Native world instance is null. The World component was probably destroyed"); } m_Body = body; List <NewtonCollider> colliderList = new List <NewtonCollider>(); TraverseColliders(body.gameObject, colliderList, body.gameObject, body); if (body.IsScene) { NewtonSceneCollider sceneCollider = body.gameObject.AddComponent <NewtonSceneCollider>(); dNewtonCollisionScene sceneShape = (dNewtonCollisionScene)sceneCollider.Create(body.World); sceneCollider.SetShape(sceneShape); m_RootCollider = sceneCollider; m_Colliders.Add(sceneCollider); sceneShape.BeginAddRemoveCollision(); foreach (NewtonCollider collider in colliderList) { m_Colliders.Add(collider); collider.m_ParentHandle = sceneShape.AddCollision(collider.GetShape()); } sceneShape.EndAddRemoveCollision(); } else if (colliderList.Count == 0) { NewtonCollider collider = body.gameObject.AddComponent <NewtonNullCollider>(); collider.SetShape(collider.Create(body.World)); m_RootCollider = collider; m_Colliders.Add(collider); } else if (colliderList.Count == 1) { m_RootCollider = colliderList[0]; m_Colliders.Add(colliderList[0]); } else { NewtonCompoundCollider compoundCollider = body.gameObject.AddComponent <NewtonCompoundCollider>(); dNewtonCollisionCompound compoundShape = (dNewtonCollisionCompound)compoundCollider.Create(body.World); compoundCollider.SetShape(compoundShape); m_RootCollider = compoundCollider; m_Colliders.Add(compoundCollider); compoundShape.BeginAddRemoveCollision(); foreach (NewtonCollider collider in colliderList) { m_Colliders.Add(collider); collider.m_ParentHandle = compoundShape.AddCollision(collider.GetShape()); } compoundShape.EndAddRemoveCollision(); } }
private void TraverseColliders(GameObject gameObject, List <NewtonCollider> colliderList, GameObject rootObject, NewtonBody body) { // Don't fetch colliders from children with NewtonBodies if ((gameObject == rootObject) || (gameObject.GetComponent <NewtonBody>() == null)) { //Fetch all colliders foreach (NewtonCollider collider in gameObject.GetComponents <NewtonCollider>()) { dNewtonCollision shape = collider.CreateBodyShape(body.World); if (shape != null) { collider.Body = body; collider.SetShape(shape); colliderList.Add(collider); } } Terrain terrain = gameObject.GetComponent <Terrain>(); if (terrain) { NewtonHeighfieldCollider heighfield = gameObject.GetComponent <NewtonHeighfieldCollider>(); if (heighfield) { TerrainData data = terrain.terrainData; int treesCount = data.treeInstanceCount; TreeInstance[] treeInstanceArray = data.treeInstances; TreePrototype[] treeProtoArray = data.treePrototypes; Vector3 posit = Vector3.zero; for (int i = 0; i < treesCount; i++) { TreeInstance tree = treeInstanceArray[i]; posit.x = tree.position.x * data.size.x; posit.y = tree.position.y * data.size.y; posit.z = tree.position.z * data.size.z; //Debug.Log("xxx0 " + posit); TreePrototype treeProto = treeProtoArray[tree.prototypeIndex]; GameObject treeGameObject = treeProto.prefab; foreach (NewtonCollider treeCollider in treeGameObject.GetComponents <NewtonCollider>()) { dNewtonCollision treeShape = treeCollider.CreateBodyShape(body.World); if (treeShape != null) { Vector3 treePosit = terrain.transform.position + treeCollider.m_Position + posit; //Debug.Log("xxx1 " + treePosit); dMatrix matrix = Utils.ToMatrix(treePosit, Quaternion.identity); treeShape.SetMatrix(matrix); treeCollider.Body = body; treeCollider.SetShape(treeShape); colliderList.Add(treeCollider); } } } } } foreach (Transform child in gameObject.transform) { TraverseColliders(child.gameObject, colliderList, rootObject, body); } } }
internal void DeregisterBody(NewtonBody nb) { m_bodies.Remove(nb); }
internal void RegisterBody(NewtonBody nb) { m_bodies.Add(nb); }