static void Add6DOF (DemoEntityManager* const scene, const dVector& origin) { dVector size (1.0f, 1.0f, 1.0f); NewtonBody* const box0 = CreateCapule (scene, origin + dVector (0.0f, 5.0f, 0.0f, 0.0f), size); NewtonBody* const box1 = CreateCapule (scene, origin + dVector (0.0f, 5.0 - size.m_y * 2.0f, 0.0f, 0.0f), size); const dFloat angle = 60.0f * 3.1415592f / 180.0f; dMatrix pinMatrix (dGrammSchmidt (dVector (0.0f, -1.0f, 0.0f, 0.0f))); // connect first box to the world dMatrix matrix0; NewtonBodyGetMatrix (box0, & matrix0[0][0]); pinMatrix.m_posit = matrix0.m_posit + dVector (0.0f, size.m_y, 0.0f, 0.0f); Custom6DOF* const joint0 = new Custom6DOF (pinMatrix, pinMatrix, box0, NULL); joint0->SetAngularLimits (dVector (-angle, -angle, -angle, 0.0f), dVector (angle, angle, angle, 0.0f)); // link the two boxes dMatrix matrix1; NewtonBodyGetMatrix (box1, &matrix1[0][0]); pinMatrix.m_posit = (matrix0.m_posit + matrix1.m_posit).Scale (0.5f); Custom6DOF* const joint1 = new Custom6DOF (pinMatrix, pinMatrix, box0, box1); joint1->SetAngularLimits (dVector (-angle, -angle, -angle, 0.0f), dVector (angle, angle, angle, 0.0f)); #ifdef _USE_HARD_JOINTS NewtonSkeletonContainer* const skeleton = NewtonSkeletonContainerCreate(scene->GetNewton(), box0, NULL); NewtonSkeletonContainerAttachBone(skeleton, box1, box0); NewtonSkeletonContainerFinalize(skeleton); #endif }
static void AddDistance (DemoEntityManager* const scene, const dVector& origin) { dVector size (1.0f, 1.0f, 1.0f); NewtonBody* const box0 = CreateCapule (scene, origin + dVector (0.0f, 5.0f, 0.0f, 0.0f), size); NewtonBody* const box1 = CreateCapule (scene, origin + dVector (0.0f, 5.0 - size.m_y * 4.0f, 0.0f, 0.0f), size); dMatrix pinMatrix (dGrammSchmidt (dVector (0.0f, -1.0f, 0.0f, 0.0f))); // connect first box to the world dMatrix matrix0; NewtonBodyGetMatrix (box0, &matrix0[0][0]); pinMatrix.m_posit = matrix0.m_posit + dVector (0.0f, size.m_y, 0.0f, 0.0f); new CustomBallAndSocket (pinMatrix, box0, NULL); // link the two boxes with a distance joint dMatrix matrix1; NewtonBodyGetMatrix (box1, &matrix1[0][0]); // get the origins dVector pivot0 (matrix0.m_posit); dVector pivot1 (matrix1.m_posit); // connect bodies at a corner new CustomDistance (pivot1, pivot0, box1, box0); #ifdef _USE_HARD_JOINTS NewtonSkeletonContainer* const skeleton = NewtonSkeletonContainerCreate(scene->GetNewton(), NULL, NULL); NewtonSkeletonContainerAttachBone(skeleton, box0, NULL); NewtonSkeletonContainerAttachBone(skeleton, box1, box0); NewtonSkeletonContainerFinalize(skeleton); #endif }
static void AddBallAndSockectWithFriction (DemoEntityManager* const scene, const dVector& origin) { dVector size (1.0f, 1.0f, 1.0f); NewtonBody* const box0 = CreateCapule (scene, origin + dVector (0.0f, 5.0f, 0.0f, 0.0f), size); NewtonBody* const box1 = CreateCapule (scene, origin + dVector (0.0f, 5.0 - size.m_y * 2.0f, 0.0f, 0.0f), size); dMatrix pinMatrix (dGrammSchmidt (dVector (0.0f, -1.0f, 0.0f, 0.0f))); // connect first box to the world dMatrix matrix0; NewtonBodyGetMatrix (box0, &matrix0[0][0]); pinMatrix.m_posit = matrix0.m_posit + dVector (0.0f, size.m_y, 0.0f, 0.0f); new CustomBallAndSocketWithFriction (pinMatrix, box0, NULL, 20.0f); // link the two boxes dMatrix matrix1; NewtonBodyGetMatrix (box1, & matrix1[0][0]); pinMatrix.m_posit = (matrix0.m_posit + matrix1.m_posit).Scale (0.5f); new CustomBallAndSocketWithFriction (pinMatrix, box1, box0, 10.0f); #ifdef _USE_HARD_JOINTS NewtonSkeletonContainer* const skeleton = NewtonSkeletonContainerCreate(scene->GetNewton(), NULL, NULL); NewtonSkeletonContainerAttachBone(skeleton, box0, NULL); NewtonSkeletonContainerAttachBone(skeleton, box1, box0); NewtonSkeletonContainerFinalize(skeleton); #endif }
static void AddLimitedBallAndSocket (DemoEntityManager* const scene, const dVector& origin) { dVector size(1.0f, 1.0f, 1.0f); NewtonBody* const base = CreateBox(scene, origin + dVector (0.0f, 5.0f + size.m_y + 0.25f, 0.0f, 0.0f), size.Scale (0.2f)); NewtonBody* const box0 = CreateCapule(scene, origin + dVector(0.0f, 5.0f, 0.0f, 0.0f), size); NewtonBody* const box1 = CreateCapule(scene, origin + dVector(0.0f, 5.0 - size.m_y * 2.0f, 0.0f, 0.0f), size); NewtonBody* const box2 = CreateCapule(scene, origin + dVector(0.0f, 5.0 - size.m_y * 4.0f, 0.0f, 0.0f), size); NewtonBodySetMassMatrix(base, 0.0f, 0.0f, 0.0f, 0.0f); dMatrix pinMatrix(dGrammSchmidt(dVector(0.0f, -1.0f, 0.0f, 0.0f))); // connect first box to the world dMatrix matrix; NewtonBodyGetMatrix(box0, &matrix[0][0]); pinMatrix.m_posit = matrix.m_posit + dVector(0.0f, size.m_y, 0.0f, 0.0f); CustomLimitBallAndSocket* const joint0 = new CustomLimitBallAndSocket(pinMatrix, box0, base); joint0->SetConeAngle (30.0f * 3.141592f / 180.0f); joint0->SetTwistAngle (-30.0f * 3.141592f / 180.0f, 30.0f * 3.141592f / 180.0f); // connect first box1 to box0 the world NewtonBodyGetMatrix(box1, &matrix[0][0]); pinMatrix.m_posit = matrix.m_posit + dVector(0.0f, size.m_y, 0.0f, 0.0f); CustomLimitBallAndSocket* const joint1 = new CustomLimitBallAndSocket(pinMatrix, box1, box0); joint1->SetConeAngle(30.0f * 3.141592f / 180.0f); joint1->SetTwistAngle(-30.0f * 3.141592f / 180.0f, 30.0f * 3.141592f / 180.0f); // connect first box2 to box1 the world NewtonBodyGetMatrix(box2, &matrix[0][0]); pinMatrix.m_posit = matrix.m_posit + dVector(0.0f, size.m_y, 0.0f, 0.0f); CustomLimitBallAndSocket* const joint2 = new CustomLimitBallAndSocket(pinMatrix, box2, box1); joint2->SetConeAngle(30.0f * 3.141592f / 180.0f); joint2->SetTwistAngle(-30.0f * 3.141592f / 180.0f, 30.0f * 3.141592f / 180.0f); #ifdef _USE_HARD_JOINTS NewtonSkeletonContainer* const skeleton = NewtonSkeletonContainerCreate(scene->GetNewton(), base, NULL); NewtonSkeletonContainerAttachBone(skeleton, box0, base); NewtonSkeletonContainerAttachBone(skeleton, box1, box0); NewtonSkeletonContainerAttachBone(skeleton, box2, box1); NewtonSkeletonContainerFinalize(skeleton); #endif }
static void AddPoweredRagDoll (DemoEntityManager* const scene, const dVector& origin) { dVector size (1.0f, 1.0f, 1.0f); NewtonBody* const box0 = CreateCapule(scene, origin + dVector(0.0f, 9.0f, 0.0f, 0.0f), size); // NewtonBody* const box1 = CreateCapule(scene, origin + dVector(0.0f, 9.0 - size.m_y * 2.0f, 0.0f, 0.0f), size); // NewtonBody* const box2 = CreateCapule(scene, origin + dVector(0.0f, 9.0 - size.m_y * 4.0f, 0.0f, 0.0f), size); // NewtonBody* const box3 = CreateCapule(scene, origin + dVector(0.0f, 9.0 - size.m_y * 6.0f, 0.0f, 0.0f), size); dMatrix pinMatrix (dGrammSchmidt (dVector (0.0f, -1.0f, 0.0f, 0.0f))); //dMatrix pinMatrix (dGrammSchmidt (dVector (1.0f, 0.0f, 0.0f, 0.0f))); // connect first box to the world dMatrix matrix0; NewtonBodyGetMatrix (box0, & matrix0[0][0]); pinMatrix.m_posit = matrix0.m_posit + dVector (0.0f, size.m_y, 0.0f, 0.0f); CustomControlledBallAndSocket* const joint0 = new CustomControlledBallAndSocket (pinMatrix, box0, NULL); joint0->SetAngularVelocity (2000.0f * 3.141592f / 180.0f); // joint0->SetPitchAngle (-45.0f * 3.141592f / 180.0f); // joint0->SetYawAngle (-85.0f * 3.141592f / 180.0f); // joint0->SetRollAngle (120.0f * 3.141592f / 180.0f); joint0->SetPitchAngle (90.0f * 3.141592f / 180.0f); /* // link the two boxes dMatrix matrix1; NewtonBodyGetMatrix (box1, &matrix1[0][0]); pinMatrix.m_posit = (matrix0.m_posit + matrix1.m_posit).Scale (0.5f); CustomControlledBallAndSocket* const joint1 = new CustomControlledBallAndSocket (pinMatrix, box0, box1); joint1->SetAngularVelocity (1000.0f * 3.141592f / 180.0f); joint1->SetPitchAngle (45.0f * 3.141592f / 180.0f); joint1->SetYawAngle ( 30.0f * 3.141592f / 180.0f); joint1->SetRollAngle (25.0f * 3.141592f / 180.0f); // link next box dMatrix matrix2; NewtonBodyGetMatrix(box2, &matrix2[0][0]); pinMatrix.m_posit = (matrix1.m_posit + matrix2.m_posit).Scale(0.5f); CustomControlledBallAndSocket* const joint2 = new CustomControlledBallAndSocket(pinMatrix, box1, box2); joint2->SetAngularVelocity(1000.0f * 3.141592f / 180.0f); joint2->SetPitchAngle(45.0f * 3.141592f / 180.0f); joint2->SetYawAngle(30.0f * 3.141592f / 180.0f); joint2->SetRollAngle(25.0f * 3.141592f / 180.0f); // link next box dMatrix matrix3; NewtonBodyGetMatrix(box3, &matrix3[0][0]); pinMatrix.m_posit = (matrix2.m_posit + matrix3.m_posit).Scale(0.5f); CustomControlledBallAndSocket* const joint3 = new CustomControlledBallAndSocket(pinMatrix, box2, box3); joint3->SetAngularVelocity(1000.0f * 3.141592f / 180.0f); joint3->SetPitchAngle(45.0f * 3.141592f / 180.0f); joint3->SetYawAngle(30.0f * 3.141592f / 180.0f); joint3->SetRollAngle(25.0f * 3.141592f / 180.0f); #ifdef _USE_HARD_JOINTS NewtonSkeletonContainer* const skeleton = NewtonSkeletonContainerCreate(scene->GetNewton(), box0, NULL); NewtonSkeletonContainerAttachBone(skeleton, box1, box0); NewtonSkeletonContainerAttachBone(skeleton, box2, box1); NewtonSkeletonContainerAttachBone(skeleton, box3, box2); NewtonSkeletonContainerFinalize(skeleton); #endif */ }