Skip to content

Commit

Permalink
correct bugs with default damping and Inertia settings
Browse files Browse the repository at this point in the history
based on ee38fae
* added missing damping stuffs to make the damping value changes effective (copycat Newtonbody.cs of version f182340)
* added 1 option toggle to set the inertia and CoM from the editor OR to calculate them from the collider (see dNewtonBody::SetCenterOfMass in dNewtonBody.cpp)
 Works with Newton Dynamics from Jan 2, 2018(7e379d7)
  • Loading branch information
ple666 committed Apr 5, 2018
1 parent f182340 commit 155d56b
Show file tree
Hide file tree
Showing 17 changed files with 1,006 additions and 982 deletions.
112 changes: 56 additions & 56 deletions Demos/Assets/Scripts/PlayerDriver.cs
@@ -1,56 +1,56 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerDriver : MonoBehaviour
{

// Use this for initialization
void Start ()
{
motor = transform.Find("motor").GetComponent<NewtonBody>();
motorJoint = transform.Find("motor").GetComponent<NewtonDoubleHingeActuator>();
}

// Update is called once per frame
void Update ()
{
if (motorJoint != null)
{
// control forward and backwoar movement
if (Input.GetKey(KeyCode.W))
{
motor.SleepState = false;
motorJoint.TargetAngle1 = 1e10f;
}
else if (Input.GetKey(KeyCode.S))
{
motor.SleepState = false;
motorJoint.TargetAngle1 = -1e10f;
}
else
{
motorJoint.TargetAngle1 = motorJoint.GetJointAngle1();
}

// control steering movement
if (Input.GetKey(KeyCode.A))
{
motor.SleepState = false;
motorJoint.TargetAngle0 = 1e10f;
}
else if (Input.GetKey(KeyCode.D))
{
motor.SleepState = false;
motorJoint.TargetAngle0 = -1e10f;
}
else
{
motorJoint.TargetAngle0 = motorJoint.GetJointAngle0();
}
}
}

NewtonBody motor = null;
NewtonDoubleHingeActuator motorJoint = null;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerDriver : MonoBehaviour
{

// Use this for initialization
void Start ()
{
motor = transform.Find("motor").GetComponent<NewtonBody>();
motorJoint = transform.Find("motor").GetComponent<NewtonUniversalActuator>();
}

// Update is called once per frame
void Update ()
{
if (motorJoint != null)
{
// control forward and backwoar movement
if (Input.GetKey(KeyCode.W))
{
motor.SleepState = false;
motorJoint.TargetAngle1 = 1e10f;
}
else if (Input.GetKey(KeyCode.S))
{
motor.SleepState = false;
motorJoint.TargetAngle1 = -1e10f;
}
else
{
motorJoint.TargetAngle1 = motorJoint.GetJointAngle1();
}

// control steering movement
if (Input.GetKey(KeyCode.A))
{
motor.SleepState = false;
motorJoint.TargetAngle0 = 1e10f;
}
else if (Input.GetKey(KeyCode.D))
{
motor.SleepState = false;
motorJoint.TargetAngle0 = -1e10f;
}
else
{
motorJoint.TargetAngle0 = motorJoint.GetJointAngle0();
}
}
}

NewtonBody motor = null;
NewtonUniversalActuator motorJoint = null;
}
Binary file modified Demos/Assets/demo_01_BasicCollisionPrimives.unity
Binary file not shown.
8 changes: 6 additions & 2 deletions NewtonPlugin/NewtonBody.cs
Expand Up @@ -94,7 +94,7 @@ public virtual void InitRigidBody()

void SetCenterOfMass ()
{
m_body.SetCenterOfMass(m_centerOfMass.x, m_centerOfMass.y, m_centerOfMass.z);
m_body.SetCenterOfMass(m_centerOfMass.x, m_centerOfMass.y, m_centerOfMass.z, m_Ixx, m_Iyy, m_Izz, m_CalculateInertia);
}

public virtual void DestroyRigidBody()
Expand Down Expand Up @@ -258,7 +258,7 @@ public Vector3 CenterOfMass
{
if (m_body != null)
{
m_body.SetCenterOfMass(value.x, value.y, value.z);
m_body.SetCenterOfMass(value.x, value.y, value.z, m_Ixx, m_Iyy, m_Izz, m_CalculateInertia);
}
}

Expand Down Expand Up @@ -337,6 +337,10 @@ protected virtual void CreateBodyAndCollision()
[Header("rigid body data")]
public float m_mass = 0.0f;
public Vector3 m_centerOfMass = new Vector3 (0.0f, 0.0f, 0.0f);
public float m_Ixx = 0.0f;
public float m_Iyy = 0.0f;
public float m_Izz = 0.0f;
public bool m_CalculateInertia=false;
public bool m_isScene = false;
public bool m_showGizmo = false;
public float m_gizmoScale = 1.0f;
Expand Down
3 changes: 2 additions & 1 deletion NewtonPlugin/NewtonPlugin.csproj
Expand Up @@ -61,12 +61,13 @@
<Compile Include="NewtonJoint.cs" />
<Compile Include="NewtonMaterial.cs" />
<Compile Include="NewtonNullCollider.cs" />
<Compile Include="NewtonPlane.cs" />
<Compile Include="NewtonSceneCollider.cs" />
<Compile Include="NewtonSlider.cs" />
<Compile Include="NewtonSlidingHinge.cs" />
<Compile Include="NewtonSphereCollider.cs" />
<Compile Include="NewtonTreeCollider.cs" />
<Compile Include="NewtonDoubleHinge.cs" />
<Compile Include="NewtonUniversal.cs" />
<Compile Include="NewtonUtils.cs" />
<Compile Include="NewtonWorld.cs" />
<Compile Include="newton_wrap.cs" />
Expand Down

0 comments on commit 155d56b

Please sign in to comment.