Changeset a79be34 in opengl-game for vulkan-game.hpp
- Timestamp:
- Dec 19, 2019, 4:37:03 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- cd1cb0f
- Parents:
- 60578ce
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.