/* * main - this is the main programme. */ int main () { TestMaterial universe; universe.initializeUniverse(); universe.TestPrecision(); return 0; }
/* * main - this is the main programme. */ int main () { #ifdef ENABLE_SIGFPE feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT); #endif TestMaterial universe = TestMaterial(NON_STP_BV_OBJECTS ); universe.initializeUniverse(); universe.TestAnimation(); return 0; }
/* * main - this is the main programme. */ int main () { #ifdef ENABLE_SIGFPE feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT); #endif TestMaterial universe = TestMaterial(); //No other objects than STP-BVs universe.initializeUniverse(); universe.TestAnimation(); return 0; }
Painting::Painting(ID3D11Device* device, ID3D11DeviceContext* context) : MeshInstance(device), texture(0), width(5.0), height(5.0) { InitTexture(context); TestMaterial* canvasMaterial = new TestMaterial(device); SetMesh(new PlaneMesh(device, width, height)); SetMaterial(canvasMaterial); canvasMaterial->Init(); SetActiveTechniqueByName("TextureTech"); canvasMaterial->SetTexture(texture); }
/* * mouseMotion - mouse motion glut callback function. * Called when the user move the mouse. Update the * camera. */ static void mouseMotion (int x, int y) { if (mouse.buttons[GLUT_RIGHT_BUTTON] == GLUT_DOWN) { if (keyboard.modifiers & GLUT_ACTIVE_CTRL) { if (keyboard.modifiers & GLUT_ACTIVE_SHIFT) { rot.z = (y - mouse.y)+(x - mouse.x); double inv[16]; trans_mat(matCam,inv); mul_mat_v(inv,vz,nz); glPushMatrix(); glLoadMatrixd(matCam); glRotated (rot.z, nz[0], nz[1], nz[2]); glGetDoublev(GL_MODELVIEW_MATRIX,matCam); glPopMatrix(); } else { /* rotation */ rot.x = (y - mouse.y); rot.y = (x - mouse.x); double inv[16]; trans_mat(matCam,inv); mul_mat_v(inv,vx,nx); mul_mat_v(inv,vy,ny); glPushMatrix(); glLoadMatrixd(matCam); glRotated (rot.x, nx[0], nx[1], nx[2]); glRotated (rot.y, ny[0], ny[1], ny[2]); glGetDoublev(GL_MODELVIEW_MATRIX,matCam); glPopMatrix(); } } else { if (keyboard.modifiers & GLUT_ACTIVE_SHIFT) { rot.z = (y - mouse.y)+(x - mouse.x); Vector3 t=universe.sObj[universe.CurrentObj]->getPosition(); universe.sObj[universe.CurrentObj]->addRotation(rot.z*0.02,Vector3(0,0,1)); universe.sObj[universe.CurrentObj]->setPosition(t); } else { /* rotation */ rot.x = (y - mouse.y); rot.y = (x - mouse.x); Vector3 t=universe.sObj[universe.CurrentObj]->getPosition(); universe.sObj[universe.CurrentObj]->addRotation(rot.x*0.02,Vector3(1,0,0)); universe.sObj[universe.CurrentObj]->addRotation(rot.y*0.02,Vector3(0,1,0)); universe.sObj[universe.CurrentObj]->setPosition(t); } } } else if (mouse.buttons[GLUT_LEFT_BUTTON] == GLUT_DOWN) { if (keyboard.modifiers & GLUT_ACTIVE_CTRL) { /* translation */ eye.x -= (x - mouse.x) * 0.0097*(eye.z/7); eye.y += (y - mouse.y) * 0.0097 *(eye.z/7); } else { universe.sObj[universe.CurrentObj]->addTranslation((x - mouse.x) *0.007,-(y - mouse.y)*0.007,0); } } else if (mouse.buttons[GLUT_MIDDLE_BUTTON] == GLUT_DOWN) { if (keyboard.modifiers & GLUT_ACTIVE_CTRL) { /* zoom */ eye.z *= (((x - mouse.x))/wid+((mouse.y-y))/hei)*2+1; if (eye.z <0.01) eye.z=0.01; } else { universe.sObj[universe.CurrentObj]->addTranslation(0,0,-((x - mouse.x)+(mouse.y-y))*0.011); } } mouse.x = x; mouse.y = y; universe.DoTest(); glutPostRedisplay (); }
static void keyPress (unsigned char key, int /*x*/, int /*y*/) { static int lightOn = 1; /* update key state */ keyboard.keymap[key] = 1; /* * handle here ponctual actions when * a key is pressed (like toggle ligthing) */ /* escape */ switch (key) { case 27: exit (0); break; /* 'l': toggle light */ case 'l': lightOn = !lightOn; break; case 32: universe.CurrentObj=(universe.CurrentObj+1)%universe.sObj.size(); break; case 8: universe.CurrentObj=(universe.CurrentObj-1)%universe.sObj.size(); break; case '0': universe.RandomTestSupportFunction(); break; case '1': universe.TestAnimation(); break; case '2': universe.TestPrecision(); break; case '3': universe.RandomTestSupportFunctionAllObjects(); break; case '5': universe.GeneralTest(); break; } if (lightOn) glEnable (GL_LIGHTING); else glDisable (GL_LIGHTING); glutPostRedisplay (); }
/* * init - application initialisation. Setup keyboard input, * mouse input, timer, camera and OpenGL. */ static void init (void) { /* * application initialization */ /* init keyboard */ memset (keyboard.keymap, 0, 256); memset (keyboard.special, 0, 256); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA| GLUT_DEPTH|GLUT_ALPHA); glutInitWindowSize (800, 600); glutCreateWindow ("Smooth collision detection"); /* init mouse */ mouse.buttons[GLUT_LEFT_BUTTON] = GLUT_UP; mouse.buttons[GLUT_MIDDLE_BUTTON] = GLUT_UP; mouse.buttons[GLUT_RIGHT_BUTTON] = GLUT_UP; mouse.x = 0; mouse.y = 0; /* init timer */ timer.current_time = 0; timer.last_time = 0; /* init camera input */ rot.x = 0.0f; eye.x = 0.0f; rot.y = 0.0f; eye.y = 0.0f; rot.z = 0.0f; eye.z = 7.0f; /* * init OpenGL */ glEnable (GL_LIGHTING); glClearColor (background[0], background[1], background[2], 1.0f); glShadeModel (GL_SMOOTH); glEnable (GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE); glShadeModel (GL_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_DST_ALPHA); #ifndef LINES_DISPLAY glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); #else glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); //glEnable(GL_LINE_SMOOTH); #endif glEnable(GL_FOG); { glFogfv (GL_FOG_COLOR, &background[0]); glFogi (GL_FOG_MODE, GL_EXP2); glFogf (GL_FOG_DENSITY, 0.00025); glFogf (GL_FOG_START, 14000.0); glFogf (GL_FOG_END, 15000.0); } glHint(GL_LINE_SMOOTH_HINT,GL_NICEST); glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST); glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); glHint (GL_FOG_HINT, GL_NICEST); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse); glLightfv(GL_LIGHT0, GL_POSITION, light0_position); glEnable(GL_LIGHT1); glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse); glLightfv(GL_LIGHT1, GL_POSITION, light1_position); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glGetDoublev(GL_MODELVIEW_MATRIX,matCam); /*inialize objects*/ universe.initializeUniverse(); //create the gl volumes. sObjGL = createGL(universe.sObj); }