-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVertex.cpp
74 lines (61 loc) · 1.77 KB
/
Vertex.cpp
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
#include "Vertex.h"
#include <cmath>
Vertex::Vertex()
{
xyz.first = 0.0f;
xyz.second = 0.0f;
xyz.third = 0.0f;
normals.push_back(triplet<float, float, float>(0.0f, 0.0f, 0.0f));
}
Vertex::Vertex(float x, float y, float z)
{
xyz.first = x;
xyz.second = y;
xyz.third = z;
}
Vertex::~Vertex()
{
//dtor
}
void Vertex::addNormal(float x, float y, float z)
{
bool found = false;
for(std::vector<triplet<float, float, float> >::iterator it = normals.begin(); it != normals.end(); ++it)
{
triplet<float, float, float> normal = *it;
if(normal.first == x && normal.second == y && normal.third == z)
{
found = true;
}
}
if(!found)
{
normals.push_back(triplet<float, float, float>(x, y, z));
}
}
void Vertex::setXyz(float x, float y, float z)
{
xyz.first = 0.0f;
xyz.second = 0.0f;
xyz.third = 0.0f;
}
triplet<float, float, float> Vertex::getXyz()
{
return xyz;
}
triplet<float, float, float> Vertex::getNormal()
{
triplet<float, float, float> normal;
for(std::vector<triplet<float, float, float> >::iterator it = normals.begin(); it != normals.end(); ++it)
{
triplet<float, float, float> tmpNormal = *it;
normal.first += tmpNormal.first;
normal.second += tmpNormal.second;
normal.third += tmpNormal.third;
}
float length = sqrt((normal.first * normal. first) + (normal.second * normal.second) + (normal.third * normal.third));
normal.first /= length;
normal.second /= length;
normal.third /= length;
return normal;
}