As far as i know the UpVector and other build in joints are declared depracated, and Julio recommends to use the UserJoint.
Usage Examples are in dCustomJoints, includes more complex Character Controller too.
At first that looked complicatet to me, but after playing around they are very easy to use and allow more possibilities than seen in any other physics engine.
To do your own up vector, create the Joint...
- Code: Select all
NewtonJoint* joint = NewtonConstraintCreateUserJoint (world, /*numberOfMaximalRows = */4, MyCallback, 0, /*childBody = */capsule,/* parentBody = */0);
NewtonJointSetUserData (joint, &myData);
Then in your Callback you can apply the constraint...
- Code: Select all
void MyCallback (const NewtonJoint* joint, float timestep, int threadIndex)
{
// up vector...
MyData* data= (MyData*) NewtonJointGetUserData (joint);
NewtonBody* body = data->body;
NewtonBodyGetMatrix (body, matrix);
vec3 axis; float angle;
CalcAxisAndAngleBetweenVectors (vec3 (0,1,0)/*upwards*/, matrix.upAxisVector, axis, angle);
NewtonUserJointAddAngularRow (joint, angle, (float*)&axis); // fix angular alignment
// you can do more things here, f.ex. constrain position to allow movement only up / downwards if on a ladder... but don't forget to increment numberOfMaximalRows for each added Row
// position for movement (optional)...
NewtonUserJointAddLinearRow (joint, (float*)&matrix.pos, (float*)&data->targetPos, (float*)&vec3(1,0,0));
NewtonUserJointAddLinearRow (joint, (float*)&matrix.pos, (float*)&data->targetPos, (float*)&vec3(0,1,0));
NewtonUserJointAddLinearRow (joint, (float*)&matrix.pos, (float*)&data->targetPos, (float*)&vec3(0,0,1)); // fix positional displacement in all dimensions
// you may want to limit maximum forces for this point to point constraint using NewtonUserJointSetRowMinimum+MaximumFriction () after each Row
}
It might be better to handle movement in force and torque callback, like you actually do.
But see there:
http://newtondynamics.com/forum/viewtopic.php?f=9&t=6722EDIT:
You could handle the orientation (look at + up vector) in f+t callback aswell avoiding any joint,
personally i'd try that first for that purpose, since a player is not constrained in space so hard.
Using axis and angle as above, you can calculate angular velocity to rotate the body upright until the next frame, convert to torque and apply it.
Angvel to torque conversation is covered here:
http://newtondynamics.com/forum/viewtopic.php?f=9&t=6570&p=46210#p46210