-
Notifications
You must be signed in to change notification settings - Fork 2
/
deform.cpp
executable file
·160 lines (131 loc) · 4.87 KB
/
deform.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/* Source: deform
* Description: Contains functions that controls the deformation simulation.
*/
//#include "render.h"
#include "physics.h"
#include "ui.h"
#include "world.h"
#include "input.h"
#include "keyboard.h"
/* Function: reset
* Description: Reinitializes the values for simulation.
* Input: None
* Output: None
*/
void reset()
{
// pModel *temp;
DeleteModels();
// temp = phyzxModels;
inputInit();
keyInit();
// resetModel(temp->pObj);
objectName = -1;
iMouseModel = 0;
userForce = vMake(0.0);
// dispPhysics(temp->pObj);
} //end reset
/* Function: resetModel
* Description: Revert the models current positions to its rest state.
* Input: src - Model Data Source
* Output: None
*/
void resetModel(phyzx *phyzxObj)
{
for (unsigned int i = 0; i <= phyzxObj->model->numvertices; i++) /* array of vertices */
{
phyzxObj->model->vertices[3*i+0] = phyzxObj->model->verticesRest[3*i+0];
phyzxObj->model->vertices[3*i+1] = phyzxObj->model->verticesRest[3*i+1];
phyzxObj->model->vertices[3*i+2] = phyzxObj->model->verticesRest[3*i+2];
phyzxObj->velocity[i] = vMake(0.0);
phyzxObj->avgVel = vMake(0.0);
phyzxObj->extForce[i] = vMake(0.0);
} //end for
} //end resetModel
/* Function: modelCopy
* Description: Copy model data into another model.
* Input: src - Model Data Source
* dest - Model Data Destination
* Output: None
*/
void modelCopy(GLMmodel *src, GLMmodel *dest)
{
dest->mtllibname = NULL;
dest->numvertices = 0;
dest->vertices = NULL;
dest->verticesRest = NULL;
dest->numnormals = 0;
dest->normals = NULL;
dest->numtexcoords = 0;
dest->texcoords = NULL;
dest->numfacetnorms = 0;
dest->facetnorms = NULL;
dest->numtriangles = 0;
dest->triangles = NULL;
dest->nummaterials = 0;
dest->materials = NULL;
dest->numgroups = 0;
dest->groups = NULL;
dest->position[0] = 0.0;
dest->position[1] = 0.0;
dest->position[2] = 0.0;
/* allocate memory for the triangles in each group */
GLMgroup *group;
group = src->groups;
while(src->groups)
{
dest->groups->triangles = (GLuint*)malloc(sizeof(GLuint) * group->numtriangles);
group->numtriangles = 0;
group->edges = (GLuint*)malloc(sizeof(GLuint) * group->numEdges * 2);
group->numEdges = 0;
group = group->next;
}
dest->numvertices = src->numvertices;
dest->vertices = (GLfloat*)malloc(sizeof(GLfloat) * 3 * (dest->numvertices + 1));
dest->verticesRest = src->verticesRest;
dest->verticesRest = (GLfloat*)malloc(sizeof(GLfloat) * 3 * (dest->numvertices + 1));
dest->numtriangles = src->numtriangles;
dest->triangles = (GLMtriangle*)malloc(sizeof(GLMtriangle) * dest->numtriangles);
dest->numnormals = src->numnormals;
if (dest->numnormals)
{
dest->normals = (GLfloat*)malloc(sizeof(GLfloat) *
3 * (dest->numnormals + 1));
}
dest->numtexcoords = src->numtexcoords;
if (dest->numtexcoords)
{
dest->texcoords = (GLfloat*)malloc(sizeof(GLfloat) *
2 * (dest->numtexcoords + 1));
}
strcpy((*dest).pathname, (*src).pathname); /* path to this model */
strcpy((*dest).mtllibname, (*src).mtllibname); /* name of the material library */
(*dest).numvertices = (*src).numvertices; /* number of vertices in model */
for (int i = 0; i <= (*dest).numvertices; i++) /* array of vertices */
{
(*dest).vertices[3*i+0] = (*src).vertices[3*i+0];
(*dest).vertices[3*i+1] = (*src).vertices[3*i+1];
(*dest).vertices[3*i+2] = (*src).vertices[3*i+2];
(*dest).verticesRest[3*i+0] = (*src).verticesRest[3*i+0];
(*dest).verticesRest[3*i+1] = (*src).verticesRest[3*i+1];
(*dest).verticesRest[3*i+2] = (*src).verticesRest[3*i+2];
} //end for
(*dest).numnormals = (*src).numnormals; /* number of normals in model */
(*dest).normals = (*src).normals; /* array of normals */
(*dest).numtexcoords = (*src).numtexcoords; /* number of texcoords in model */
(*dest).texcoords = (*src).texcoords; /* array of texture coordinates */
(*dest).numfacetnorms = (*src).numfacetnorms; /* number of facetnorms in model */
(*dest).facetnorms = (*src).facetnorms; /* array of facetnorms */
(*dest).numtriangles = (*src).numtriangles; /* number of triangles in model */
(*dest).facetnorms = (*src).facetnorms; /* array of triangles */
(*dest).nummaterials = (*src).nummaterials; /* number of materials in model */
(*dest).materials = (*src).materials; /* array of materials */
(*dest).numgroups = (*src).numgroups; /* number of groups in model */
(*dest).groups = (*src).groups; /* linked list of groups */
(*dest).textureMode = (*src).textureMode;
/* position of the model */
(*dest).position[0] = (*src).position[0];
(*dest).position[1] = (*src).position[1];
(*dest).position[2] = (*src).position[2];
strcpy((*dest).directory, (*src).directory); /* the folder where the model is */
} //end modelCopy