Simple Joints Use

mephisto

17-01-2011 21:52:48

This is a simple car made by joints ... I quickly tryied to use d6joint to simulate a connection between the wheel and the chassis but the d6joint isn't simple in use(it requiers docs reading) so I connected the wheels by FixedJoints :D. But changing the joints to d6joints will make a true car... and eventually unlock use of torque etc...

Critter::Body* chassis[2];
Critter::BodyDescription chassis_dsc;

NxOgre::BoxDescription boxDsc;
boxDsc.mSize.set(2,1,3);

NxOgre::Vec3 chassisPos[2];
chassisPos[0].set(0,1,0);
chassisPos[1].set(0,2,0);

chassis_dsc.mMass = 10.0f;


chassis[0] = mRenderSystem->createBody(boxDsc, chassisPos[0], "cube.1m.mesh", chassis_dsc);
chassis[0]->getSceneNode()->scale(2,1,3);

boxDsc.reset();
boxDsc.mSize.set(2,1,2);
chassis[1] = mRenderSystem->createBody(boxDsc, chassisPos[1], "cube.1m.mesh", chassis_dsc);
boxDsc.mSize.set(2,1,2);
chassis[1]->getSceneNode()->scale(2,1,2);
NxOgre::FixedJoint* fixed_joint;
NxOgre::FixedJointDescription fixed_joint_dsc;
fixed_joint_dsc.mMaxForce = 1000.0f;
fixed_joint = mScene->createFixedJoint(chassis[0]->getShape(0)->getRigidBody()
, chassis[1]->getShape(0)->getRigidBody(),fixed_joint_dsc);

NxOgre::SphereDescription wheelSphere_dsc;
NxOgre::Sphere* wheel_shape[4];


Critter::BodyDescription wheelBody_dsc;
wheelBody_dsc.mMass = 5.0f;
Critter::Body* wheel[4];

NxOgre::Vec3 wheel_pos[4];

wheel_pos[0].set(1.5, 0.1, 1);
wheel_pos[1].set(1.5, 0.1, -1);
wheel_pos[2].set(-1.5, 0.1, 1);
wheel_pos[3].set(-1.5, 0.1, -1);

NxOgre::FixedJoint* wheel_joint[4];
for(int i=0; i<4; i++)
{
wheel = mRenderSystem->createBody(wheelSphere_dsc, wheel_pos, "Ellipsoid.mesh", wheelBody_dsc);
wheel->getSceneNode()->scale(1.0f, 1.0f, 1.0f);
wheel_joint = mScene->createFixedJoint(wheel->getShape(0)->getRigidBody(),
chassis[0]->getShape(0)->getRigidBody(), fixed_joint_dsc);
}

betajaen

17-01-2011 21:55:46

Why not use the WheelShape? It's more reliable and controllable than the Joint system.

mephisto

17-01-2011 22:08:54

Yes, you are right I will try.(I wasnt aware that it posses suspension) but the joints remain usefull for example a ragdoll... etc...

betajaen

17-01-2011 22:13:42

Oh, yes.

If you replace your FixedJoint, with a RevoluteJoint, then you can use the motor feature to rotate the wheels.

mephisto

18-01-2011 10:39:53

Wheel shape use... I tryied many suspension configurations and found a way on how we can use them :
How I can Render the wheels?

NxOgre::WheelDescription wheels_dsc[4];
NxOgre::SpringDescription suspensionDsc;

// more the SuspensionTravel is smaller and more can be the the difference between those 2 params
// Spring must have the same order size that the body mass
suspensionDsc.mDamper = 50.0f;
suspensionDsc.mSpring = 300.0f;


wheels_dsc[0].mFlags |= NxOgre::Enums::ShapeFlags_Visualisation;
wheels_dsc[0].mMotorTorque = 0.0f;
wheels_dsc[0].mSuspension = suspensionDsc;
// This is something like maximum spring distorsion length
wheels_dsc[0].mSuspensionTravel = 1.0f;

NxOgre::Vec3 wheel_pos[4];

wheel_pos[0].set(1.5, 0.1, 1);
wheel_pos[1].set(1.5, 0.1, -1);
wheel_pos[2].set(-1.5, 0.1, 1);
wheel_pos[3].set(-1.5, 0.1, -1);

