A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by mauro78 » Wed Oct 28, 2009 4:38 pm
Hi!
I've Correctly implemented a Custom Kinematic Joint and
LocalSubmitConstraints look like this:
- Code: Select all
NewtonUserJointAddLinearRow (mpJoint, &matrix0.m_posit[0], &mPosition[0], &pin0[0]);
NewtonUserJointAddLinearRow (mpJoint, &matrix0.m_posit[0], &mPosition[0], &pin1[0]);
NewtonUserJointAddLinearRow (mpJoint, &matrix0.m_posit[0], &mPosition[0], &pin2[0]);
Now I'd like to to limit rotation: I don't want any kind of rotation, Is that possible?
I added for example a limit on Y axis with AddAngularRow...but the object still rotates
Regards
p.s.
I've successfully used CustomKinematicJoint of Newton 2.0 to obtain a similar effect but I'd like to learn how to use Custom Joints so I'm tring to do that
Mauro
http://www.breakinglass.com
-
mauro78
-
- Posts: 13
- Joined: Mon Feb 16, 2009 5:40 pm
by Julio Jerez » Wed Oct 28, 2009 5:24 pm
you can check how I do it in the Player controller joints, and you can just cut and past the fragment of code into yuo r own joint.
See the Wiki player controler demo in tutorials 200's
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by mauro78 » Thu Oct 29, 2009 4:04 am
Hi Julio in the tutorial 202 I don't think that I can see the code....couse You just call subroutine from a library; I found this method in the source code file CustomPlayerController.cpp:
- Code: Select all
void CustomPlayerController::SubmitConstraints (dFloat timestep, int threadIndex)
{
dFloat mag;
dFloat angle;
dFloat invIxx;
dFloat invIyy;
dFloat invIzz;
dFloat invMass;
dMatrix matrix0;
dMatrix matrix1;
dVector velocity;
// save the gravity before collision force are applied
NewtonBodyGetForceAcc (m_body0, &m_gravity[0]);
NewtonBodyGetInvMass(m_body0, &invMass, &invIxx, &invIyy, &invIzz);
m_gravity = m_gravity.Scale (invMass);
// calculate the position of the pivot point and the Jacobian direction vectors, in global space.
CalculateGlobalMatrix (m_localMatrix0, m_localMatrix1, matrix0, matrix1);
// if the body ha rotated by some amount, the there will be a plane of rotation
dVector lateralDir (matrix0.m_front * matrix1.m_front);
mag = lateralDir % lateralDir;
if (mag > 1.0e-6f) {
// if the side vector is not zero, it means the body has rotated
mag = dSqrt (mag);
lateralDir = lateralDir.Scale (1.0f / mag);
angle = dAsin (mag);
// add an angular constraint to correct the error angle
NewtonUserJointAddAngularRow (m_joint, angle, &lateralDir[0]);
// in theory only one correction is needed, but this produces instability as the body may move sideway.
// a lateral correction prevent this from happening.
dVector frontDir (lateralDir * matrix1.m_front);
NewtonUserJointAddAngularRow (m_joint, 0.0f, &frontDir[0]);
} else {
// if the angle error is very small then two angular correction along the plane axis do the trick
NewtonUserJointAddAngularRow (m_joint, 0.0f, &matrix0.m_up[0]);
NewtonUserJointAddAngularRow (m_joint, 0.0f, &matrix0.m_right[0]);
}
// get linear velocity
if (m_playerState == m_onLand) {
// dFloat mag2;
NewtonBodyGetVelocity(m_body0, &velocity[0]);
// Get the global matrices of each rigid body.
const dVector& frontDir = matrix0.m_up;
const dVector& strafeDir = matrix0.m_right;
const dVector& upDir = matrix0.m_front;
dVector desiredVeloc (frontDir.Scale (m_forwardSpeed) + upDir.Scale (velocity % upDir) + strafeDir.Scale (-m_sideSpeed));
// dFloat maxSpeed = dAbs (m_forwardSpeed) > dAbs (m_sideSpeed) ? dAbs (m_forwardSpeed) : dAbs (m_sideSpeed);
// mag2 = desiredVeloc % desiredVeloc;
// if (mag2 > 1.0e-6f) {
// desiredVeloc = desiredVeloc.Scale (maxSpeed /dSqrt (mag2));
// }
NewtonBodySetVelocity(m_body0, &desiredVeloc[0]);
}
}
so...you're talking about that piece of code??
Regards
Mauro
http://www.breakinglass.com
-
mauro78
-
- Posts: 13
- Joined: Mon Feb 16, 2009 5:40 pm
by Julio Jerez » Thu Oct 29, 2009 8:11 am
yes tha code if you are planning on player controller with some free dof
if you are looking for a fully kynematic joint to controll bodies as if they were kynematic pieces
checkout tutorial 103, It has wiki commnet and the joint has the code. See section with comments
// adding two Kinematic controlled object
It explain how to make them.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 2 guests