- Code: Select all
D3DXMATRIX Mat0, Mat1, Mat2;
D3DXMatrixTranslation(&Mat0, 0.0f, 0.0f, -3.0f);
D3DXMatrixTranslation(&Mat1, 0.0f, 0.0f, 0.0f);
D3DXMatrixTranslation(&Mat2, 0.0f, 0.0f, 3.0f);
D3DXVECTOR3 size(1.0f, 1.0f, 3.0f);
float mass = 2.0f;
float Ixx = 0.7f * mass * (size.y * size.y + size.z * size.z) / 12.0f;
float Iyy = 0.7f * mass * (size.x * size.x + size.z * size.z) / 12.0f;
float Izz = 0.7f * mass * (size.x * size.x + size.y * size.y) / 12.0f;
NewtonCollision* coll = NewtonCreateBox(NWorld, size.x, size.y, size.z, 0, 0);
b0 = NewtonCreateBody(NWorld, coll, Mat0);
NewtonBodySetMassMatrix(b0, mass, Ixx, Iyy, Izz);
b1 = NewtonCreateBody(NWorld, coll, Mat1);
NewtonBodySetMassMatrix(b1, mass, Ixx, Iyy, Izz);
b2 = NewtonCreateBody(NWorld, coll, Mat2);
NewtonBodySetMassMatrix(b2, mass, Ixx, Iyy, Izz);
D3DXVECTOR3 pivot0, pivot1;
pivot0 = D3DXVECTOR3(0.0f, 0.0f, -1.5f);
pivot1 = D3DXVECTOR3(0.0f, 0.0f, 1.5f);
NewtonJoint* j0 = NewtonConstraintCreateBall(NWorld, pivot0, b1, b0);
NewtonJoint* j1 = NewtonConstraintCreateBall(NWorld, pivot1, b2, b1);
float cone = D3DXToRadian(90.0f);
float twist = 0.0f;
D3DXVECTOR3 pin = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
NewtonBallSetConeLimits(j0, pin, cone, twist);
NewtonBallSetConeLimits(j1, pin, cone, twist);
NewtonBodySetForceAndTorqueCallback( b0, ApplyForceAndTorque );
NewtonBodySetForceAndTorqueCallback( b1, ApplyForceAndTorque );
NewtonBodySetForceAndTorqueCallback( b2, ApplyForceAndTorque );
Video of a problem:
Thanks for your time.