[Solved] Problem with joints

NoodlesOnMyBack

14-03-2008 04:01:46

Im trying to create a ragdoll, im using as a base the ragdoll examples on the AGEIA Sdk, im doing this:


NxOgre::Body *Head = mScene->createBody("fragment;sphere.2m.mesh", new NxOgre::SphereShape(0.5), rootPos, "Mass: 10");

NxOgre::Body *torso = mScene->createBody("fragment;sphere.2m.mesh", new NxOgre::SphereShape(0.95), rootPos, "Mass: 10");

JointParams jp;
jp.setToDefault();

NxOgre::SphericalJoint *sj = mScene->createSphericalJoint(Head,torso,jpos,jp);
sj->setGlobalAxis(Vector3(0,1,0));


The joint work, but its static, not elastic, i tried doing:


Head->joinWith(torso,jp);


But i want to add SphericalJoint not any other, any ideas?

betajaen

14-03-2008 08:16:45

Nearly everything is created through the Scene.

mScene->createXXXXJoint();

NoodlesOnMyBack

14-03-2008 09:05:23

Nearly everything is created through the Scene.

mScene->createXXXXJoint();


Im not sure i understand what do you mean... im actually doing the same thing if you look at the code

NxOgre::SphericalJoint *sj = mScene->createSphericalJoint(Head,torso,jpos,jp2);

And i create a pointer to the SphericalJoint so i can change the GlobalAxis of the actor, since both actors are atached trought the Y axis.
My problem is that the joint is rigid, there is no ragdoll effect

betajaen

14-03-2008 09:23:41

Apologies. I only glanced at your code and post thus didn't see the big part of it and thought you was trying to create a sphericalJoint through the fixedJoint shortcut function.

Anyway, jPos is the intersection or in between point between head and torso? Does the PhysX tutorial have anything in the NxSphericalJointDescription that can be applied to the JointParams?

NoodlesOnMyBack

14-03-2008 10:52:04

No problem, jpos is the root position of the object plus new position

jpos.x = root.x;
jpos.y = root.y + 8.8;
jpos.z = root.z;

The positions and shapes are the same as in the example.
I noticed something, in the Physx example the actor's bodies intersect themselves a little bit:



But in my game i cant do that, they dont intersect between them.

this is the demo:


