Page 1 of 1

Coordinate system/ dynamically placing objects on the map

Posted: Fri Jun 08, 2007 1:19 pm
by Worteltaart
Consider the following.

I'm loading an XML file containing some (static) world data, for example trees and rocks on certain places.

This produces tiles of which the world is composed (for ease think of a 2d map, so only x en y coordinates exist), so while running the application we see a world in which we can travel.

But, now I would want to add object to the world dynamically, like when i click a certain button and then click a certain spot on the map I want a mesh to be drawn on that position.

Ofcourse I would need to know the x and y coordinates of the point specified.

Here comes the question, what is a good why of getting the coordinates of the point clicked ON the map, should we come up with our own coordinate system, or how should we handle this?

Posted: Fri Jun 08, 2007 2:25 pm
by LLDD
If I understood it properly, you should do something like this:
1) Get a ray using getRayFromScreenCoordinates.
2) Make it collide with your level.
3) Place a new object on the collission coordinates.
________
Justin bieber

Posted: Fri Jun 08, 2007 2:32 pm
by Worteltaart
Hmm ok, I have to look into that, not very familiar with collision yet.

And just 'asking' the current cursor location in the worldspace?

Posted: Fri Jun 08, 2007 3:40 pm
by bitplane
same thing. each pixel on your screen exists as a 3d line within your cameras fustrum. you can get this line using getRayFromScreenCoordinates like LLDD said, and use this to find a collision with your world (see the collision example)