Car simulation

Toby

20-07-2006 23:25:51

Hello,

I started for few days to use NxOgre and Ogre3D. For my test I use x06 tutorial and I change code. Then I have a probleme to attached well my wheels mesh.

I created a node for each wheel, attached to scene node of body car. When simulate is called I update steer for node. But mesh dont follow suspension just steering.


mVehicle->mWheel[i].mNode = mVehicle->mBody->mNode->createChildSceneNode(mVehicle->mName + _meshName + ".lwheel." + Ogre::StringConverter::toString(i));
mVehicle->mWheel[i].mNode->setPosition(mWheels[i].mPosition);
mVehicle->mWheel[i].mNode->setOrientation(mWheels[i].mOrientation);
mVehicle->mWheel[i].mNode->yaw(Ogre::Degree(90) + Ogre::Radian(mVehicle->mWheel[i].mWheel->getSteerAngle()));
mVehicle->mWheel[i].mNode->roll(Ogre::Radian(mVehicle->mWheel[i].mWheel->getAxleSpeed()));

mVehicle->mWheel[i].mNode->attachObject(mVehicle->mBody->owner->mSceneMgr->createEntity(mVehicle->mName + _meshName + ".wheel." + Ogre::StringConverter::toString(i),_meshName));


Must I change completly code and remove vehicleBlueprint, create a body for each wheel and create a motorised joint?

Thanks, and sorry if I seams newbie. :roll:

foxbat

21-07-2006 05:43:23

Your problem is that you are getting your wheel's position from the mPosition member of the NxOgre wheel object. This value is only used once to create the wheel, and doesn't get updated after that.

I think you will need to get the wheel position from the PhysX shape associated with each wheel. You could try doing this by using

mVehicle->mWheel[i]->mWheel->getSuspensionTravel()


That should return the value of the suspension distance along the Y axis. You could then just add this to the origional mPosition, to get the actual position of the wheel. I haven't tested this, but I think it should work.

Toby

21-07-2006 10:10:22

Ok, I will try it. I began to look on Shape class PhysX documentation but I have not see it function.
Thanks.

magura

22-07-2006 00:49:28

cheers for that tip.

Im taking a break from my mobility scooter simulator currently, but looking to get back into it shortly - this will help me put animated wheels into the sim

Toby

24-07-2006 13:04:47

Ho I tried it but my wheel move from Z axis. And not refresh coord.
Something wrong?

Can I use joint?
Or I miss understand something about torque for move car and wheel?

Thanks. :cry:

betajaen

24-07-2006 13:14:13

Nope joints are a bad thing with wheelShapes. The wheelShapes are actual shapes like the cubes are, except they are more dynamic and you can move them at will. Just attach them along with your main car shape to the body or vehicle class. And you should be ready to go.

Then to move it, you iterate though each wheel you want to turn, or drive and just access the functions.

All of this is in the vehicle class in NxOgre, and the raycast demo in the PhysX tutorials if you get stuck.

Toby

25-07-2006 13:18:23

yes, I will look on this class and tutorial.

ps: I do some advertissement for you in France. :wink:

Toby

01-08-2006 19:47:57

Hi,
I search in documentation and find many things useful. My car have wheel describe by a wheelshape and I see in debug mode suspension work well.
My meshes representing wheels are attached by node on body car and I actualize steer angle well. But wheels mesh do not follow damper.

After use getSuspensionTravel method I ue this:

mWheel.mNode->setPosition( NxTools::convert(mWheel.mWheel->getLocalPosition()));

But something wrong, position does not refresh.

thx.

betajaen

01-08-2006 21:54:03

Do you mean by not refreshing, they are not moving up or down?

If so; Is the node attached to the car or the Root SceneNode if so try getGlobalPosition()

I'm overhauling the vehicle system anyway in Preview 4.0 so I'll probably have all the bugs ironed out (and probably introduce a few new ones). :wink:

Toby

02-08-2006 20:56:59

Yes it's my problem. But getGlobalPosition do not help me anymore.
Wheel are a childNode of body node.

mVehicle->mWheel[i].mNode = mVehicle->mBody->mNode->createChildSceneNode(mVehicle->mName + _meshName + ".lwheel." + Ogre::StringConverter::toString(i));


And I attached it:
mVehicle->mWheel[i].mNode->attachObject(mVehicle->mBody->owner->mSceneMgr->createEntity(mVehicle->mName + _meshName + ".wheel." + Ogre::StringConverter::toString(i),_meshName));


When I refresh position I do this:


mWheel[i].mNode->setPosition( NxTools::convert(mWheel[i].mWheel->getLocalPosition()));
mWheel[i].mNode->setOrientation(NxTools::convert(mWheel[i].mWheel->getLocalOrientation()));
mWheel[i].mNode->yaw(Ogre::Degree(90) + Ogre::Radian(mWheel[i].mWheel->getSteerAngle()));



NxReal wheelPerimeter = NxTwoPi * mWheel[i].mWheel->getRadius();
float newTurnVelocity = getDriveVelocity() / wheelPerimeter;
mWheel[i]._turnVelocity = newTurnVelocity;

mWheel[i]._turnAngle -= mWheel[i]._turnVelocity * _time * NxTwoPi;

mWheel[i].mNode->roll(Ogre::Radian( mWheel[i]._turnAngle) );



Well I let also rolling and steering for other people.
Warning: turnAngle must be negative if car go back.
And it is not exact because you must take velocity of wheel, I getDriveVelocity of car.

two links which demonstrate problem

http://web.image.processing.free.fr/media/Movie/ArtCarDeuswheelsuspensionoff.avi
http://web.image.processing.free.fr/media/Movie/ArtCarDeuswheelsuspensionoffside.avi