class Ragdoll
{
public:
Ragdoll(const NxVec3& pos)
{
NxQuat qRotLeft, qRotRight, qRotAround;
qRotLeft.fromAngleAxis(90, NxVec3(0,0,1));
qRotRight.fromAngleAxis(-90, NxVec3(0,0,1));
qRotAround.fromAngleAxis(180, NxVec3(0,0,1));

NxMat33 mRotLeft, mRotRight, mRotAround;
mRotLeft.fromQuat(qRotLeft);
mRotRight.fromQuat(qRotRight);
mRotAround.fromQuat(qRotAround);

// Create body parts
head = CreateSphere(NxVec3(0,8.8,0), 0.5, 10);
torso = CreateSphere(NxVec3(0,7,0), 0.95, 10);
pelvis = CreateSphere(NxVec3(0,5.8,0), 0.7, 10);

leftUpperArm = CreateCapsule(NxVec3(0.5,8.5,0), 1, 0.4, 10);
leftUpperArm->setGlobalOrientationQuat(qRotRight);
leftForeArm = CreateCapsule(NxVec3(2,8.5,0), 1, 0.3, 10);
leftForeArm->setGlobalOrientationQuat(qRotRight);
leftHand = CreateBox(NxVec3(3.5,8.5,0), NxVec3(0.3,0.3,0.1), 10);
leftHand->setGlobalOrientationQuat(qRotRight);

rightUpperArm = CreateCapsule(NxVec3(-0.5,8.5,0), 1, 0.4, 10);
rightUpperArm->setGlobalOrientationQuat(qRotLeft);
rightForeArm = CreateCapsule(NxVec3(-2,8.5,0), 1, 0.3, 10);
rightForeArm->setGlobalOrientationQuat(qRotLeft);
rightHand = CreateBox(NxVec3(-3.5,8.5,0), NxVec3(0.3,0.3,0.1), 10);
rightHand->setGlobalOrientationQuat(qRotLeft);

leftThigh = CreateCapsule(NxVec3(0.6,6,0), 1.5, 0.5, 10);
leftThigh->setGlobalOrientationQuat(qRotAround);
leftCalf = CreateCapsule(NxVec3(0.6,3.5,0), 1.5, 0.35, 10);
leftCalf->setGlobalOrientationQuat(qRotAround);
leftFoot = CreateBox(NxVec3(0.6,1.5,0.2), NxVec3(0.4,0.2,0.75), 10);
leftFoot->setGlobalOrientationQuat(qRotAround);

rightThigh = CreateCapsule(NxVec3(-0.6,6,0), 1.5, 0.5, 10);
rightThigh->setGlobalOrientationQuat(qRotAround);
rightCalf = CreateCapsule(NxVec3(-0.6,3.5,0), 1.5, 0.35, 10);
rightCalf->setGlobalOrientationQuat(qRotAround);
rightFoot = CreateBox(NxVec3(-0.6,1.5,0.2), NxVec3(0.4,0.2,0.75), 10);
rightFoot->setGlobalOrientationQuat(qRotAround);

// Joint body parts together
neck = CreateBodySphericalJoint(head,torso,NxVec3(0,8.8,0),NxVec3(0,1,0));
leftShoulder = CreateBodySphericalJoint(leftUpperArm,torso,NxVec3(0.5,8.5,0),NxVec3(1,0,0));
rightShoulder = CreateBodySphericalJoint(rightUpperArm,torso,NxVec3(-0.5,8.5,0),NxVec3(-1,0,0));
spine = CreateBodySphericalJoint(torso,pelvis,NxVec3(0,7,0),NxVec3(0,-1,0));
leftHip = CreateBodySphericalJoint(leftThigh,pelvis,NxVec3(0.6,6,0),NxVec3(0,-1,0));
rightHip = CreateBodySphericalJoint(rightThigh,pelvis,NxVec3(-0.6,6,0),NxVec3(0,-1,0));

leftElbow = CreateRevoluteJoint(leftForeArm,leftUpperArm,NxVec3(2,8.5,0),NxVec3(0,0,-1));
rightElbow = CreateRevoluteJoint(rightForeArm,rightUpperArm,NxVec3(-2,8.5,0),NxVec3(0,0,-1));

leftWrist = CreateRevoluteJoint2(leftHand,leftForeArm,NxVec3(0,-0.15,0),NxVec3(0,1.3,0),NxVec3(0,1,0),NxVec3(0,1,0));
rightWrist = CreateRevoluteJoint2(rightHand,rightForeArm,NxVec3(0,-0.15,0),NxVec3(0,1.3,0),NxVec3(0,1,0),NxVec3(0,1,0));

leftKnee = CreateRevoluteJoint(leftCalf,leftThigh,NxVec3(0.6,3.5,0),NxVec3(1,0,0));
rightKnee = CreateRevoluteJoint(rightCalf,rightThigh,NxVec3(-0.6,3.5,0),NxVec3(-1,0,0));

leftAnkle = CreateRevoluteJoint(leftFoot,leftCalf,NxVec3(0.6,1.3,0),NxVec3(1,0,0));
rightAnkle = CreateRevoluteJoint(rightFoot,rightCalf,NxVec3(-0.6,1.3,0),NxVec3(-1,0,0));
};

NxActor* head;
NxActor* torso;
NxActor* pelvis;
NxActor* leftUpperArm;
NxActor* rightUpperArm;
NxActor* leftForeArm;
NxActor* rightForeArm;
NxActor* leftHand;
NxActor* rightHand;
NxActor* leftThigh;
NxActor* rightThigh;
NxActor* leftCalf;
NxActor* rightCalf;
NxActor* leftFoot;
NxActor* rightFoot;

NxSphericalJoint* neck;
NxSphericalJoint* leftShoulder;
NxSphericalJoint* rightShoulder;
NxSphericalJoint* spine;
NxSphericalJoint* leftHip;
NxSphericalJoint* rightHip;

NxRevoluteJoint* leftElbow;
NxRevoluteJoint* rightElbow;
NxRevoluteJoint* leftWrist;
NxRevoluteJoint* rightWrist;
NxRevoluteJoint* leftKnee;
NxRevoluteJoint* rightKnee;
NxRevoluteJoint* leftAnkle;
NxRevoluteJoint* rightAnkle;
};

