Find face index

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
Willow
Posts: 2
Joined: Fri Jan 22, 2016 12:13 am

Find face index

Post by Willow »

I would like to know if i can identify the face i found from the getCollisionPoint function.
For example on a chess board mesh, i find the current collided face have index 32, so i can process it to find the case on the chessboard.
What the method to implement that feature?

Code: Select all

 
core::line3d<f32> raytrace = collMan->getRayFromScreenCoordinates(device->getCursorControl()->getPosition(), cam);
core::vector3df out1;
core::triangle3df out2;
scene::ISceneNode* node2;
if (collMan->getCollisionPoint(raytrace, chessBoardNode->getTriangleSelector(), out1, out2, node2) == true)
{
    // findIndexFromTriangle(out2) ???
}
 
Thanks to help me a bit, i am lost on that part
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Find face index

Post by CuteAlien »

You can't get the index (the interface is used in different ways - sometimes there is more than one array involved so a index wouldn't work there). But in case of a chessboard it should be possible to calculate the chess-board position from the returned collision position easily. If the board is unrotated it's probably something like (int) ((collision.x-board.left.x) / (board.width/8.f)) and (int) ((collision.z-board.left.y) / (board.height8.f)). With rotated board nearly the same - but transfrom the collision results first by the inverse of the board-node transformation matrix.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Find face index

Post by Mel »

A straight answer to your question would be no, irrlicht won't identify faces in its triangle selectors, or relate the found faces in any way to the actual meshes, you need something else. But building your own structure can't be very complex.

I figure that you're doing a chess game and that you want to pick both pieces and destination squares. Perhaps you could use empty nodes to reference the squares of the chessboard and pick them just as any other node, as empty nodes have bounding boxes you can reference. But you have to set them. I hope this helps! good luck!
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Willow
Posts: 2
Joined: Fri Jan 22, 2016 12:13 am

Re: Find face index

Post by Willow »

Thanks for your responses. Finally i will lets the 64 cubes on the chessboard :lol:
Post Reply