Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Ricardo m. GarcĂ­a

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Joints with PhysX

   1  
   2  class Ragdoll
   3  {
   4  public:
   5     Ragdoll(const NxVec3& pos)
   6     {
   7        NxQuat qRotLeft, qRotRight, qRotAround;
   8        qRotLeft.fromAngleAxis(90, NxVec3(0,0,1));
   9        qRotRight.fromAngleAxis(-90, NxVec3(0,0,1));
  10        qRotAround.fromAngleAxis(180, NxVec3(0,0,1));
  11  
  12        NxMat33 mRotLeft, mRotRight, mRotAround;
  13        mRotLeft.fromQuat(qRotLeft);
  14        mRotRight.fromQuat(qRotRight);
  15        mRotAround.fromQuat(qRotAround);
  16  
  17        // Create body parts
  18        head = CreateSphere(NxVec3(0,8.8,0), 0.5, 10);
  19        torso = CreateSphere(NxVec3(0,7,0), 0.95, 10);
  20        pelvis = CreateSphere(NxVec3(0,5.8,0), 0.7, 10);
  21  
  22        leftUpperArm = CreateCapsule(NxVec3(0.5,8.5,0), 1, 0.4, 10);
  23        leftUpperArm->setGlobalOrientationQuat(qRotRight);
  24        leftForeArm = CreateCapsule(NxVec3(2,8.5,0), 1, 0.3, 10);
  25        leftForeArm->setGlobalOrientationQuat(qRotRight);
  26        leftHand = CreateBox(NxVec3(3.5,8.5,0), NxVec3(0.3,0.3,0.1), 10);
  27        leftHand->setGlobalOrientationQuat(qRotRight);
  28  
  29        rightUpperArm = CreateCapsule(NxVec3(-0.5,8.5,0), 1, 0.4, 10);
  30        rightUpperArm->setGlobalOrientationQuat(qRotLeft);
  31        rightForeArm = CreateCapsule(NxVec3(-2,8.5,0), 1, 0.3, 10);
  32        rightForeArm->setGlobalOrientationQuat(qRotLeft);
  33        rightHand = CreateBox(NxVec3(-3.5,8.5,0), NxVec3(0.3,0.3,0.1), 10);
  34        rightHand->setGlobalOrientationQuat(qRotLeft);
  35  
  36        leftThigh = CreateCapsule(NxVec3(0.6,6,0), 1.5, 0.5, 10);
  37        leftThigh->setGlobalOrientationQuat(qRotAround);
  38        leftCalf = CreateCapsule(NxVec3(0.6,3.5,0), 1.5, 0.35, 10);
  39        leftCalf->setGlobalOrientationQuat(qRotAround);
  40        leftFoot = CreateBox(NxVec3(0.6,1.5,0.2), NxVec3(0.4,0.2,0.75), 10);
  41        leftFoot->setGlobalOrientationQuat(qRotAround);
  42  
  43        rightThigh = CreateCapsule(NxVec3(-0.6,6,0), 1.5, 0.5, 10);
  44        rightThigh->setGlobalOrientationQuat(qRotAround);
  45        rightCalf = CreateCapsule(NxVec3(-0.6,3.5,0), 1.5, 0.35, 10);
  46        rightCalf->setGlobalOrientationQuat(qRotAround);
  47        rightFoot = CreateBox(NxVec3(-0.6,1.5,0.2), NxVec3(0.4,0.2,0.75), 10);
  48        rightFoot->setGlobalOrientationQuat(qRotAround);
  49  
  50        // Joint body parts together
  51        neck = CreateBodySphericalJoint(head,torso,NxVec3(0,8.8,0),NxVec3(0,1,0));
  52        leftShoulder = CreateBodySphericalJoint(leftUpperArm,torso,NxVec3(0.5,8.5,0),NxVec3(1,0,0));
  53        rightShoulder = CreateBodySphericalJoint(rightUpperArm,torso,NxVec3(-0.5,8.5,0),NxVec3(-1,0,0));
  54        spine = CreateBodySphericalJoint(torso,pelvis,NxVec3(0,7,0),NxVec3(0,-1,0));
  55        leftHip = CreateBodySphericalJoint(leftThigh,pelvis,NxVec3(0.6,6,0),NxVec3(0,-1,0));
  56        rightHip = CreateBodySphericalJoint(rightThigh,pelvis,NxVec3(-0.6,6,0),NxVec3(0,-1,0));
  57  
  58        leftElbow = CreateRevoluteJoint(leftForeArm,leftUpperArm,NxVec3(2,8.5,0),NxVec3(0,0,-1));
  59        rightElbow = CreateRevoluteJoint(rightForeArm,rightUpperArm,NxVec3(-2,8.5,0),NxVec3(0,0,-1));
  60  
  61        leftWrist = CreateRevoluteJoint2(leftHand,leftForeArm,NxVec3(0,-0.15,0),NxVec3(0,1.3,0),NxVec3(0,1,0),NxVec3(0,1,0));
  62        rightWrist = CreateRevoluteJoint2(rightHand,rightForeArm,NxVec3(0,-0.15,0),NxVec3(0,1.3,0),NxVec3(0,1,0),NxVec3(0,1,0));
  63  
  64        leftKnee = CreateRevoluteJoint(leftCalf,leftThigh,NxVec3(0.6,3.5,0),NxVec3(1,0,0));
  65        rightKnee = CreateRevoluteJoint(rightCalf,rightThigh,NxVec3(-0.6,3.5,0),NxVec3(-1,0,0));
  66  
  67        leftAnkle = CreateRevoluteJoint(leftFoot,leftCalf,NxVec3(0.6,1.3,0),NxVec3(1,0,0));
  68        rightAnkle = CreateRevoluteJoint(rightFoot,rightCalf,NxVec3(-0.6,1.3,0),NxVec3(-1,0,0));
  69     };
  70  
  71     NxActor* head;
  72     NxActor* torso;
  73     NxActor* pelvis;
  74     NxActor* leftUpperArm;
  75     NxActor* rightUpperArm;
  76     NxActor* leftForeArm;
  77     NxActor* rightForeArm;
  78     NxActor* leftHand;
  79     NxActor* rightHand;
  80     NxActor* leftThigh;
  81     NxActor* rightThigh;
  82     NxActor* leftCalf;
  83     NxActor* rightCalf;
  84     NxActor* leftFoot;
  85     NxActor* rightFoot;
  86  
  87     NxSphericalJoint* neck;
  88     NxSphericalJoint* leftShoulder;
  89     NxSphericalJoint* rightShoulder;
  90     NxSphericalJoint* spine;
  91     NxSphericalJoint* leftHip;
  92     NxSphericalJoint* rightHip;
  93  
  94     NxRevoluteJoint* leftElbow;
  95     NxRevoluteJoint* rightElbow;
  96     NxRevoluteJoint* leftWrist;
  97     NxRevoluteJoint* rightWrist;
  98     NxRevoluteJoint* leftKnee;
  99     NxRevoluteJoint* rightKnee;
 100     NxRevoluteJoint* leftAnkle;
 101     NxRevoluteJoint* rightAnkle;
 102  }; 
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS