V-ART
arrow.cpp
Go to the documentation of this file.
1 //FixMe: Translate to English, put headers.
2 
3 #include <iostream>
4 #include "vart/arrow.h"
5 #include "vart/meshobject.h"
6 #include "vart/mesh.h"
7 #include "vart/transform.h"
8 
9 using namespace std;
10 using namespace VART;
11 
12 float VART::Arrow::relativeRadius = 0.02;
15 
16 // Construtor que cria uma seta no eixo X de tamanho LENGTH (seta padrao)
17 VART::Arrow::Arrow(double length){
18  Inicializa(length);
19 }
20 
21 // Construtor que cria uma seta a partir de um ponto e uma direcao (seta generica)
23 {
24  // calcula a norma do vetor
25  Inicializa(direction.Length());
26 
27  // TRANSFORMACOES QUE LEVAM A SETA PADRAO ATE A SETA GENERICA
28  // rotacao em Z
29  double angulo;
30  Point4D projecao_direction = direction;
31  if ((direction.GetX() == 0) && (direction.GetZ() == 0))
32  angulo = 1.570796327;
33  else{
34  projecao_direction.SetY(0);
35  angulo = projecao_direction.GenericAngleTo(direction);
36  if(direction.GetY() < 0)
37  angulo = angulo * (-1);
38  }
39  Transform rotationZ;
40  rotationZ.MakeZRotation(angulo);
41  // rotacao em Y
42  angulo = projecao_direction.GenericAngleTo(Point4D::X());
43  if(projecao_direction.GetZ() > 0)
44  angulo = angulo * (-1);
45  Transform rotationY;
46  rotationY.MakeYRotation(angulo);
47  // translacao que leva a origem da seta padrao ate a origem da seta generica
48  Transform translacao2;
49  translacao2.MakeTranslation(point);
50 
51  //MATRIZ DE TRANSFORMACAO
52  Transform transformacao;
53  transformacao = translacao2 * rotationY * rotationZ;
54  /* aplico essa transformacao a cada um dos pontos da seta padrao para que ela
55  se transforme na seta generica */
56  ApplyTransform(transformacao);
57 }
58 
59 // metodo que inicializa uma seta. Este metodo eh usado nos construtores para
60 // gerar uma seta.
61 void VART::Arrow::Inicializa(double length)
62 {
63  double radius, baseLength, headRadius;
64 
65  radius = length * relativeRadius;
66  baseLength = length * relativeBaseLength;
67  headRadius = length * relativeHeadRadius;
68 
69  // Array com as coordenadas dos vertices
70  double coordinateArray[] = {0, -radius, -radius, //0
71  0, -radius, radius, //1
72  0, radius, radius, //2
73  0, radius, -radius, //3
74  baseLength, -radius, -radius, //4
75  baseLength, -radius, radius, //5
76  baseLength, radius, radius, //6
77  baseLength, radius, -radius, //7
78  baseLength, -headRadius, -headRadius, //8 face 6
79  baseLength, -headRadius, headRadius, //9 face 6
80  baseLength, headRadius, headRadius, //10 face 6
81  baseLength, headRadius, -headRadius, //11 face 6
82  length, 0, 0, //12 face 7
83  baseLength, -headRadius, -headRadius, //8 face 9
84  baseLength, -headRadius, -headRadius, //8 face 10
85  baseLength, -headRadius, headRadius, //9 face 7
86  baseLength, -headRadius, headRadius, //9 face 10
87  baseLength, headRadius, headRadius, //10 face 7
88  baseLength, headRadius, headRadius, //10 face 8
89  baseLength, headRadius, -headRadius, //11 face 8
90  baseLength, headRadius, -headRadius, //11 face 9
91  length, 0, 0, //12 face 8
92  length, 0, 0, //12 face 9
93  length, 0, 0}; //12 face 10
94 
95  double* endOfCoordinateArray = coordinateArray + sizeof(coordinateArray)/sizeof(double);
96 
97  // Array que define as faces quadradas
98  unsigned int indexArrayQuadraticFaces[] = { 0,1,2,3, // face 1
99  1,5,6,2, // face 2
100  2,6,7,3, // face 3
101  3,7,4,0, // face 4
102  4,5,1,0, // face 5
103  8,9,10,11}; // face 6
104  unsigned int* endOfIndexArrayQuadraticFaces = indexArrayQuadraticFaces + sizeof(indexArrayQuadraticFaces)/sizeof(int);
105 
106  // Array que define as faces triangulares
107  unsigned int indexArrayTriangularFaces[] = {12,10,9, // face 7
108  12,11,10, // face 8
109  11,12,8, // face 9
110  8,12,9}; // face 10
111 
112  unsigned int* endOfIndexArrayTriangularFaces = indexArrayTriangularFaces + sizeof(indexArrayTriangularFaces)/sizeof(int);
113 
114  // creates the base of the arrow
115  VART::Mesh meshQuadratic;
116  vertCoordVec.assign(coordinateArray,endOfCoordinateArray);
117  meshQuadratic.type = VART::Mesh::QUADS;
118  meshQuadratic.indexVec.assign(indexArrayQuadraticFaces,endOfIndexArrayQuadraticFaces);
119  meshQuadratic.material = VART::Material::PLASTIC_GREEN(); // default material
120  meshList.push_back(meshQuadratic);
121 
122  // creates the head of the arrow
123  VART::Mesh meshTriangular;
124  vertCoordVec.assign(coordinateArray,endOfCoordinateArray);
125  meshTriangular.type = VART::Mesh::TRIANGLES;
126  meshTriangular.indexVec.assign(indexArrayTriangularFaces,endOfIndexArrayTriangularFaces);
127  meshTriangular.material = VART::Material::PLASTIC_GREEN(); // default material
128  meshList.push_back(meshTriangular);
129 
130  ComputeVertexNormals();
131  ComputeBoundingBox();
132  ComputeRecursiveBoundingBox();
133 }
static float relativeBaseLength
Definition: arrow.h:22
Points and vectors using homogeneous coordinates.
Definition: point4d.h:22
double Length() const
Returns the vector's length.
Definition: point4d.cpp:111
void MakeTranslation(const Point4D &translationVector)
Turns transform into a translation.
Definition: transform.cpp:56
MeshType type
Definition: mesh.h:66
Header file for V-ART class "Mesh".
static float relativeHeadRadius
Definition: arrow.h:13
double GetZ() const
Definition: point4d.h:80
double GetY() const
Definition: point4d.h:79
A mesh is part of an graphical object, in which faces are made of vertices according to some rule of ...
Definition: mesh.h:30
Geometric transformations.
Definition: transform.h:24
void MakeYRotation(double radians)
Turns transform into a rotation around the Y axis.
Definition: transform.cpp:73
Header file for V-ART class "Transform".
Arrow(double length)
Definition: arrow.cpp:17
void SetY(double y)
Definition: point4d.h:113
std::vector< unsigned int > indexVec
indexes of the vertices (start at 0) defining faces
Definition: mesh.h:62
Header file for V-ART class "MeshObject".
static const Material & PLASTIC_GREEN()
Definition: material.cpp:88
double GetX() const
Definition: point4d.h:78
void MakeZRotation(double radians)
Turns transform into a rotation around the Z axis.
Definition: transform.cpp:82
double GenericAngleTo(const Point4D &p) const
Definition: point4d.cpp:152
Material material
Definition: mesh.h:65
static float relativeRadius
Definition: arrow.h:21