Changeset 5527206 in opengl-game
- Timestamp:
- Jun 22, 2018, 5:07:15 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- dba67b2
- Parents:
- c94a699
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
rc94a699 r5527206 25 25 26 26 #include <cstdio> 27 #include <cstdlib> 28 #include <ctime> 27 29 #include <iostream> 28 30 #include <fstream> … … 72 74 }; 73 75 74 #define NUM_KEYS (512)75 #define ONE_DEG_IN_RAD ((2.0f * M_PI) / 360.0f) // 0.017444444 (maybe make this a const instead)76 77 const int KEY_STATE_UNCHANGED = -1;78 const bool FULLSCREEN = false;79 const bool SHOW_FPS = false;80 const bool DISABLE_VSYNC = false; // disable vsync to see real framerate81 unsigned int MAX_UNIFORMS = 0; // Requires OpenGL constants only available at runtime, so it can't be const82 83 int key_state[NUM_KEYS];84 bool key_pressed[NUM_KEYS];85 86 int width = 640;87 int height = 480;88 89 double fps;90 91 vec3 cam_pos;92 93 mat4 view_mat;94 mat4 proj_mat;95 96 // TODO: Consider using a list instead since it will make element deletion more efficient97 vector<SceneObject> objects;98 queue<Event> events;99 100 SceneObject* clickedObject = NULL;101 SceneObject* selectedObject = NULL;102 103 float NEAR_CLIP = 0.1f;104 float FAR_CLIP = 100.0f;105 106 // Should really have some array or struct of UI-related variables107 bool isRunning = true;108 109 ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);110 111 76 void glfw_error_callback(int error, const char* description); 112 77 … … 188 153 GLuint model_mat_idx_vbo); 189 154 155 float getRandomNum(float low, float high); 156 157 #define NUM_KEYS (512) 158 #define ONE_DEG_IN_RAD ((2.0f * M_PI) / 360.0f) // 0.017444444 (maybe make this a const instead) 159 160 const int KEY_STATE_UNCHANGED = -1; 161 const bool FULLSCREEN = false; 162 const bool SHOW_FPS = false; 163 const bool DISABLE_VSYNC = false; // disable vsync to see real framerate 164 unsigned int MAX_UNIFORMS = 0; // Requires OpenGL constants only available at runtime, so it can't be const 165 166 int key_state[NUM_KEYS]; 167 bool key_pressed[NUM_KEYS]; 168 169 int width = 640; 170 int height = 480; 171 172 double fps; 173 174 vec3 cam_pos; 175 176 mat4 view_mat; 177 mat4 proj_mat; 178 179 // TODO: Consider using a list instead since it will make element deletion more efficient 180 vector<SceneObject> objects; 181 queue<Event> events; 182 183 SceneObject* clickedObject = NULL; 184 SceneObject* selectedObject = NULL; 185 186 float NEAR_CLIP = 0.1f; 187 float FAR_CLIP = 100.0f; 188 189 // Should really have some array or struct of UI-related variables 190 bool isRunning = true; 191 192 ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); 193 190 194 int main(int argc, char* argv[]) { 191 195 cout << "New OpenGL Game" << endl; … … 231 235 glewExperimental = GL_TRUE; 232 236 glewInit(); 237 238 srand(time(0)); 233 239 234 240 /* … … 816 822 model_mat_idx_vbo); 817 823 824 /* 818 825 spawnAsteroid(vec3(0.0f, -1.2f, -21.5f), color_sp, 819 826 shaderBufferInfo, … … 861 868 ubo, 862 869 model_mat_idx_vbo); 870 */ 863 871 864 872 GLuint vao = 0; … … 964 972 int frame_count = 0; 965 973 double elapsed_seconds_fps = 0.0f; 974 double elapsed_seconds_spawn = 0.0f; 966 975 double previous_seconds = glfwGetTime(); 967 976 … … 991 1000 992 1001 frame_count++; 1002 } 1003 1004 elapsed_seconds_spawn += elapsed_seconds; 1005 if (elapsed_seconds_spawn > 0.5f) { 1006 spawnAsteroid(vec3(getRandomNum(-1.3f, 1.3f), getRandomNum(-3.0f, -1.0f), getRandomNum(-5.5f, -4.5f)), color_sp, 1007 shaderBufferInfo, 1008 points_vbo, 1009 colors_vbo, 1010 selected_colors_vbo, 1011 texcoords_vbo, 1012 normals_vbo, 1013 ubo, 1014 model_mat_idx_vbo); 1015 1016 elapsed_seconds_spawn = 0.0f; 993 1017 } 994 1018 … … 1049 1073 } 1050 1074 1051 if (key_pressed[GLFW_KEY_DOWN]) { 1052 transformObject(objects[1], translate(mat4(), vec3(0.0f, 0.0f, 0.03f)), ubo); 1053 transformObject(objects[2], translate(mat4(), vec3(0.0f, 0.0f, 0.06f)), ubo); 1054 transformObject(objects[3], translate(mat4(), vec3(0.0f, 0.0f, 0.04f)), ubo); 1055 transformObject(objects[4], translate(mat4(), vec3(0.0f, 0.0f, 0.06f)), ubo); 1056 transformObject(objects[5], translate(mat4(), vec3(0.0f, 0.0f, 0.04f)), ubo); 1075 for (int i = 1; i < objects.size(); i++) { 1076 if (!objects[i].deleted) { 1077 transformObject(objects[i], translate(mat4(), vec3(0.0f, 0.0f, 0.04f)), ubo); 1078 } 1057 1079 } 1058 1080 … … 1871 1893 model_mat_idx_vbo); 1872 1894 } 1895 1896 float getRandomNum(float low, float high) { 1897 return low + ((float)rand()/RAND_MAX) * (high-low); 1898 }
Note:
See TracChangeset
for help on using the changeset viewer.