I want to attache a cylinder to my body but instead of of having the cylinder along the x axis, I want it along the z axis. So I do this:
- Code: Select all
dMatrix orientation;
orientation.m_front = dVector (0.0f, 0.0f, 1.0f, 0.0f); // this is the player up direction
orientation.m_up = dVector (1.0f, 0.0f, 0.0f, 0.0f); // this is the player front direction
orientation.m_right = orientation.m_front * orientation.m_up; // this is the player sideway direction
NewtonCollision *colup = NewtonCreateCylinder(nworldcol,
r,
h,
0,
&orientation[0][0]
);
I think that's correct so far.
Now I also want to offset the cylinder along the zaxis so the center of the cylinder is not where the position of the body is. I want the center of the cylinder B be shifted by d relative to the origin of the body A:

So I tried this:
- Code: Select all
dMatrix orientation;
orientation.m_front = dVector (0.0f, 0.0f, 1.0f, 0.0f); // this is the player up direction
orientation.m_up = dVector (1.0f, 0.0f, 0.0f, 0.0f); // this is the player front direction
orientation.m_right = orientation.m_front * orientation.m_up; // this is the player sideway direction
orientation.m_posit = dVector (0.0f, 0.0f, d, 1.0f);
NewtonCollision *colup = NewtonCreateCylinder(nworldcol,
r,
h,
0,
&orientation[0][0]
);
I'm not sure if maybe it has to be -d. Or maybe it has to be dVector (+-d, 0.0f, 0.0f, 1.0f) ? I don't know, which one would be correct?
I'm also doing this afterwards
- Code: Select all
dVector origin;
dVector inertia;
NewtonConvexCollisionCalculateInertialMatrix (colup, &inertia[0], &origin[0]);
body = NewtonCreateBody (nworld, colup);
NewtonBodySetMassMatrix (body, mass, mass * inertia.m_x, mass * inertia.m_y, mass * inertia.m_z);
NewtonBodySetCentreOfMass (body, &origin[0]);
Here I'm not sure at all. NewtonConvexCollisionCalculateInertialMatrix calculates the inertia and origin of the collision shape alone, so the offset is not taken into consideration. And then I set the massmatrix and the center of mass again without considering the shifting of d along the z axis. Don't I have to put d in there as well somewhere?