NxOgre::ShapeDescriptions car_shapes_dsc;
Critter::Body* car;
Critter::BodyDescription car_body_dsc;
car_body_dsc.mMass = 100.0f;
NxOgre::BoxDescription chassis_dsc;
chassis_dsc.mId = 4;
chassis_dsc.mLocalPose = NxOgre::Vec3(0,2,0);
chassis_dsc.mSize.set(2,1,3);

for(int i=0; i<4; i++)
{
wheels_dsc = wheels_dsc[0];
wheels_dsc.mId = i;
wheels_dsc.mLocalPose = wheel_pos;
car_shapes_dsc.push_back(&wheels_dsc);
}
car_shapes_dsc.push_back(&chassis_dsc);
NxOgre::Vec3 car_pos(-15, 25, 0);
car = mRenderSystem->createBody(car_shapes_dsc, car_pos, "cube.1m.mesh", car_body_dsc);

mephisto

19-01-2011 17:47:29

Today I tryied joints (jsut the pure basics) , hope will help somebody or somebody will correct if there is an error ...

NxOgre::BoxDescription shape_dsc[30];
Critter::BodyDescription body_dsc[30];
Critter::Body* body[30];
NxOgre::Vec3 body_pos[30];

NxOgre::RevoluteJointDescription rjdsc;
NxOgre::SphericalJointDescription sjdsc;
NxOgre::D6JointDescription d6jdsc;
NxOgre::FixedJointDescription fjdsc;

for(int i=0; i<30; i++)
{
shape_dsc.mSize.set(5, 5, 5);
body_dsc.mMass = 200 - i*5;
body_pos.set(0, i*10 + 30, 0);
body = mRenderSystem->createBody(shape_dsc, body_pos, "cube.1m.mesh", body_dsc);
body->getSceneNode()->scale(5,5,5);
}


NxOgre::JointLimitSoftDescription swing1Limit;
swing1Limit.mDamping = 50.0f;
swing1Limit.mRestitution = 0.5;
swing1Limit.mSpring = 50.0f;
swing1Limit.mValue = NxOgre::Math::Pi;

NxOgre::JointLimitSoftDescription linearLimit;
linearLimit = swing1Limit;

for(int i=0; i<29; i++)
{
rjdsc.mLocalAnchor[0].set(0,7,0);
rjdsc.mLocalAnchor[1].set(0,-7,0);
rjdsc.mLocalAxis[0].set(0, 1, 0);
rjdsc.mLocalAxis[1].set(0, 1, 0);
rjdsc.mLocalNormal[0].set(1, 0, 0);
rjdsc.mLocalNormal[1].set(1, 0, 0);
rjdsc.mJointFlags |= NxOgre::Enums::JointFlag_Visualisation;
rjdsc.mMaxForce = 100000.0f;
rjdsc.mMaxTorque = 100000.0f;

sjdsc.mLocalAxis[0].set(0, 1, 0);
sjdsc.mLocalAxis[1].set(0, 1, 0);
sjdsc.mLocalNormal[0].set(1, 0, 0);
sjdsc.mLocalNormal[1].set(1, 0, 0);
sjdsc.mJointFlags |= NxOgre::Enums::JointFlag_Visualisation;
sjdsc.mMaxForce = 100000.0f;
sjdsc.mMaxTorque = 100000.0f;
sjdsc.mLocalAnchor[0].set(0,7,0);
sjdsc.mLocalAnchor[1].set(0,-7,0);
sjdsc.mSwingAxis.set(0, body_pos.y, 0);

fjdsc.mLocalAnchor[0].set(0, 7, 0);
fjdsc.mLocalAnchor[1].set(0, -7, 0);
fjdsc.mLocalAxis[0].set(0, 1, 0);
fjdsc.mLocalAxis[1].set(0, 1, 0);
fjdsc.mLocalNormal[0].set(1, 0, 0);
fjdsc.mLocalNormal[1].set(1, 0, 0);
fjdsc.mMaxForce = 10000.0f;
fjdsc.mMaxTorque = 10000.0f;
fjdsc.mSpringType = NxOgre::Enums::JointSpringType_Acceleration;

d6jdsc.mLocalAxis[0].set(1, 0, 0);
d6jdsc.mLocalAxis[1].set(1, 0, 0);
d6jdsc.mLocalNormal[0].set(0, 1, 0);
d6jdsc.mLocalNormal[1].set(0, 1, 0);
d6jdsc.mJointFlags |= NxOgre::Enums::JointFlag_Visualisation;
d6jdsc.mMaxForce = 100000.0f;
d6jdsc.mMaxTorque = 100000.0f;
d6jdsc.mLocalAnchor[0].set(0,7,0);
d6jdsc.mLocalAnchor[1].set(0,-7,0);
d6jdsc.mSwing1Limit = swing1Limit;
d6jdsc.mLinearLimit = linearLimit;
d6jdsc.mMaxForce = 100000.0f;
d6jdsc.mMaxTorque = 100000.0f;
//d6jdsc.mSwing1Motion = NxOgre::Enums::D6JointMotion_Limited;
// I am getting assertion when setting NxOgre::Enums::D6JointMotion_Limited;

//mScene->createFixedJoint(body, body, fjdsc);
mScene->createSphericalJoint(body, body, sjdsc);
//mScene->createRevoluteJoint(body, body, rjdsc);
//mScene->createD6Joint(body, body, d6jdsc);
}

