Changeset dba67b2 in opengl-game
- Timestamp:
- Jun 27, 2018, 1:53:47 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 3d06b4e
- Parents:
- 5527206
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
NewOpenGLGame.vcxproj
r5527206 rdba67b2 157 157 <Text Include="gl.log" /> 158 158 <Text Include="opengl-notes.txt" /> 159 <Text Include="README.txt" /> 159 160 <Text Include="TODO.txt" /> 160 161 </ItemGroup> -
README.txt
r5527206 rdba67b2 31 31 32 32 Download the precompiled 32bit binaries of GLFW and GLEW. Create lib/ and 33 include/ folders in the root opengl-game directory you cloned. Copy the include/GL/ and include/GLFW/ folders into your include/ folder and all the files in 34 the lib/ folders of the GLFW and GLEW libraries into your lib/ folder. Also 35 copy the .dll files into the root opengl-game directory. This should be enough 36 to compile and run the project. 33 include/ folders in the root opengl-game directory you cloned. 34 Copy the include/GL/ and include/GLFW/ folders into your include/ folder. 37 35 38 I would like to figure out how to statically compile glew and glfw to eliminate the need for the dlls. 36 For GLEW, copy lib/RELEASE/Win32/glew32s.lib into your lib folder. 37 For GLFW, copy lib-vc2015/glfw3.lib into your lib folder. 38 39 Download GLM and copy the glm folder (the one with all the .hpp files) into the include/ folder you made above. 40 GLM is a header-only library, so there is nothing to copy into the lib/ folder. 41 42 Open and run NewOpenGLGame.sln in Visual Studio 2017 and run it. -
new-game.cpp
r5527206 rdba67b2 8 8 9 9 #define _USE_MATH_DEFINES 10 #define GLM_SWIZZLE11 12 // This is to fix a non-alignment issue when passing vec4 params.13 // Check if it got fixed in a later version of GLM14 #define GLM_FORCE_PURE15 10 16 11 #include <glm/mat4x4.hpp> … … 378 373 }; 379 374 380 T_model = translate(mat4( ), vec3(0.45f, -1.5f, 0.0f));381 R_model = rotate(mat4( ), 0.0f, vec3(0.0f, 1.0f, 0.0f));375 T_model = translate(mat4(1.0f), vec3(0.45f, -1.5f, 0.0f)); 376 R_model = rotate(mat4(1.0f), 0.0f, vec3(0.0f, 1.0f, 0.0f)); 382 377 obj.model_base = T_model*R_model; 383 378 … … 413 408 }; 414 409 415 T_model = translate(mat4( ), vec3(-0.5f, -1.5f, -1.00f));416 R_model = rotate(mat4( ), 0.5f, vec3(0.0f, 1.0f, 0.0f));410 T_model = translate(mat4(1.0f), vec3(-0.5f, -1.5f, -1.00f)); 411 R_model = rotate(mat4(1.0f), 0.5f, vec3(0.0f, 1.0f, 0.0f)); 417 412 obj.model_base = T_model*R_model; 418 413 … … 791 786 obj.selected_colors = { 0.0f }; 792 787 793 T_model = translate(mat4( ), vec3(0.0f, -1.2f, 1.8f));794 R_model = rotate(mat4( ), 20.0f * (float)ONE_DEG_IN_RAD, vec3(1.0f, 0.0f, 0.0f));795 R_model = mat4( );796 obj.model_base = T_model * R_model * scale(mat4( ), vec3(0.1f, 0.1f, 0.1f));788 T_model = translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.8f)); 789 R_model = rotate(mat4(1.0f), 20.0f * (float)ONE_DEG_IN_RAD, vec3(1.0f, 0.0f, 0.0f)); 790 R_model = mat4(1.0f); 791 obj.model_base = T_model * R_model * scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f)); 797 792 798 793 addObjectToSceneDuringInit(obj); … … 921 916 float cam_pitch = -50.0f * 2.0f * 3.14159f / 360.0f; 922 917 923 mat4 T = translate(mat4( ), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z));924 mat4 yaw_mat = rotate(mat4( ), -cam_yaw, vec3(0.0f, 1.0f, 0.0f));925 mat4 pitch_mat = rotate(mat4( ), -cam_pitch, vec3(1.0f, 0.0f, 0.0f));918 mat4 T = translate(mat4(1.0f), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z)); 919 mat4 yaw_mat = rotate(mat4(1.0f), -cam_yaw, vec3(0.0f, 1.0f, 0.0f)); 920 mat4 pitch_mat = rotate(mat4(1.0f), -cam_pitch, vec3(1.0f, 0.0f, 0.0f)); 926 921 mat4 R = pitch_mat * yaw_mat; 927 922 view_mat = R*T; … … 1056 1051 /* 1057 1052 if (key_state[GLFW_KEY_SPACE] == GLFW_PRESS) { 1058 transformObject(objects[1], translate(mat4( ), vec3(0.3f, 0.0f, 0.0f)), ubo);1053 transformObject(objects[1], translate(mat4(1.0f), vec3(0.3f, 0.0f, 0.0f)), ubo); 1059 1054 } 1060 1055 if (key_pressed[GLFW_KEY_RIGHT]) { 1061 transformObject(objects[2], translate(mat4( ), vec3(0.01f, 0.0f, 0.0f)), ubo);1056 transformObject(objects[2], translate(mat4(1.0f), vec3(0.01f, 0.0f, 0.0f)), ubo); 1062 1057 } 1063 1058 if (key_pressed[GLFW_KEY_LEFT]) { 1064 transformObject(objects[2], translate(mat4( ), vec3(-0.01f, 0.0f, 0.0f)), ubo);1059 transformObject(objects[2], translate(mat4(1.0f), vec3(-0.01f, 0.0f, 0.0f)), ubo); 1065 1060 } 1066 1061 */ 1067 1062 1068 1063 if (key_pressed[GLFW_KEY_RIGHT]) { 1069 transformObject(objects[0], translate(mat4( ), vec3(0.01f, 0.0f, 0.0f)), ubo);1064 transformObject(objects[0], translate(mat4(1.0f), vec3(0.01f, 0.0f, 0.0f)), ubo); 1070 1065 } 1071 1066 if (key_pressed[GLFW_KEY_LEFT]) { 1072 transformObject(objects[0], translate(mat4( ), vec3(-0.01f, 0.0f, 0.0f)), ubo);1067 transformObject(objects[0], translate(mat4(1.0f), vec3(-0.01f, 0.0f, 0.0f)), ubo); 1073 1068 } 1074 1069 1075 1070 for (int i = 1; i < objects.size(); i++) { 1076 1071 if (!objects[i].deleted) { 1077 transformObject(objects[i], translate(mat4( ), vec3(0.0f, 0.0f, 0.04f)), ubo);1072 transformObject(objects[i], translate(mat4(1.0f), vec3(0.0f, 0.0f, 0.04f)), ubo); 1078 1073 } 1079 1074 } … … 1090 1085 float dist = cam_speed * elapsed_seconds; 1091 1086 if (key_pressed[GLFW_KEY_A]) { 1092 vec3 dir = (inverse(R) * vec4(-1.0f, 0.0f, 0.0f, 1.0f)).xyz();1087 vec3 dir = vec3(inverse(R) * vec4(-1.0f, 0.0f, 0.0f, 1.0f)); 1093 1088 cam_pos += dir * dist; 1094 1089 … … 1096 1091 } 1097 1092 if (key_pressed[GLFW_KEY_D]) { 1098 vec3 dir = (inverse(R) * vec4(1.0f, 0.0f, 0.0f, 1.0f)).xyz();1093 vec3 dir = vec3(inverse(R) * vec4(1.0f, 0.0f, 0.0f, 1.0f)); 1099 1094 cam_pos += dir * dist; 1100 1095 … … 1102 1097 } 1103 1098 if (key_pressed[GLFW_KEY_W]) { 1104 vec3 dir = (inverse(R) * vec4(0.0f, 0.0f, -1.0f, 1.0f)).xyz();1099 vec3 dir = vec3(inverse(R) * vec4(0.0f, 0.0f, -1.0f, 1.0f)); 1105 1100 cam_pos += dir * dist; 1106 1101 … … 1108 1103 } 1109 1104 if (key_pressed[GLFW_KEY_S]) { 1110 vec3 dir = (inverse(R) * vec4(0.0f, 0.0f, 1.0f, 1.0f)).xyz();1105 vec3 dir = vec3(inverse(R) * vec4(0.0f, 0.0f, 1.0f, 1.0f)); 1111 1106 cam_pos += dir * dist; 1112 1107 … … 1132 1127 */ 1133 1128 if (cam_moved) { 1134 T = translate(mat4( ), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z));1135 1136 mat4 yaw_mat = rotate(mat4( ), -cam_yaw, vec3(0.0f, 1.0f, 0.0f));1137 mat4 pitch_mat = rotate(mat4( ), -cam_pitch, vec3(1.0f, 0.0f, 0.0f));1129 T = translate(mat4(1.0f), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z)); 1130 1131 mat4 yaw_mat = rotate(mat4(1.0f), -cam_yaw, vec3(0.0f, 1.0f, 0.0f)); 1132 mat4 pitch_mat = rotate(mat4(1.0f), -cam_pitch, vec3(1.0f, 0.0f, 0.0f)); 1138 1133 R = pitch_mat * yaw_mat; 1139 1134 … … 1203 1198 vec4 ray_clip = vec4(x, y, -1.0f, 1.0f); 1204 1199 vec4 ray_eye = inverse(proj_mat) * ray_clip; 1205 ray_eye = vec4( ray_eye.xy(), -1.0f, 1.0f);1200 ray_eye = vec4(vec2(ray_eye), -1.0f, 1.0f); 1206 1201 vec4 ray_world = inverse(view_mat) * ray_eye; 1207 1202 … … 1225 1220 1226 1221 if (-NEAR_CLIP >= click_point.z && click_point.z > -FAR_CLIP && click_point.z > closest_point.z) { 1227 closest_point = click_point.xyz();1222 closest_point = vec3(click_point); 1228 1223 closest_object = &*it; 1229 1224 } … … 1340 1335 vec3 normal = vec3(v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x); 1341 1336 1342 vec3 local_ray = (inverse(obj->model_mat) * world_ray).xyz();1343 vec3 local_cam = (inverse(obj->model_mat) * cam).xyz();1337 vec3 local_ray = vec3(inverse(obj->model_mat) * world_ray); 1338 vec3 local_cam = vec3(inverse(obj->model_mat) * cam); 1344 1339 1345 1340 local_ray = local_ray - local_cam; … … 1380 1375 obj.id = objects.size(); // currently unused 1381 1376 obj.num_points = obj.points.size() / 3; 1382 obj.model_transform = mat4( );1377 obj.model_transform = mat4(1.0f); 1383 1378 obj.deleted = false; 1384 1379 … … 1445 1440 // Move the object outside the render bounds of the scene so it doesn't get rendered 1446 1441 // TODO: Find a better way of hiding the object until the next time buffers are repopulated 1447 transformObject(obj, translate(mat4( ), vec3(0.0f, 0.0f, FAR_CLIP * 1000.0f)), ubo);1442 transformObject(obj, translate(mat4(1.0f), vec3(0.0f, 0.0f, FAR_CLIP * 1000.0f)), ubo); 1448 1443 obj.deleted = true; 1449 1444 } … … 1880 1875 obj.selected_colors = { 0.0f }; 1881 1876 1882 mat4 T = translate(mat4( ), pos);1883 mat4 R = rotate(mat4( ), 60.0f * (float)ONE_DEG_IN_RAD, vec3(1.0f, 1.0f, -1.0f));1884 obj.model_base = T * R * scale(mat4( ), vec3(0.1f, 0.1f, 0.1f));1877 mat4 T = translate(mat4(1.0f), pos); 1878 mat4 R = rotate(mat4(1.0f), 60.0f * (float)ONE_DEG_IN_RAD, vec3(1.0f, 1.0f, -1.0f)); 1879 obj.model_base = T * R * scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f)); 1885 1880 1886 1881 addObjectToScene(obj, shaderBufferInfo,
Note:
See TracChangeset
for help on using the changeset viewer.