#include <GL/glu.h>#include <FL/glut.H>#include <cstdio>#include <cstdlib>#include <iostream>#include "glm.H"#include <cmath>#include "camera.H"#include "biker.H"#include "pv_tools.h"Include dependency graph for graphics.cxx:

Defines | |
| #define | ESCAPE 27 |
| #define | NUM_MODELS 18 |
Typedefs | |
| typedef float | float3 [3] |
| typedef float | float4 [4] |
| typedef double | double3 [3] |
| typedef double | double4 [4] |
Functions | |
| int | db_draw_biker () |
| void | db_displayFunc () |
| void | db_driver () |
| void | keyboard (unsigned char key, int x, int y) |
| void | mouse (int button, int state, int x, int y) |
| void | motion (int x, int y) |
| void | GenerateLists () |
| void | LoadModels () |
| void | db_bike_init () |
| int | startUpGLUT (int argc, char **argv) |
Variables | |
| double3 | locationlist [17] |
| double4 | orientationlist [17] |
| GLMmodel * | bikerModel [NUM_MODELS] |
| GLuint | model_list [NUM_MODELS] |
| char * | model_file [NUM_MODELS] |
| GLboolean | facet_normal = GL_FALSE |
| GLfloat | smoothing_angle = 90.0 |
| GLfloat | scale = 1.0 |
| GLdouble | pan_x = 0.0 |
| GLdouble | pan_y = 0.0 |
| GLdouble | pan_z = 0.0 |
| GLint | mouse_state = -1 |
| GLint | mouse_button = -1 |
| GLboolean | bounding_box = GL_FALSE |
| GLboolean | performance = GL_FALSE |
| GLboolean | stats = GL_FALSE |
| GLfloat | weld_distance = 0.00001 |
| GLuint | material_mode [NUM_MODELS] |
| totalSim | biker |
| int | done = 0 |
| int | old_x |
| int | old_y |
| int | dragging = 0 |
| char | model_name [256] |
| int | lookAtBody = 0 |
| float | groundX = 0 |
| float | groundY = 0 |
| float | groundZ = 0 |
| Camera | camera |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
00057 {
00058 return(biker.draw);
00059 }
|
|
|
00063 {
00064 int numModel;
00065 float normalize, xaxis, yaxis, zaxis, alpha;
00066
00067 //Modification: 08/27/2002 Pascal
00068 if(1){
00069 //if (biker.draw) {
00070 biker.draw = 0;
00071 //change scene graph
00072 //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00073 //glEnable(GL_LIGHTING);
00074 //glEnable(GL_COLOR_MATERIAL);
00075 glColor3f(0.5, 0.5, 0.5);
00076 //glMatrixMode(GL_MODELVIEW);
00077 //glLoadIdentity();
00078 //camera.UseCamera();
00079
00080 biker.bikeOrient(locationlist, orientationlist);
00081
00082 glPushMatrix();
00083 glTranslatef(20.0*floor(locationlist[0][0]/20.0),20.0*floor(locationlist[0][1]/20.0),0.0);
00084 // groundX = locationlist[0][0];
00085 // groundY = locationlist[0][1];
00086 // glTranslatef(groundX,groundY,groundZ);
00087 glRotatef(90,1,0,0);
00088 glCallList(model_list[NUM_MODELS-1]);
00089 glPopMatrix();
00090
00091 for (numModel=0;numModel<NUM_MODELS-1;numModel++) {
00092 alpha = acosf(orientationlist[numModel][3]);
00093 normalize = orientationlist[numModel][0]*orientationlist[numModel][0] +
00094 orientationlist[numModel][1]*orientationlist[numModel][1] +
00095 orientationlist[numModel][2]*orientationlist[numModel][2];
00096 xaxis = orientationlist[numModel][0] / normalize;
00097 yaxis = orientationlist[numModel][1] / normalize;
00098 zaxis = orientationlist[numModel][2] / normalize;
00099 glPushMatrix();
00100 glTranslatef(locationlist[numModel][0],
00101 locationlist[numModel][1],
00102 locationlist[numModel][2]);
00103 if(numModel == lookAtBody){
00104 camera.SetLookAt(locationlist[numModel][0],
00105 locationlist[numModel][1],
00106 locationlist[numModel][2]);
00107 }
00108 glRotatef (360.0 / PI * alpha, xaxis, yaxis, zaxis);
00109 glCallList(model_list[numModel]);
00110 glPopMatrix();
00111 }
00112 //glutSwapBuffers();
00113 }
00114 }
|
|
|
00117 {
00118 // if(biker_loop()){
00119 // done = 1;
00120 // glutIdleFunc(NULL);
00121 // }
00122
00123 biker.bikerLoop();
00124
00125 //glutPostRedisplay();
00126
00127 }
|
|
||||||||||||||||
|
00130 {
00131
00132 switch (key) {
00133 case '-':
00134 case '_':
00135 camera.ZoomByFactor(.5);
00136 break;
00137
00138 case '+':
00139 case '=':
00140 camera.ZoomByFactor(2);
00141 break;
00142
00143 case 'z':
00144 camera.RotateZ(5);
00145 break;
00146 case 'Z':
00147 camera.RotateZ(-5);
00148 break;
00149 case ',':
00150 case '<':
00151 lookAtBody = lookAtBody+NUM_MODELS-1-1;
00152 lookAtBody %= NUM_MODELS-1;
00153 break;
00154 case '.':
00155 case '>':
00156 lookAtBody = lookAtBody+1;
00157 lookAtBody %= NUM_MODELS-1;
00158 break;
00159 case '[':
00160 biker.bikerLowControl.changeRidingDirection(1);
00161 break;
00162 case ']':
00163 biker.bikerLowControl.changeRidingDirection(-1);
00164 break;
00165
00166 case ESCAPE:
00167 exit (0);
00168 break;
00169 default:
00170 break;
00171 }
00172 //glutPostRedisplay();
00173 }
|
|
||||||||||||||||||||
|
|
|
||||||||||||
|
|
|
|
00201 {
00202 GLfloat ambient[] = { 0.2, 0.2, 0.2, 1.0 };
00203 GLfloat diffuse[] = { 0.8, 0.8, 0.8, 1.0 };
00204 GLfloat specular[] = { 0.0, 0.0, 0.0, 1.0 };
00205 GLfloat shininess = 65.0;
00206 int numModel;
00207
00208 for (numModel=0;numModel<NUM_MODELS;numModel++) {
00209 if (model_list[numModel])
00210 glDeleteLists(model_list[numModel], 1);
00211 }
00212
00213 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
00214 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
00215 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
00216 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
00217
00218 /* generate a list */
00219 for (numModel=0;numModel<NUM_MODELS;numModel++) {
00220 if (material_mode[numModel] == 0) {
00221 if (facet_normal)
00222 model_list[numModel] = glmList(bikerModel[numModel], GLM_FLAT);
00223 else
00224 model_list[numModel] = glmList(bikerModel[numModel], GLM_SMOOTH);
00225 }else if (material_mode[numModel] == 1) {
00226 if (facet_normal)
00227 model_list[numModel] = glmList(bikerModel[numModel], GLM_FLAT | GLM_COLOR);
00228 else
00229 model_list[numModel] = glmList(bikerModel[numModel], GLM_SMOOTH | GLM_COLOR);
00230 }else if (material_mode[numModel] == 2) {
00231 if (facet_normal)
00232 model_list[numModel] = glmList(bikerModel[numModel], GLM_FLAT | GLM_MATERIAL);
00233 else
00234 model_list[numModel] = glmList(bikerModel[numModel], GLM_SMOOTH | GLM_MATERIAL);
00235 }
00236 }
00237 }
|
|
|
00240 {
00241 bikerModel[0] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Thesis/Models/Biker/sim_PELVIS_pelvis.obj");
00242 std::cout << "Loaded PELVIS" << std::endl;
00243 bikerModel[1] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Thesis/Models/Biker/torsoWithHead.obj");
00244 std::cout << "Loaded TORSO" << std::endl;
00245 bikerModel[2] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Thesis/Models/Biker/sim_ULEGR_upperlegR.obj");
00246 std::cout << "Loaded ULEGR" << std::endl;
00247 bikerModel[3] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Thesis/Models/Biker/sim_ULEGL_upperlegL.obj");
00248 std::cout << "Loaded ULEGL" << std::endl;
00249 bikerModel[4] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Thesis/Models/Biker/sim_LLEGR_lowerlegR.obj");
00250 std::cout << "Loaded LLEGR" << std::endl;
00251 bikerModel[5] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Thesis/Models/Biker/sim_LLEGL_lowerlegL.obj");
00252 std::cout << "Loaded LLEGL" << std::endl;
00253 bikerModel[6] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Thesis/Models/Biker/sim_FOOTR_RWB.obj");
00254 std::cout << "Loaded FOOTR" << std::endl;
00255 bikerModel[7] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Thesis/Models/Biker/sim_FOOTL_RWB.obj");
00256 std::cout << "Loaded FOOTL" << std::endl;
00257 bikerModel[8] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Bike/Biker/sim_UARMR_upperarmR.obj");
00258 std::cout << "Loaded UARMR" << std::endl;
00259 bikerModel[9] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Bike/Biker/sim_UARML_upperarmL.obj");
00260 std::cout << "Loaded UARML" << std::endl;
00261 bikerModel[10] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Thesis/Models/Biker/lowerArmAndHandL.obj");
00262 std::cout << "Loaded LARMR" << std::endl;
00263 bikerModel[11] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Thesis/Models/Biker/lowerArmAndHandL.obj");
00264 std::cout << "Loaded LARML" << std::endl;
00265 bikerModel[12] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Thesis/Models/Biker/sim_FRAME_FRAME.obj");
00266 std::cout << "Loaded FRAME" << std::endl;
00267 bikerModel[13] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Thesis/Models/Biker/sim_RWHEEL_RWHEEL.obj");
00268 std::cout << "Loaded RWHEEL" << std::endl;
00269 bikerModel[14] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Thesis/Models/Biker/sim_FORK_FORK.obj");
00270 std::cout << "Loaded FORK" << std::endl;
00271 bikerModel[15] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Thesis/Models/Biker/sim_FWHEEL_FWHEEL.obj");
00272 std::cout << "Loaded FWHEEL" << std::endl;
00273 bikerModel[16] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Thesis/Models/Biker/sim_CRANK_CRANK.obj");
00274 std::cout << "Loaded CRANK" << std::endl;
00275 bikerModel[17] = glmReadOBJ ("/net/uf6/dbrogan/Sim/Bike/Biker/ground36.obj");
00276 std::cout << "Loaded GROUND" << std::endl;
00277 for (int numModel=0;numModel<NUM_MODELS;numModel++) {
00278 // scale = glmUnitize(model[numModel]);
00279 glmFacetNormals(bikerModel[numModel]);
00280 glmVertexNormals(bikerModel[numModel], smoothing_angle);
00281 if (bikerModel[numModel]->nummaterials > 0) {
00282 material_mode[numModel] = 2;
00283 }
00284
00285 }
00286 /* create new display lists */
00287 GenerateLists();
00288 }
|
|
|
00290 {
00291 camera.UseOffSet(true);
00292 camera.SetLocation(0,7.0,0);
00293 camera.SetLookAt(0,0,0);
00294
00295 for(int numModel=0;numModel<NUM_MODELS;numModel++) {
00296 model_list[numModel] = 0;
00297 model_file[numModel] = NULL;
00298 material_mode[numModel] = 0;
00299 }
00300
00301 LoadModels();
00302
00303 biker.bikeOrient(locationlist, orientationlist);
00304
00305 groundZ = 0;
00306 groundX = locationlist[0][0];
00307 groundY = locationlist[0][1];
00308 }
|
|
||||||||||||
|
00311 {
00312 int numModel;
00313
00314 glutInit(&argc, argv);
00315 glutInitWindowPosition(100, 100);
00316 glutInitWindowSize(640, 480);
00317 glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
00318 glutCreateWindow("Biker Guy");
00319 glutDisplayFunc(db_displayFunc);
00320 glutMouseFunc(mouse);
00321 glutMotionFunc(motion);
00322 glutKeyboardFunc(keyboard);
00323 glEnable(GL_DEPTH_TEST);
00324 glClearDepth(1.0f); // Depth Buffer Setup
00325 glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);// Really Nice Perspective Calculations
00326 glShadeModel(GL_SMOOTH); // Enable Smooth Shading
00327 glClearColor(0.0f, 0.0f, 0.5f, 0.5f); // Black Background
00328
00329 glMatrixMode(GL_PROJECTION);
00330 gluPerspective( /* field of view in degree */ 22.0,
00331 /* aspect ratio */ 640.0 / 480.0,
00332 /* Z near */ 1.0,
00333 /* Z far */ 1000.0);
00334
00335 glMatrixMode(GL_MODELVIEW);
00336 glLoadIdentity();
00337 glEnable(GL_LIGHTING);
00338 glEnable(GL_CULL_FACE);
00339 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00340 glEnable(GL_LIGHT0);
00341 camera.UseOffSet(true);
00342 camera.SetLocation(0,7.0,0);
00343 camera.SetLookAt(0,0,0);
00344
00345
00346
00347
00348
00349 for (numModel=0;numModel<NUM_MODELS;numModel++) {
00350 model_list[numModel] = 0;
00351 model_file[numModel] = NULL;
00352 material_mode[numModel] = 0;
00353 }
00354 LoadModels();
00355
00356
00357 // biker_loop();
00358 biker.bikeOrient(locationlist, orientationlist);
00359 groundZ = 0;
00360 groundX = locationlist[0][0];
00361 groundY = locationlist[0][1];
00362 glutIdleFunc(db_driver);
00363 glutMainLoop();
00364
00365 return 0;
00366
00367 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.2.18