CSEngine
Loading...
Searching...
No Matches
Vertex.h
1#pragma once
2
3#include "../../../Matrix.h"
4#include "VertexSkinData.h"
5#include <vector>
6// #include <iostream>
7
8namespace CSE {
9
10 class Vertex {
11 public:
12 Vertex(int index, vec3 position, VertexSkinData* weightsData = nullptr) {
13 m_index = index;
14 m_position = position;
15 m_weightsData = weightsData;
16 // std::cout << "index = " << index << '\n';
17 }
18
19 ~Vertex() {
20
21 }
22
23 int getIndex() {
24 return m_index;
25 }
26
27 float getLength() {
28 return m_length;
29 }
30
31 bool isSet() {
32 return m_textureIndex != -1 && m_normalIndex != -1;
33 }
34
35 bool hasSameTextureAndNormal(int textureIndexOther, int normalIndexOther) {
36 return textureIndexOther == m_textureIndex && normalIndexOther == m_normalIndex;
37 }
38
39 void setTextureIndex(int textureIndex) {
40 m_textureIndex = textureIndex;
41 }
42
43 void setNormalIndex(int normalIndex) {
44 m_normalIndex = normalIndex;
45 }
46
47 vec3 getPosition() {
48 return m_position;
49 }
50
51 int getTextureIndex() {
52 return m_textureIndex;
53 }
54
55 int getNormalIndex() {
56 return m_normalIndex;
57 }
58
59 Vertex* getDuplicateVertex() {
60 return m_duplicateVertex;
61 }
62
63 void setDuplicateVertex(Vertex* duplicateVertex) {
64 m_duplicateVertex = duplicateVertex;
65 }
66
67 VertexSkinData* getWeightsData() const {
68 return m_weightsData;
69 }
70
71 void addTangent(vec3 tangent) {
72 m_tangents.push_back(tangent);
73 }
74
75 void averageTangents() {
76 if (m_tangents.empty()) {
77 return;
78 }
79 for (vec3 tangent : m_tangents) {
80 m_avgTangent += tangent;
81 }
82 m_avgTangent.Normalize();
83 }
84
85 const vec3& getAvgTangent() const {
86 return m_avgTangent;
87 }
88
89 private:
90 vec3 m_position;
91
92 int m_textureIndex = -1;
93 int m_normalIndex = -1;
94
95 Vertex* m_duplicateVertex = nullptr;
96
97 int m_index;
98 float m_length;
99
100 std::vector<vec3> m_tangents;
101 vec3 m_avgTangent = vec3{ 0, 0, 0 };
102 VertexSkinData* m_weightsData;
103 };
104}