Changeset a79be34 in opengl-game


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

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • shaders/ship.vert

    r60578ce ra79be34  
    2727
    2828// 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);
     29vec3 light_position_world = vec3(0.0, 0.0, 2.0);
     30vec3 light2_position_world = vec3(0.0, 1.5, -0.1);
    3331
    3432// TODO: This does not account for scaling in the model matrix
  • vulkan-game.cpp

    r60578ce ra79be34  
    267267   // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly
    268268   // the same data. Add an option to make some pipelines not use indexing
    269    /*
    270269   shipPipeline.addObject(
     270      centerObject<ShipVertex>(
    271271      addObjectIndex<ShipVertex>(shipPipeline.getObjects().size(),
    272272      addVertexNormals<ShipVertex>({
     
    466466         {{  1.5f,   0.0f,   0.0f}, {0.0f, 0.0f, 0.3f}},
    467467         {{  1.3f,   0.0f,  -0.3f}, {0.0f, 0.0f, 0.3f}},
    468       })), {
     468      }))), {
    469469           0,   1,   2,   3,   4,   5,
    470470           6,   7,   8,   9,  10,  11,
     
    497497         135, 136, 137,
    498498      }, commandPool, graphicsQueue);
    499    */
    500 
    501    // z-range is 0 to 1, with +1 pointing into the screen
    502    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);
    522499
    523500   shipPipeline.createDescriptorSetLayout();
     
    549526
    550527   float cam_yaw = 0.0f;
    551    float cam_pitch = 0.0f; // -50.0f;
     528   float cam_pitch = -50.0f;
    552529
    553530   mat4 yaw_mat = rotate(mat4(1.0f), radians(-cam_yaw), vec3(0.0f, 1.0f, 0.0f));
  • 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.