Jump to content
  • Advertisement
Sign in to follow this  
bradbobak

OpenGL 2d to 3d

This topic is 4865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys.. I'm new to openGL.. I don't know if this is the right place to post this or for beginners.. but here goes anyhow.. I set my projection 'glFrustum(-1.0, 1.0, -1.0, 1.0, 10.0, 100.0); then I draw some quads (anyx, anyy, -90.0f) (I'm using SDL) then I'd like to get mouse coords from sdl and find out what quad I'm in.. (This is basically for a 2dish done in 3d rpg) Pointers, references, ideas, comments, etc welcome -- Bradd

Share this post


Link to post
Share on other sites
Advertisement
okay, that looks interesting and may be useful in the future.. but let me explain what I'm
trying to do here..

I make an openGL window with a projection.. my camera is top-down..

I will be using a grid (at a constant Z).. I will then get the mouse coords via SDL..

my grid center will be (0, 0, constZ).. going out in each direction by 1.0f.. so
each grid BOX will be (x * 1.0f, (x+1) * 1.0f), same for Y, and Z is constant


now my X and Y for the grid will be a multiple of 1.0f BUT I get screen coords from SDL which I'd like to find out what X, Y grid box (on a constZ) the mouse pointer is in..

basically I want to map SDL's x, y to a box on constZ and find out what box I'm in..

I don't care about any renderings above or below this constZ.. I want to know the grid box on the constZ plane that SDL's x, y map to..

hopefully this is understandable..


Thanks, Bradd

Share this post


Link to post
Share on other sites
I still say you need gluUnproject. The reason for this is the calculations are dependant on the view matrix (the camera's position).

If your camera never moves along Z, then you could feasably calculate some kind of mapping from screen space to your map space, and just multiply the coordinates by that scale. For example, if one grid tile takes _exactly_ five screen space pixels, you can just divide the mouse coordinates by five, offset by the map origin and you have map coordinates.

It probably won't be perfect, you'll have to do a bunch of calculations by hand, and it won't be any better than not using gluUnproject in the first place.

Share this post


Link to post
Share on other sites
If your camera never moves along Z,[/Quote]

Trust me on this one use glUnProject, i tried doing the calculations self, and i still did scaling *how ever i had an ortho scene*, but stick the gluUnproject the reason being is that once you have done it right you can look from anywhere in your scene and still get the correct coordinates *an absolute must for a 3d strategy game*

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!