Toby

15-08-2006 23:02:29

My first problem are not solve yet(Ogre node do not follow suspension). But I have a second. I do not manage to slip on the side my cars. I change dynami friction to side but nothing.


mWheels[i].mFrictionToFront = 0.1f;
mWheels[i].mFrictionToSide = 0.99f;


mTireMat = mVehicle->_owner->createMaterial(_meshName + ".tire." + Ogre::StringConverter::toString(i),2.0,mWheels[i].mFrictionToSide,0);

mTireMat->mMat->setStaticFrictionV(mWheels[i].mFrictionToFront * 4);
mTireMat->mMat->setDynamicFrictionV(mWheels[i].mFrictionToFront);
mTireMat->mMat->setDirOfAnisotropy(NxVec3(1,0,0));
mTireMat->mMat->setFrictionCombineMode(NX_CM_MULTIPLY);
mTireMat->mMat->setFlags(NX_MF_ANISOTROPIC);
mWheels[i].mWheelShape->mShapeDesc.materialIndex = mTireMat->getMaterialIndex();


Some help??

betajaen

15-08-2006 23:58:48

Oh sorry man, forgot about this thread.

You mean like things power sliding? I haven't managed to get that working yet either, it may be due to the limitations of the Wheel Shape or something that PhysX can't do.

When I start up on the vehicle system, this is one of the things I want in. Even if it has to be done by hand via custom code.

Toby

16-08-2006 12:36:05

Don't worry.
I want to reduce friction to side. Can I do it via PhysX also? And when it will work on NxOgre I update my preview version.

For my suspension's problem. I tried to attached node to global scene and to actualize position by getGlobalPosition but it is same.

Toby

11-09-2006 09:07:32

To reduce friction: I remove tire's material because when I change value this didn t affect car's behaviour. But I change NxTireFunctionDesc for lateral and longitudal. Behaviour is not perfect because now car seams to permenantly slide a bite.


For suspension position I don t find solution. My mesh node stay at original position.

NickM

12-09-2006 07:09:24

PhysX tutorial 704 seems to slide sideways (once I'd swapped their 30 odd thousand poly wheels for my own, so that I could get more than .01 frames a second lol) have you taken a look at how that works?

Toby

13-09-2006 12:45:02

Where can I find this tutorial?
in physX or NxOgre??
I didn t find it.

betajaen

13-09-2006 13:44:50

The 704's are PhysX 2.4.4 or NxOgre CVS.

Toby

26-09-2006 12:59:12

Well i didn t find 704 but 701 703. but I managed tpo do what I want. it is not perfect but it works.

Also my wheels roll, steer but never follow suspension. I use NxWheelShape and i have one actor for body and wheels. Wheels are attached to body and shape seems to follow spring suspension.
I use a shapegroup and assign a shape for each wheel. I get each and getLocalPosition of it. But this method get always initial position of wheel.
I am lost. How to get current position of suspension?

I look in ageia documentation, car example with NxWheelShape and it get LocalPosition as me but mine doesn t work.
:( :( :( :( :( :cry: :cry:

Toby

17-11-2006 21:24:59

I don t know how to get suspension position yet. But I have a way to do.


NxShape* const *shapeG ;
shapeG = mBody->mActor->getShapes();

mWheels[i].mWheel = static_cast<NxWheelShape *>(shapeG[i+1]);
NxConvexShape* cs = static_cast<NxConvexShape *>(shapeG[0]); //Body car


NxWheelContactData contactData;
NxShape* ContactShape = mWheels[i].mWheel->getContact( contactData );


if(ContactShape != NULL)
{
Vector3 mDirection = mBody->mNode->getWorldOrientation().Inverse() * (NxTools::convert(contactData.contactPoint ) - mBody->mNode->getWorldPosition());
float mDistance = mDirection.normalise( ); //distance between body and wheel


//mInitialLocalPos initial position of wheel according to body

mWheels[i].mNode->setPosition(mWheels[i].mInitialLocalPos.x, mWheels[i].mInitialLocalPos.y + mWheels[i].mWheel->getRadius() - mDistance, mWheels[i].mInitialLocalPos.z);
}
else
{
mWheels[i].mNode->setPosition(mWheels[i].mInitialLocalPos.x, mWheels[i].mInitialLocalPos.y -mWheels[i].mWheel->getSuspensionTravel() + mWheels[i].mWheel->getRadius(), mWheels[i].mInitialLocalPos.z);


}


When contact!= NULL I get contactPoint and try to find distance between this point and body car and set LocalPosition of my wheel Node. But strange behaviour appears.

<~Creatine~>

23-11-2006 17:36:22

Hello!

I have a little problem with my car. My modeller made a car.mesh and exports it with ofusion. (Unfortunately ofusion can't save scale, position etc data in .mesh)
If I try rotate the mesh it is turning, but when it is moving in physics world it returns the "default" position.


mVehicle->mBody->mNode->yaw(Ogre::Degree(90));


How can I rotate the car mesh separated and permanented?

betajaen

23-11-2006 18:11:23

Well obviously.

You do realise that PhysX or NxOgre does not pay attention to the node's position or orientation? The node is just a visualisation of the collision model.

As with with all parts of NxOgre you should adjust the orientation via the physics route and ignore Ogre.

mVehicle->setGlobalOrientation(...);

<~Creatine~>

23-11-2006 18:28:36

Well obviously.

You do realise that PhysX or NxOgre does not pay attention to the node's position or orientation? The node is just a visualisation of the collision model.

As with with all parts of NxOgre you should adjust the orientation via the physics route and ignore Ogre.

mVehicle->setGlobalOrientation(...);


Yep, I realised not payed node positon of ideas. Thanks, this totally free thread. :)