mephisto

19-01-2011 23:10:26

Oh I forgot to put outside "for" the descriptions... :oops: :oops:

mephisto

23-01-2011 23:41:13

I am working on a simple tank with "chenilles" but without the machine ... just Basic Bodies... and joints

mephisto

27-01-2011 19:58:08

I want to rotate shape and ogre mesh :
/*(critterbody)*/
m_MotorWheel->getSceneNode()->pitch(Ogre::Radian(Ogre::Math::PI / 2.0f), Ogre::Node::TransformSpace::TS_WORLD); // i tried world and local and other rotations
m_WheelOrientation.set(NxOgre::Radian(3.14/2), NxOgre::Enums::Axis::X);
m_MotorWheel->getShape(0)->setGlobalPose(m_WheelOrientation); // tried setLocal and global;

I also tried to do the same in the shape description but nothing...
Can somebody tell me whats wrong?

deshan

28-01-2011 03:57:06

I guess it's reset by the joint.
What is the joint type?
Unless it is D6, you could try by registering a joint motor

mephisto

28-01-2011 23:55:40

thx for response...No I used RevoluteJoint. but finally I resolved the problem by setting initially the "Pose" of the shapes and graphic meshes. I was motivated and documented my self about how to set the Matrix44 parameters. :D
I used :
NxOgre::Matrix44 GlobalPose(...) the 8th constructror.

But now I have another problem, I am coding a physical platform to a tank(it can be just vehicle, its universal). But I dont know if I should use the Machine class or simple amortised hinge (D6joint) should be OK. I suppose that the machine class is more stable and optimized ...?
The best would be to post something like small demo about how to use the machine class in order to try it...

deshan

30-01-2011 16:12:43

There was a bloddymess(Nxogre 1.5.x) example for machine, (physics + rendering worked for me)

viewtopic.php?f=6&t=10348#p59407

do not move to bloddymess, try to run it with buggys wires

~deshn

mephisto

01-02-2011 21:18:34

oh nice thank you. I am using Detritus now but concidering this I will upgrade to buggys wires.

mephisto

02-02-2011 21:08:48

What is the WheelBlueprint (in blodymess) and how do I replace it in Detritus version?

betajaen

02-02-2011 21:37:23

WheelDescription

Blueprint=Description

mephisto

02-02-2011 22:03:57

To "createWheelMachinePart" I must pass a Wheel to the first parameter. But the wheel must exist. So the wheel should be created using wheelDescription;
The question is how to create the wheel as wheel is a shape and is rendered by the pointRederable.?

mephisto

03-02-2011 11:56:34

I wanted update to Buggy Swires, I got this when compiling :

1>c:\ogre\nxogre\build\source\nxogrememoryresource.cpp(191) : warning C4715: 'NxOgre::MemoryResource::write' : not all control paths return a value

bool MemoryResource::write(const void* src, size_t src_size)
{

if (mStatus != Enums::ResourceStatus_Opened)
{
return false;
}

if (mAccess != Enums::ResourceAccess_ReadAndWrite)
{
return false;
}

_willFit(src_size);
mMemory.put_at(mIndex, src, src_size);
mIndex += src_size;

}

betajaen

03-02-2011 12:04:11

It's just a warning. I'll fix it in the next commit.

