Think I'm too stupid for OgreOde atm. Anyhow, a question...

Problems building or running the engine, queries about how to use features etc.
AssiDragon
Greenskin
Posts: 145
Joined: Wed Apr 28, 2004 12:10 pm
Location: Hungary

Think I'm too stupid for OgreOde atm. Anyhow, a question...

Post by AssiDragon »

It's been (probably) asked a million times and now once more. :/

I've been trying to get OgreOde into my app, and well, it works but not as supposed to. I'm sure the mistake is somewhere among these lines as Monster's OgreOde tutorials work fine; however, the damn thing beats me as I was unable to spot the source of the problem after five hours of looking through and trying. I know this sounds very lame, but if someone would by any chance find the problem here, I'd be overly glad...

This snippet creates the OgreOde world:

Code: Select all

GamePhysicsTerrainListener::GamePhysicsTerrainListener(const String& mapname)
{
	_world = new OgreOde::World(mgr);

	_world->setGravity(Vector3(0,-9.80665,0));
	_world->setCFM(10e-5);
	_world->setERP(0.8);
	_world->setAutoSleep(true);
	_world->setContactCorrectionVelocity(1.0);
	_world->setShowDebugObjects(true);

	lt = new Col_Listener(); //That's the collision listening class.
	_world->setCollisionListener(lt);

	_terrain = new OgreOde::TerrainGeometry(mapname,_world->getDefaultSpace());
	_terrain->setHeightListener(this);

	_stepper = new OgreOde::ForwardFixedQuickStepper(0.001);
	_stepper->setAutomatic(OgreOde::Stepper::AutoMode_PostFrame,root);
	_stepper->setStepListener(lt);

	_space = _world->getDefaultSpace();
}
This one is used for adding new boxes into it:

Code: Select all

void GamePhysicsTerrainListener::addNewObject(SceneNode* node)
{
	OgreOde::MeshInformer mi;
	OgreOde::BoxGeometry* playerg = mi.createSingleStaticBox(node);
	OgreOde::Body* playerb = new OgreOde::Body();
	
	playerb->setMass(OgreOde::BoxMass(1, size));

	node->attachObject(playerb);
	playerg->setBody(playerb);

	LogManager::getSingleton().logMessage("NOTE: OgreODE object added.");

	_geoms.push_back(playerg);
	_bodies.push_back(playerb);
}
...and this is the collision callback class.

Code: Select all

class Col_Listener : public OgreOde::CollisionListener
{
public:
	Col_Listener(){}
	~Col_Listener(){}
	virtual bool collision(OgreOde::Contact* contact)
	{
		LogManager::getSingleton().logMessage("COLLISION!!!");
		return true;
	};
};
Hope is the first step on the road to disappointment.
User avatar
monster
OGRE Community Helper
OGRE Community Helper
Posts: 1098
Joined: Mon Sep 22, 2003 2:40 am
Location: Melbourne, Australia

Post by monster »

In what way does it not work as it's supposed to?

It crashes?
Things don't collide?
Things explode off into infinity?
It doesn't compile?

More information please.
:)
AssiDragon
Greenskin
Posts: 145
Joined: Wed Apr 28, 2004 12:10 pm
Location: Hungary

Post by AssiDragon »

Oh sorry! Well, it works all normal except it doesnt call the collision listener no matter what. Stepper works fine (the stepper listener showed it), I can apply forces and change the parameters of things all alright, but collisions somehow gone on vacation.

Great wrapper btw =)
Hope is the first step on the road to disappointment.
User avatar
monster
OGRE Community Helper
OGRE Community Helper
Posts: 1098
Joined: Mon Sep 22, 2003 2:40 am
Location: Melbourne, Australia

Post by monster »

So the collisions happen, they just don't get reported via your collision listener?

Try stepping through your code to see why the listener's not being called. Specifically, put some breakpoints in;

Code: Select all

int Geometry::collide(Geometry* geometry,CollisionListener* listener)
AssiDragon
Greenskin
Posts: 145
Joined: Wed Apr 28, 2004 12:10 pm
Location: Hungary

Post by AssiDragon »

