then i have an alternative question:
how can i deactivate a body? - nothing is colliding with it, the body will not simulated etc. but i don't want to delete the body and i will set the matrix of the body each frame.
Moderators: Sascha Willems, walaber
JernejL wrote:viewtopic.php?f=15&t=4056&p=27525&hilit=rigid+joint (example rigid joint implementation)
JoeJ wrote:JernejL wrote:viewtopic.php?f=15&t=4056&p=27525&hilit=rigid+joint (example rigid joint implementation)
That works and while it's not 100% stiff it's surely a good way to attach a player to a car, if that's still what you want it for.
carli2 wrote:I tried that, but I did not really understand where to get matrix0 and matrix1 from. I took the matrix of the two joined bodies
// setup ...
NewtonJoint* joint = NewtonConstraintCreateUserJoint (world, 3, MyCallback, carBodyPtr, playerBodyPtr);
MyData data
data.body0 = carBodyPtr;
data.body1 = playerBodyPtr;
NewtonJointSetUserData (joint, &data);
// callback...
void MyCallback (const NewtonJoint* joint, float timestep, int threadIndex)
{
MyData* data= (MyData*) NewtonJointGetUserData (joint);
dMatrix matrix0, matrix1;
NewtonBodyGetMatrix (data->body0, matrix0);
NewtonBodyGetMatrix (data->body1, matrix1);
matrix1.posit += matrix1.up.scale (10.0); // create some offset
NewtonUserJointAddLinearRow (joint, (float*)&matrix0.posit, (float*)&matrix1.posit, (float*)&matrix0.up);
NewtonUserJointAddLinearRow (joint, (float*)&matrix0.posit, (float*)&matrix1.posit, (float*)&matrix0.front);
NewtonUserJointAddLinearRow (joint, (float*)&matrix0.posit, (float*)&matrix1.posit, (float*)&matrix0.right); // fix positional displacement in all dimensions
}
procedure callback(const userJoint: PNewtonJoint; timestep : Float; threadIndex : int); cdecl;
var m0, m1: TMatrix4;
p0, p1: TVec3;
begin
NewtonBodyGetMatrix(NewtonJointGetBody0(userJoint), @m0[0][0]);
NewtonBodyGetMatrix(NewtonJointGetBody1(userJoint), @m1[0][0]);
p0:=MatrixGetTransform(m0); // the is-matrix
p1:=MatrixGetTransform(TJoint(NewtonJointGetUserData(userJoint)).matrix*m1); // read out the relative matrix and calculate the target should-be-matrix
// movement for going to the right position
NewtonUserJointAddLinearRow(userJoint, p0, p1, @m1[0][0]);
NewtonUserJointAddLinearRow(userJoint, p0, p1, @m1[1][0]);
NewtonUserJointAddLinearRow(userJoint, p0, p1, @m1[2][0]);
// copy rotation and orientation
NewtonUserJointAddAngularRow(userJoint, 0, @IdentityMatrix[0][0]);
NewtonUserJointAddAngularRow(userJoint, 0, @IdentityMatrix[1][0]);
NewtonUserJointAddAngularRow(userJoint, 0, @IdentityMatrix[2][0]);
end;
carli2 wrote: NewtonUserJointAddAngularRow(userJoint, 0, @IdentityMatrix[0][0]);
NewtonUserJointAddAngularRow(userJoint, 0, @IdentityMatrix[1][0]);
NewtonUserJointAddAngularRow(userJoint, 0, @IdentityMatrix[2][0]);
JoeJ wrote:carli2 wrote: NewtonUserJointAddAngularRow(userJoint, 0, @IdentityMatrix[0][0]);
NewtonUserJointAddAngularRow(userJoint, 0, @IdentityMatrix[1][0]);
NewtonUserJointAddAngularRow(userJoint, 0, @IdentityMatrix[2][0]);
That code makes me think that it either simply prohibits any rotation for the bodies, or does nothing.
Have you tried: Is it still possible to rotate the bodies? Is their orientation linked to each other?
Julios example uses 3 other linear constraints to link the bodies orientations at the end of his example.
It would be possible to achieve the same result with 2 angular constraints. But you'd need to find axis and angle of rotation, which is numercally instable in case of a satisfied situation.
I can rotate and move around three linked objects as they were one single object.
JoeJ wrote:I can rotate and move around three linked objects as they were one single object.
Tried out myself - you're right.
But there is another problem with it:
If a large force hits the bodies (car crash, collisions...), their relative rotation can get distorted.
Julios method would try to fix that distortion, while your method tries to keep the distortion.
Users browsing this forum: No registered users and 1 guest