Changeset a79be34 in opengl-game
- Timestamp:
- Dec 19, 2019, 4:37:03 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- cd1cb0f
- Parents:
- 60578ce
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
shaders/ship.vert
r60578ce ra79be34 27 27 28 28 // fixed point light positions 29 //vec3 light_position_world = vec3(0.0, 0.0, 2.0); 30 //vec3 light2_position_world = vec3(0.0, 1.5, -0.1); 31 vec3 light_position_world = vec3(7.0, -7.0, -10.0); 32 vec3 light2_position_world = vec3(4.0, -3.0, -10.0); 29 vec3 light_position_world = vec3(0.0, 0.0, 2.0); 30 vec3 light2_position_world = vec3(0.0, 1.5, -0.1); 33 31 34 32 // TODO: This does not account for scaling in the model matrix -
vulkan-game.cpp
r60578ce ra79be34 267 267 // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly 268 268 // the same data. Add an option to make some pipelines not use indexing 269 /*270 269 shipPipeline.addObject( 270 centerObject<ShipVertex>( 271 271 addObjectIndex<ShipVertex>(shipPipeline.getObjects().size(), 272 272 addVertexNormals<ShipVertex>({ … … 466 466 {{ 1.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 467 467 {{ 1.3f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 468 })) , {468 }))), { 469 469 0, 1, 2, 3, 4, 5, 470 470 6, 7, 8, 9, 10, 11, … … 497 497 135, 136, 137, 498 498 }, commandPool, graphicsQueue); 499 */500 501 // z-range is 0 to 1, with +1 pointing into the screen502 shipPipeline.addObject(503 addObjectIndex<ShipVertex>(shipPipeline.getObjects().size(),504 addVertexNormals<ShipVertex>({505 {{ 40.0f, 40.0f, 72.0f}, {0.0f, 0.6f, 0.0f}},506 {{ -40.0f, 40.0f, 80.0f}, {0.0f, 0.6f, 0.0f}},507 {{ -40.0f, -40.0f, 80.0f}, {0.0f, 0.6f, 0.0f}},508 {{ 40.0f, 40.0f, 72.0f}, {0.0f, 0.6f, 0.0f}},509 {{ -40.0f, -40.0f, 80.0f}, {0.0f, 0.6f, 0.0f}},510 {{ 40.0f, -40.0f, 72.0f}, {0.0f, 0.6f, 0.0f}},511 512 {{ 8.0f, 8.0f, 34.0f}, {0.0f, 0.0f, 0.7f}},513 {{ -8.0f, 8.0f, 30.0f}, {0.0f, 0.0f, 0.7f}},514 {{ -8.0f, -8.0f, 30.0f}, {0.0f, 0.0f, 0.7f}},515 {{ 8.0f, 8.0f, 34.0f}, {0.0f, 0.0f, 0.7f}},516 {{ -8.0f, -8.0f, 30.0f}, {0.0f, 0.0f, 0.7f}},517 {{ 8.0f, -8.0f, 34.0f}, {0.0f, 0.0f, 0.7f}},518 })), {519 0, 1, 2, 3, 4, 5,520 6, 7, 8, 9, 10, 11,521 }, commandPool, graphicsQueue);522 499 523 500 shipPipeline.createDescriptorSetLayout(); … … 549 526 550 527 float cam_yaw = 0.0f; 551 float cam_pitch = 0.0f; //-50.0f;528 float cam_pitch = -50.0f; 552 529 553 530 mat4 yaw_mat = rotate(mat4(1.0f), radians(-cam_yaw), vec3(0.0f, 1.0f, 0.0f)); -
vulkan-game.hpp
r60578ce ra79be34 4 4 #define GLM_FORCE_RADIANS 5 5 #define GLM_FORCE_DEPTH_ZERO_TO_ONE // Since, in Vulkan, the depth range is 0 to 1 instead of -1 to 1 6 #define GLM_FORCE_ LEFT_HANDED6 #define GLM_FORCE_RIGHT_HANDED 7 7 8 8 #include <glm/glm.hpp> … … 186 186 vector<VertexType> addObjectIndex(unsigned int objIndex, vector<VertexType> vertices); 187 187 188 template<class VertexType> 189 vector<VertexType> centerObject(vector<VertexType> vertices); 190 188 191 void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags, 189 192 vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, vector<VkDescriptorBufferInfo>& bufferInfoList); … … 207 210 vec3 p3 = vertices[i+2].pos; 208 211 209 // flip the y axis so that +y points up 210 vec3 normal = -normalize(cross(p2 - p1, p3 - p1)); 212 vec3 normal = normalize(cross(p2 - p1, p3 - p1)); 211 213 212 214 // Add the same normal for all 3 vertices … … 228 230 } 229 231 232 template<class VertexType> 233 vector<VertexType> VulkanGame::centerObject(vector<VertexType> vertices) { 234 float min_x = vertices[0].pos.x; 235 float max_x = vertices[0].pos.x; 236 float min_y = vertices[0].pos.y; 237 float max_y = vertices[0].pos.y; 238 float min_z = vertices[0].pos.z; 239 float max_z = vertices[0].pos.z; 240 241 // start from the second point 242 for (unsigned int i = 1; i < vertices.size(); i++) { 243 if (min_x > vertices[i].pos.x) { 244 min_x = vertices[i].pos.x; 245 } else if (max_x < vertices[i].pos.x) { 246 max_x = vertices[i].pos.x; 247 } 248 249 if (min_y > vertices[i].pos.y) { 250 min_y = vertices[i].pos.y; 251 } else if (max_y < vertices[i].pos.y) { 252 max_y = vertices[i].pos.y; 253 } 254 255 if (min_z > vertices[i].pos.z) { 256 min_z = vertices[i].pos.z; 257 } else if (max_z < vertices[i].pos.z) { 258 max_z = vertices[i].pos.z; 259 } 260 } 261 262 vec3 center = vec3(min_x + max_x, min_y + max_y, min_z + max_z) / 2.0f; 263 264 for (unsigned int i = 0; i < vertices.size(); i++) { 265 vertices[i].pos -= center; 266 } 267 268 return vertices; 269 } 270 230 271 #endif // _VULKAN_GAME_H
Note:
See TracChangeset
for help on using the changeset viewer.