mirror of
https://github.com/izzy2lost/wipeout-rewrite.git
synced 2026-07-06 00:20:05 -07:00
Merge pull request #145 from jnm-n64dev/shake-fix
reimplement camera shake
This commit is contained in:
@@ -37,6 +37,7 @@ void camera_update(camera_t *camera, ship_t *ship, droid_t *droid) {
|
||||
camera->last_position = camera->position;
|
||||
(camera->update_func)(camera, ship, droid);
|
||||
camera->real_velocity = vec3_mulf(vec3_sub(camera->position, camera->last_position), 1.0/system_tick());
|
||||
camera_update_shake(camera);
|
||||
}
|
||||
|
||||
void camera_update_race_external(camera_t *camera, ship_t *ship, droid_t *droid) {
|
||||
@@ -173,3 +174,18 @@ void camera_update_attract_random(camera_t *camera, ship_t *ship, droid_t *droid
|
||||
|
||||
(camera->update_func)(camera, ship, droid);
|
||||
}
|
||||
|
||||
void camera_set_shake(camera_t *camera, float duration) {
|
||||
camera->shake_timer = duration;
|
||||
}
|
||||
|
||||
void camera_update_shake(camera_t *camera) {
|
||||
if (camera->shake_timer > 0.0f) {
|
||||
camera->shake.x = (-(rand_float(0.0f, camera->shake_timer)) + (camera->shake_timer * 0.5f));
|
||||
camera->shake.y = (-(rand_float(0.0f, camera->shake_timer)) + (camera->shake_timer * 0.5f));
|
||||
camera->shake_timer -= system_tick();
|
||||
}
|
||||
else {
|
||||
camera->shake.x = camera->shake.y = camera->shake_timer = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#include "../types.h"
|
||||
#include "droid.h"
|
||||
|
||||
#define CAMERA_SHAKE_LONG (20.0f * (1.0f / 30.0f))
|
||||
#define CAMERA_SHAKE_SHORT (2.0f * (1.0f / 30.0f))
|
||||
|
||||
typedef struct camera_t {
|
||||
vec3_t position;
|
||||
vec3_t velocity;
|
||||
@@ -15,6 +18,8 @@ typedef struct camera_t {
|
||||
bool has_initial_section;
|
||||
float update_timer;
|
||||
void (*update_func)(struct camera_t *, ship_t *, droid_t *);
|
||||
vec2_t shake;
|
||||
float shake_timer;
|
||||
} camera_t;
|
||||
|
||||
void camera_init(camera_t *camera, section_t *section);
|
||||
@@ -28,5 +33,7 @@ void camera_update_attract_internal(camera_t *, ship_t *camShip, droid_t *);
|
||||
void camera_update_static_follow(camera_t *, ship_t *camShip, droid_t *);
|
||||
void camera_update_attract_random(camera_t *, ship_t *camShip, droid_t *);
|
||||
void camera_update_rescue(camera_t *, ship_t *camShip, droid_t *);
|
||||
void camera_set_shake(camera_t *, float duration);
|
||||
void camera_update_shake(camera_t *);
|
||||
|
||||
#endif
|
||||
|
||||
+4
-1
@@ -3,6 +3,7 @@
|
||||
#include "../platform.h"
|
||||
#include "../system.h"
|
||||
#include "../utils.h"
|
||||
#include "../render.h"
|
||||
|
||||
#include "object.h"
|
||||
#include "track.h"
|
||||
@@ -104,9 +105,10 @@ void race_update(void) {
|
||||
|
||||
// Draw 3D
|
||||
render_set_view(g.camera.position, g.camera.angle);
|
||||
render_set_screen_position(g.camera.shake);
|
||||
|
||||
render_set_cull_backface(false);
|
||||
scene_draw(&g.camera);
|
||||
scene_draw(&g.camera);
|
||||
track_draw(&g.camera);
|
||||
render_set_cull_backface(true);
|
||||
|
||||
@@ -116,6 +118,7 @@ void race_update(void) {
|
||||
particles_draw();
|
||||
|
||||
// Draw 2d
|
||||
render_set_screen_position(vec2(0,0));
|
||||
render_set_view_2d();
|
||||
|
||||
if (flags_is(g.ships[g.pilot].flags, SHIP_RACING)) {
|
||||
|
||||
@@ -202,7 +202,7 @@ void ship_player_update_race(ship_t *self) {
|
||||
if (self->ebolt_effect_timer > 0.1) {
|
||||
self->ebolt_effect_timer -= 0.1;
|
||||
if (flags_is(self->flags, SHIP_VIEW_INTERNAL)) {
|
||||
// SetShake(2); // FIXME
|
||||
camera_set_shake(&g.camera, CAMERA_SHAKE_SHORT);
|
||||
}
|
||||
self->angular_velocity.y += rand_float(-0.5, 0.5);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "game.h"
|
||||
#include "image.h"
|
||||
#include "particle.h"
|
||||
#include "camera.h"
|
||||
|
||||
extern int32_t ctrlNeedTargetIcon;
|
||||
extern int ctrlnearShip;
|
||||
@@ -384,7 +385,7 @@ void weapon_update_mine(weapon_t *self) {
|
||||
if (flags_not(ship->flags, SHIP_SHIELDED)) {
|
||||
if (ship->pilot == g.pilot) {
|
||||
ship->velocity = vec3_sub(ship->velocity, vec3_mulf(ship->velocity, 0.125));
|
||||
// SetShake(20); // FIXME
|
||||
camera_set_shake(&g.camera, CAMERA_SHAKE_LONG);
|
||||
}
|
||||
else {
|
||||
ship->speed = ship->speed * 0.125;
|
||||
@@ -434,7 +435,7 @@ void weapon_update_missile(weapon_t *self) {
|
||||
ship->velocity = vec3_sub(ship->velocity, vec3_mulf(ship->velocity, 0.75));
|
||||
ship->angular_velocity.z += rand_float(-0.1, 0.1);
|
||||
ship->turn_rate_from_hit = rand_float(-0.1, 0.1);
|
||||
// SetShake(20); // FIXME
|
||||
camera_set_shake(&g.camera, CAMERA_SHAKE_LONG);
|
||||
}
|
||||
else {
|
||||
ship->speed = ship->speed * 0.03125;
|
||||
@@ -482,7 +483,7 @@ void weapon_update_rocket(weapon_t *self) {
|
||||
ship->velocity = vec3_sub(ship->velocity, vec3_mulf(ship->velocity, 0.75));
|
||||
ship->angular_velocity.z += rand_float(-0.1, 0.1);;
|
||||
ship->turn_rate_from_hit = rand_float(-0.1, 0.1);;
|
||||
// SetShake(20); // FIXME
|
||||
camera_set_shake(&g.camera, CAMERA_SHAKE_LONG);
|
||||
}
|
||||
else {
|
||||
ship->speed = ship->speed * 0.03125;
|
||||
|
||||
Reference in New Issue
Block a user