1. Simon Claret
  2. Parallel Programming

Commits

Simon Claret  committed d87f09c

remove junk

  • Participants
  • Parent commits c4fe339
  • Branches default

Comments (0)

Files changed (1)

File p2.cpp

-// CPSC 314 Vjan2007
-// Project 2 Sample Code
-
-//p2.cpp
-//main function
-
-#include "defs.h"
-
-//global struct to store the program state
-ProgramState state;
-
-//speed tracking
-SpeedState ss(0.05, 0.5);
-
-//state tracking for part 1
-TripleState ts(0, 0, 0); //translate state
-TripleState rs(0, 0, 0); //rotate state
-
-//state tracking for part 2
-TripleState es(50, 10, 10); //eye point
-TripleState ls( 50, 10, -75); //lookat point
-TripleState us(0, 1, 0); //up vector
-
-//mouse state tracking for parts 3 and 4
-MouseState ms(0, 0, 0, 0);
-
-//state tracking for part 4
-int just_warped = 0;
-
-int lastFrameTime = 0;
-float Shininess = 50;
-GLdouble mvm[16];
-GLdouble original_mvm[16];
-int mvm_cache_initialized = 0;
-int original_mvm_initialized = 0;
-
-//a utility used in part 4)
-void WarpToCenter(void)
-{
-    int xpos = state.windowWidth/2;
-    int ypos = state.windowHeight/2;
-    glutWarpPointer((int) xpos, (int) ypos);
-    ms.sx = xpos;
-    ms.sy = ypos;
-    just_warped = 1;
-}
-
-//a utility function used in part 3
-void PostmultiplyAndSave() {
-    glMultMatrixd(mvm);
-    glGetDoublev(GL_MODELVIEW_MATRIX, mvm);
-}
-
-void TimerFunc(int value) {
-    glutTimerFunc(50, TimerFunc, 0);
-    if (state.cameraMode == 3)
-    {
-        if (ms.state == 0) {
-            //change yaw
-            if(mvm_cache_initialized == 1) {
-                glLoadIdentity();
-                glRotated(0.005*ms.GetXLength(), 0, 1, 0);
-                PostmultiplyAndSave();
-            }
-            //change pitch
-            if(mvm_cache_initialized == 1) {
-                glLoadIdentity();
-                glRotated(-0.005*ms.GetYLength(), 1, 0, 0);
-                PostmultiplyAndSave();
-            }
-
-        }
-    }
-}
-
-void MouseFunc(int button, int state, int x, int y) {
-    if (button == 0) {
-        if (state == 0) {
-            ms.sx = x;
-            ms.sy = y;
-            ms.state = 0;
-        }
-        else if (state == 1) {
-            ms.ex = x;
-            ms.ey = y;
-            ms.state = 1;
-        }
-    }
-}
-
-void MotionFunc(int x, int y) {
-    ms.ex = x;
-    ms.ey = y;
-}
-
-void PassiveMotionFunc(int x, int y) {
-    if (state.cameraMode == 4) {
-        if (just_warped == 0) {
-            ms.ex = x;
-            ms.ey = y;
-            //change yaw
-            if(mvm_cache_initialized == 1) {
-                glLoadIdentity();
-                glRotated(0.05*ms.GetXLength(), 0, 1, 0);
-                PostmultiplyAndSave();
-            }
-            //change pitch
-            if(mvm_cache_initialized == 1) {
-                glLoadIdentity();
-                glRotated(-0.05*ms.GetYLength(), 1, 0, 0);
-                PostmultiplyAndSave();
-            }
-            WarpToCenter();
-        }
-        else {
-            just_warped = 0;
-        }
-    }
-}
-
-//resets the state trackers to their default values
-void ResetDefaults() {
-    ts.Reset();
-    rs.Reset();
-
-    es.Reset();
-    ls.Reset();
-    us.Reset();
-
-    mvm_cache_initialized = 0;
-
-    if (original_mvm_initialized == 1){
-        glLoadMatrixd(original_mvm);
-        original_mvm_initialized = 0;
-    }
-
-    WarpToCenter();
-
-    glutSetCursor(GLUT_CURSOR_INHERIT);
-    printf("Reset\n");
-}
-
-void DrawGrid(float width, int subdivision) {
-    //Draws a grid of GL_LINES as a reference point
-    glDisable(GL_LIGHTING);
-    
-    glBegin(GL_LINES);
-    
-    for(int i = 0; i<=subdivision; i++) {
-        float stepsize = width/((float) (subdivision));
-        float ratio = 1/((float) subdivision);
-        
-        glColor3f(1-i*ratio, i*ratio, 0);
-        glVertex3f(-width/2 + i*stepsize, 0, width/2);
-        glColor3f(i*ratio, 1-i*ratio, 0);
-        glVertex3f(-width/2 + i*stepsize, 0, -width/2);
-        
-        glColor3f(0, i*ratio, 1-i*ratio);
-        glVertex3f(width/2, 0, -width/2 + i*stepsize);
-        glColor3f(0, 1-i*ratio, i*ratio);
-        glVertex3f(-width/2, 0, -width/2 + i*stepsize);
-    }
-    glEnd();
-    
-    glEnable(GL_LIGHTING);
-}
-
-void DrawCube(float x, float y, float z, float sx, float sy, float sz) {
-    //draw a parameterised rectangular prism
-    glPushMatrix();
-    glTranslatef(x, y, z);
-    glScalef(sx, sy, sz);
-    glutSolidCube(1.0);
-    glPopMatrix();
-}
-
-void DrawPost(float x, float y, float z) {
-    //draws a chess rook at the specified coordinates
-    //used to provide wayPoints in the scene
-    
-    glPushMatrix();
-    glTranslatef(x, y, z);
-    
-    glColor3f(0.0, 0.0, 1.0);
-    
-    DrawCube(0, 0, 0, 2, 1.5, 2);
-    DrawCube(0, 2.2, 0, 1.5, 4, 1.5);
-    DrawCube(0, 4.1, 0, 1.7, 0.7, 1.7);
-    
-    glPopMatrix();
-}
-
-
-void DisplayFunc() {
-    
-    //clear screen
-    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-    
-    //Set up Projection matrix
-    glMatrixMode( GL_PROJECTION );
-    glLoadIdentity();
-    float aspect = (float) state.windowWidth / (float) state.windowHeight;
-    gluPerspective(45, aspect, 1, 1000);
-    
-    //Set up Modelview matrix
-    glMatrixMode( GL_MODELVIEW );
-    
-    if (state.cameraMode == 2) {
-        glLoadIdentity();
-        gluLookAt(es.x, es.y, es.z, ls.x, ls.y, ls.z, us.x, us.y, us.z);
-    }
-    
-    if (state.cameraMode == 3 || state.cameraMode == 4) {
-        //apply incremental transformation to the current transformation from
-        //the last frame we drew
-        if (mvm_cache_initialized == 1) {
-            glLoadMatrixd(mvm);
-        }
-        if (original_mvm_initialized == 0)
-        {
-            //cache in case we have to reset
-            glGetDoublev(GL_MODELVIEW_MATRIX, original_mvm);
-            original_mvm_initialized = 1;
-        }
-        //store the model-view matrix
-        glGetDoublev(GL_MODELVIEW_MATRIX, mvm);
-        mvm_cache_initialized = 1;
-    }
-    
-    
-    //push, so our modeling transforms do not disrupt the Modelview Matrix
-    //if we do not preserve the modelview matrix, we cannot do camera-centric
-    //control
-    glPushMatrix();
-    
-    if (state.cameraMode == 1) {
-        glTranslated(-ts.x, -ts.y, -ts.z);
-        glRotated(-rs.x, 1, 0, 0);
-        glRotated(-rs.y, 0, 1, 0);
-        glRotated(-rs.z, 0, 0, 1);
-    }
-    
-    glEnable(GL_LIGHTING);
-    DrawPost(-50, 0, -50);
-    DrawPost(-50, 0, 0);
-    DrawPost(-50, 0, 50);
-    DrawPost(0, 0, -50);
-    DrawPost(0, 0, 50);
-    DrawPost(50, 0, -50);
-    DrawPost(50, 0, 0);
-    DrawPost(50, 0, -50);
-    DrawGrid(100, 100);
-    
-    glPopMatrix();
-    
-    // draw the buffer to the screen
-    glFlush();
-    glutSwapBuffers();
-    
-}
-
-void IdleFunc() {
-    glutPostRedisplay();
-}
-
-void ReshapeFunc(int w, int h) {
-    //saves the window width and height when the window changes shape
-    //this is used to compute the aspect when setting the projection matrix
-    glViewport( 0, 0, w, h );
-    state.windowWidth = w;
-    state.windowHeight = h;
-    glutPostRedisplay();
-}
-
-void KeyboardFunc(unsigned char key, int x, int y) {
-    //global commands
-    switch (key) {
-        case '`':
-            exit(0);
-            break;
-        case '1':
-            printf("Camera Mode 1\n");
-            state.cameraMode = 1;
-            ResetDefaults();
-            break;
-        case '2':
-            printf("Camera Mode 2\n");
-            state.cameraMode = 2;
-            ResetDefaults();
-            glTranslated(0, 0, ss.tincrement);
-            glMultMatrixd(mvm);
-            
-            break;
-        case '3':
-            printf("Camera Mode 3\n");
-            state.cameraMode = 3;
-            ResetDefaults();
-            break;
-        case '4':
-            printf("Camera Mode 4\n");
-            state.cameraMode = 4;
-            ResetDefaults();
-            glutSetCursor(GLUT_CURSOR_NONE);
-            break;
-        case '=':
-            ss.IncreaseSpeed();
-            break;
-        case '-':
-            ss.DecreaseSpeed();
-            break;
-        case 'r':
-            ResetDefaults();
-            break;
-    }
-    
-    if (state.cameraMode == 1) {
-        switch (key) {
-            case 'x':
-                ts.x += ss.tincrement;
-                break;
-            case 'X':
-                ts.x -= ss.tincrement;
-                break;
-            case 'y':
-                ts.y += ss.tincrement;
-                break;
-            case 'Y':
-                ts.y -= ss.tincrement;
-                break;
-            case 'z':
-                ts.z += ss.tincrement;
-                break;
-            case 'Z':
-                ts.z -= ss.tincrement;
-                break;
-            case 'a':
-                rs.x += ss.aincrement;
-                break;
-            case 'A':
-                rs.x -= ss.aincrement;
-                break;
-            case 'b':
-                rs.y += ss.aincrement;
-                break;
-            case 'B':
-                rs.y -= ss.aincrement;
-                break;
-            case 'c':
-                rs.z += ss.aincrement;
-                break;
-            case 'C':
-                rs.z -= ss.aincrement;
-                break;
-        }
-    }
-    if (state.cameraMode == 2) {
-        switch (key) {
-            case 'x':
-                es.x += ss.tincrement;
-                break;
-            case 'X':
-                es.x -= ss.tincrement;
-                break;
-            case 'y':
-                es.y += ss.tincrement;
-                break;
-            case 'Y':
-                es.y -= ss.tincrement;
-                break;
-            case 'z':
-                es.z += ss.tincrement;
-                break;
-            case 'Z':
-                es.z -= ss.tincrement;
-                break;
-            case 'a':
-                ls.x += ss.tincrement;
-                break;
-            case 'A':
-                ls.x -= ss.tincrement;
-                break;
-            case 'b':
-                ls.y += ss.tincrement;
-                break;
-            case 'B':
-                ls.y -= ss.tincrement;
-                break;
-            case 'c':
-                ls.z += ss.tincrement;
-                break;
-            case 'C':
-                ls.z -= ss.tincrement;
-                break;
-            case 'd':
-                us.x += ss.tincrement;
-                break;
-                
-            case 'D':
-                us.x -= ss.tincrement;
-                break;
-            case 'e':
-                us.y += ss.tincrement;
-                break;
-            case 'E':
-                us.y -= ss.tincrement;
-                break;
-            case 'f':
-                us.z += ss.tincrement;
-                break;
-            case 'F':
-                us.z -= ss.tincrement;
-                break;
-        }
-    }
-    
-    if (state.cameraMode == 3 || state.cameraMode == 4) {
-        switch (key) {
-            case 'w':
-                if(mvm_cache_initialized == 1) {
-                    glLoadIdentity();
-                    glTranslated(0, 0, ss.tincrement);
-                    PostmultiplyAndSave();
-                }
-                break;
-            case 's':
-                if(mvm_cache_initialized == 1) {
-                    glLoadIdentity();
-                    glTranslated(0, 0, -ss.tincrement);
-                    PostmultiplyAndSave();
-                }
-                break;
-        }
-    }
-    
-    if (state.cameraMode == 3) {
-        switch (key) {
-            case 'a':
-                if(mvm_cache_initialized == 1) {
-                    glLoadIdentity();
-                    glRotated(-ss.aincrement, 0, 0, 1);
-                    PostmultiplyAndSave();
-                }
-                break;
-            case 'd':
-                if(mvm_cache_initialized == 1) {
-                    glLoadIdentity();
-                    glRotated(ss.aincrement, 0, 0, 1);
-                    PostmultiplyAndSave();
-                }
-                break;
-        }
-    }
-    
-    if (state.cameraMode == 4) {
-        switch (key) {
-            case 'a':
-                if(mvm_cache_initialized == 1) {
-                    glLoadIdentity();
-                    glTranslated(0.2*ss.aincrement, 0, 0);
-                    PostmultiplyAndSave();
-                }
-                break;
-            case 'd':
-                if(mvm_cache_initialized == 1) {
-                    glLoadIdentity();
-                    glTranslated(0.2*-ss.aincrement, 0, 0);
-                    PostmultiplyAndSave();
-                }
-                break;
-            case 'k':
-                if(mvm_cache_initialized == 1) {
-                    glLoadIdentity();
-                    glTranslated(0, 0.2*-ss.aincrement, 0);
-                    PostmultiplyAndSave();
-                }
-                break;
-            case 'l':
-                if(mvm_cache_initialized == 1) {
-                    glLoadIdentity();
-                    glTranslated(0, 0.2*ss.aincrement, 0);
-                    PostmultiplyAndSave();
-                }
-                break;
-        }
-    }
-    
-    
-}
-
-void init() {
-    //initialise GL state variables
-    
-    GLfloat mat_ambient[] = { 0.2, 0.2, 0.2, 1};
-    GLfloat mat_diffuse[] = { 0.6, 0.6, 0.6, 1};
-    GLfloat mat_specular[] = { 0.5, 0.5 , 0.5, 1.0 };
-    GLfloat position0[] = {50, -10, -10.0, 1.0};
-    
-    GLfloat lightAmbient[] = { 1, 1, 1, 1};
-    GLfloat lightDiffuse[] = { 1, 1, 1, 1};
-    GLfloat lightSpecular[] = { 1, 1, 1, 1};
-    GLfloat lightZero[] = {0, 0, 0, 1};
-    
-    glShadeModel(GL_FLAT);
-    //glShadeModel(GL_SMOOTH);
-    
-    glClearColor(0, 0, 0, 0.0); 	//setting bg color
-    glEnable(GL_DEPTH_TEST);	 	//required for z-buffer
-    glViewport(0, 0, state.windowWidth, state.windowWidth);
-    
-    // set material propreties
-    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);	 // material
-    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
-    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
-    glMaterialfv(GL_FRONT, GL_SHININESS, &Shininess);
-    
-    //initialise lighting state
-    
-    // set light properties
-    glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lightZero);	// global ambient light
-    glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
-    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
-    glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular);
-    glLightfv( GL_LIGHT0, GL_POSITION, position0 );
-    
-    glEnable( GL_LIGHTING );
-    glEnable( GL_LIGHT0 );
-    glEnable(GL_DEPTH_TEST);
-    glEnable(GL_NORMALIZE);
-    
-    //glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
-    //glEnable(GL_COLOR_MATERIAL);
-    
-    //set initial camera position:
-    glMatrixMode( GL_MODELVIEW );
-    glLoadIdentity();
-    gluLookAt(50, 10, 10, 50, 10, -75, 0, 1, 0);
-    
-}
-
-int main(int argc, char** argv) {
-    //initialise program state
-    state.shading = true;
-    state.cameraMode = 1;
-    state.windowWidth = 640;
-    state.windowHeight = 480;
-    
-    //setup window
-    glutInit(&argc, argv);
-    //RGB color, z-buffer, double drawing buffer
-    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
-    glutInitWindowPosition(100, 100);
-    glutInitWindowSize(state.windowWidth, state.windowHeight);
-    
-    glutCreateWindow("CPSC 314 project 2");
-    
-    //Set glut callback functions
-    glutDisplayFunc(DisplayFunc);
-    glutIdleFunc(IdleFunc);
-    glutKeyboardFunc(KeyboardFunc);
-    glutMouseFunc(MouseFunc);
-    glutMotionFunc(MotionFunc);
-    glutPassiveMotionFunc(PassiveMotionFunc);
-    glutReshapeFunc(ReshapeFunc);
-    glutTimerFunc(50, TimerFunc, 0);
-    
-    init();
-    
-    glutMainLoop();
-    
-    return 0;
-}