]> isoptera.lcsc.edu Git - example_engine/.git/commitdiff
Fixed vehicle so it's ready for Thursday
authorSeth Long <sslong@lcsc.edu>
Wed, 20 Nov 2024 22:22:58 +0000 (14:22 -0800)
committerSeth Long <sslong@lcsc.edu>
Wed, 20 Nov 2024 22:22:58 +0000 (14:22 -0800)
game.h
main.cpp
vehicle.cpp
vehicle.h

diff --git a/game.h b/game.h
index f819ebdcc38713b1725df9c83e1342d3991cb76a..8ba01d775d14ba424ffd59cb8c4e236799f1cddc 100644 (file)
--- 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);
 
 
index c380e0adc5e619cce619cb1797497a20b125d254..b2e8fa6f88484234706c3530e9de82a61c095b78 100644 (file)
--- 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 */
index bdf19ce010d74dacb5ce7fb75af359053a3dbe92..fb7a39e59991b184b17fc1f3db26566662ffa181 100644 (file)
@@ -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);
 }      
index 185b53f674eb8704156c5a36ee568408fbecb9c8..54829bb3acf2bd0a7bfe067c4c359f02417a2d63 100644 (file)
--- 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);