Moderators: Sascha Willems, walaber
void dCustomKinematicController::Init (NewtonBody* const body, const dMatrix& matrix)
{
CalculateLocalMatrix(matrix, m_localMatrix0, m_localMatrix1);
m_autoSleepState = NewtonBodyGetSleepState(body);
//NewtonBodySetAutoSleep(body, 0);
NewtonBodySetSleepState(body, 0);
void NewtonDynamicsJoint::SetTargetRotation(const Quat& rotation, const float blend)
{
if (type == KINEMATIC)
{
dQuaternion rotf;
Quat q = entity[0]->body->nextquat.Slerp(rotation, blend);
q = q.Normalize();
rotf.m_q0 = q.w;
rotf.m_q1 = -q.x;
rotf.m_q2 = -q.y;
rotf.m_q3 = -q.z;
((dCustomKinematicController*)newtonuserjoint)->SetTargetRotation(rotf);
((dCustomKinematicController*)newtonuserjoint)->ResetAutoSleep();
}
}
rotf.m_q0 = q.w;
rotf.m_q1 = -q.x;
rotf.m_q2 = -q.y;
rotf.m_q3 = -q.z;
pHySiQuE wrote:The problem persists.
Here is my code:
- Code: Select all
void NewtonDynamicsJoint::SetTargetRotation(const Quat& rotation, const float blend)
{
if (type == KINEMATIC)
{
dQuaternion rotf;
Quat q = entity[0]->body->nextquat.Slerp(rotation, blend);
q = q.Normalize();
rotf.m_q0 = q.w;
rotf.m_q1 = -q.x;
rotf.m_q2 = -q.y;
rotf.m_q3 = -q.z;
((dCustomKinematicController*)newtonuserjoint)->SetTargetRotation(rotf);
((dCustomKinematicController*)newtonuserjoint)->ResetAutoSleep();
}
}
Here is a demo:
https://www.leadwerks.com/testgame.zip
- Select "New Game".
- Walk up to a crate and press "E" to pick it up.
- Move the mouse around a bit to see the rotation.
if (m_pickMode) {
dQuaternion rotation (matrix0);
if (m_targetRot.DotProduct (rotation) < 0.0f) {
rotation.Scale(-1.0f);
}
dFloat dot = rotation.DotProduct(m_targetRot);
if (dot < 0.9995f) {
dMatrix rot (dGrammSchmidt(dVector (rotation.m_q1, rotation.m_q2, rotation.m_q3)));
dFloat angle = 2.0f * dAcos(dClamp(rotation.m_q0, dFloat(-1.0f), dFloat(1.0f)));
NewtonUserJointAddAngularRow (m_joint, -angle, &rot.m_front[0]);
NewtonUserJointSetRowMinimumFriction (m_joint, -m_maxAngularFriction);
NewtonUserJointSetRowMaximumFriction (m_joint, m_maxAngularFriction);
void dCustomKinematicController::SetMaxLinearFriction(dFloat accel)
{
dFloat Ixx;
dFloat Iyy;
dFloat Izz;
dFloat mass;
NewtonBodyGetMass (m_body0, &mass, &Ixx, &Iyy, &Izz);
m_maxLinearFriction = dAbs (accel) * mass;
}
void dCustomKinematicController::SetMaxLinearFriction(dFloat frictionForce)
{
m_maxLinearFriction = dAbs (frictionForce);
}
void dCustomKinematicController::SetMaxAngularFriction(dFloat frictionTorque)
{
m_maxAngularFriction = dAbs (frictionTorque);
}
Julio Jerez wrote:Joe try to get the latest so that you can see what we are working with Sweenie.
void NewtonDynamicsJoint::SetTargetRotation(const Quat& rotation, const float blend)
{
if (type == KINEMATIC)
{
dQuaternion rotf;
Quat q = entity[0]->body->nextquat.Slerp(rotation, blend);
q = q.Normalize();
rotf.m_q0 = q.w;
rotf.m_q1 = -q.x;
rotf.m_q2 = -q.y;
rotf.m_q3 = -q.z;
((dCustomKinematicController*)newtonuserjoint)->SetTargetRotation(rotf);
((dCustomKinematicController*)newtonuserjoint)->ResetAutoSleep();
}
}
void NewtonDynamicsJoint::SetTargetRotation(const Quat& rotation, const float blend)
{
if (type == KINEMATIC)
{
dQuaternion rotf;
Quat q = entity[0]->body->nextquat.Slerp(rotation, blend);
q = q.Normalize();
rotf.m_q0 = q.w;
rotf.m_q1 = q.x;
rotf.m_q2 = q.y;
rotf.m_q3 = q.z;
((dCustomKinematicController*)newtonuserjoint)->SetTargetRotation(rotf);
((dCustomKinematicController*)newtonuserjoint)->ResetAutoSleep();
}
}
Users browsing this forum: No registered users and 23 guests