Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* Added function to translate screen coords to game coords.

  • Loading branch information...
commit 2101f196db61e3ec85dc87b523a0b0f2dfb020b0 1 parent 4a6a77f
Edgar Simo-Serra authored

Showing 2 changed files with 24 additions and 0 deletions. Show diff stats Hide diff stats

  1. +23 0 src/opengl_render.c
  2. +1 0  src/opengl_render.h
23 src/opengl_render.c
@@ -529,6 +529,29 @@ void gl_gameToScreenCoords( double *nx, double *ny, double bx, double by )
529 529
530 530
531 531 /**
  532 + * @brief Converts screen coordinates to ingame coordinates.
  533 + *
  534 + * @param[out] nx New ingame X coord.
  535 + * @param[out] ny New ingame Y coord.
  536 + * @param bx Screen X coord to translate.
  537 + * @param by Screen Y coord to translate.
  538 + */
  539 +void gl_screenToGameCoords( double *nx, double *ny, int bx, int by )
  540 +{
  541 + double cx,cy, gx,gy, z;
  542 +
  543 + /* Get parameters. */
  544 + cam_getPos( &cx, &cy );
  545 + z = cam_getZoom();
  546 + gui_getOffset( &gx, &gy );
  547 +
  548 + /* calculate position - we'll use relative coords to player */
  549 + *nx = (bx - SCREEN_W/2. - gx) / z + cx;
  550 + *ny = (by - SCREEN_H/2. - gy) / z + cy;
  551 +}
  552 +
  553 +
  554 +/**
532 555 * @brief Blits a sprite, position is relative to the player.
533 556 *
534 557 * Since position is in "game coordinates" it is subject to all
1  src/opengl_render.h
@@ -21,6 +21,7 @@ void gl_exitRender (void);
21 21 * Coordinate translation.
22 22 */
23 23 void gl_gameToScreenCoords( double *nx, double *ny, double bx, double by );
  24 +void gl_screenToGameCoords( double *nx, double *ny, int bx, int by );
24 25
25 26
26 27 /*

0 comments on commit 2101f19

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