3d position from mouse click

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
after-life
Posts: 69
Joined: Wed Mar 30, 2005 8:16 am
Location: Keerbergen, Belgium

3d position from mouse click

Post by after-life »

hi, im trying to make the basics of a mmorpg.
I have a 3d camera set up and im planning to make the player move around with mouse clicks, my only problem is: how do i get the 3D position on a map after a mouseclick?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

use getRayFromScreenCoordinate to get a ray coming from your mouse position in to the scene, then check for a collision with the floor.
first see the collision tutorial to set up your floor's triangle selector

Code: Select all

line3d<f32> raytrace = colmgr->getRayFromScreenCoordinates(device->getCursorControl()->getPosition(), camera);
colmgr->getCollisionPoint(raytrace, triangleselector, tracetarget, tracetriangle);
after-life
Posts: 69
Joined: Wed Mar 30, 2005 8:16 am
Location: Keerbergen, Belgium

Post by after-life »

i think this returns a triangle, not a 3d vector,
and what is tracetarget and tracetriangle supposed to be?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

it returns a triangle as well as the vector, tracetarget is the vector
see
http://irrlicht.sourceforge.net/docu/cl ... nager.html
after-life
Posts: 69
Joined: Wed Mar 30, 2005 8:16 am
Location: Keerbergen, Belgium

Post by after-life »

k thx, i get it know, ill try to implement it :D
Irme
Posts: 55
Joined: Sat Jul 16, 2005 8:24 am

Post by Irme »

So i've implemented this into my current project as well. My only problem is - it can be very hard for my ray to collide sometimes. Sometimes i have to hover around the object until it registers my mouse there. But if i turn move the camera to a different angle its a lot easier to hover over and get the collision event to happen with the mouse cursor.

I guess my question is this - How can i make it more sensitive to detect the collision to make sure my mouse is over a node from no matter where the camera is?

I've tried changing the 'minpolycount' to various different numbers not seeing any change either. Can somebody point me in the right direction?


Thanks
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Irme, you can try to use a bounding box collision, "getCollisionSelectorFromBoundingBox" or someting like that, i might be a little of..

If you use this itll just use the box for collision and make it alot easier to select things from all angles, on the downside if you hav too many small objects side by side it may be a little inaccurate.

Cheers
Irme
Posts: 55
Joined: Sat Jul 16, 2005 8:24 am

Post by Irme »

Thanks for the info - i'll give it a try when i get home :)
Irme
Posts: 55
Joined: Sat Jul 16, 2005 8:24 am

Post by Irme »

Well it did help, I'm now using "GetSceneNodeFromScreenCoordinatesBB" and passing it the mouse coords and its working much better, but there are a few models that don't work right, unless i move the camera around a bit. Any other sugestions?

I can post a video to explain what is happening if it will help.
Post Reply