View Full Version : point and click pathfinding in a 3D engine
03 March 2006, 06:33 AM
I am a beginner to 3d game design, and I am beginning to experiment with a 3d game engine.
Here's what I'm trying to do (basically) I have a 3d scene with a character. The camera will move to follow the character in the scene. Basically I want the user to click on a point on the ground, and have the character walk there.
Now pathfinding is a whole 'nother story, and I'll deal with that next- but- how can I translate the 2d mouse position into a point in 3d space on the ground plane? Conceptually? I haven't even started coding this yet but I'm trying to think out how it would work.
I mean, if it was a flat, 2D game, the X position of the mouse and Y position of the mouse would be the same as that point on the flat floor. But since it's in 3D, I can't think of a way to to translate those and X and Y absolute positions on the screen into a corresponding place on the floor plane.
I'm sorry if that's not clear. (I'm saying I want to do something like Ankh or Out From Boneville, point and click but in a 3D world.)
Thanks ahead of time for helping a 'newb.
03 March 2006, 06:39 AM
My mistake, i meant to post this in game programming. I'll dupe it there.
03 March 2006, 07:06 AM
You could render additional info to the framebuffer (i mean not only colors). For instance, for any pixel in the FB you'd have your RGB(A) channels plus a triangle index. The index wouldn't show on screen, but you would be able to read it back from the FB after the scene was rendered. You then know what triangle was used to render pixel(x,y). If a sole triangle number is not accurate enough for your needs, you could add a component to your framebuffer where you would render barycentric coordinates. Triangle index + bary coords would be enough to find the world space coordinates in a given scene.
How you implement this depends vastly on your library, and there are probably additional complexities but this is only the general idea after all :) . If your engine is OpenGL based, have a look at the red book. There's a chapter on this topic.
Hope it helps.
03 March 2006, 06:25 PM
THank you! I'm basically a beginner, and although I think I follow the concept you're suggesting ('render' an invisible layer, falt on the screen with color values, so that I could read the color value clicked and gain a coordinate from this).
I'll have to look up what barycentric means.
All your help is appreciated. Just to note I moved this over to game development (http://forums.cgsociety.org/showthread.php?t=338153) because this may have been the wrong forum to post in.
03 March 2006, 06:25 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.