-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeometry.h
More file actions
111 lines (88 loc) · 3.19 KB
/
Copy pathgeometry.h
File metadata and controls
111 lines (88 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#pragma once
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#define GLM_ENABLE_EXPERIMENTAL
#include "glm/gtx/hash.hpp"
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
struct Vertex{
glm::vec3 pos;
glm::vec3 norm;
glm::vec3 col;
static VkVertexInputBindingDescription getBindingDescription(){
VkVertexInputBindingDescription bindingDescription{};
bindingDescription.binding = 0;
bindingDescription.stride = sizeof(Vertex);
bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;// can be VK_VERTEX_INPUT_RATE_INSTANCED
return bindingDescription;
}
static std::array<VkVertexInputAttributeDescription, 3> getAttributeDescriptions(){
std::array<VkVertexInputAttributeDescription, 3> attributeDescriptions{};
attributeDescriptions[0].binding = 0;
attributeDescriptions[0].location = 0;
attributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
attributeDescriptions[0].offset = offsetof(Vertex, pos);
attributeDescriptions[1].binding = 0;
attributeDescriptions[1].location = 1;
attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
attributeDescriptions[1].offset = offsetof(Vertex, norm);
attributeDescriptions[2].binding = 0;
attributeDescriptions[2].location = 2;
attributeDescriptions[2].format = VK_FORMAT_R32G32B32_SFLOAT;
attributeDescriptions[2].offset = offsetof(Vertex, col);
return attributeDescriptions;
}
};
struct Quaternion{
double q[4];
void set(double axis[3], double theta);
glm::mat4x4 getMatrix();
Quaternion times(Quaternion quat);
void renormalize();
};
template <typename T>
class MemoryManager;
class Model{
public:
Model(MemoryManager<Vertex>* v, MemoryManager<uint16_t>* i, std::vector<Vertex> verts, std::vector<uint16_t> inds);
~Model();
int getVertStart() const {return vertStart;};
int getVertLength() const {return vertLength;};
int getIndsStart() const {return indsStart;};
int getIndsLength() const {return indsLength;};
glm::mat4x4 getModelTransform() const {return modelTransform;};
void moveTo(float newPos[3]);
void setRotation(Quaternion quat);
private:
MemoryManager<Vertex>* vertsMM;
MemoryManager<uint16_t>* indsMM;
Vertex* vertsMem;
uint16_t* indsMem;
int vertStart;
int vertLength;
int indsStart;
int indsLength;
glm::mat4x4 modelTransform;
float pos[3];
Quaternion q;
};
class InstancedModel: public Model{// a version of model which stores multiple transforms
public:
InstancedModel(MemoryManager<Vertex>* v, MemoryManager<uint16_t>* i, std::vector<Vertex> verts, std::vector<uint16_t> inds);
~InstancedModel();
std::vector<glm::mat4x4> getModelTransforms() const {return transforms;};
void moveITo(int i, float newPos[3]);
void setIRotation(int i, Quaternion quat);
private:
std::vector<glm::mat4x4> transforms;
std::vector<float> poses;
std::vector<Quaternion> qs;
};