#include <raylib.h>
+#include <raymath.h>
#include "structs.h"
Camera3D cam;
Matrix barrow_transform;
Vector3 barrow_position;
+Vector3 player_velocity;
+Vector3 player_rotation;
+
+float forward_speed = 0.075f;
+float forward_speed_decay = 0.05f;
+float rotate_speed = 0.5f;
+float rotate_speed_decay = 0.05f;
+
+void process_inputs()
+{
+ /* I guess GetRayCollisionMesh is the best solution here
+ but cameras don't know what they're touching so I'll
+ have to roll my own movement */
+
+ KeyboardKey key = GetKeyPressed();
+ do
+ {
+ if (IsKeyDown(KEY_W) || IsKeyDown(KEY_K))
+ {
+ player_velocity.x = forward_speed;
+ }
+ else if (IsKeyDown(KEY_S) || IsKeyDown(KEY_J))
+ {
+ player_velocity.x = -forward_speed;
+ }
+
+ if (IsKeyDown(KEY_A) || IsKeyDown(KEY_H))
+ {
+ player_rotation.x = -rotate_speed;
+ }
+ else if (IsKeyDown(KEY_D) || IsKeyDown(KEY_L))
+ {
+ player_rotation.x = rotate_speed;
+ }
+
+ switch(key)
+ {
+ default:
+ {} break;
+ };
+ }
+ while((key = GetKeyPressed()));
+}
+
void initialize_renderer()
{
barrow_position = (Vector3){-8.0f, 0.0f, -8.0f};
barrow_model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = diffuse_texture;
cam = (Camera3D){0};
- cam.position = barrow_position; //(Vector3){18.0f, 21.0f, 18.0f};
- cam.position.y += 1.0f;
- cam.target = (Vector3){0.0f, 0.0f, 0.0f};
+ cam.position = barrow_position;
+ cam.position.y += 3.0f;
+ cam.target = (Vector3){0.0f, cam.position.y * 0.66f, 0.0f};
cam.up = (Vector3){0.0f, 1.0f, 0.0f};
cam.fovy = 45.0f;
cam.projection= CAMERA_PERSPECTIVE;
+
+ DisableCursor();
}
void start_render_loop()
SetTargetFPS(target_fps);
while (!WindowShouldClose())
{
- UpdateCamera(&cam, CAMERA_CUSTOM);
+ process_inputs();
+
+ UpdateCameraPro(&cam, player_velocity, player_rotation, 0.0f);
BeginDrawing();
ClearBackground(LIGHTGRAY);
DrawTexture(barrow_texture, 64, 64, RAYWHITE);
DrawFPS(10, 10);
EndDrawing();
+
+ /* Decay forward velocity and rotation */
+ player_velocity.x = Lerp(player_velocity.x, 0.0f, forward_speed_decay);
+ player_rotation.x = Lerp(player_rotation.x, 0.0f, rotate_speed_decay);
}
UnloadImage(barrow_image);