Changeset 3b84bb6 in opengl-game for vulkan-game.hpp
- Timestamp:
- Feb 25, 2020, 6:51:02 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 44f23af
- Parents:
- 2da64ef
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.hpp
r2da64ef r3b84bb6 58 58 mat4 model_base; 59 59 mat4 model_transform; 60 vec3 center; 61 float radius; 60 62 }; 61 63 … … 217 219 void addObject(vector<SceneObject<VertexType, SSBOType>>& objects, 218 220 GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, 219 const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo); 221 const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo, 222 bool pipelinesCreated); 220 223 221 224 template<class VertexType, class SSBOType> … … 229 232 vector<VertexType> addObjectIndex(unsigned int objIndex, vector<VertexType> vertices); 230 233 231 template<class VertexType >232 v ector<VertexType> centerObject(vector<VertexType> vertices);234 template<class VertexType, class SSBOType> 235 void centerObject(SceneObject<VertexType, SSBOType>& object); 233 236 234 237 void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags, … … 246 249 }; 247 250 251 // TODO: Right now, it's basically necessary to pass the identity matrix in for ssbo.model 252 // and to change the model matrix later by setting model_transform and then calling updateObject() 253 // Figure out a better way to allow the model matrix to be set during objecting creation 248 254 template<class VertexType, class SSBOType> 249 255 void VulkanGame::addObject(vector<SceneObject<VertexType, SSBOType>>& objects, 250 256 GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, 251 const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo) { 257 const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo, 258 bool pipelinesCreated) { 252 259 size_t numVertices = pipeline.getNumVertices(); 253 260 … … 257 264 258 265 objects.push_back({ vertices, indices, ssbo, mat4(1.0f), mat4(1.0f) }); 259 260 pipeline.addVertices(vertices, indices, commandPool, graphicsQueue); 266 centerObject(objects.back()); 267 268 bool storageBufferResized = pipeline.addObject(vertices, indices, ssbo, commandPool, graphicsQueue); 269 270 if (pipelinesCreated) { 271 if (storageBufferResized) { 272 } 273 274 createCommandBuffers(); 275 } 261 276 } 262 277 … … 302 317 } 303 318 304 template<class VertexType> 305 vector<VertexType> VulkanGame::centerObject(vector<VertexType> vertices) { 319 template<class VertexType, class SSBOType> 320 void VulkanGame::centerObject(SceneObject<VertexType, SSBOType>& object) { 321 vector<VertexType>& vertices = object.vertices; 322 306 323 float min_x = vertices[0].pos.x; 307 324 float max_x = vertices[0].pos.x; … … 313 330 // start from the second point 314 331 for (unsigned int i = 1; i < vertices.size(); i++) { 315 if (min_x > vertices[i].pos.x) { 316 min_x = vertices[i].pos.x; 317 } else if (max_x < vertices[i].pos.x) { 318 max_x = vertices[i].pos.x; 332 vec3& pos = vertices[i].pos; 333 334 if (min_x > pos.x) { 335 min_x = pos.x; 336 } else if (max_x < pos.x) { 337 max_x = pos.x; 319 338 } 320 339 321 if (min_y > vertices[i].pos.y) {322 min_y = vertices[i].pos.y;323 } else if (max_y < vertices[i].pos.y) {324 max_y = vertices[i].pos.y;340 if (min_y > pos.y) { 341 min_y = pos.y; 342 } else if (max_y < pos.y) { 343 max_y = pos.y; 325 344 } 326 345 327 if (min_z > vertices[i].pos.z) {328 min_z = vertices[i].pos.z;329 } else if (max_z < vertices[i].pos.z) {330 max_z = vertices[i].pos.z;346 if (min_z > pos.z) { 347 min_z = pos.z; 348 } else if (max_z < pos.z) { 349 max_z = pos.z; 331 350 } 332 351 } … … 338 357 } 339 358 340 return vertices; 359 object.radius = std::max(center.x, center.y); 360 object.radius = std::max(object.radius, center.z); 361 object.center = vec3(0.0f, 0.0f, 0.0f); 341 362 } 342 363
Note:
See TracChangeset
for help on using the changeset viewer.