A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by blackbird_dream » Fri Mar 09, 2018 5:59 am
There is no way to get the CoM of a NB in Unity ?
Thks
I'd like to implement the function AddForceAtPos. For the moment I can write :
- Code: Select all
void AddForceAtPos(NewtonBody Body, Vector3 Force, Vector3 Point)
{
Vector3 Torque,LeverArm;
LeverArm= Point-Body.Position;
Torque = Vector3.Cross(LeverArm, Force);
Body.GetBody().AddForce(Force.x,Force.y,Force.z);
Body.GetBody().AddTorque(Torque.x,Torque.y,Torque.z);
}
But this assumes CoM being at the origin of the body
I've scan the dll and I saw the setter implemented in it.
-
blackbird_dream
-
- Posts: 354
- Joined: Wed Jun 07, 2006 3:08 pm
- Location: France
by Sweenie » Fri Mar 09, 2018 7:42 am
Ok, added a GetCenterOfMass function as well.
It should work but couldn't try it out since I'm having the latest version of Newton installed that has some breaking changes in the custom joints that prevents me from compiling the unity plugin.
I don't have time right now to fix this so don't update your Newton repository to any commit after Feb 20, 2018
It seems it is the NewtonUniversal joint name change to NewtonDoubleHinge that is the issue.
-
Sweenie
-
- Posts: 498
- Joined: Mon Jan 24, 2005 7:59 am
- Location: Sweden
by blackbird_dream » Fri Mar 09, 2018 8:09 am
thks.
for the moment I keep the current version.
-
blackbird_dream
-
- Posts: 354
- Joined: Wed Jun 07, 2006 3:08 pm
- Location: France
by blackbird_dream » Tue Mar 13, 2018 10:33 am
I can't make it work.
I tried :
- Code: Select all
Vector3 CoM;
CoM=Body.CenterOfMass;
CoM=Body.GetBody().GetCenterOfMass();
Both failed.
I've had a look at NewtonBody.cs
Maybe I can copy&paste public Vector3 Omega l225-246 ?
-
blackbird_dream
-
- Posts: 354
- Joined: Wed Jun 07, 2006 3:08 pm
- Location: France
by blackbird_dream » Tue Mar 13, 2018 10:40 am
It seems to work adding:
- Code: Select all
public Vector3 CenterOfMass
{
get
{
if (m_body != null)
{
IntPtr omgPtr = m_body.GetCenterOfMass();
Marshal.Copy(omgPtr, m_vec3Ptr, 0, 3);
return new Vector3(m_vec3Ptr[0], m_vec3Ptr[1], m_vec3Ptr[2]);
}
return Vector3.zero;
}
set
{
if (m_body != null)
{
m_body.SetCenterOfMass(value.x, value.y, value.z);
}
}
}
to NewtonBody.cs
-
blackbird_dream
-
- Posts: 354
- Joined: Wed Jun 07, 2006 3:08 pm
- Location: France
by blackbird_dream » Tue Mar 13, 2018 10:46 am
Now I updated the AddForceAtPos function. Is it right ?
- Code: Select all
void AddForceAtPos(NewtonBody Body, Vector3 Force, Vector3 Point)
{
Vector3 Torque,LeverArm,CoM, CoM_glob;
Matrix4x4 matrix = Matrix4x4.identity;
CoM =Body.CenterOfMass;
matrix.SetTRS(Body.Position, Body.Rotation, Vector3.one);
CoM_glob=matrix* CoM;
LeverArm = Point-CoM_glob;
Torque = Vector3.Cross(LeverArm, Force);
Body.GetBody().AddForce(Force.x,Force.y,Force.z);
Body.GetBody().AddTorque(Torque.x,Torque.y,Torque.z);
}
-
blackbird_dream
-
- Posts: 354
- Joined: Wed Jun 07, 2006 3:08 pm
- Location: France
by blackbird_dream » Thu Mar 15, 2018 4:18 am
gosh it's wrong I mess around with Vector3 and Vector4
This is better :
- Code: Select all
void AddForceAtPos(NewtonBody Body, Vector3 Force, Vector3 Point)
{
Vector3 Torque, LeverArm , CoM, CoM_Glob;
Matrix4x4 matrix = Matrix4x4.identity;
CoM = Body.CenterOfMass;
matrix.SetTRS(Body.Position, Body.Rotation, Vector3.one);
CoM_Glob = matrix.MultiplyPoint(CoM);
LeverArm = Point - CoM_Glob;
Torque = Vector3.Cross(LeverArm , Force);
Body.GetBody().AddForce(Force.x, Force.y, Force.z);
Body.GetBody().AddTorque(Torque.x, Torque.y, Torque.z);
}
-
blackbird_dream
-
- Posts: 354
- Joined: Wed Jun 07, 2006 3:08 pm
- Location: France
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 18 guests