summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorSchark <jordan@schark.online>2023-05-12 02:14:15 -0700
committerSchark <jordan@schark.online>2023-05-12 02:14:15 -0700
commit743d7f3ef9709a89c6ba48ed83e26a0bdfbdd200 (patch)
treef1f959406c201e2a9c2e1515f0bc09200145e8fc /src/main.c
parent4b23f2fcc44fc636d8d4dbe94881cf937c54199b (diff)
downloadgamedev-743d7f3ef9709a89c6ba48ed83e26a0bdfbdd200.tar.gz
gamedev-743d7f3ef9709a89c6ba48ed83e26a0bdfbdd200.zip
y-shearing!
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/main.c b/src/main.c
index 34a4d0e..3069e66 100644
--- a/src/main.c
+++ b/src/main.c
@@ -108,10 +108,15 @@ void raycast(Player *player, int width, int height) {
// calculate height of line on screen
int line_height = (int)(screen_height / perp_wall_dist);
- int draw_start = -line_height / 2 + screen_height / 2;
- if (draw_start < 0) { draw_start = 0; }
- int draw_end = line_height / 2 + screen_height / 2;
- if (draw_end >= screen_height) { draw_end = screen_height - 1; }
+ //int draw_start = -line_height / 2 + screen_height / 2;
+ //if (draw_start < 0) { draw_start = 0; }
+ //int draw_end = line_height / 2 + screen_height / 2;
+ //if (draw_end >= screen_height) { draw_end = screen_height - 1; }
+ int pitch = screen_height / 2 * player->look_angle;
+ int start_y = -line_height / 2 + screen_height / 2 + pitch;
+ if (start_y < 0) { start_y = 0; }
+ int end_y = line_height / 2 + screen_height / 2 + pitch;
+ if (end_y >= screen_height) { end_y = screen_height - 1; }
// colors :)
@@ -144,11 +149,15 @@ void raycast(Player *player, int width, int height) {
// TODO: recommended to put this in its own function or something at some point,
// as it deals with library calls outside of this function's scope
- glBegin(GL_LINES);
- glColor3ub(color.r, color.g, color.b);
- glVertex2i(x, draw_start);
- glVertex2i(x, draw_end);
- glEnd();
+
+ for (int y = start_y; y < end_y; y++) {
+ glBegin(GL_LINES);
+ glColor3ub(color.r, color.g, color.b);
+ glVertex2i(x, start_y);
+ glVertex2i(x, end_y);
+ glEnd();
+ }
+
}
}
@@ -165,6 +174,7 @@ int main(int argc, char *argv[]) {
player.dir_y = 0.0f; // facing right
player.plane_x = 0.0f; // FOV related
player.plane_y = 0.66f; // FOV related
+ player.look_angle = 0.0f;
player.move_speed = 0.02f;
player.sensitivity = 0.001f;
@@ -221,8 +231,6 @@ int main(int argc, char *argv[]) {
glfwSetWindowTitle(window, title);
nb_frames = 0;
last_time += 1.0;
- } else if (current_time - last_time >= 0.7) {
- //glfwSetCursorPos(window, mode->width / 2, mode->height / 2);
}
// clear window