cppbug

buggy cube - cube.cpp

Apr 25th, 2014
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include "cube.hpp"
  2. #include <windows.h>    // only on windows ;)
  3. #include <GL/glut.h>
  4.  
  5. Cube::Cube(float a)
  6. {
  7.     this->a = a;
  8.     angle = 0;
  9. }
  10.  
  11. void Cube::draw() const
  12. {
  13.     glTranslatef(0, 0, -150);
  14.     glRotatef(angle, 0, 1, 0);
  15.    
  16.     glBegin(GL_QUADS);
  17.         // left face
  18.         glColor3f(0.0f, 1.0f, 0.0f);
  19.         glVertex3f(-a/2, a/2, a/2);
  20.         glVertex3f(-a/2,-a/2, a/2);
  21.         glVertex3f(-a/2,-a/2,-a/2);
  22.         glVertex3f(-a/2, a/2,-a/2);
  23.  
  24.         // right face
  25.         glColor3f(0.0f, 0.0f, 1.0f);
  26.         glVertex3f (a/2, a/2, a/2);
  27.         glVertex3f( a/2,-a/2, a/2);
  28.         glVertex3f( a/2,-a/2,-a/2);
  29.         glVertex3f( a/2, a/2,-a/2);
  30.  
  31.         // bottom face
  32.         glColor3f(1.0f, 1.0f, 0.0f);
  33.         glVertex3f( a/2,-a/2, a/2);
  34.         glVertex3f(-a/2,-a/2, a/2);
  35.         glVertex3f(-a/2,-a/2,-a/2);
  36.         glVertex3f( a/2,-a/2,-a/2);
  37.  
  38.         // top face
  39.         glColor3f(1.0f,1.0f, 1.0f);
  40.         glVertex3f( a/2, a/2, a/2);
  41.         glVertex3f(-a/2, a/2, a/2);
  42.         glVertex3f(-a/2, a/2,-a/2);
  43.         glVertex3f( a/2, a/2,-a/2);
  44.  
  45.         // back face
  46.         glColor3f(1.0f, 0.5f, 0.0f);
  47.         glVertex3f( a/2, a/2,-a/2);
  48.         glVertex3f(-a/2, a/2,-a/2);
  49.         glVertex3f(-a/2,-a/2,-a/2);
  50.         glVertex3f( a/2,-a/2,-a/2);
  51.  
  52.         // front face
  53.         glColor3f(1.0f, 0.0f, 0.0f);
  54.         glVertex3f( a/2, a/2, a/2);
  55.         glVertex3f(-a/2, a/2, a/2);
  56.         glVertex3f(-a/2,-a/2, a/2);
  57.         glVertex3f( a/2,-a/2, a/2);
  58.        
  59.     glEnd();
  60. }
  61.  
  62. void Cube::tick()
  63. {
  64.     angle++;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment