Walaber! your vehicles arn't working

danharibo

14-01-2007 12:51:13

Urm so yeah, i copyd your vehicles class, rmoved bits and i got this:
#include "Vehicle.h"


int Vehicle::mEntityCount = 5;

// Vehicle constructor. this creates and sets up the entire vehicle!
Vehicle::Vehicle(Ogre::SceneManager* mgr, OgreNewt::World* world, Ogre::Vector3& position, Ogre::Quaternion& orient) : OgreNewt::Vehicle()
{
// save the scene manager
mSceneMgr = mgr;
mWorld = world;


// first thing we need to do is create the rigid body for the main chassis.
Ogre::Entity* bod = mSceneMgr->createEntity("Vehicle"+Ogre::StringConverter::toString(mEntityCount++), "RR_Car.mesh");
Ogre::SceneNode* bodNode = mSceneMgr->createSceneNode();
//getRootSceneNode()->createChildSceneNode();
bodNode->attachObject(bod);
OgreNewt::Collision* mColl;
OgreNewt::Body* mBod;
mColl = new OgreNewt::CollisionPrimitives::ConvexHull(mWorld,bodNode);
mBod = new OgreNewt::Body(mWorld,mColl);
delete mColl;

//now that we have defined the chassis, we can call the "init()" function. this is a helper function that
// simply sets up some internal wiring of the vehicle class that makes eveything work :) it also calls the virtual
// function "setup" to finish building the vehicle.
// you pass this function the body to be used as the main chassis, and the up direction of the world (for suspension purposes).
init( mBod, Ogre::Vector3(0,1,0) );

// the above function calls our "setup" function, which takes care of the rest of the vehicle setup.

}


// virtual function - setup(). this actually builds the tires, etc.
void Vehicle::setup()
{
// okay, we have the main chassis all setup. let's do a few things to it:
m_chassis->setStandardForceCallback();
// we don't want the vehicle to freeze, because we'll be unable to control it.
m_chassis->setAutoFreeze(0);


// okay, let's add tires!
// all offsets here are in local space of the vehicle.
Ogre::Vector3 offset(1.8,-1.6,0.87);

int tireNum = 0;
for (int x=-1;x<=1;x+=2)
{
for (int z=-1;z<=1;z+=2)
{

// okay, let's create the tire itself. we'll use the OgreNewt::Vehicle::Tire class for this. most of the
// parameters are self-explanatory... try changing some of them to see what happens.
Ogre::Quaternion tireorient = Ogre::Quaternion(Ogre::Degree(0), Ogre::Vector3::UNIT_Y);
Ogre::Vector3 tirepos = offset * Ogre::Vector3(x,0.5f,z);
Ogre::Vector3 pin(0,0,x);
Ogre::Real mass = 15.0;
Ogre::Real width = 0.3;
Ogre::Real radius = 0.5;
Ogre::Real susShock = 30.0;
Ogre::Real susSpring = 200.0;
Ogre::Real susLength = 1.2;
bool steering;


// first, load the visual mesh that represents the tire.
Ogre::Entity* ent = mSceneMgr->createEntity("Tire"+Ogre::StringConverter::toString(mEntityCount++), "RR_Car_wheel.mesh");
// make a scene node for the tire.
Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
node->attachObject( ent );
node->setScale( Ogre::Vector3(radius, radius, width) );

if (x > 0)
steering = true;
else
steering = false;

// create the actual tire!
vTire* tire = new vTire(this, tireorient, tirepos, pin, mass, width, radius,
susShock, susSpring, susLength, 0, steering);

// attach the tire to the node.
tire->attachToNode( node );

}
}

}


Vehicle::vTire::~vTire()
{
// destroy entity, and scene node.
Ogre::Entity* ent = (Ogre::Entity*)m_node->getAttachedObject(static_cast<unsigned short>(0));
m_node->detachAllObjects();
m_node->getCreator()->destroyEntity( ent );
m_node->getParentSceneNode()->removeAndDestroyChild( m_node->getName() );
}

Vehicle::~Vehicle(void)
{
std::vector< vTire* > toDelete;

// delete tire objects.
for (vTire* tire = (vTire*)getFirstTire(); tire; tire=(vTire*)getNextTire(tire))
{
toDelete.push_back( tire );
}

while (!toDelete.empty())
{
vTire* tire = toDelete.back();
delete tire;
toDelete.pop_back();
}

// finally, destroy entity and node from chassis.
Ogre::Entity* ent = (Ogre::Entity*)m_chassis->getOgreNode()->getAttachedObject(static_cast<unsigned short>(0));
m_chassis->getOgreNode()->detachAllObjects();
m_chassis->getOgreNode()->getCreator()->destroyEntity( ent );
m_chassis->getOgreNode()->getParentSceneNode()->removeAndDestroyChild( m_chassis->getOgreNode()->getName() );

destroy();
}



// This is the important callback, which is the meat of controlling the vehicle.
void Vehicle::userCallback()
{

// foop through wheels, adding torque and steering, and updating their positions.
for (vTire* tire = (vTire*)getFirstTire(); tire; tire=(vTire*)getNextTire(tire))
{
// set the torque and steering! non-steering tires get the torque.

// is this a steering tire?
if (tire->mSteeringTire)
tire->setSteeringAngle( mSteering );
else
tire->setTorque( mTorque );

// finally, this command updates the location of the visual mesh.
tire->updateNode();
}

}



But it crashes, and i can't seem t find the crash.
it crashes here:
mBod = new OgreNewt::Body(mWorld,mColl);

Maklaud

14-01-2007 13:17:11

Why you commented this line:
//getRootSceneNode()->createChildSceneNode();

Maybe this is the right variant? :
Ogre::SceneNode* bodNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();

danharibo

14-01-2007 13:34:23

It still crashes,
it points me to:
const NewtonWorld* getNewtonWorld() const { return m_world; }
from
mBod = new OgreNewt::Body(mWorld,mColl);

iversons

16-01-2007 14:47:33

I do not think it is not working, please try. I have tried the vehicle one and it should be okay.

walaber

17-01-2007 03:01:21

most likely you have not created a world object. do you have a line in your code somewhere where you create the OgreNewt::World object?

danharibo

18-01-2007 16:47:53

yes, i fixed it, but the suspension exploded once it bounces.