paradoxer
12-09-2008 15:27:33
This code is beta:
#include "ExampleApplication.h"
#include "NxPhysics.h"
#include "NxCooking.h"
#include "Stream.h"
#include "NXU_helper.h"
inline Vector3 toOgre(const NxVec3 &v) {
return Vector3(v.x, v.y, v.z);
}
inline NxVec3 toNx(const Vector3 &v) {
return NxVec3(v.x, v.y, v.z);
}
inline Quaternion toOgre(const NxQuat &q) {
return Quaternion(q.w, q.x, q.y, q.z);
}
inline NxQuat toNx(Quaternion& q, bool _normalise = true) {
if (_normalise) q.normalise();
NxQuat a; a.x = q.x; a.y = q.y; a.z = q.z; a.w = q.w;
return a;
}
struct Atom
{
NxActor *actor;
SceneNode *node;
};
class PhysXFrameListener: public ExampleFrameListener
{
private:
SceneManager* mSceneMgr;
NxPhysicsSDK *PxSDK;
NxScene *PxScene;
std::vector<NxActor*> atoms;
std::vector<SceneNode*> nodes;
int AtomID;
String nameOfBone[12];
Entity *ent;
SceneNode *node;
Skeleton *skel;
public:
PhysXFrameListener( RenderWindow* win, Camera* cam, SceneManager *sceneMgr )
: ExampleFrameListener(win, cam), mSceneMgr(sceneMgr)
{
int dis = 100;
initializePhysX();
createPhysicScene();
ent = mSceneMgr->createEntity("www","Body.mesh");
node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-100,0,0));
node->attachObject(ent);
ent = mSceneMgr->createEntity("www1","Body.mesh");
node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,0,0));
node->attachObject(ent);
skel = ent->getSkeleton();
for (int i = 0; i < 24; i++)
skel->getBone(i)->setManuallyControlled(true);
nameOfBone[0] = "L_Calf";
nameOfBone[1] = "L_Thigh";
nameOfBone[2] = "R_Calf";
nameOfBone[3] = "R_Thigh";
nameOfBone[4] = "Pelvis";
nameOfBone[5] = "Spine";
nameOfBone[6] = "Spine1";
nameOfBone[7] = "L_UpperArm";
nameOfBone[8] = "L_Forearm";
nameOfBone[9] = "R_UpperArm";
nameOfBone[10] = "R_Forearm";
nameOfBone[11] = "Head";
createPers(0);
}
void createPers(int i)
{
int dis = 30;
createBody(nameOfBone[0], Vector3(0,0 + dis,0), i);
createBody(nameOfBone[1], Vector3(0,20 + dis,0), i);
createCalfJoint(atoms[0],atoms[1],NxVec3(1,0,0), NxVec3(0,11 + dis,0));
createBody(nameOfBone[2], Vector3(7.5,0 + dis,0), i);
createBody(nameOfBone[3], Vector3(7.5,20 + dis,0), i);
createCalfJoint(atoms[2],atoms[3],NxVec3(1,0,0), NxVec3(7.5,11 + dis,0));
createBody(nameOfBone[4], Vector3(3.5,30 + dis,0), i);
createThingJoint(atoms[1],atoms[4],NxVec3(1,0,0), NxVec3(0,30 + dis,0));
createThingJoint(atoms[3],atoms[4],NxVec3(1,0,0), NxVec3(7.5,30 + dis,0));
createBody(nameOfBone[5], Vector3(3.8,36 + dis,0), i);
createPelvisJoint(atoms[4],atoms[5],NxVec3(1,0,0), NxVec3(3.8,36 + dis,0));
createBody(nameOfBone[6], Vector3(3.8,45 + dis,0), i);
createSpine1Joint(atoms[5],atoms[6],NxVec3(1,0,0), NxVec3(3.8,45 + dis,0));
createBody(nameOfBone[7], Vector3(17,47 + dis,-4), i);
createClavicleJoint(atoms[6],atoms[7],NxVec3(0,1,0), NxVec3(13,47 + dis,0));
createBody(nameOfBone[8], Vector3(32,47 + dis,-4), i);
createUpperArmJoint(atoms[7],atoms[8],NxVec3(0,1,0), NxVec3(22,47 + dis,0));
createBody(nameOfBone[9], Vector3(-9,47 + dis,-4), i);
createClavicleJoint(atoms[6],atoms[9],NxVec3(0,-1,0), NxVec3(-5,47 + dis,0));
createBody(nameOfBone[10], Vector3(-24,47 + dis,-4), i);
createUpperArmJoint(atoms[9],atoms[10],NxVec3(0,-1,0), NxVec3(-14,47 + dis,0));
createBody(nameOfBone[11], Vector3(4,55 + dis,0), i);
createHeadJoint(atoms[6],atoms[11],NxVec3(0,1,0), NxVec3(3,53 + dis,0));
//for (int i = 0; i < 12; i++)
// atoms->raiseBodyFlag(NX_BF_KINEMATIC);
}
void createCalfJoint(NxActor *actor0, NxActor *actor1, NxVec3 globalAxis, NxVec3 globalAnchor)
{
NxD6JointDesc d6Desc;
d6Desc.actor[0] = actor0;
d6Desc.actor[1] = actor1;
d6Desc.setGlobalAnchor(globalAnchor);
d6Desc.setGlobalAxis(globalAxis);
d6Desc.twistMotion = NX_D6JOINT_MOTION_LIMITED;
d6Desc.swing1Motion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.swing2Motion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.xMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.yMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.zMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.projectionMode = NX_JPM_NONE;
d6Desc.twistLimit.low.value = -0.9*NxPi;
d6Desc.twistLimit.low.restitution = 0;
d6Desc.twistLimit.low.spring = 0;
d6Desc.twistLimit.low.damping = 0;
d6Desc.twistLimit.high.value = 0*NxPi;
d6Desc.twistLimit.high.restitution = 0;
NxJoint* d6Joint = PxScene->createJoint(d6Desc);
}
void createThingJoint(NxActor *actor0, NxActor *actor1, NxVec3 globalAxis, NxVec3 globalAnchor)
{
NxD6JointDesc d6Desc;
d6Desc.actor[0] = actor0;
d6Desc.actor[1] = actor1;
d6Desc.setGlobalAnchor(globalAnchor);
d6Desc.setGlobalAxis(globalAxis);
d6Desc.twistMotion = NX_D6JOINT_MOTION_LIMITED;
d6Desc.swing1Motion = NX_D6JOINT_MOTION_LIMITED;
d6Desc.swing2Motion = NX_D6JOINT_MOTION_LIMITED;
d6Desc.xMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.yMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.zMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.projectionMode = NX_JPM_NONE;
d6Desc.swing1Limit.value = 0.1*NxPi;
d6Desc.swing1Limit.restitution = 0;
d6Desc.swing1Limit.spring = 0;
d6Desc.swing1Limit.damping = 0;
d6Desc.swing2Limit.value = 0.1*NxPi;
d6Desc.swing2Limit.restitution = 0;
d6Desc.swing2Limit.spring = 0;
d6Desc.swing2Limit.damping = 0;
d6Desc.twistLimit.low.value = -0.5*NxPi;
d6Desc.twistLimit.low.restitution = 0;
d6Desc.twistLimit.low.spring = 0;
d6Desc.twistLimit.low.damping = 0;
d6Desc.twistLimit.high.value = 0.3*NxPi;
d6Desc.twistLimit.high.restitution = 0;
d6Desc.driveOrientation.rotate(NxVec3(1,-1,0));
NxJoint* d6Joint = PxScene->createJoint(d6Desc);
}
void createPelvisJoint(NxActor *actor0, NxActor *actor1, NxVec3 globalAxis, NxVec3 globalAnchor)
{
NxD6JointDesc d6Desc;
d6Desc.actor[0] = actor0;
d6Desc.actor[1] = actor1;
d6Desc.setGlobalAnchor(globalAnchor);
d6Desc.setGlobalAxis(globalAxis);
d6Desc.twistMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.swing1Motion = NX_D6JOINT_MOTION_LIMITED;
d6Desc.swing2Motion = NX_D6JOINT_MOTION_LIMITED;
d6Desc.xMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.yMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.zMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.projectionMode = NX_JPM_NONE;
d6Desc.swing2Limit.value = 0.02*NxPi;
d6Desc.swing2Limit.restitution = 0;
d6Desc.swing2Limit.spring = 0;
d6Desc.swing2Limit.damping = 0;
d6Desc.twistLimit.low.value = -0.02*NxPi;
d6Desc.twistLimit.low.restitution = 0;
d6Desc.twistLimit.low.spring = 0;
d6Desc.twistLimit.low.damping = 0;
d6Desc.twistLimit.high.value = 0.04*NxPi;
d6Desc.twistLimit.high.restitution = 0;
d6Desc.driveOrientation.rotate(NxVec3(1,-1,0));
NxJoint* d6Joint = PxScene->createJoint(d6Desc);
}
void createSpine1Joint(NxActor *actor0, NxActor *actor1, NxVec3 globalAxis, NxVec3 globalAnchor)
{
NxD6JointDesc d6Desc;
d6Desc.actor[0] = actor0;
d6Desc.actor[1] = actor1;
d6Desc.setGlobalAnchor(globalAnchor);
d6Desc.setGlobalAxis(globalAxis);
d6Desc.twistMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.swing1Motion = NX_D6JOINT_MOTION_LIMITED;
d6Desc.swing2Motion = NX_D6JOINT_MOTION_LIMITED;
d6Desc.xMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.yMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.zMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.projectionMode = NX_JPM_NONE;
d6Desc.swing2Limit.value = 0.02*NxPi;
d6Desc.swing2Limit.restitution = 0;
d6Desc.swing2Limit.spring = 0;
d6Desc.swing2Limit.damping = 0;
d6Desc.twistLimit.low.value = -0.02*NxPi;
d6Desc.twistLimit.low.restitution = 0;
d6Desc.twistLimit.low.spring = 0;
d6Desc.twistLimit.low.damping = 0;
d6Desc.twistLimit.high.value = 0.04*NxPi;
d6Desc.twistLimit.high.restitution = 0;
d6Desc.driveOrientation.rotate(NxVec3(1,-1,0));
NxJoint* d6Joint = PxScene->createJoint(d6Desc);
}
void createClavicleJoint(NxActor *actor0, NxActor *actor1, NxVec3 globalAxis, NxVec3 globalAnchor)
{
NxD6JointDesc d6Desc;
d6Desc.actor[0] = actor0;
d6Desc.actor[1] = actor1;
d6Desc.setGlobalAnchor(globalAnchor);
d6Desc.setGlobalAxis(globalAxis);
d6Desc.twistMotion = NX_D6JOINT_MOTION_LIMITED;
d6Desc.swing1Motion = NX_D6JOINT_MOTION_LIMITED;
d6Desc.swing2Motion = NX_D6JOINT_MOTION_LIMITED;
d6Desc.xMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.yMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.zMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.projectionMode = NX_JPM_NONE;
d6Desc.swing1Limit.value = 1*NxPi;
d6Desc.swing1Limit.restitution = 0;
d6Desc.swing1Limit.spring = 0;
d6Desc.swing1Limit.damping = 0;
d6Desc.swing2Limit.value = 0.5*NxPi;
d6Desc.swing2Limit.restitution = 0;
d6Desc.swing2Limit.spring = 0;
d6Desc.swing2Limit.damping = 0;
d6Desc.twistLimit.low.value = -0.4*NxPi;
d6Desc.twistLimit.low.restitution = 0;
d6Desc.twistLimit.low.spring = 0;
d6Desc.twistLimit.low.damping = 0;
d6Desc.twistLimit.high.value = 1*NxPi;
d6Desc.twistLimit.high.restitution = 0;
d6Desc.driveOrientation.rotate(NxVec3(1,-1,0));
NxJoint* d6Joint = PxScene->createJoint(d6Desc);
}
void createUpperArmJoint(NxActor *actor0, NxActor *actor1, NxVec3 globalAxis, NxVec3 globalAnchor)
{
NxD6JointDesc d6Desc;
d6Desc.actor[0] = actor0;
d6Desc.actor[1] = actor1;
d6Desc.setGlobalAnchor(globalAnchor);
d6Desc.setGlobalAxis(globalAxis);
d6Desc.twistMotion = NX_D6JOINT_MOTION_LIMITED;
d6Desc.swing1Motion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.swing2Motion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.xMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.yMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.zMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.projectionMode = NX_JPM_NONE;
d6Desc.twistLimit.low.value = -0.9*NxPi;
d6Desc.twistLimit.low.restitution = 0;
d6Desc.twistLimit.low.spring = 0;
d6Desc.twistLimit.low.damping = 0;
NxJoint* d6Joint = PxScene->createJoint(d6Desc);
}
void createHeadJoint(NxActor *actor0, NxActor *actor1, NxVec3 globalAxis, NxVec3 globalAnchor)
{
NxD6JointDesc d6Desc;
d6Desc.actor[0] = actor0;
d6Desc.actor[1] = actor1;
d6Desc.setGlobalAnchor(globalAnchor);
d6Desc.setGlobalAxis(globalAxis);
d6Desc.twistMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.swing1Motion = NX_D6JOINT_MOTION_LIMITED;
d6Desc.swing2Motion = NX_D6JOINT_MOTION_LIMITED;
d6Desc.xMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.yMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.zMotion = NX_D6JOINT_MOTION_LOCKED;
d6Desc.projectionMode = NX_JPM_NONE;
d6Desc.swing2Limit.value = 0.6*NxPi;
d6Desc.swing2Limit.restitution = 0;
d6Desc.swing2Limit.spring = 0;
d6Desc.swing2Limit.damping = 0;
d6Desc.twistLimit.low.value = -0.9*NxPi;
d6Desc.twistLimit.low.restitution = 0;
d6Desc.twistLimit.low.spring = 0;
d6Desc.twistLimit.low.damping = 0;
d6Desc.twistLimit.high.value = 0.9*NxPi;
d6Desc.twistLimit.high.restitution = 0;
d6Desc.driveOrientation.rotate(NxVec3(1,-1,0));
NxJoint* d6Joint = PxScene->createJoint(d6Desc);
}
void createBody(String name, Vector3 pos, int i)
{
//Ñ
Prophet
30-09-2008 09:27:57
Yes, I took a look at it yesterday and it looks really nice. Makes me wonder why I created the Loader... Anyway, I will definitely try to learn ragdolls, but I haven't tried anything with it so far, but it will be my next little project.
About simulation; as I said, I've had one week of trial and errors with MaxScript, so that feels miles away. But since Autodesk bought Maya, perhaps we could try and co-work something that works for both? I haven't tried Maya, so I don't know the differences between them, but from the screens I've seen they look quite identical.
xadh00m
30-09-2008 16:51:21
To make things clear: The approach I had in mind with Maya was a
whole PlugIn (C++ project). IMHO using PhysX would be easy with this approach.
Maybe such a simulation can also be made with scripts but I´m afraid there is
no way to use PhysX directly.
Scythe is a nice tool but if you work some time with it you see many bugs and
interface problems. Unfortunately the author did not use Maya, 3dsMax or the
Blender (so everyone can use it) as user interface to integrate a PhysX workflow
and invested month of work creating existing interfaces which are in part buggy...
And now Scythe is buried
This is the reason why I like your "Loader" approach as a first step.