Changeset f9a242b in opengl-game
- Timestamp:
- May 25, 2018, 4:04:45 AM (7 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- e3ca955
- Parents:
- 4f3262f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
r4f3262f rf9a242b 104 104 void printVector(string label, vec3 v); 105 105 void print4DVector(string label, vec4 v); 106 107 void addObjectToScene(SceneObject& obj); 106 108 107 109 void renderMainMenu(); … … 259 261 GLuint texture_sp = loadShaderProgram("./texture.vert", "./texture.frag"); 260 262 263 SceneObject obj; 261 264 mat4 T_model, R_model; 262 265 263 266 // triangle 264 objects.push_back(SceneObject()); 265 objects[0].id = 0; 266 objects[0].shader_program = color_sp; 267 objects[0].vertex_vbo_offset = 0; 268 objects[0].points = { 267 obj = SceneObject(); 268 obj.shader_program = color_sp; 269 obj.points = { 269 270 0.0f, 0.5f, 0.0f, 270 271 -0.5f, -0.5f, 0.0f, … … 274 275 0.0f, 0.5f, 0.0f, 275 276 }; 276 obj ects[0].colors = {277 obj.colors = { 277 278 1.0f, 0.0f, 0.0f, 278 279 0.0f, 0.0f, 1.0f, … … 282 283 1.0f, 0.0f, 0.0f, 283 284 }; 284 obj ects[0].texcoords = {285 obj.texcoords = { 285 286 1.0f, 1.0f, 286 287 0.0f, 1.0f, … … 290 291 1.0f, 0.0f 291 292 }; 292 objects[0].normals = { 293 0.0f, 0.0f, 1.0f, 294 0.0f, 0.0f, 1.0f, 295 0.0f, 0.0f, 1.0f, 296 0.0f, 0.0f, -1.0f, 297 0.0f, 0.0f, -1.0f, 298 0.0f, 0.0f, -1.0f, 299 }; 300 objects[0].selected_colors = { 301 0.0f, 1.0f, 0.0f, 302 0.0f, 1.0f, 0.0f, 303 0.0f, 1.0f, 0.0f, 304 0.0f, 1.0f, 0.0f, 305 0.0f, 1.0f, 0.0f, 306 0.0f, 1.0f, 0.0f, 307 }; 308 objects[0].num_points = objects[0].points.size() / 3; 293 obj.selected_colors = { 294 0.0f, 1.0f, 0.0f, 295 0.0f, 1.0f, 0.0f, 296 0.0f, 1.0f, 0.0f, 297 0.0f, 1.0f, 0.0f, 298 0.0f, 1.0f, 0.0f, 299 0.0f, 1.0f, 0.0f, 300 }; 309 301 310 302 T_model = translate(mat4(), vec3(0.45f, 0.0f, 0.0f)); 311 303 R_model = rotate(mat4(), 0.0f, vec3(0.0f, 1.0f, 0.0f)); 312 objects[0].model_mat = T_model*R_model; 304 obj.model_mat = T_model*R_model; 305 306 addObjectToScene(obj); 313 307 314 308 // square 315 objects.push_back(SceneObject()); 316 objects[1].id = 1; 317 objects[1].shader_program = texture_sp; 318 objects[1].vertex_vbo_offset = 6; 319 objects[1].points = { 309 obj = SceneObject(); 310 obj.shader_program = texture_sp; 311 obj.points = { 320 312 0.5f, 0.5f, 0.0f, 321 313 -0.5f, 0.5f, 0.0f, … … 325 317 0.5f, -0.5f, 0.0f, 326 318 }; 327 obj ects[1].colors = {319 obj.colors = { 328 320 1.0f, 0.0f, 0.0f, 329 321 0.0f, 0.0f, 1.0f, … … 333 325 1.0f, 0.0f, 0.0f, 334 326 }; 335 obj ects[1].texcoords = {327 obj.texcoords = { 336 328 1.0f, 1.0f, 337 329 0.0f, 1.0f, … … 341 333 1.0f, 0.0f 342 334 }; 343 objects[1].normals = { 344 0.0f, 0.0f, 1.0f, 345 0.0f, 0.0f, 1.0f, 346 0.0f, 0.0f, 1.0f, 347 0.0f, 0.0f, 1.0f, 348 0.0f, 0.0f, 1.0f, 349 0.0f, 0.0f, 1.0f, 350 }; 351 objects[1].selected_colors = { 335 obj.selected_colors = { 352 336 0.0f, 0.6f, 0.9f, 353 337 0.0f, 0.6f, 0.9f, … … 357 341 0.0f, 0.6f, 0.9f, 358 342 }; 359 objects[1].num_points = objects[1].points.size() / 3;360 343 361 344 T_model = translate(mat4(), vec3(-0.5f, 0.0f, -1.00f)); 362 345 R_model = rotate(mat4(), 0.5f, vec3(0.0f, 1.0f, 0.0f)); 363 objects[1].model_mat = T_model*R_model; 346 obj.model_mat = T_model*R_model; 347 348 addObjectToScene(obj); 349 350 // player ship 351 obj = SceneObject(); 352 obj.shader_program = color_sp; 353 obj.points = { 354 0.0f, 0.5f, 0.0f, 355 -0.5f, -0.5f, 0.0f, 356 0.5f, -0.5f, 0.0f, 357 0.5f, -0.5f, 0.0f, 358 -0.5f, -0.5f, 0.0f, 359 0.0f, 0.5f, 0.0f, 360 }; 361 obj.colors = { 362 0.0f, 0.0f, 0.3f, 363 0.0f, 0.0f, 0.3f, 364 0.0f, 0.0f, 0.3f, 365 0.0f, 0.0f, 0.3f, 366 0.0f, 0.0f, 0.3f, 367 0.0f, 0.0f, 0.3f, 368 }; 369 obj.texcoords = { 370 1.0f, 1.0f, 371 0.0f, 1.0f, 372 0.0f, 0.0f, 373 1.0f, 1.0f, 374 0.0f, 0.0f, 375 1.0f, 0.0f 376 }; 377 obj.selected_colors = { 378 0.0f, 1.0f, 0.0f, 379 0.0f, 1.0f, 0.0f, 380 0.0f, 1.0f, 0.0f, 381 0.0f, 1.0f, 0.0f, 382 0.0f, 1.0f, 0.0f, 383 0.0f, 1.0f, 0.0f, 384 }; 385 386 T_model = translate(mat4(), vec3(0.0f, -0.65f, 0.0f)); 387 R_model = rotate(mat4(), -1.0f, vec3(1.0f, 0.0f, 0.0f)); 388 obj.model_mat = T_model * R_model; 389 390 addObjectToScene(obj); 364 391 365 392 vector<SceneObject>::iterator obj_it; … … 1023 1050 } 1024 1051 1052 void addObjectToScene(SceneObject& obj) { 1053 obj.id = objects.size(); // currently unused 1054 obj.num_points = obj.points.size() / 3; 1055 1056 static GLint vbo_offset = 0; 1057 obj.vertex_vbo_offset = vbo_offset; 1058 vbo_offset += obj.num_points; 1059 1060 obj.normals.reserve(obj.points.size()); 1061 for (int i = 0; i < obj.points.size(); i += 9) { 1062 vec3 point1 = vec3(obj.points[i], obj.points[i+1], obj.points[i + 2]); 1063 vec3 point2 = vec3(obj.points[i+3], obj.points[i + 4], obj.points[i + 5]); 1064 vec3 point3 = vec3(obj.points[i+6], obj.points[i + 7], obj.points[i + 8]); 1065 1066 vec3 normal = normalize(cross(point2 - point1, point3 - point1)); 1067 1068 // Add the same normal for all 3 points 1069 for (int j = 0; j < 3; j++) { 1070 obj.normals.push_back(normal.x); 1071 obj.normals.push_back(normal.y); 1072 obj.normals.push_back(normal.z); 1073 } 1074 } 1075 1076 objects.push_back(obj); 1077 } 1078 1025 1079 void renderMainMenu() { 1026 1080 }
Note:
See TracChangeset
for help on using the changeset viewer.