Skip to content
Browse files

* Added function to translate screen coords to game coords.

  • Loading branch information...
1 parent 4a6a77f commit 2101f196db61e3ec85dc87b523a0b0f2dfb020b0 @bobbens committed Oct 23, 2010
Showing with 24 additions and 0 deletions.
  1. +23 −0 src/opengl_render.c
  2. +1 −0 src/opengl_render.h
View
23 src/opengl_render.c
@@ -529,6 +529,29 @@ void gl_gameToScreenCoords( double *nx, double *ny, double bx, double by )
/**
+ * @brief Converts screen coordinates to ingame coordinates.
+ *
+ * @param[out] nx New ingame X coord.
+ * @param[out] ny New ingame Y coord.
+ * @param bx Screen X coord to translate.
+ * @param by Screen Y coord to translate.
+ */
+void gl_screenToGameCoords( double *nx, double *ny, int bx, int by )
+{
+ double cx,cy, gx,gy, z;
+
+ /* Get parameters. */
+ cam_getPos( &cx, &cy );
+ z = cam_getZoom();
+ gui_getOffset( &gx, &gy );
+
+ /* calculate position - we'll use relative coords to player */
+ *nx = (bx - SCREEN_W/2. - gx) / z + cx;
+ *ny = (by - SCREEN_H/2. - gy) / z + cy;
+}
+
+
+/**
* @brief Blits a sprite, position is relative to the player.
*
* Since position is in "game coordinates" it is subject to all
View
1 src/opengl_render.h
@@ -21,6 +21,7 @@ void gl_exitRender (void);
* Coordinate translation.
*/
void gl_gameToScreenCoords( double *nx, double *ny, double bx, double by );
+void gl_screenToGameCoords( double *nx, double *ny, int bx, int by );
/*

0 comments on commit 2101f19

Please sign in to comment.
Something went wrong with that request. Please try again.