From e6574e9920356a5b5ef238d53fed697216667b66 Mon Sep 17 00:00:00 2001 From: Krishna Date: Sat, 27 Mar 2010 03:42:17 -0400 Subject: [PATCH] Added burst effect when moving between levels --- appwindow.cpp | 2 +- particle.cpp | 19 ++++-- particle.hpp | 14 ++++- viewer.cpp | 158 +++++++++++++++++++++++++++++++++----------------- viewer.hpp | 4 +- 5 files changed, 134 insertions(+), 63 deletions(-) diff --git a/appwindow.cpp b/appwindow.cpp index 3365d9e..ae0bb99 100644 --- a/appwindow.cpp +++ b/appwindow.cpp @@ -59,7 +59,7 @@ AppWindow::AppWindow() // by default, so it'll take up the rest of the window. //m_viewer.set_size_request(300, 600); - m_viewer.set_size_request(600, 400); + m_viewer.set_size_request(900, 600); m_vbox.pack_start(m_viewer); show_all(); diff --git a/particle.cpp b/particle.cpp index 8cd5f0c..ac71a0f 100644 --- a/particle.cpp +++ b/particle.cpp @@ -1,13 +1,14 @@ #include "particle.hpp" #include -Particle::Particle(Point3D position, float radius, Vector3D velocity, float d, int colIndex, Vector3D acceleration) +Particle::Particle(Point3D position, float radius, Vector3D velocity, float d, float *col, Vector3D acceleration, int shape) { pos = position; rad = radius; vel = velocity; decay = d; - colourIndex = colIndex; + colour = col; + this->shape = shape; // Defaults alpha = 1.f; accel = acceleration; @@ -61,15 +62,25 @@ bool Particle::step(float t) return false; } -void Particle::setColour(int colIndex) +void Particle::setColourIndex(int colIndex) { colourIndex = colIndex; } -int Particle::getColour() +int Particle::getColourIndex() { return colourIndex; } +float* Particle::getColour() +{ + return colour; +} + +int Particle::getShape() +{ + return shape; +} + Particle::~Particle() { diff --git a/particle.hpp b/particle.hpp index b494b39..1f842d6 100644 --- a/particle.hpp +++ b/particle.hpp @@ -8,7 +8,7 @@ class Particle { public: Particle(); - Particle(Point3D pos, float radius, Vector3D velocity, float decay, int colIndex, Vector3D acceleration); + Particle(Point3D pos, float radius, Vector3D velocity, float decay, float *col, Vector3D acceleration, int shape = 0); virtual ~Particle(); float getDecay(); @@ -17,12 +17,19 @@ class Particle Vector3D getVelocity(); float getAlpha(); void setAlpha(); - void setColour(int colIndex); - int getColour(); + void setColourIndex(int colIndex); + int getColourIndex(); + float* getColour(); bool step(float t); + int getShape(); + + + protected: private: + + float *colour; float decay; Point3D pos; float rad; @@ -30,5 +37,6 @@ class Particle Vector3D accel; float alpha; int colourIndex; + int shape; }; #endif diff --git a/viewer.cpp b/viewer.cpp index e8843fe..1ae2350 100644 --- a/viewer.cpp +++ b/viewer.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include "appwindow.hpp" @@ -145,12 +144,11 @@ void Viewer::on_realize() moveSound = sm.LoadSound("move.ogg"); turnSound = sm.LoadSound("turn.ogg"); // sm.PlaySound(backgroundMusic); - - // Just enable depth testing and set the background colour. - // glEnable(GL_DEPTH_TEST); - + // Sphere for particles + particleSphere = gluNewQuadric(); + glClearDepth (1.0f); glDepthFunc (GL_LEQUAL); @@ -382,10 +380,12 @@ bool Viewer::on_expose_event(GdkEventExpose* event) { levelUpAnimation = false; int numFireworks = 10; - for (int i = 0;iblocksJustCleared.size();i++) + for (unsigned int i = 0;iblocksJustCleared.size();i++) { addParticleBox(game->blocksJustCleared[i].c, game->blocksJustCleared[i].r, game->blocksJustCleared[i].col); } @@ -619,42 +619,76 @@ void Viewer::drawParticles(bool step) float mag; Point3D pos; float rad; + float *colour; Vector3D velocity; Point3D col; float alpha; - for (int i = 0;igetPos(); rad = particles[i]->getRadius(); alpha = particles[i]->getAlpha(); - mag = pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2]; - mag = (1.f/mag); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(mag * pos[0], mag * pos[1], mag * pos[2], alpha); - glPushMatrix(); - glTranslatef(pos[0], pos[1], pos[2]); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, texture[particles[i]->getColour() - 1]); - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); - glVertex3d(0, 0, 1); - glTexCoord2f(1.0f, 0.0f); - glVertex3d(rad, 0, 1); - glTexCoord2f(1.0f, 1.0f); - glVertex3d(rad, rad, 1); - glTexCoord2f(0.0f, 1.0f); - glVertex3d(0, rad, 1); - glEnd(); - glPopMatrix(); - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); + if (particles[i]->getShape() == 0) + { + mag = pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2]; + mag = (1.f/mag); + glColor4f(mag * pos[0], mag * pos[1], mag * pos[2], alpha); + glPushMatrix(); + glTranslatef(pos[0], pos[1], pos[2]); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texture[particles[i]->getColourIndex() - 1]); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); + glVertex3d(0, 0, 1); + glTexCoord2f(1.0f, 0.0f); + glVertex3d(rad, 0, 1); + glTexCoord2f(1.0f, 1.0f); + glVertex3d(rad, rad, 1); + glTexCoord2f(0.0f, 1.0f); + glVertex3d(0, rad, 1); + glEnd(); + glPopMatrix(); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + } + else if (particles[i]->getShape() == 1 && step) + { + colour = particles[i]->getColour(); + GLUquadricObj *sphere = gluNewQuadric(); + glColor4f(colour[0], colour[1], colour[2], alpha); + gluQuadricNormals(sphere, GLU_SMOOTH); // Create Smooth Normals ( NEW ) + gluQuadricTexture(sphere, GL_TRUE); + glPushMatrix(); + glTranslatef(pos[0], pos[1], pos[2]); + gluSphere(sphere, rad, 32, 32); + glPopMatrix(); + delete(sphere); + + if (colour[1] > 1) + { + colour[1] = 1; + colour[0] = 0; + } + + if (colour[2] > 1) + colour[2] = 1; + + if (colour[0] > 0) + { + colour[1] += 0.2; + } + else + colour[2] += 0.2; + } + if (step && particles[i]->step(0.1)) { particles.erase(particles.begin() + i); } } - glDisable(GL_BLEND); + glDisable(GL_BLEND); } void Viewer::addParticleBox(float x, float y, int colour) { @@ -662,13 +696,19 @@ void Viewer::addParticleBox(float x, float y, int colour) float radius = 0.2f; float decay = 2.f; float n = 10.f; + float empty[3]; + empty[0] = 0; + empty[1] = 0; + empty[2] = 0; for (int i = 0;isetColourIndex(colour); + particles.push_back(p); pos[0] = x + (j / n); } pos[1] = pos[1] + 1.f/n; @@ -679,19 +719,33 @@ void Viewer::addFireworks(float x, float y) { Point3D pos(x, y, 0); float radius = 0.2f; - float decay = 3.f; + float decay = 2.5f; float n = 10.f; for (int i = 0;i=0;i--) // row { for (int j = WIDTH - 1; j>=0;j--) // column @@ -750,9 +803,6 @@ void Viewer::drawShadowVolumes() drawShadowCube (i, j, GL_QUADS ); } - - - // Draw outline for cube } } @@ -762,7 +812,7 @@ void Viewer::drawShadowVolumes() Point3D lightPoint(lightPos[0], lightPos[1], lightPos[2]); glColor4d(0, 0, 0, 0.3); - for (int i = 0;i(h, e) ); std::cerr << "back face " << Vector3D(0, 0, -1).dot(lightVec) << "\n"; } - for (int i = 0;i=0;j--) // column { if(loadBumpMapping && game->get(i, j) != -1) - drawBumpCube (i, j, game->get(i, j), GL_QUADS, draw3D ); + drawBumpCube (i, j, game->get(i, j), draw3D ); else if(game->get(i, j) != -1) drawCube (i, j, game->get(i, j), GL_QUADS, draw3D ); @@ -1196,7 +1246,7 @@ bool Viewer::on_motion_notify_event(GdkEventMotion* event) return true; } -void Viewer::drawBumpCube(float y, float x, int colourId, GLenum mode, bool draw3D) +void Viewer::drawBumpCube(float y, float x, int colourId, bool draw3D) { // Set The First Texture Unit To Normalize Our Vector From The Surface To The Light. // Set The Texture Environment Of The First Texture Unit To Replace It With The @@ -2019,7 +2069,7 @@ int Viewer::GenNormalizationCubeMap(unsigned int size, GLuint &texid) 0, GL_RGB8, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data); bytePtr = 0; - for(int j=0; j #include #include "particle.hpp" +#include // The "main" OpenGL widget class Viewer : public Gtk::GL::DrawingArea { public: @@ -122,7 +123,7 @@ class Viewer : public Gtk::GL::DrawingArea { void drawBackground(); void drawCube(float y, float x, int colourId, GLenum mode, bool draw3D = true); - void drawBumpCube(float y, float x, int colourId, GLenum mode, bool draw3D = true); + void drawBumpCube(float y, float x, int colourId, bool draw3D = true); DrawMode currentDrawMode; // The angle at which we are currently rotated @@ -206,6 +207,7 @@ class Viewer : public Gtk::GL::DrawingArea { bool moveLightSource; bool motionBlur; bool levelUpAnimation; + GLUquadricObj *particleSphere; }; #endif