aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortslil clingman <>2021-10-25 22:17:35 -0400
committertslil clingman <>2021-10-25 22:17:35 -0400
commit486935299e4b7e097754611d9f8dd40003351ae4 (patch)
treea87b9d02639ec87c3f9e83d77addb95a8c9e412e /src
parent681d7f8a489b4dbfa0712351c1d993d2df47469c (diff)
Mouse look!
Diffstat (limited to 'src')
-rw-r--r--src/main.zig7
-rw-r--r--src/render.zig2
2 files changed, 8 insertions, 1 deletions
diff --git a/src/main.zig b/src/main.zig
index 781b9a7..6a10921 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -103,6 +103,10 @@ pub fn main() !void {
window.setFramerateLimit(40);
+ // TODO: implement this in the SFML wrapper and make a PR
+ sf.c.sfRenderWindow_setMouseCursorGrabbed(window.ptr, 1);
+ sf.c.sfRenderWindow_setMouseCursorVisible(window.ptr, 0);
+
// Load the background skybox, really `skycylinder', and assign it to a
// sprite -- it's set to repeating so that it goes on forever. We need to
// scale the sprite so that drawing 1/4 of backTextureWidth fills the Screen
@@ -153,6 +157,9 @@ pub fn main() !void {
if (isKeyPressed(.C)) plyr.height -= 0.1;
if (isKeyPressed(.V)) plyr.height += 0.1;
+ plyr.ang -= @intToFloat(f32, sf.window.mouse.getPosition(window).x) / constants.ScreenWidth - 0.5;
+ sf.window.mouse.setPosition(.{.x = constants.ScreenWidth / 2, .y = 0}, window);
+
const rotation = 2.0 * PI / 200.0;
if (isKeyPressed(.Left)) plyr.ang += rotation;
if (isKeyPressed(.Right)) plyr.ang -= rotation;
diff --git a/src/render.zig b/src/render.zig
index f2f06ae..49595dd 100644
--- a/src/render.zig
+++ b/src/render.zig
@@ -321,7 +321,7 @@ pub fn Renderer(PlaneWidth: f32, PlaneHeight: f32) type {
const should_try_to_draw_layer = switch (layer.polygon) {
.square => hit: {
// we have to compute texture_frac by hand.
- var texfrac : f32 = undefined;
+ var texfrac: f32 = undefined;
// Using the notation in the below diagram,
// we want face_i to have [0.25i, 0.25(i+1)]
// of the texture.