NoodlesOnMyBack

15-03-2008 00:41:31

does anyone know at least how is it possible to put 2 actors together with this slightly intersection between them? is this some kind of flag on the actors that i dont know? because i think im doing the same thing as in the example

NoodlesOnMyBack

15-03-2008 02:42:15

Here is the initialization of Physx:

Is one of these parameters related with the problem of the actors not intersecting themselves?


void InitNx()
{
// Create the physics SDK
gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION);
if (!gPhysicsSDK) return;

// Set the physics parameters
gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01);

// Set the debug visualization parameters
gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1);
gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1);
gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1);
gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LIMITS, 1);

// Create the scene
NxSceneDesc sceneDesc;
sceneDesc.gravity = gDefaultGravity;
sceneDesc.simType = NX_SIMULATION_HW;
gScene = gPhysicsSDK->createScene(sceneDesc);
if(!gScene){
sceneDesc.simType = NX_SIMULATION_SW;
gScene = gPhysicsSDK->createScene(sceneDesc);
if(!gScene) return;
}

// Create the default material
NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0);
defaultMaterial->setRestitution(0.5);
defaultMaterial->setStaticFriction(0.5);
defaultMaterial->setDynamicFriction(0.5);

// Create the objects in the scene
groundPlane = CreateGroundPlane();

guy = new Ragdoll(NxVec3(0,0,0));

gSelectedActor = guy->head;
gCameraPos = NxVec3(0,10,-20);
gCameraSpeed = 20;
gForceStrength = 200000;
bPause = true;

// Initialize HUD
InitializeHUD();

// Get the current time
UpdateTime();

// Start the first frame of the simulation
if (gScene) StartPhysics();
}

Aiursrage2k

15-03-2008 13:57:18

Are you sure your scene has gravity

From the first code block you posted you are creating those actors in the same place "rootPos"

NoodlesOnMyBack

15-03-2008 18:20:40

Are you sure your scene has gravity

From the first code block you posted you are creating those actors in the same place "rootPos"


I just cut the code to show a better example, the actors are well positioned, and yes, there is gravity, i turn it OFF to see if the actors are in position, then i turn it ON.
Right now im trying to implement the code that Spacedude posted about ragdolls, so im doing this with the Ageia SDK directly, so i'll post my results soon (hopefully).

NoodlesOnMyBack

17-03-2008 06:13:02

I fixed it, i only had to setup the NxSphericalJointDesc descriptor and fill it with the right data for the joint:


NxSphericalJointDesc sphericalDesc;

sphericalDesc.setGlobalAnchor(nxvec);
sphericalDesc.setGlobalAxis(Axis);

sphericalDesc.flags |= NX_SJF_TWIST_LIMIT_ENABLED;
sphericalDesc.twistLimit.low.value = -(NxReal)0.025*NxPi;
sphericalDesc.twistLimit.low.hardness = 0.5;
sphericalDesc.twistLimit.low.restitution = 0.5;
sphericalDesc.twistLimit.high.value = (NxReal)0.025*NxPi;
sphericalDesc.twistLimit.high.hardness = 0.5;
sphericalDesc.twistLimit.high.restitution = 0.5;

sphericalDesc.flags |= NX_SJF_SWING_LIMIT_ENABLED;
sphericalDesc.swingLimit.value = (NxReal)0.25*NxPi;
sphericalDesc.swingLimit.hardness = 0.5;
sphericalDesc.swingLimit.restitution = 0.5;

sphericalDesc.flags |= NX_SJF_TWIST_SPRING_ENABLED;
sphericalDesc.twistSpring.spring = 0.5;
sphericalDesc.twistSpring.damper = 1;

sphericalDesc.flags |= NX_SJF_SWING_SPRING_ENABLED;
sphericalDesc.swingSpring.spring = 0.5;
sphericalDesc.swingSpring.damper = 1;

sphericalDesc.projectionDistance = (NxReal)0.15;
sphericalDesc.projectionMode = NX_JPM_POINT_MINDIST;

JointParams jp;
jp.setToDefault();
jp.fromNxJointDesc(sphericalDesc);

//NxOgre::SphericalJoint *sj =
mScene->createSphericalJoint(a1,a2,pos,jp);