-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject3D.cpp
More file actions
67 lines (65 loc) · 2.18 KB
/
Copy pathobject3D.cpp
File metadata and controls
67 lines (65 loc) · 2.18 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
#include "linalg.h"
#include "object3D.h"
namespace Aloschil
{
using namespace std;
//----------------------------------------------------------------------------
// This is a public API. Refer to object3D.h for details.
//----------------------------------------------------------------------------
void Face::setPoints(std::vector<Matrix> pointsToSet)
{
points=pointsToSet;
updateNormal();
}
//----------------------------------------------------------------------------
// This is a public API. Refer to object3D.h for details.
//----------------------------------------------------------------------------
Face Face::getInvertedFace()
{
Face result;
int numberOfPoints = (int)points.size();
for(int i=numberOfPoints-1;i>=0;--i)
{
result.points.push_back(points[i]);
}
result.updateNormal();
return result;
}
//----------------------------------------------------------------------------
// This is a public API. Refer to object3D.h for details.
//----------------------------------------------------------------------------
void Face::print()
{
vector<Matrix>::iterator curPoint=points.begin();
vector<Matrix>::iterator endPoint=points.end();
printf("Face points:\n");
for(;curPoint!=endPoint;++curPoint)
{
(*curPoint).print();
}
printf("Face normal:\n");
normal.print();
}
//----------------------------------------------------------------------------
// This is a public API. Refer to object3D.h for details.
//----------------------------------------------------------------------------
Face operator *(const Matrix &m,const Face &face)
{
Face result;
vector<Matrix>::const_iterator curPoint=face.points.begin();
vector<Matrix>::const_iterator endPoint=face.points.end();
for(;curPoint!=endPoint;++curPoint)
{
result.points.push_back(m*(*curPoint));
}
result.updateNormal();
return result;
}
//----------------------------------------------------------------------------
// This is a public API. Refer to object3D.h for details.
//----------------------------------------------------------------------------
void Face::updateNormal()
{
normal = normalize(getCrossProduct(points[1]-points[0],points[2]-points[1]));
}
}