Skip to content

Commit

Permalink
sea floor fix, commentaries, and pacman fix
Browse files Browse the repository at this point in the history
  • Loading branch information
albf committed May 6, 2014
1 parent f874c86 commit 526a7d6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 24 deletions.
6 changes: 0 additions & 6 deletions grid.ppm

This file was deleted.

40 changes: 27 additions & 13 deletions pacMan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pacMan::pacMan(float posx, float posy, float posz, float velx, float vely, float
modeTime=0;
}

// Just update the time, to know how to move the mouth
void pacMan::animate() {
if(modeTime==0) {
time++;
Expand All @@ -23,35 +24,46 @@ void pacMan::animate() {
}
}

// Draw function
void pacMan::draw() {
x += xInc;
x += xInc; // update coordinates
y += yInc;
z += zInc;

glColor4f(1, 1, 0, 1);
glColor4f(1, 1, 0, 1); // yellow color

glPushMatrix();
glTranslatef(x, y, z);
glScalef(scale, scale, scale);

glPushMatrix(); // first side of the pacman
glRotatef(-time*5,1,0,0);
drawHalfSphere(80, 80, 1);
glTranslatef(x, y, z); // move pacman
getCrossProduct(xInc, yInc, zInc, 0, 0, 1); // get cross product
glRotatef(getAngle(xInc, yInc, zInc, 0, 0, 1), xcp, ycp, zcp); // rotate to look to where it is moving

glScalef(scale, scale, scale); // scale

glColor4f(0, 0, 0, 0.8);
glTranslatef(-0.5,0.5,0.8);
// first side of the pacman
glPushMatrix();
// First Half
glRotatef(-time*5,1,0,0); // rotation of the first side
drawHalfSphere(80, 80, 1); // draw it's first half

// First Eye
glColor4f(0, 0, 0, 0.8);
glTranslatef(-0.5,0.5,0.8); // go to the position
glScalef(0.75/scale, 0.75/scale, 0.75/scale);
drawHalfSphere(80,80,2);
drawHalfSphere(80,80,2); // draw a full sphere this time

// Second Eye
glScalef(scale/0.75, scale/0.75, scale/0.75);
glTranslatef(+1,0,0);
glTranslatef(+1,0,0); // go to the position
glScalef(0.75/scale, 0.75/scale, 0.75/scale);
drawHalfSphere(80,80,2);
drawHalfSphere(80,80,2); // draw a full sphere thi time

glPopMatrix(); // end of first side of pacman

glColor4f(1, 1, 0, 1);
glPushMatrix(); // second side of the pacman

// Second Half
glRotatef(180,0,0,1);
glRotatef(-time*5,1,0,0);
drawHalfSphere(80, 80, 1);
Expand All @@ -60,6 +72,8 @@ void pacMan::draw() {
glPopMatrix();
}

/* Draw half of sphere : Took TP1 and executed just half of the for-loop if sides=1,
* or the full loop if sides=2 */
static void drawHalfSphere(int lats, int longs, int sides) {
int i, j;
for(i = 0; i <= lats; i++) {
Expand Down
2 changes: 1 addition & 1 deletion seaFloor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ seaFloor::seaFloor() {

void seaFloor::init(Viewer &v) {
/* read in image for texture */
grid = readPPMfile("grid.ppm");
grid = readPPMfile("seafloor.ppm");
/* create a texture object */
glGenTextures(1, &gridTex);
/* make it the current texture */
Expand Down
14 changes: 10 additions & 4 deletions viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ void Viewer::init() {
addRenderable(&diver);
bubble_space=diver.ratio/3;

time=0;
time=0; // to help in the animation
toggleRecord=false; // for saving snapshots

startTimer(50);
startTimer(50); // timer to come back
}

// Timed event, called at the time defined in viewer::init() functio.)
Expand Down Expand Up @@ -139,7 +140,9 @@ void Viewer::draw() {
(*it)->draw();
}

swapBuffers(); // clean buffers
swapBuffers(); // clean buffers

if(toggleRecord) saveSnapshot(); // save snapshot if on
}

void Viewer::animate() {
Expand Down Expand Up @@ -196,7 +199,10 @@ void Viewer::keyPressEvent(QKeyEvent *e) {
glDisable(GL_LIGHTING);
// ... and so on with all events to handle here!

} else {
}
else if (e->key()==Qt::Key_R) {
toggleRecord = !toggleRecord; }
else {
// if the event is not handled here, process it as default
QGLViewer::keyPressEvent(e);
}
Expand Down
3 changes: 3 additions & 0 deletions viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class Viewer : public QGLViewer
int time;
int bubble_frequency;
float bubble_space;

// Record Variables
bool toggleRecord;

/* Scene methods */
protected :
Expand Down

0 comments on commit 526a7d6

Please sign in to comment.