Changeset 06d959f in opengl-game


Ignore:
Timestamp:
Nov 27, 2019, 5:19:23 PM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
e1308e8
Parents:
0cf1a23
Message:

Add an addVertexNormals method to VulkanGame that calculates the normals given a list of vertices

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • graphics-pipeline_vulkan.hpp

    r0cf1a23 r06d959f  
    1111
    1212#include "vulkan-utils.hpp"
    13 
    14 using namespace std;
    1513
    1614// TODO: Maybe change the name of this struct so I can call the list something other than descriptorInfoList
     
    5755
    5856      const vector<SceneObject<VertexType>>& getObjects();
    59       bool addObject(const vector<VertexType>& vertices, vector<uint16_t> indices, VkCommandPool commandPool,
     57      void addObject(const vector<VertexType>& vertices, vector<uint16_t> indices, VkCommandPool commandPool,
    6058         VkQueue graphicsQueue);
    6159
     
    413411
    414412template<class VertexType>
    415 bool GraphicsPipeline_Vulkan<VertexType>::addObject(const vector<VertexType>& vertices, vector<uint16_t> indices,
     413void GraphicsPipeline_Vulkan<VertexType>::addObject(const vector<VertexType>& vertices, vector<uint16_t> indices,
    416414      VkCommandPool commandPool, VkQueue graphicsQueue) {
    417415
     
    426424      idx += numVertices;
    427425   }
    428    objects.push_back({vertices, indices });
     426   objects.push_back({ vertices, indices });
    429427
    430428   VulkanUtils::copyDataToBuffer(device, physicalDevice, commandPool, vertices, vertexBuffer, numVertices,
     
    435433      graphicsQueue);
    436434   numIndices += indices.size();
    437 
    438    return true;
    439435}
    440436
  • vulkan-game.hpp

    r0cf1a23 r06d959f  
    3232   vec3 pos;
    3333   vec3 color;
     34   vec3 normal;
    3435};
    3536
     
    158159      void createSyncObjects();
    159160
     161      template<class VertexType>
     162      vector<VertexType> addVertexNormals(vector<VertexType> vertices);
     163
    160164      template<class UniformType>
    161165      void createUniformBuffers(vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory,
     
    191195}
    192196
     197template<class VertexType>
     198vector<VertexType> VulkanGame::addVertexNormals(vector<VertexType> vertices) {
     199   for (unsigned int i = 0; i < vertices.size(); i += 3) {
     200      vec3 p1 = vertices[i].pos;
     201      vec3 p2 = vertices[i+1].pos;
     202      vec3 p3 = vertices[i+2].pos;
     203
     204      vec3 normal = normalize(cross(p2 - p1, p3 - p1));
     205      normal.z = -normal.z;
     206
     207      // Add the same normal for all 3 vertices
     208      vertices[i].normal = normal;
     209      vertices[i+1].normal = normal;
     210      vertices[i+2].normal = normal;
     211   }
     212
     213   return vertices;
     214}
     215
    193216#endif // _VULKAN_GAME_H
Note: See TracChangeset for help on using the changeset viewer.