void Tracker :: setup() { initVideo(); initVideoGrabber(); initVideoPlayer(); cameraRadius = 200; updateCameraPos( videoSmlRect.width * 0.5, videoSmlRect.height * 0.5 ); bUpdateCameraPos = false; }
void GLWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); updateCameraPos(); emit render(); }
void mouseMoved(int x, int y) { if (not fps) { if (mouse.first) { rotateX += posMouse.first - x; rotateY += posMouse.second - y; posMouse.first = x; posMouse.second = y; updateCameraPos(); } else if (mouse.second) { zoom += float(y-posMouse.second)/rHeight; if (zoom < 0.01) zoom = 0.01; posMouse.second = y; updateCameraType(); } } }
void updateCamera() { updateCameraType(); updateCameraPos(); }
void display(void){ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); if (GetAsyncKeyState(VK_END)) { radius+=0.25; zoomFactor += 0.02; } if (GetAsyncKeyState(VK_HOME)) { if (radius > 2) radius-=0.25; zoomFactor -= 0.02; } // Zoom by changing view frustum /* glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0*zoomFactor,(float)width/(float)height,0.2,80.0); glMatrixMode(GL_MODELVIEW); */ if (currentAction == NAVIGATE) ; else updateCameraPos(); gluLookAt(lookFromx, lookFromy, lookFromz, lookAtx, lookAty, lookAtz, upx, upy, upz); glEnable(GL_TEXTURE_2D); // Draw Boundary Walls glTexImage2D( // initialize texture GL_TEXTURE_2D, // texture is 2-d 0, // resolution level 0 GL_RGB, // internal format boundaryWallPix[0].nCols, // image width boundaryWallPix[0].nRows, // image height 0, // no border GL_RGB, // my format GL_UNSIGNED_BYTE, // my type boundaryWallPix[0].pixel); // the pixels for (int i = 0; i < numBoundaryWalls; i++) { drawMesh(boundaryWalls[i]); } // Draw Inner Walls glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, innerWallPix[0].nCols, innerWallPix[0].nRows, 0, GL_RGB, GL_UNSIGNED_BYTE, innerWallPix[0].pixel); for (int i = 0; i < numInnerWalls; i++) { drawMesh(innerWalls[i]); } VECTOR3D temp = VECTOR3D(personBody->translation.x + 7.0, personBody->translation.y, personBody->translation.z); if (temp.GetQuaddLength() < 9){ doors[0]->angles.y = 90.0; doors[0]->translation.x = -10.0; doors[0]->translation.z = -1.5; doors[1]->angles.y = -90.0; doors[1]->translation.x = -4.0; doors[1]->translation.z = -1.5; } else { doors[0]->angles.y = 0.0; doors[0]->translation.x = -8.5; doors[0]->translation.z = 0.0; doors[1]->angles.y = 0.0; doors[1]->translation.x = -5.5; doors[1]->translation.z = 0.0; } temp = VECTOR3D(personBody->translation.x, personBody->translation.y, personBody->translation.z+8.0); if (temp.GetQuaddLength() < 9){ doors[2]->angles.y = 90.0; doors[2]->translation.x = 1.0; doors[2]->translation.z = -10.0; doors[3]->angles.y = -90.0; doors[3]->translation.x = 1.0; doors[3]->translation.z = -6.0; //cout << "Distance is < 4.0" << endl; } else { doors[2]->angles.y = 0.0; doors[2]->translation.x = 0.0; doors[2]->translation.z = -9.0; doors[3]->angles.y = 0.0; doors[3]->translation.x = 0.0; doors[3]->translation.z = -7.0; //cout << "Distance is greater than 1" << endl; } // Draw left doors glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, doorPix[0].nCols, doorPix[0].nRows, 0, GL_RGB, GL_UNSIGNED_BYTE, doorPix[0].pixel); drawMesh(doors[0]); drawMesh(doors[2]); // Draw right doors glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, doorPix[1].nCols, doorPix[1].nRows, 0, GL_RGB, GL_UNSIGNED_BYTE, doorPix[1].pixel); drawMesh(doors[1]); drawMesh(doors[3]); // Draw Floor glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, floorPix[0].nCols, floorPix[0].nRows, 0, GL_RGB, GL_UNSIGNED_BYTE, floorPix[0].pixel); terrainGrid->DrawGrid(gridSize); // Draw Person drawMesh(personBody, personHead); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); for (int i = 0; i < 12; i++){ drawObj(cobj[i]); } glDisable(GL_TEXTURE_2D); glutSwapBuffers(); }
/******************************************************************* City Modelling Program ********************************************************************/ ////////// #include <windows.h> #include <gl/gl.h> #include <gl/glu.h> //#include <gl/glut.h> #include "Dependencies\freeglut\freeglut.h" #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <utility> #include <vector> #include "VECTOR3D.h" #include "TerrainGrid.h" #include "Mesh.h" #include "RGBpixmap.h" #include "ComplexObj.h" void initOpenGL(); void display(void); void reshape(int w, int h); void mouse(int button, int state, int x, int y); void mouseMotionHandler(int xMouse, int yMouse); void keyboard(unsigned char key, int x, int y); void functionKeys(int key, int x, int y); void timer(int value); VECTOR3D ScreenToWorld(int x, int y); void updateCameraPos(); void limitCameraAngle(); bool hasCollision(const Mesh* a, Mesh* b[], Mesh* c[], Mesh* d[], float offset, int sizeb, int sizec, int sized); bool hasObjCollision(const Mesh* a, ComplexObj *cobj[], int sizee); void createBoundaryWalls(); void createInnerWalls(); void createDoors(); static int currentButton; static unsigned char currentKey; #define M_PI 3.14159265358979323846 const float FPS = 30.0; // City Interaction State Variable enum Action {TRANSLATE, ROTATE, RAISE, SCALE, EXTRUDE, SELECT, MULTIPLESELECT, DESELECT_ALL, NAVIGATE}; enum Action currentAction = TRANSLATE; GLfloat light_position0[] = {12.0, 6.0,-12.0,1.0}; GLfloat light_position1[] = {-12.0, 6.0,12.0,1.0}; GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0}; GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat light_ambient[] = {0.2, 0.2, 0.2, 1.0}; // Person mesh - head + body Mesh *personBody; GLUquadricObj *personHead; // City terrain mesh TerrainGrid *terrainGrid = NULL; int gridSize = 16; // Wall Meshes Mesh *boundaryWalls[4]; // boundary walls that surround the world Mesh *innerWalls[20]; // inner walls of the rooms & world Mesh *doors[20]; // inner walls of the rooms & world float wallHeight = 1.0f; // wall height of all (boundary, inner) walls int numBoundaryWalls = 0, numInnerWalls = 0, numDoors = 0; RGBpixmap floorPix[1], boundaryWallPix[1], innerWallPix[1], doorPix[2]; // Room Objects ComplexObj *cobj[12]; //int nextobj = 0; //index to objects array to store next cube ComplexObj *navobj; //selected object in NAVIGATE mode bool objCollision = false; // state to toggle avatar and object collision float trsize = 0.2, scsize = 0.2, rosize = 5.0; //translation, scaling and rotation angle deltas // Textures GLuint textureId; // Camera Control VECTOR3D lookFrom; VECTOR3D lookAt; VECTOR3D up; float radius = 8; // Camera Distance float lookFromx = 0; // Camera X Position float lookFromy = 0; // Camera Y Position float lookFromz = radius; // Camera Z Position float angleTheta = 0; // Camera X angle float anglePhi = 80; // Camera Y angle float upx = 0; // Up Vector float upy = 1; float upz = 0; float lookAtx = 0; // Camera is looking at float lookAty = 0; float lookAtz = 0; float camerax = 0; // Camera X Position float cameray = 0; // Camera Y Position float cameraz = radius; // Camera Z Position static float zoomFactor = 1.0; float xbefore; // Previous X position of tank float zbefore; // Previous Y position of tank float collision_offset = 0.4; //GLint glutWindowWidth = 750; //GLint glutWindowHeight = 500; GLint glutWindowWidth = 1200; GLint glutWindowHeight = 800; GLint viewportWidth = glutWindowWidth; GLint viewportHeight = glutWindowHeight; // Wolrd Boundaries GLdouble worldLeftBase = -8.0; GLdouble worldRightBase = 8.0; GLdouble worldBottomBase= -8.0; GLdouble worldTopBase = 8.0; // World view boundaries GLdouble wvLeftBase = worldLeftBase, wvRightBase = worldRightBase, wvBottomBase = worldBottomBase, wvTopBase = worldTopBase; int main(int argc, char **argv){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); //glutInitWindowSize(750, 500); glutInitWindowSize(glutWindowWidth, glutWindowHeight); glutInitWindowPosition(100, 100); glutCreateWindow("Room Navigator"); floorPix[0].readBMPFile("FloorWood01.bmp"); boundaryWallPix[0].readBMPFile("WallBrick02.bmp"); innerWallPix[0].readBMPFile("WallWood01.bmp"); doorPix[0].readBMPFile("Door01L.bmp"); doorPix[1].readBMPFile("Door01R.bmp"); initOpenGL(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutMotionFunc(mouseMotionHandler); glutKeyboardFunc(keyboard); glutSpecialFunc(functionKeys); glutTimerFunc(1000.0 / FPS, timer, 0); glutMainLoop(); return 0; } int width, height; VECTOR3D scale; VECTOR3D trans; VECTOR3D angles; // Setup openGL */ void initOpenGL(){ glViewport(0, 0, (GLsizei) viewportWidth, (GLsizei) viewportHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0*zoomFactor,(float)viewportWidth/(float)viewportHeight,0.2,80.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Set up and enable lighting glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_POSITION, light_position0); glLightfv(GL_LIGHT1, GL_POSITION, light_position1); glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glClearColor(0.6, 0.6, 0.6, 0.0); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); //Nice perspective. glHint(GL_PERSPECTIVE_CORRECTION_HINT , GL_NICEST); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); updateCameraPos(); gluLookAt(lookFromx, lookFromy, lookFromz,lookAtx, lookAty, lookAtz, upx, upy, upz); //Texture glGenTextures(1, &textureId); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // store pixels by byte glBindTexture(GL_TEXTURE_2D, textureId); // select current texture (0) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Set up Terrain Grid VECTOR3D origin = VECTOR3D(-16.0f, 0.0f, 16.0f); terrainGrid = new TerrainGrid(gridSize, 32.0); // gridsize = 16 terrainGrid->InitGrid(gridSize, origin, 32.0, 32.0); createBoundaryWalls(); // Create boundary walls createInnerWalls(); // create inner walls createDoors(); // create doors // Create a person (Head+Body) - initially oriented along z axis direction (-ve z dir (0,0,-1) & ccw => angles.y = 0) scale.x = 0.5; scale.y = 1.4; scale.z = 0.2; trans.x = -2.0; trans.y = 0; trans.z = 8.0; personBody = createMesh(scale, trans, 1.0, 1); personBody->angles.x = personBody->angles.y = personBody->angles.z = 0.0; personBody->selected = true; // Create room objects (4 kinds) for (int i = 0; i < 12; i++){ cobj[i] = createObj(); } createShield(cobj[0]); cobj[0]->translation.Set( 0.0, 2.0, 15.0); cobj[0]->angles.Set(0.0, 180.0, 0.0); createShield(cobj[1]); cobj[1]->translation.Set(-8.0, 2.0, -15.0); createShield(cobj[2]); cobj[2]->translation.Set( 8.0, 2.0, -15.0); createTable( cobj[3]); cobj[3]->translation.Set(14.0, 0.0, 2.0); createTable( cobj[4]); cobj[4]->translation.Set(14.0, 0.0,-2.0); createTable( cobj[5]); cobj[5]->translation.Set(-14.0,0.0,-2.0); createVase( cobj[6]); cobj[6]->translation.Set(14.0, 0.0, 4.0); createVase( cobj[7]); cobj[7]->translation.Set(-14.0, 0.0,-14.0); createVase( cobj[8]); cobj[8]->translation.Set(14.0, 0.0,-14.0); createPicFrame(cobj[9]); cobj[9]->translation.Set(8.0, 2.0, 15.0); cobj[9]->angles.Set(0.0, 180.0, 0.0); createPicFrame(cobj[10]); cobj[10]->translation.Set(-15.0, 2.0, -8.0); cobj[10]->angles.Set(0.0, 90.0, 0.0); createPicFrame(cobj[11]); cobj[11]->translation.Set(15.0, 2.0, -8.0); cobj[11]->angles.Set(0.0, -90.0, 0.0); }