English 中文(简体)
我如何把2D屏幕改为2D地图,以公开方式进行协调 GL?
原标题:How do I transform a 2D screen coordinate to a 2D map coordinate in openGL?
  • 时间:2011-11-13 01:09:20
  •  标签:
  • opengl

I am working on a small game that uses a 2D map (made up out of tiles). I would now like to find out what tile is being selected by the user. As the map can move and scale (glTranslate(), glScale(), etc), I m not entirely sure a direct conversion is possible. So how do I obtain the "map" coordinates from the mouse coordinates on my screen?

最佳回答

If the map is drawn in 2D on the screen with no perspective, then it should just be some basic math to determine which tile is selected, based on the tile width and the translation.

例如,你可以做这样的事情:

int selectedTileX = (translatedX + mouseX) / tileWidth;
int selectedTileY = (translatedY + mouseY) / tileHeight;

However this is specific to your engine.


If it is drawn with perspective, then you can use gluUnProject to get object coordinates out of window coordinates (or you could mimic this function with your own).

问题回答

暂无回答




相关问题
OpenGL 3D Selection

I am trying to create a 3D robot that should perform certain actions when certain body parts are clicked. I have successfully (sort of) implemented picking in that if you click on any x-plane part, it ...

CVDisplayLink instead of NSTimer

I have started to implement cvDisplayLink to drive the render loop instead of nstimer, as detailed in this technical note https://developer.apple.com/library/archive/qa/qa1385/_index.html Is it ...

Can the iPhone simulator handle PVR textures?

I have a really weird problem with PVR textures on the iPhone simulator- the framerate falls through the floor on the iPhone simulator, but on the iPhone itself it works just fine. Has anyone had any ...

Calculate fps (frames per second) for iphone app

I am using an opengl es iphone application. What is the most accurate way to calculate the frames per second of my application for performance tuning?

Java - Zoom / 3D Data Visualization Libraries

What are the best libraries/frameworks for doing 3D and/or Zoom interfaces in Java? I d like to be able to do some prototyping of creating new types of interfaces for navigating within data and ...

FLTK in Cygwin using Eclipse (Linking errors)

I have this assignment due that requires the usage of FLTK. The code is given to us and it should compile straight off of the bat, but I am having linking errors and do not know which other libraries ...

热门标签