Scaling colliders

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
Baiame
Posts: 41
Joined: Sun Oct 15, 2006 11:33 am

Scaling colliders

Post by Baiame »

Hello. Searched the forums, and couldn't find anything on this problem (surprisingly).

I wanted to do raycasting on a large plane. I did this:

Code: Select all

IAnimatedMesh* planeMesh=smgr->getMesh("plane.x");
 IAnimatedMeshSceneNode* planeNode=smgr->addAnimatedMeshSceneNode(planeMesh);
 planeNode->setRotation(vector3df(180, 0, 0));
 planeNode->setScale(vector3df(1000.0, 1, 1000.0));
 planeNode->setVisible(false);
Not very pretty. Irrlicht doesn't seem to have a plane primitive, so I loaded a model. And even though the mesh is static, I created an IAnimatedMesh, as I couldn't find a way to load a model as a normal IMesh (without an intermediatory IAnimatedMesh stage). Anyway, I don't think that has anything to do with my problem. For the collision:

Code: Select all

 ITriangleSelector* planeCollision = smgr->createTriangleSelector(planeMesh->getMesh(0), planeNode);
 planeNode->setTriangleSelector(planeCollision);
 planeCollision->drop();
And then, in the loop:

Code: Select all

 cmgr->getCollisionPoint (cmgr->getRayFromScreenCoordinates(mouse->getPosition()),  
 planeCollision, mousePointAt, triDump);
It kind of works (only for a tiny part of the plane). I figured out that the problem is that the collider is copied from the mesh, and is not scaled along with the scene node it is added to. I think I need a way to scale a collider (I looked through the IMesh, IAnimatedMesh, ITriangleSelector, and ISceneNode classes in the doco, and couldn't find a way). Any help would be greatly appreciated.
Gladius_Coldhead
Posts: 56
Joined: Thu Oct 12, 2006 5:15 am

Post by Gladius_Coldhead »

Try to believe and understand,
There´s nothing you can do, believe: it´s true
A river of wine refresh your eyes,
Calling us to rock our souls

Even you still laughing at me
You think that I´m the Foll
The fool is you!
So I can tell: I leave my words,
There´s nothing you can do,
Believe: it´s true!
Baiame
Posts: 41
Joined: Sun Oct 15, 2006 11:33 am

Post by Baiame »

^ So it's impossible? Thanks for the help, but it would've been better had you stated that fact through something other than obscure lyrics, haha.

Anyway, I tried to just make the plane mesh bigger, which was a mission in itself. It seems that the .x exporter that Blender includes sees the need resize the mesh to within 1*1*1 when you export, so I had to manually edit the .x file. Anyway, I decided I would raycast to the plane, then move the plane to the raycast position.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

If all you want to do is find where a line from the camera through the mouse cursor intersects a plane, I don't understand why you're not using the plane3d template. It has a getIntersectionWithLine() method that you can use to do exactly that. Just use the collision manager to get a line from the camera and mouse position, and then find the intersection points of the line and the plane...

Regardless, you shouldn't have to do any scaling on the selector. The selector is supposed to use the scene nodes transformation matrix to transform the triangles returned in the call to getTriangles(). If you make the plane visible you should see it and the selector should return triangles that make up that plane. You might try removing the setVisible() call to make absolutely sure that the plane is as big as hou think it should be.

Travis
Baiame
Posts: 41
Joined: Sun Oct 15, 2006 11:33 am

Post by Baiame »

getTriangles()? What class is that function a part of? I couldn't find it in the doco. I had checked with a visible mesh, and it definitely was the size I expected (using my method). I don't know anything about this getTriangles() function, so I was probably doing somethng wrong.

Anyway, thanks for informing me of the plane3d template. That should make life easier.

EDIT- Damn, I can't get the getIntersectionWithLimitedLine function to work. I'm doing:

Code: Select all

plane->getIntersectionWithLimitedLine(cam->getPosition(), 
cmgr->getRayFromScreenCoordinates(mouse->getPosition()), 
mousePointAt);
"plane" is a plane3df, "cmgr" is my scene collision manager, and mousePointAt is a vector3df. I get a "no matching function for call to `irr::core::plane3d<irr::f32>::getIntersectionWithLimitedLine(const irr::core::vector3df, irr::core::line3d<irr::f32>, irr::core::vector3df&)' error on the last line of the getIntersection function call. Why?

EDIT2- Nevermind, figured it out. I had forgotten that getRayFromScreenCoordinates returns a line3d, not a vector3d. I just put that parameter in brackets, stuck the .getVector() function call at the end, and now it works. Thanks for your help, everyone.
Post Reply