/** * @brief Converts ingame coordinates to screen coordinates. * * @param[out] nx New screen X coord. * @param[out] ny New screen Y coord. * @param bx Game X coord to translate. * @param by Game Y coord to translate. */ void gl_gameToScreenCoords( double *nx, double *ny, double bx, double 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 - cx) * z + gx + SCREEN_W/2.; *ny = (by - cy) * z + gy + SCREEN_H/2.; }
/** * @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 Plays a sound based on position. * * @param sound Sound to play. * @param px X position of the sound. * @param py Y position of the sound. * @param vx X velocity of the sound. * @param vy Y velocity of the sound. * @return Voice identifier on success. */ int sound_playPos( int sound, double px, double py, double vx, double vy ) { alVoice *v; alSound *s; Pilot *p; double cx, cy, dist; int target; if (sound_disabled) return 0; if ((sound < 0) || (sound >= sound_nlist)) return -1; target = cam_getTarget(); /* Following a pilot. */ p = pilot_get(target); if (target && (p != NULL)) { if (!pilot_inRange( p, px, py )) return 0; } /* Set to a position. */ else { cam_getPos(&cx, &cy); dist = pow2(px - cx) + pow2(py - cy); if (dist > pilot_sensorRange()) return 0; } /* Gets a new voice. */ v = voice_new(); /* Get the sound. */ s = &sound_list[sound]; /* Try to play the sound. */ if (sound_sys_playPos( v, s, px, py, vx, vy )) return -1; /* Actually add the voice to the list. */ v->state = VOICE_PLAYING; v->id = ++voice_genid; voice_add(v); return v->id; }
/** * @brief Renders the background images. */ static void background_renderImages( background_image_t *bkg_arr ) { int i; background_image_t *bkg; double px,py, x,y, xs,ys, z; /* Must have an image array created. */ if (bkg_arr == NULL) return; /* Render images in order. */ for (i=0; i<array_size(bkg_arr); i++) { bkg = &bkg_arr[i]; cam_getPos( &px, &py ); x = px + (bkg->x - px) * bkg->move - bkg->scale*bkg->image->sw/2.; y = py + (bkg->y - py) * bkg->move - bkg->scale*bkg->image->sh/2.; gl_gameToScreenCoords( &xs, &ys, x, y ); z = cam_getZoom(); z *= bkg->scale; gl_blitScale( bkg->image, xs, ys, z*bkg->image->sw, z*bkg->image->sh, &bkg->col ); } }