Now this will sound stupid... how do I know if collisions happen or not? I thought when a collision takes place the collisionlistener is called and that makes the required steps, like determining if this collision is a collision or not afterall...

Objects just pass through each other here, but I thought this was because the listener doesnt get called. ...I guess I missed something? lol *goes back to look at ogreode*
Hope is the first step on the road to disappointment.
User avatar
monster
OGRE Community Helper
OGRE Community Helper
Posts: 1098
Joined: Mon Sep 22, 2003 2:40 am
Location: Melbourne, Australia

Post by monster »

If you hadn't set your collision listener properly (like you hadn't overriden the virtual method properly) then it wouldn't be getting called, but the default collision processing should ensure that everything still works OK.

In your case you say that things just pass through each other, in which case, no the collisions either aren't happening or are getting ignored or you're rejecting them in your callback.

In your case, I suspect it's because you aren't putting the boxes into a space, you should be doing;

Code: Select all

OgreOde::BoxGeometry* playerg = mi.createSingleStaticBox(node,_space);
You could also use createSingleDynamicBox instead, which does stuff like attaching the node and positioning the geometry automatically.
AssiDragon
Greenskin
Posts: 145
Joined: Wed Apr 28, 2004 12:10 pm
Location: Hungary

Post by AssiDragon »

EDIT:

You are not a monster. You are a magician. ;) This thing works great. 8)

Actually, I had another problem but much to my surprise this wasnt my code this time :D Applying the fix from this thread http://www.ogre3d.org/phpBB2/viewtopic. ... in+ogreode fixed it right away, and now everything works fine and happy.

Thanks a lot for your help and bearing that "little" ignorance from my side. 8) *goes back to his airplane crash simulation*
Hope is the first step on the road to disappointment.
User avatar
monster
OGRE Community Helper
OGRE Community Helper
Posts: 1098
Joined: Mon Sep 22, 2003 2:40 am
Location: Melbourne, Australia

Post by monster »

Yep that's the fix. Although actually, it shouldn't work. The getHeightAt bit should be;

Code: Select all

Real TerrainGeometry::getHeightAt(const Vector3& position)
{
    _ray.setOrigin(position);
    _ray_query->setRay(_ray);
    
    _height_at = 0.0;

    _ray_query->execute(this);
    return position.y - _height_at;
}

bool TerrainGeometry::queryResult(MovableObject *obj,Real distance)
{
    return false;
}

bool TerrainGeometry::queryResult(SceneQuery::WorldFragment *fragment,Real distance)
{
    _height_at = distance;
    return false;
}
And obviously you'll have to add the _height_at member to the TerrainGeometry declaration.

The (other) crucial bit is that you're using a version of the Terrain scene manager which respects the return value from your query listener. Either make the changes from that thread, or use 0.15.2 or Ogre, which has those changes in it.

The added bonus now is that you can run the Landscape demo in debug mode!

Glad you got it working!
User avatar
monster
OGRE Community Helper
OGRE Community Helper
Posts: 1098
Joined: Mon Sep 22, 2003 2:40 am
Location: Melbourne, Australia

Post by monster »

...and with those changes, and the new edge list builder in 0.15.2 meaning my dodgy Jeep mesh can cast stencil shadows, the Landscape demo runs even faster and looks even cooler;
Image
User avatar
monster
OGRE Community Helper
OGRE Community Helper
Posts: 1098
Joined: Mon Sep 22, 2003 2:40 am
Location: Melbourne, Australia

Post by monster »

There's also boxes to play around with;
Image
AssiDragon
Greenskin
Posts: 145
Joined: Wed Apr 28, 2004 12:10 pm
Location: Hungary

Post by AssiDragon »

Whoa, looks nice :D *wishes his laptop could cast shadows at 15+FPS lol*
Hope is the first step on the road to disappointment.
User avatar
SpannerMan
Gold Sponsor
Gold Sponsor
Posts: 446
Joined: Fri May 02, 2003 10:05 am
Location: UK

Post by SpannerMan »

Absolutely awesome screenshots monster!
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67

Post by sinbad »

@monster: Excellent, it's great to see the new release helped. Are you gonna commit these OgreODE changes to cvs?