mephisto

03-02-2011 12:31:43

Oh jointHelper NICE! I have juste switched to buggy.
in Detritus I had to scale the graphic like this : body->getSceneNode()->scale(NxOgre...
now it's
body->getNode->setScale(Ogre::..

I just chaged this but I am having a problem, ( I have a car with 8 wheels with revolutejoints) the graphic meshes for wheels aren't rendered correctly(only 2 wheels are rendered). And same problem with other objects that are linked with joints . I suppose that I have something wrong with joints? May be You have an idea?

mephisto

07-02-2011 15:46:56

I wanted to use the D6 fuction setAngularVelocity, but I got this when compiling :

error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall NxOgre::D6Joint::setDriveAngularVelocity(class NxOgre::Vec3 const &)" (__imp_?setDriveAngularVelocity@D6Joint@NxOgre@@QAEXABVVec3@2@@Z)

And I didnt find the definition in D6Joint.cpp and Joint.cpp

mephisto

07-02-2011 22:50:45

I am using D6Joint for car, I have set suspension and configured necessary DOFs. But I am having problems on how to make the "drive system" . It seems that the function Critter::Body->setAngular/linear Velocity works only to set it initially. So considering this I must use the joint functions to make the car moving?
I have specified the mSwingDrive, but dont know how to use... Can someone post "code" or just explain how to use it... :(

mephisto

09-02-2011 16:38:12

May be I am wrong but I have verified there is no definitions for those functions :
(in buggy swires and detritus)

NxOgreD6Joint.h

void setDrivePosition(const Vec3& position);
void setDriveOrientation(const Quat& orientation);
void setDriveLinearVelocity(const Vec3& linearVelocity);
void setDriveAngularVelocity(const Vec3& angularVelocity);

(those functions are important when updating the drive)

betajaen

09-02-2011 16:46:41

Alright. Make a note in the LeJean thread, and then I'll remember to put them in.

mephisto

13-02-2011 21:52:56

Why when I do this :

Critter::BodyDescription bdy;
NxOgre::Vec3 pos(1, 1, 1);
NxOgre::BoxDescription sh(1, 1, 1);

for(int i=0; i<200; i++)
{
bdy.mMass = 10.0f;

pos.set(rand() % 100, i + rand() % 100, rand() % 100);

mRenderSystem->createBody(sh, pos, "cube.1m.mesh", bdy);
}

only 1 Box is being rendered with the "cube.1m.mesh" ?

mephisto

14-02-2011 10:58:54

I resolved the problem like this :

Critter::BodyDescription bdy[200];

for(int i=0; i<200; i++)
{
bdy.mMass = 10.0f;
sh.mSize = NxOgre::Vec3(1, 1, 1);

pos.set(rand() % 100, i + rand() % 100, rand() % 100);

mRenderSystem->createBody(sh, pos, "cube.1m.mesh", bdy);
}

The createBody functions are diffenrent between Detritus and Buggy Swires :

Buggy :

Body* RenderSystem::createBody(const NxOgre::ShapeDescription& shape, const NxOgre::Matrix44& pose, const Ogre::String& meshName, BodyDescription& description)
{

if (description.mNode == 0)
description.mNode = NxOgre::GC::safe_new2<Node>(mSceneManager, this, NXOGRE_GC_THIS);

description.mNode->setPose(pose);

if (meshName.length())
description.mNode->createAndAttachEntity(meshName);

Body* body = NxOgre::GC::safe_new4<Body>(shape, pose, description, this, NXOGRE_GC_THIS);

mBodies.insert(body->getNameHash(), body);

return body;
}

Detritus :

Body* RenderSystem::createBody(const NxOgre::ShapeDescription& shape, const NxOgre::Matrix44& pose, const Ogre::String& meshName, BodyDescription& description)
{
description.mNode = mSceneManager->getRootSceneNode()->createChildSceneNode(NxOgre::Vec3(pose).as<Ogre::Vector3>(), NxOgre::Quat(pose).as<Ogre::Quaternion>());
if (meshName.length())
description.mNode->attachObject(mSceneManager->createEntity(getUniqueName("entity"), meshName));

Body* body = NxOgre::GC::safe_new4<Body>(shape, pose, description, this, NXOGRE_GC_THIS);

mBodies.insert(body->getNameHash(), body);

return body;
}