-
Notifications
You must be signed in to change notification settings - Fork 2
/
extrudedMesh.h
143 lines (117 loc) · 3.23 KB
/
extrudedMesh.h
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//This is the header file for the Point3, Vector3, VertexID, Face,
//and Mesh classes.
#define WINDOWS
#ifdef WINDOWS
#include <Windows.h>
#include <gl/GL.h>
#include <gl/GLU.h>
#include <gl/glut.h>
#endif
#ifdef LINUX
#include <GL/glut.h>
#endif
#ifdef MAC
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#endif
#include <cmath>
#include <fstream>
#include <iostream>
using namespace std;
#ifndef MeshClasses
#define MeshClasses
//This is the definition of the point class
class Point3
{
public:
//the x, y, and z coordinates of the point
float x, y, z;
//constructors for the Point3 class
Point3 (float xx, float yy, float zz){x = xx; y = yy; z = zz;}
Point3() {x = y = z = 0;}
Point3(const Point3& other) {x=other.x; y=other.y; z=other.z;}
//set the point either by passing x, y, & z or by passing a point
void set (float dx, float dy, float dz){x = dx; y = dy; z = dz;}
void set (Point3& p){x = p.x; y = p.y; z = p.z;}
//build a homogeneous point from the point
void build4tuple(float v[])
{
//load 4-tuple with this color: v[3]=1 for homogeneous
v[0] = x;
v[1] = y;
v[2] = z;
v[3] = 1.0f;
}
};
//This is the definition for Vector3 -- a three dimensional vector
//class
class Vector3
{
public:
//the x, y, and z direction of the vector
float x, y, z;
//constructors for the vector class
Vector3() {x = 0; y = 0; z = 0;}
Vector3(float xx, float yy, float zz) { x = xx; y = yy; z = zz;}
Vector3(const Vector3& v) { x = v.x; y = v.y; z = v.z;}
//set a vector's values
void set(float dx, float dy, float dz) {x = dx; y = dy; z = dz;}
void set (Vector3 & v) { x = v.x; y = v.y; z = v.z;}
//reverse the vector
void flip() { x = -x; y = -y; z = -z;}
//determine a vector between two points
void setDiff (Point3& a, Point3& b)
{
x = a.x - b.x;
y = a.y - b.y;
z = a.z - b.z;
}
//normalize a vector to unit length
void normalize();
//determine the cross product of a vector
Vector3 cross (Vector3 b);
//determine the dot product of a vector
float dot (Vector3 b);
};
//################# VertexID ###################
class VertexID{
public:
int vertIndex; // index of this vert in the vertex list
int normIndex; // index of this vertex's normal
};
//#################### Face ##################
class Face{
public:
int nVerts; // number of vertices in this face
VertexID * vert; // the list of vertex and normal indices
Face(){nVerts = 0; vert = NULL;} // constructor
~Face(){delete[] vert; nVerts = 0;} // destructor
};
//###################### Mesh #######################
class Mesh{
protected:
int numVerts; // number of vertices in the mesh
Point3* pt; // array of 3D vertices
int numNorms; // number of normal vectors for the mesh
Vector3 *norm; // array of normals
int numFaces; // number of faces in the mesh
Face* face; // array of face data
public:
Mesh(); // constructor
~Mesh(); // destructor
// to read in a filed mesh
int readmesh(char * fileName);
void draw(); // use OpenGL to draw this mesh
//For the ith face, determine a normal
//using Newell's method.
Vector3 newellMethod(int i);
};
class ExtrudedMesh: public Mesh
{
public:
ExtrudedMesh();
ExtrudedMesh(Point3[], int numPts, int height);
void draw();
};
#endif