From: Seth Long Date: Wed, 20 Nov 2024 22:22:58 +0000 (-0800) Subject: Fixed vehicle so it's ready for Thursday X-Git-Url: https://isoptera.lcsc.edu/gitweb/?a=commitdiff_plain;h=9556c2f77ac359e0040eee020b9e21aafe28f3dd;p=example_engine%2F.git Fixed vehicle so it's ready for Thursday --- diff --git a/game.h b/game.h index f819ebd..8ba01d7 100644 --- a/game.h +++ b/game.h @@ -61,12 +61,6 @@ class gameobject { virtual void activate(size_t index) {} }; -/* -class vehicle : virtual public gameobject { -public: - virtual void vehicle_move() {}; -}; -*/ class loaded_object : virtual public gameobject { public: @@ -91,6 +85,11 @@ class block_object : virtual public gameobject { }; +class vehicle : virtual public block_object { +public: + virtual void vehicle_move() {}; +}; + class wall_block : public loaded_object, public block_object { public: wall_block(const char* of, const char* tf, glm::vec3 s) : loaded_object(of, tf, s) { @@ -112,7 +111,6 @@ struct key_status { #define INIT(x) #endif - /* Player globals */ EXTERN glm::vec3 player_position; EXTERN float player_heading; @@ -122,10 +120,7 @@ EXTERN float player_fall_speed INIT(0); EXTERN gameobject *player_platform INIT(0); EXTERN size_t player_platform_index INIT(0); EXTERN struct key_status player_key_status; - - -#include "vehicle.h" -EXTERN flying_carpet *current_vehicle INIT(0); +EXTERN vehicle *current_vehicle INIT(0); EXTERN size_t vehicle_index INIT(0); diff --git a/main.cpp b/main.cpp index c380e0a..b2e8fa6 100644 --- a/main.cpp +++ b/main.cpp @@ -14,6 +14,7 @@ #include "geometric_objects.h" #include "hud.h" #include "door.h" +#include "vehicle.h" std::mutex grand_mutex; @@ -428,7 +429,7 @@ int main(int argc, char** argv) { objects.push_back(&spawned_blocks); flying_carpet fc; - fc.locations.push_back(glm::vec3(30, -5, 450)); + fc.addpanel(glm::vec3(30, -5, 450), glm::vec2(3.0, 3.0), glm::vec2(1, 1)); objects.push_back(&fc); /* Initialize game objects */ diff --git a/vehicle.cpp b/vehicle.cpp index bdf19ce..fb7a39e 100644 --- a/vehicle.cpp +++ b/vehicle.cpp @@ -1,12 +1,13 @@ #include "game.h" +#include "vehicle.h" void flying_carpet::vehicle_move() { - glm::vec3 step_to_point = player_position; + glm::vec3 step_to_point = locations[0]; if(player_key_status.forward){ - step_to_point += 0.5f * glm::vec3(sinf(player_heading), 0, cosf(player_heading)); + step_to_point += 0.5f * glm::vec3(sinf(player_heading), sinf(player_elevation), cosf(player_heading)); } if(player_key_status.backward){ - step_to_point += 0.5f * glm::vec3(-sinf(player_heading), 0, -cosf(player_heading)); + step_to_point += 0.5f * glm::vec3(-sinf(player_heading), -sinf(player_elevation), -cosf(player_heading)); } if(player_key_status.left){ step_to_point += 0.5f * glm::vec3(sinf(player_heading + M_PI/2), 0, cosf(player_heading + M_PI/2)); @@ -15,10 +16,12 @@ void flying_carpet::vehicle_move() { step_to_point += 0.5f * glm::vec3(-sinf(player_heading + M_PI/2), 0, -cosf(player_heading + M_PI/2)); } locations[vehicle_index] = step_to_point; - player_position = step_to_point; + player_position = glm::vec3(step_to_point.x, step_to_point.y + 3.0f, step_to_point.z); + ups[0] = glm::rotate(glm::mat4(1.0f), player_heading, glm::vec3(0, 1, 0)) * glm::vec4(0, 0, 1, 1); } void flying_carpet::activate(size_t index) { current_vehicle = this; vehicle_index = index; + player_position = locations[0] + glm::vec3(0, 3, 0); } diff --git a/vehicle.h b/vehicle.h index 185b53f..54829bb 100644 --- a/vehicle.h +++ b/vehicle.h @@ -2,7 +2,7 @@ #include "geometric_objects.h" -class flying_carpet : virtual public flat_panel { +class flying_carpet : virtual public vehicle, virtual public flat_panel { public: flying_carpet() : flat_panel("brick.jpg") { size = glm::vec3(10, 1, 10);