#pragma once /* Set this to WINDOWS for Windows, UNIX for Linux, BSD, etc. */ #define UNIX /* This is needed to allow fopen, fread, etc. */ #ifdef WINDOWS #define _CRT_SECURE_NO_WARNINGS #define M_PI 3.141592653 #endif /* General-purpose C includes */ #include #include /* General-purpose C++ includes */ #include #include #include /* Data Structures */ #include #include /* OpenGL Loader */ #ifdef UNIX #include // glad on Windows #else #include #endif /* OpenGL Includes */ #include #include #include #include /* Tiny obj loader - loads Wavefront .obj files */ #include "tiny_obj_loader.h" /* Provides stbi_image to load textures */ #include "stb_image.h" using namespace std; using namespace glm; struct globals { float height = 800; float width = 1280; bool shutdown = false; vec3 player_position; float heading = 0.0; float elevation = 0.0; bool forward = false; bool backward = false; bool left = false; bool right = false; bool run = false; }; vec3 get_lookat_point(int direction = 0, float r = 0.0); char* get_source(const char *filename); class GameObject { public: /* Identifiers for OpenGL resources */ unsigned int v_attrib; unsigned int tc_attrib; unsigned int vp_uniform; unsigned int program; unsigned int vbuf; unsigned int ebuf; unsigned int tex; unsigned int element_count; unsigned int models_buffer; /* Properties not related to OpenGL */ vector models; bool visible = true; void add_location(vec3 location); bool init(const char* object_file, const char* texture_file, bool flip_xy = false); void draw(mat4 vp); virtual void movement(float) {}; // takes the number of milliseconds since the last run }; class SolidObject : public GameObject { public: /* When we think about collisions */ bool collision = false; bool blocks_player = false; void collided(GameObject& other, size_t our_instance, size_t other_instance); virtual bool is_inside(vec3 point, float margin) {return false;} //some_format get_hit_box(); bool is_over(); /* Vector of sizes of instance? Or are all the instances the same size? */ /* Something for bouncing? */ }; #ifdef MAIN globals g; vector game_objects; vector solid_objects; #else extern globals g; extern vector game_objects; extern vector solid_objects; #endif struct vertex { float x, y, z, u, v; }; bool operator==(const vertex& a, const vertex& o); ostream& operator<<(ostream& out, vec3 v); /* Other objects that aren't base classes go next */ #include "misc_objects.h"