forked from picciau-g/superfacets-2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormals.cpp
executable file
·65 lines (53 loc) · 1.48 KB
/
normals.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
/*
*
* 2014
* Author: Giulia Picciau - DIBRIS, Università degli studi di Genova
* Supervisors: Leila De Floriani - DIBRIS, Università degli studi di Genova
* Patricio Simari - Department of Electrical Engineering and Computer Science, The Catholic University of America
*
* Title: Fast and scalable mesh superfacets
* Submission to Pacific Graphics 2014
*
*
**/
#include "normals.h"
Normals::Normals()
{
}
/**
* @brief Normals::Normals calculates normals to a plane (represented with 3 points)
* @param a first point
* @param b second point
* @param c third point
*/
Normals::Normals(Vertex3D a, Vertex3D b, Vertex3D c){
float vec1[3], vec2[3];
vec1[0]=b.getX()-a.getX();
vec1[1]=b.getY()-a.getY();
vec1[2]=b.getZ()-a.getZ();
vec2[0]=c.getX()-a.getX();
vec2[1]=c.getY()-a.getY();
vec2[2]=c.getZ()-a.getZ();
this->nx=(vec1[1]*vec2[2])-(vec1[2]*vec2[1]);
this->ny=(vec1[2]*vec2[0])-(vec1[0]*vec2[2]);
this->nz=(vec1[0]*vec2[1])-(vec1[1]*vec2[0]);
//To have them in range [0,1]
Normalize();
}
/**
* @brief Normals::Normalize to have normal components in the interval [0,1]
*/
void Normals::Normalize(){
float normFact=sqrt(nx*nx + ny*ny + nz*nz);
nx /= normFact;
ny /= normFact;
nz /= normFact;
}
/**
* @brief Normals::dotProd scalar product
* @param N normal vector
* @return
*/
float Normals::dotProd(Normals N){
return this->nx*N.nx + this->ny*N.ny + this->nz*N.nz;
}