Changeset a79be34 in opengl-game for vulkan-game.hpp


Ignore:
Timestamp:
Dec 19, 2019, 4:37:03 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
cd1cb0f
Parents:
60578ce
Message:

Finish copying the ship pipeline to VulkanGame

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.hpp

    r60578ce ra79be34  
    44#define GLM_FORCE_RADIANS
    55#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_HANDED
     6#define GLM_FORCE_RIGHT_HANDED
    77
    88#include <glm/glm.hpp>
     
    186186      vector<VertexType> addObjectIndex(unsigned int objIndex, vector<VertexType> vertices);
    187187
     188      template<class VertexType>
     189      vector<VertexType> centerObject(vector<VertexType> vertices);
     190
    188191      void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags,
    189192         vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, vector<VkDescriptorBufferInfo>& bufferInfoList);
     
    207210      vec3 p3 = vertices[i+2].pos;
    208211
    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));
    211213
    212214      // Add the same normal for all 3 vertices
     
    228230}
    229231
     232template<class VertexType>
     233vector<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
    230271#endif // _VULKAN_GAME_H
Note: See TracChangeset for help on using the changeset viewer.