forked from fortmeier/CUDA-FE-With-Haptics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
134 lines (107 loc) · 3.84 KB
/
main.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
/***************************************************************************/
/* CUDA based TLED Solver */
/* {c} 2008-2010 Karsten Noe */
/* The Alexandra Institute */
/* See our blog on cg.alexandra.dk */
/***************************************************************************/
#include <GL/glew.h>
#include <vector>
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include "TLEDSolver.h"
using namespace TLED;
static int wWidth = 1024, wHeight = 1024;
TetrahedralTLEDState* state;
TetrahedralMesh* mesh;
TriangleSurface* surface;
void display()
{
glPushMatrix();
for (int i=0; i<40; i++)
{
calculateGravityForces(mesh, state);
doTimeStep(mesh, state);
applyFloorConstraint(mesh, state, -30);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
display(0,mesh, state, surface);
glPopMatrix();
glutPostRedisplay();
glutSwapBuffers();
}
void keyboard( unsigned char key, int x, int y) {
switch( key) {
case 27:
exit (0);
break;
case 'n':
mesh = loadMesh("data/torus_low_res.msh");
surface = loadSurfaceOBJ("data/torus_low_res.msh.obj");
precompute(mesh, state, 0.001f, 0.0f, 0.0f, 10007.0f, 5500.0f, 0.5f, 10.0f);
break;
/*case 'm':
mesh = loadMesh("data/torus_low_res.msh");
surface = loadSurfaceOBJ("torus_low_res.msh.obj");
precompute(mesh, state, 0.001f, 0.0f, 0.0f, 1007.0f, 49329.0f, 0.5f, 10.0f);
break;*/
case 'b':
mesh = loadMesh("data/torus_low_res.msh");
surface = loadSurfaceOBJ("data/torus_low_res.msh.obj");
precompute(mesh, state, 0.001f, 0.0f, 0.0f, 100007.0f, 493.0f, 0.5f, 10.0f);
break;
case 'v':
mesh = loadMesh("data/torus_low_res.msh");
surface = loadSurfaceOBJ("data/torus_low_res.msh.obj");
precompute(mesh, state, 0.001f, 0.0f, 0.0f, 100007.0f, 200.0f, 0.5f, 10.0f);
break;
default: break;
}
}
void reshape(int x, int y) {
wWidth = x; wHeight = y;
glViewport(0, 0, x, y);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-4, 4, -4, 4, 5, 200);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_LIGHTING);
//float redMaterial[] = { 1, 1, 1, 1 };
float lightmat[] = { 0.7f, 0.7f, 0.7f, 0.001f };
float lightamb[] = { 0.7f, 0.7f, 0.7f, 0.001f };
float lightpos[] = { 0.f, 0.f, 1500.f, 1.f};
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightmat);
gluLookAt(-40,0,-40,0,0,0,0,1,0);
glutPostRedisplay();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
printf("***********************************************************************\n");
printf("TLED solver CUDA implementation by Karsten Noe.\n");
printf("Press v,b,n or m to reload model and use different material parameters.\n");
printf("***********************************************************************\n");
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(wWidth, wHeight);
glutCreateWindow("TLED");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutReshapeFunc(reshape);
glewInit();
if (! glewIsSupported(
"GL_ARB_vertex_buffer_object"
)) {
fprintf( stderr, "ERROR: Support for necessary OpenGL extensions missing.");
fflush( stderr);
return -1;
}
state = new TetrahedralTLEDState();
mesh = loadMesh("data/torus_low_res.msh");
surface = loadSurfaceOBJ("data/torus_low_res.msh.obj");
precompute(mesh, state, 0.001f, 0.0f, 0.0f, 1007.0f, 49329.0f, 0.5f, 10.0f);
atexit(cleanupDisplay);
glutMainLoop();
return 0;
}