collision detection with rotated mesh?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
warden
Posts: 11
Joined: Thu Nov 24, 2005 3:54 pm

collision detection with rotated mesh?

Post by warden »

Hi there,

i'm doing a "top-view-car-drive-through-a-city"-game. nothing big, just a simple thing. I use a testscenenode as a car and a q3map as a city mesh.

Viewing setup is: map is loaded in and rotated by -90 degrees around x, so it fits into the x-y-plane, camera is looking from -z into the scene, thus looking at the car from top, just like in micro machines games. X is to the right, Y is up vector.

However, adding collision detection causes very strange behaviour of my car... it's not steerable to the right and sticks to the lower end of the map.

Could it be that the triangle selector selects the triangles as they were still in the x-z-plane? that it doesn't get the rotation of the mesh node?

plz share your ideas with me and have a look at my code:

Code: Select all

//add quake3 map with city architecture, rotated by 90 deg around x
device->getFileSystem()->addZipFileArchive("../../media/citymap.pk3");
scene::IAnimatedMesh* citymesh = smgr->getMesh("city.bsp");
scene::ISceneNode* citynode = 0;
if (citymesh) {
	citynode = smgr->addOctTreeSceneNode(citymesh->getMesh(0));
	citynode->setRotation(core::vector3df(-90,0,0));
	citynode->setMaterialFlag(video::EMF_LIGHTING, true);
	citynode->getMaterial(0).Shininess = 20.0f;
}
	
// add collision detection
scene::ITriangleSelector* cityselector = smgr->createOctTreeTriangleSelector(citymesh->getMesh(0), citynode, 16);
citynode->setTriangleSelector(cityselector);
cityselector->drop();

//add a camera, looking onto the x-y plane from z, with y as up-vector
scene::ICameraSceneNode* cam = smgr->addCameraSceneNode();
cam->setTarget(core::vector3df(0,0,0));
cam->setPosition(core::vector3df(0,0,-300));
cam->setRotation(core::vector3df(0,0,0));
cam->setUpVector(core::vector3df(0,1,0));


//add the car... myCar is a testscenenode with modified control and texturing etc
myCar* car = new myCar(10,core::vector3df(0,0,-50),core::vector3df(1,1,1),0,smgr,0.2,15,0.01);
scene::ISceneNodeAnimatorCollisionResponse* car_anim = smgr->createCollisionResponseAnimator(cityselector, car->getNode(),core::vector3df(0.01,0.01,0.01),core::vector3df(0,0,1),core::vector3df(0,0,0), 4);
car->getNode()->addAnimator(car_anim);
car_anim->drop();
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I've not looked at your code in depth, and i'm not sure if i understand exactly what your problem is, but could it be due to gravity? You said the car sticks to the bottom of the map, and it sounds like you have your map vertically in the world coordinates (as it's int he X,Y plane), and so if your car had gravity on it would just stay at the bottom of the map i guess...

The collision detection shouldn't ignore rotation and such of the node though.
Image Image Image
Guest

Post by Guest »

thanks for your note, it's not the gravity. i miscompiled the q3 map and had a little error in it with some overlapping objects. pheeeew!

now it works just right. thanks anyway :)
Post Reply