Skip to content

Commit

Permalink
input: use joystick for moving, pointer for rotation
Browse files Browse the repository at this point in the history
Implement a control style a la "The Conduit", where the pointer is used
to rotate the camera, and the joystick is used for moving. This still
needs some work (we probably want to show a small pointer on the Wii
screen, because currently it's hard to know where exactly you are
pointing at), but should give an idea. Having playing "The COnduit" for
a while, this feels much more natural to me.

This depends on xtreme8000#17 in order to be tested on the PC.

Addresses issue xtreme8000#1.
  • Loading branch information
mardy committed Sep 14, 2023
1 parent c53d9ee commit f666411
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions source/game/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,25 @@ void camera_ray_pick(struct world* w, float gx0, float gy0, float gz0,
void camera_physics(struct camera* c, float dt) {
assert(c);

float jdx, jdy;
if(input_joystick(dt, &jdx, &jdy)) {
c->rx -= jdx * 2.0F;
c->ry -= jdy * 2.0F;
float px, py, pangle;
const float rotation_c = 20.0F;
if(input_pointer(&px, &py, &pangle)) {
c->rx -= (px - gfx_width() / 2) / (gfx_width() * rotation_c);
c->ry += (py - gfx_height() / 2) / (gfx_height() * rotation_c);
// pangle could be used for rz, but that would be veeery weird :-)
}

float acc_x = 0, acc_y = 0, acc_z = 0;
float speed_c = 40.0F;

float jdx, jdy;
if(input_joystick(dt, &jdx, &jdy)) {
float joy_speed_c = 40.0F * speed_c;
acc_x += (cos(c->rx) * -jdx + sin(c->rx) * sin(c->ry) * jdy) * joy_speed_c;
acc_y += cos(c->ry) * jdy * speed_c;
acc_z += (sin(c->rx) * jdx + cos(c->rx) * sin(c->ry) * jdy) * joy_speed_c;
}

float air_friction = 0.05F;

if(input_held(IB_LEFT)) {
Expand Down
2 changes: 1 addition & 1 deletion source/game/gui/screen_ingame.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <malloc.h>

static void screen_ingame_reset(struct screen* s, int width, int height) {
input_pointer_enable(false);
input_pointer_enable(true);
}

void screen_ingame_render3D(struct screen* s, mat4 view) {
Expand Down

0 comments on commit f666411

Please sign in to comment.