vehicle tires

Grom

14-03-2007 12:01:49

for vehicles, is it better to load the tires as separate meshes so that they can rotate independently of the body? Or is there some better method of mesh's (perhaps with bones or sub-meshes) that I don't know about.

betajaen

14-03-2007 12:06:40

The former. If everyone else is doing it with Ogre I see why not.

luis

14-03-2007 15:06:05

yes, a separate mesh is better, and if you have some kind of CFG/xml file to load the car's meshfiles plus a class to calculate mesh dimentions to build the collision primitive it will save you a lot of time.
Specially if a modeller is working with you testing the meshes "in-game".

You could use bones to make the suspension follow the tire (but i dont know how to do it). May be using a manually controlled bone i think....

Grom

14-03-2007 19:05:44

how exactly do vehicles work in NxOgre? I can't find any example code, but I do see the presence of a wheelShape. However, from the line "float _radius = 0.5f; // Temp" at the top of the constructor, I'm assuming it's incomplete. Is there working vehicle (4 wheels and a chassis) code anywhere?

betajaen

14-03-2007 19:26:39

Only what exists on my hard drive.

This post explains how to use it-> http://www.ogre3d.org/phpBB2addons/view ... 1337#21337

I can provide the wheel mesh if you need a reference of the correct wheel orientation when modelling, but apart from that. It's fairly simple.

Grom

15-03-2007 13:44:45


I can provide the wheel mesh if you need a reference of the correct wheel orientation when modelling


yes please

betajaen

15-03-2007 13:48:19

Here you go.

Grom

15-03-2007 14:06:03



I got the same skew with my own mesh. any idea why that might happen?

betajaen

15-03-2007 14:08:50

Looks like a quaternion gone wonky.

This is the full code for Tutorial 702

/*

#####################################################################
# #
# NxOgre Tutorial 702 : Suspension and Torque #
# #
# #
# Written by Robin Southern #
# #
#####################################################################

Preamble:

If you don't know the difference between a SceneManager and a Scene-
Node you should start with the Ogre tutorials at the Wiki[1]. As
these tutorials tend to push the Ogre code aside and deal more with
nxOgre.

[1] http://www.ogre3d.org/wiki/


Documentation and Tutorials:

- Betajaen's Guide to NxOgre, Chapter ?
- http://www.nxogre.org/NxTutorial102
- PhysX Training Programs, Lesson 102


Keys:

- Escape Quit
- F1 Save a screenshot
- F2 Debug Rendering On
- F3 Debug Rendering Off
- I,J,K,L Apply torque to the sphere in the X or Z Axis.
- U,M Apply torque to the sphere in the Y axis.


*/

#include "nxOgre.h"
#include "Ogre.h"
#include "tutorialApplication.h"

using namespace nxOgre;
using namespace Ogre;
using namespace std;

class NxTutorial : public SimpleTutorial {

public:


world *mWorld;
scene *mScene;

body *myCube;


wheelSet myWheels;

SceneNode* testWheel;

float wheelShapeRollAngle;

SceneNode *cm;

void start() {


mWorld = new world();
mScene = mWorld->createScene("Main",mSceneMgr);
mScene->hasGravity();
mScene->hasFloor();

mScene->createStaticBody("terrain", "", new heightfieldShape("terraincm.png", 4096,4096,300,513,513));

for (int i=0;i<16;i++)
mScene->createBody("", "cube.1m.mesh", new cubeShape(1), 10, Vector3(16,8+i,16));

//mScene->createStaticBody("Slide","cube.1m.mesh",new cubeShape(Vector3(16,0.1,16)),params<rigidbody>("scale:16 0.1 16"),pose(Vector3(0,1,0),Quaternion(Radian(Degree(10)),Vector3(1,0,0))));

myCube = mScene->createBody("myCube","racecar.mesh",new cubeShape(Vector3(1,1,3)),100.0f,Vector3(2048,80,2048));
myCube->mActor->setCMassOffsetLocalPosition(NxVec3(0,-1,0));

myWheels = wheelSet::createFourWheelSet(myCube, Vector3(-1,-0.1f,1.25f), Vector3(-0.75f,-0.1f,-1.25f), 2.5f);
myWheels.addEntities("wheel50cmx10cmx50cm.mesh");

myCube->mNode->attachObject(mCamera);
mCamera->setPosition(0,0,0);

}

//////////////////////////////////////////////////////////////////////////////////////////////////


void stop() {

myCube->mNode->detachObject(mCamera->getName());
mSceneMgr->getRootSceneNode()->attachObject(mCamera);

delete mWorld;
}

//////////////////////////////////////////////////////////////////////////////////////////////////


void newFrame(float _time) {

mCamera->lookAt(myCube->getGlobalPosition());

float kph = myCube->mActor->getLinearVelocity().magnitude() * 3.6;

mCaption3->setCaption("KPH " + StringConverter::toString(kph));

if (isKeyDown(X)) {
myWheels.turn(Degree(1));
}
else if (isKeyDown(NEG_X)) {
myWheels.turn(Degree(-1));
}

if (isKeyDown(Z)) {
myWheels.setMotorTorque(75);
}
else if (isKeyDown(NEG_Z)) {
myWheels.setMotorTorque(-75);
}
else {
myWheels.setMotorTorque(0);
}


}


//////////////////////////////////////////////////////////////////////////////////////////////////

void getTutorialSettings() {
mTutorialName = "702";
mTutorialDescription = "Suspension and Torque";
}

//////////////////////////////////////////////////////////////////////////////////////////////////

void prestart() {}
void prestop() {}
void GUIbuttonPressed(BetaGUI::Button *ref) {}

//////////////////////////////////////////////////////////////////////////////////////////////////

};


TUTORIAL_VOIDMAIN("118, Suspension and Torque")


See if anything is missing or iffy in your code.

Grom

15-03-2007 16:00:10

alright I set up my tires so that they have a radius of 0.5. I altered the code a bit so as to take the radius as input, for some reason 0.25 works properly with a mesh set up as 0.5 radius. (maybe physx is taking diameter instead of radius?) then in wheel::addEntity I set the scale of the Entity to Ogre::Vector3(radius*4, radius*4, radius*4).

Now the tires are on the ground and scaleable