All posts by kpark

Hierarchical Transformation

Hierarchical Transformation

SimpleCar

사용자 삽입 이미지
3744046228.cpp
SimpleRobot
사용자 삽입 이미지
6981026919.cpp
SimpleSolar



//main.cpp ———————————————-
SimpleCar* car;
SimpleSolar* solar;
SimpleRobot* robot;
SimpleMobile* mobile;


void init()
{
// 중간생략
 car = new SimpleCar();
 robot = new SimpleRobot();
 solar = new SimpleSolar();
 mobile = new SimpleMobile();
}


void display()
{
// 중간생략
 car->draw(&spMain, Projection, View, World);
 robot->draw(&spMain, Projection, View, World);
 solar->draw(&spMain, Projection, View, World);
 mobile->draw(&spMain, Projection, View, World);

}


void update()
{
// 중간생략
 car->update((float)deltaTime);
 robot->update((float)deltaTime);
 solar->update((float)deltaTime);
 mobile->update((float)deltaTime);


 glutPostRedisplay();
}


void specialkey(int key, int x, int y )
{
 switch (key) 
 {   
 case GLUT_KEY_LEFT:
  robot->setTheta(g_theta-=10.0f);
  break; 
 case GLUT_KEY_RIGHT:   
  robot->setTheta(g_theta+=10.0f);
  break; 
// 중간생략
 }
 glutPostRedisplay();
}

OpenGL/GLM Transformation

 // MVP matrix
 Projection = glm::perspective(g_fovy, g_aspect, g_zNear, g_zFar);
 View = glm::lookAt(g_eye, g_at, g_up);
 spMain.useProgram();
 spMain.setUniform(“gProjection”, Projection);
 spMain.setUniform(“gView”, View);

 // p’ = M3 * M2 * M1 * p (OpenGL uses Column-Major Order)
 glm::mat4 Tx = glm::translate(glm::mat4(1.0f), glm::vec3(3.0f, 0.0f, 0.0f)); // RHS x+ right
 glm::mat4 Rz = glm::rotate(glm::mat4(1.0f), 45.0f, glm::vec3(0.0f, 0.0f, 1.0f)); // RHS z+ (X->Y rotation)
 glm::mat4 S = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f, 0.7f, 1.0f)); // RHS

 World = glm::mat4(1.0f);
 spMain.setUniform(“gModel”, World);
 cube1->draw();

 
 // p’= R T p (red) => translate, and then rotate
 glm::mat4 RT = Rz * Tx; // Translate X, and then Rotate Z
 World = RT;
 spMain.setUniform(“gModel”, World);
 cube2->draw();

 
 // p’= T R p (green) => rotate, and then translate
 glm::mat4 TR = Tx * Rz; // Rotate Z, and then Translate X
 World = TR;
 spMain.setUniform(“gModel”, World);
 cube3->draw();

 
 // p’= T R S p (blue) => scale, and then rotate, and then translate
 glm::mat4 TRS = Tx * Rz * S; // Scale XY, and then Rotate Z, and then Translate X
 World = TRS;
 spMain.setUniform(“gModel”, World);
 cube4->draw();

사용자 삽입 이미지

OpenGL/GLM Transformation (Column-Major Order)

glm::mat4 A(1.0f, 0.0f, 0.0f, 0.0f, // column1
                       0.0f, 2.0f, 0.0f, 0.0f, // column2
                       0.0f, 0.0f, 4.0f, 0.0f, // column3
                      
1.0f, 2.0f, 3.0f, 1.0f); // column4
// A =
// 1 0 0 1
// 0 2 0 2
// 0 0 4 3
// 0 0 0 1

glm::mat4 B(1.0f, 0.0f, 0.0f, 0.0f, // column1
                       0.0f, 1.0f, 0.0f, 0.0f,
// column2
                       0.0f, 0.0f, 1.0f, 0.0f,
// column3
                       2.0f, 2.0f, 2.0f, 1.0f); // column4
// B =
// 1 0 0 2
// 0 1 0 2
// 0 0 1 2
// 0 0 0 1

glm::mat4 C = A*B;
// C = A*B =
// 1 0 0 3
// 0 2 0 6
// 0 0 4 11
// 0 0 0 1

glm::mat4 D = B*A;
// D = B*A =
// 1 0 0 3
// 0 2 0 4
// 0 0 4 5
// 0 0 0 1

glm::mat4 E = glm::inverse(A);  // inverse
// E = inverse(A) =
// 1 0 0 -1
// 0 0.5 0 -1
// 0 0 0.25 -0.75
// 0 0 0 1

glm::mat4 I = A * E;   // I = A * A-1
// I = A*E =
// 1 0 0 0
// 0 1 0 0
// 0 0 1 0
// 0 0 0 1

// p’ = M * p (OpenGL/GLM uses Column-Major Order)
glm::vec4 p = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f);
// p = (1, 0, 0)


glm::vec4 q = A * p;
// q = A * p = (2, 2, 3)

glm::vec4 r = B * p;
// r = B * p = (3, 2, 2)

glm::vec4 s = C * p;
// s = A * B * p = (4, 6, 11)

glm::vec4 t = D * p;
// t = B * A * p = (4, 4, 5)

glm::mat4 Tx,Ty,Tz;
Tx = glm::translate(glm::mat4(1.0f), glm::vec3(2.0f, 0.0f, 0.0f)); // RHS x+ right
Ty = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 2.0f, 0.0f)); // RHS y+ up
Tz = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 2.0f)); // RHS z+ front
// Tx =
// 1 0 0 2
// 0 1 0 0
// 0 0 1 0
// 0 0 0 1

glm::mat4 Rx,Ry,Rz,Ra;
Rx = glm::rotate(glm::mat4(1.0f), 30.0f, glm::vec3(1.0f, 0.0f, 0.0f)); // RHS x+ (Y->Z rotation) OpenGL uses DEGREE angle
Ry = glm::rotate(glm::mat4(1.0f), 60.0f, glm::vec3(0.0f, 1.0f, 0.0f)); // RHS y+ (Z->X rotation)
Rz = glm::rotate(glm::mat4(1.0f), 45.0f, glm::vec3(0.0f, 0.0f, 1.0f)); // RHS z+ (X->Y rotation)
Ra = glm::rotate(glm::mat4(1.0f), 45.0f, glm::vec3(1.0f, 1.0f, 1.0f)); // RHS (arbitrary axis)
// Rx =
// 1 0 0 0
// 0 0.999958 -0.0091384 0
// 0 0.0091384 0.999958 0
// 0 0 0 1

// Ry =
// 0.999833 0 0.018276 0
// 0 1 0 0
// -0.018276 0 0.999833 0
// 0 0 0 1

// Rz =
// 0.999906 -0.0137074 0 0
// 0.0137074 0.999906 0 0
// 0 0 1 0
// 0 0 0 1

// Ra =
// 0.999937 -0.00788263 0.00794526 0
// 0.00794526 0.999937 -0.00788263 0
// -0.00788263 0.00794526 0.999937 0
// 0 0 0 1

glm::mat4 Sx,Sy,Sz;
Sx = glm::scale(glm::mat4(1.0f), glm::vec3(2, 1, 1)); // RHS
Sy = glm::scale(glm::mat4(1.0f), glm::vec3(1, 2, 1)); // RHS
Sz = glm::scale(glm::mat4(1.0f), glm::vec3(1, 1, 2)); // RHS
// Sy =
// 1 0 0 0
// 0 2 0 0
// 0 0 1 0
// 0 0 0 1

// p’ = M3 * M2 * M1 * p (OpenGL uses Column-Major Order)
glm::mat4 TR = Tx * Rz; // Rotate Z, and then Translate X
glm::mat4 RT = Rz * Tx; // Translate X, and then Rotate Z
glm::mat4 TRS = Tx * Rz * Sy; // Scale Y, and then Rotate Z, and then Translate X
glm::mat4 SRT = Sy * Rz * Tx; // Translate X, and then Rotate Z, and then Scale Y
// Tx*Rz =
// 0.707107 -0.707107 0 2
// 0.707107 0.707107 0 0
// 0 0 1 0
// 0 0 0 1

// Rz*Tx =
// 0.707107 -0.707107 0 1.41421
// 0.707107 0.707107 0 1.41421
// 0 0 1 0
// 0 0 0 1

// Tx*Rz*Sy =
// 0.707107 -1.41421 0 2
// 0.707107 1.41421 0 0
// 0 0 1 0
// 0 0 0 1

// Sy*Rz*Tx =
// 0.707107 -0.707107 0 1.41421
// 1.41421 1.41421 0 2.82843
// 0 0 1 0
// 0 0 0 1

OpenGL Transformation Matrix uses Column-Major Order

// p’ = M3 * M2 * M1 * p (OpenGL uses Column-Major Order)
// p’= R T p (red) => translate, and then rotate
// p’= T R p (green) => rotate, and then translate
// p’= T R S p (blue) => scale, and then rotate, and then translate

OpenGL 1.x or 2.x
http://dis.dankook.ac.kr/lectures/cg10/entry/Transform

OpenGL 3.x or 4.x using GLM
http://dis.dankook.ac.kr/lectures/cg14/entry/OpenGLGLM-Transformation-Column-Major-Order

Vector/Matrix/Plane

Vector/Matrix/Plane Test

glmVectorMatrix.zip

void mprint(glm::mat4 Mat)
{
 printf(“\n %f %f %f %f
           \n %f %f %f %f
           \n %f %f %f %f
           \n %f %f %f %f\n\n”,
         
   Mat[0][0], Mat[1][0], Mat[2][0], Mat[3][0],      
   Mat[0][1], Mat[1][1], Mat[2][1], Mat[3][1],      
   Mat[0][2], Mat[1][2], Mat[2][2], Mat[3][2],      
   Mat[0][3], Mat[1][3], Mat[2][3], Mat[3][3]);
}

float theta(const glm::vec3 &v1,  const glm::vec3 &v2)
{
 float len1 = (float)sqrtf(v1[0]*v1[0] + v1[1]*v1[1] + v1[2]*v1[2]);
 float len2 = (float)sqrtf(v2[0]*v2[0] + v2[1]*v2[1] + v2[2]*v2[2]);
 return (float)acosf(dot(v1, v2)/len1*len2);
}

glm::vec3 computeNormal(glm::vec3& a, glm::vec3& b, glm::vec3& c)
{
 glm::vec3 normal = glm::normalize(glm::cross(c – a, b – a));
 return normal;
}

void vec3Test()
{
    const float v[3] = { 1.0f, 2.0f, 3.0f };
    vec3 a(0.0f, 0.0f, 0.0f), b(1.0f, 2.0f, 3.0f), c(b);
    vec3 d = c;
    vec3 e = c;
    vec3 f = a;
    cout << “a = ” << a[0] << ” ” << a[1] << ” ” << a[2] << endl;
    cout << “b = ” << b[0] << ” ” << b[1] << ” ” << b[2] << endl;
    cout << “c = ” << c[0] << ” ” << c[1] << ” ” << c[2] << endl;
    cout << “d = ” << d[0] << ” ” << d[1] << ” ” << d[2] << endl;
    cout << “e = ” << e[0] << ” ” << e[1] << ” ” << e[2] << endl;
    a[0] = 4;
    a[1] = 5;
    a[2] = 6;
    cout << “after assignments, a (4,5,6) ” << endl;
    cout << “a = ” << a[0] << ” ” << a[1] << ” ” << a[2] << endl;
    cout << “b = ” << b[0] << ” ” << b[1] << ” ” << b[2] << endl;

    cout << “Unary Operation” << endl;
    a += b;
    cout << “a += b  ” << endl;
    cout << “a = ” << a[0] << ” ” << a[1] << ”  ” << a[2] << endl;
    a -= b;
    cout << “a -= b  ” << endl;
    cout << “a = ” << a[0] << ” ” << a[1] << ” ” << a[2] << endl;
    a *= 1.5;
    cout << “a *= 1.5  ” << endl;
    cout << “a = ” << a[0] << ” ” << a[1] << ” ” << a[2] << endl;
    a /= 1.5;
    cout << “a /= 1.5  ” << endl;
    cout << “a = ” << a[0] << ” ” << a[1] << ” ” << a[2] << endl;

    cout << “Binary Operation” << endl;
    c = a + b;
    cout << “c = a + b  ->  c ” << endl;
    cout << “c = ” << c[0] << ” ” << c[1] << ” ” << c[2] << endl;
    c = a – b;
    cout << “c = a – b  ->  c ” << endl;
    cout << “c = ” << c[0] << ” ” << c[1] << ” ” << c[2] << endl;

    cout << “a == b” << endl;
    if (a == b)
        cout << ” is true” << endl;
    else
        cout << ” is false” << endl;

    cout << “b == d” << endl;
    if (b == d)
        cout << ” is true” << endl;
    else
        cout << ” is false” << endl;

    // magnitude
    cout << “a = ” << a[0] << ” ” << a[1] << ” ” << a[2] << endl;
    cout << “b = ” << b[0] << ” ” << b[1] << ” ” << b[2] << endl;
    cout << “a magnitude = ” << (float)sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]) << endl;
   
cout << “b magnitude = ” << (float)sqrt(b[0]*b[0] + b[1]*b[1] +
b[2]*b[2]) << endl;
 
   // normalize
   c = normalize(a);
   cout << “c = normalize(a) = ” << c[0] << ” ” << c[1] << ” ” << c[2] << endl;
   cout << “c magnitude = ” << (float)sqrt(c[0]*c[0] + c[1]*c[1] + c[2]*c[2]) << endl;
   d = normalize(b);
   cout << “d = normalize(b) = ” << d[0] << ” ” << d[1] << ” ” << d[2] << endl;
   cout << “d magnitude = ” << (float)sqrt(d[0]*d[0] + d[1]*d[1] + d[2]*d[2]) << endl;
 
   // dot product, theta, cross product, compute normal
   cout << “dot(a, b) = ” << dot(a, b) << endl;
   cout << “a,b angle = ” << degrees(theta(a, b)) << endl;
   e = cross(a, b);
   cout << “e = cross(a, b) = ” << e[0] << ” ” << e[1] << ” ” << e[2] << endl;
   f = cross(vec3(1.0f, 3.0f, -4.0f), vec3(2.0f, -5.0f, 8.0f));
   cout << “(1, 3, -4) x (2, -5, 8) = ” << f[0] << ” ” << f[1] << ” ” << f[2] << endl;

  glm::vec3 g = computeNormal(glm::vec3(1.0f, 0.0f, 0.0f),
  glm::vec3(1.0f, 1.0f, 0.0f), glm::vec3(1.0f, 2.0f, 3.0f));
  cout << “g = ” << g[0] << ” ” << g[1] << ” ” << g[2] << endl;
}

void mat4Test()
{
 // matrix test
 glm::mat4 A(1.0f, 0.0f, 0.0f, 0.0f, // column1              
                      0.0f, 2.0f, 0.0f, 0.0f, // column2         
                      0.0f, 0.0f, 4.0f, 0.0f, // column3
                      1.0f, 2.0f, 3.0f, 1.0f); // column4
 cout << “A = ”   << endl;
 mprint(A);

 glm::mat4 B(1.0f, 0.0f, 0.0f, 0.0f, // column1    
                     0.0f, 1.0f, 0.0f, 0.0f, // column2
                     0.0f, 0.0f, 1.0f, 0.0f, // column3
                     2.0f, 2.0f, 2.0f, 1.0f); // column4
 cout << “B = ”               << endl;
 mprint(B);

 glm::mat4 C = A * B; // multiplication
 cout << “C = A*B = ”         << endl;
 mprint(C);

 glm::mat4 D = B * A; // multiplication
 cout << “D = B*A = ”         << endl;
 mprint(D);

 glm::mat4 E = glm::inverse(A);
 // inverse
 cout << “E = inverse(A) = ”  << endl;
 mprint(E);

 glm::mat4 I = A * E;   // multiplication
 cout << “I = A*E = ”         << endl;
 mprint(I);

 glm::vec4 p = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f);
 glm::vec4 q = A * p;
 glm::vec4 r = B * p;
 glm::vec4 s = C * p;
 glm::vec4 t = D * p;
 cout << “q = A*p = ”   << endl;
 printf(“(1, 0, 0, 1) => (%f, %f, %f, %f)\n”, q[0], q[1], q[2], q[3]);
 cout << “r = B*p = ”   << endl;
 printf(“(1, 0, 0, 1) => (%f, %f, %f, %f)\n”, r[0], r[1], r[2], r[3]);
 cout << “s = A*B*p = ”  << endl;
 printf(“(1, 0, 0, 1) => (%f, %f, %f, %f)\n”, s[0], s[1], s[2], s[3]);
 cout << “t = B*A*p = ”         << endl;
 printf(“(1, 0, 0, 1) => (%f, %f, %f, %f)\n”, t[0], t[1], t[2], t[3]);

 glm::mat4 Tx, Ty, Tz;
 Tx = glm::translate(glm::mat4(1.0f), glm::vec3(2.0f, 0.0f, 0.0f)); // RHS x+ right
 Ty = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 2.0f, 0.0f)); // RHS y+ up
 Tz = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 2.0f)); // RHS z+ front
 printf(“Tx\n”);
 mprint(Tx);
 
 glm::vec4 Position = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f);
 glm::vec4 tV = Tx * Position;
 printf(“(1, 0, 0, 1) => (%f, %f, %f, %f)\n”, tV[0], tV[1], tV[2], tV[3]);

 glm::mat4 Rx, Ry, Rz, Ra;
 Rx = glm::rotate(glm::mat4(1.0f), 30.0f, glm::vec3(1.0f, 0.0f, 0.0f));
 Ry = glm::rotate(glm::mat4(1.0f), 60.0f, glm::vec3(0.0f, 1.0f, 0.0f));
 Rz = glm::rotate(glm::mat4(1.0f), 45.0f, glm::vec3(0.0f, 0.0f, 1.0f));
 Ra = glm::rotate(glm::mat4(1.0f), 45.0f, glm::vec3(1.0f, 1.0f, 1.0f));
 printf(“R\n”);
 mprint(Rx);
 mprint(Ry);
 mprint(Rz);
 mprint(Ra);

 glm::vec4 tV1 = Ra * Position;
 printf(“Ra * Position(1, 0, 0, 1) => (%f, %f, %f, %f)\n”, tV1[0], tV1[1], tV1[2], tV1[3]);

 glm::mat4 Sx, Sy, Sz;
 Sx = glm::scale(glm::mat4(1.0f), glm::vec3(2, 1, 1));
 Sy = glm::scale(glm::mat4(1.0f), glm::vec3(1, 2, 1));
 Sz = glm::scale(glm::mat4(1.0f), glm::vec3(1, 1, 2));
 printf(“Sy\n”);
 mprint(Sy);

 glm::vec4 tV2 = Sy * Position;
 printf(“(1, 0, 0, 1) => (%f, %f, %f, %f)\n”, tV2[0], tV2[1], tV2[2], tV2[3]);

 glm::mat4 TR = Tx * Rz; // Rotate Z and then Translate X
 printf(“TR\n”);
 mprint(TR);

 glm::vec4 tV3 = TR * Position;
 printf(“(1, 0, 0, 1) => (%f, %f, %f, %f)\n”, tV3[0], tV3[1], tV3[2], tV3[3]);

 mat4 RT = Rz * Tx; // Translate X and then Rotate Z
 printf(“RT\n”);
 mprint(RT);

 glm::vec4 tV4 = RT * Position;
 printf(“(1, 0, 0, 1) => (%f, %f, %f, %f)\n”, tV4[0], tV4[1], tV4[2], tV4[3]);
}

Lab5

CatmullRom Animation 도형을 그려본다.
(n-key를 누를 시, “사”-도형이 아지랑이 피어오르듯이 올라간다)

9955640780.cpp9560298062.cpp

Sa::Sa(glm::vec3 p_) : GeometryPositionColor()
{
 p = p_;
 for (int i=0; i<4; i++) pipe[i] = Parallelpiped();

 std::vector<KeyFrame> keyframes;
 keyframes.push_back(KeyFrame(glm::vec3(0, 0, 0), 0)); // Posotion & Time
 keyframes.push_back(KeyFrame(glm::vec3(1, 1, 0), 2000));
// Posotion & Time
 keyframes.push_back(KeyFrame(glm::vec3(-1, 2, 0),
4000
));
// Posotion & Time
 keyframes.push_back(KeyFrame(glm::vec3(2, 3, 0), 6000)); // Posotion & Time
 curve = new CatmullRomCurveAnimation(keyframes, false);
// loop을 원하면 true

 init();
}

void Sa::init() // “사”
{
 glm::vec3 p0 = p;
 pipe[0].set(p0, glm::vec3(0.3f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.3f), glm::vec3(0.7f, 1.0f, 0.0f));
 glm::vec3 p1 = p + glm::vec3(1.4f, 0.0f, 0.0f);
 pipe[1].set(p1, glm::vec3(0.3f, 0.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 0.3f), glm::vec3(-0.7f, 1.0f, 0.0f));
 glm::vec3 p2 = p + glm::vec3(2.0f, 0.0f, 0.0f);
 pipe[2].set(p2, glm::vec3(0.3f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.3f), glm::vec3(0.0f, 1.0f,
0.0f));
 glm::vec3 p3 = p + glm::vec3(2.3f, 0.35f, 0.0f);
 pipe[3].set(p3, glm::vec3(0.5f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.3f), glm::vec3(0.0f, 0.3f, 0.0f));
}

void Sa::draw(bool wireframe)
{
 for (int i=0; i<4; i++) pipe[i].draw();
}

// GeometryPositionColor 의 update을 override
bool Sa::update(float elapsedTime)
{
 if (active)
 {
  if (curve)
  {
   curve->updatePosition(elapsedTime);
   p = curve->getPosition();

   // if time is greater than duration, then set time to duration and set active to false
   if (!curve->getLoop() && elapsedTime >=  curve->getDuration())
   {
    done = true;
    active = false;
   }
  }
  init();
 }
 return true;
}

Sa class


class Parallelpiped : public
GeometryPositionColor
{
public:
 Parallelpiped(glm::vec3 p_=glm::vec3(0, 0, 0), glm::vec3 u=glm::vec3(1, 0, 0), glm::vec3 v=glm::vec3(0, 0, 1), glm::vec3 w=glm::vec3(0, 1, 0));
 void set(glm::vec3 p_, glm::vec3 u_, glm::vec3 v_, glm::vec3 w_);
 void init();
 void draw(bool wireframe=false);


private:
 //glm::vec3 p; // BL position
 glm::vec3 u;
 glm::vec3 v;
 glm::vec3 w;
};



class Sa : public GeometryPositionColor
{
public:
 Sa(glm::vec3 p=glm::vec3(0, 0, 0));
 void init();
 void draw(bool wireframe=false);



private:
 //glm::vec3 p; // BL position
 Parallelpiped pipe[4];
};




Parallelpiped::Parallelpiped(glm::vec3 p_, glm::vec3 u_, glm::vec3 v_,
glm::vec3 w_) : GeometryPositionColor()
{
 set(p_, u_, v_, w_);
}

void Parallelpiped::set(glm::vec3 p_, glm::vec3 u_, glm::vec3 v_, glm::vec3 w_)
{
 p = p_;
 u = u_;
 v = v_;
 w = w_;
 init();
}



void Parallelpiped::init()
{
 glm::vec3 pu = p + u;
 glm::vec3 pv = p + v;
 glm::vec3 pw = p + w;
 glm::vec3 puv = p + u + v;
 glm::vec3 pvw = p + v + w;
 glm::vec3 puw = p + u + w;
 glm::vec3 puvw = p + u + v + w;



 glm::vec3 frontNormal = glm::cross(u, w);
 glm::vec3 backNormal = glm::cross(w, u);
 glm::vec3 rightNormal = glm::cross(v, w);
 glm::vec3 leftNormal = glm::cross(w, v);
 glm::vec3 topNormal = glm::cross(u, v);
 glm::vec3 bottomNormal = glm::cross(v, u);



 // Front face
 vbo.addData(&p[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&pu[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&puw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&p[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&puw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&pw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color



 // Back face
 vbo.addData(&puv[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&pv[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&pvw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&puv[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&pvw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&puvw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color



 // Left face
 vbo.addData(&pv[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&p[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&pw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&pv[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&pw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&pvw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color



 // Right face
 vbo.addData(&pu[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&puv[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&puvw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&pu[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&puvw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&puw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color



 // Top face
 vbo.addData(&pw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&puw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&puvw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&pw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&puvw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&pvw[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color



 // Bottom face
 vbo.addData(&pv[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&puv[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&pu[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&pv[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&pu[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color
 vbo.addData(&p[0],
sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3)); //
vertex color



 numVertices = 36;



 // VAO &
VBOs
 vbo.createVBO();
 vbo.bindVBO();
 vbo.uploadDataToGPU(GL_STATIC_DRAW);



 glGenVertexArrays(1, &vao);
 glBindVertexArray(vao);



 int iDataStride = 2 * sizeof(glm::vec3); // vertex &
color
 int iDataOffset =
0;
 glEnableVertexAttribArray(0);
 glVertexAttribPointer(0, 3,
GL_FLOAT, GL_FALSE, iDataStride, (void*)iDataOffset);
 iDataOffset +=
sizeof(glm::vec3);
 glEnableVertexAttribArray(1);
 glVertexAttribPointer(1,
3, GL_FLOAT, GL_FALSE, iDataStride, (void*)iDataOffset);



 isLoaded = true;
}



void Parallelpiped::draw(bool wireframe)
{
 if (!isLoaded)
return;
 glBindVertexArray(vao);
 glDrawArrays(GL_TRIANGLES, 0,
numVertices);
}



Sa::Sa(glm::vec3 p_) : GeometryPositionColor()
{
 p = p_;
 for (int i = 0; i < 4; i++)
  pipe[i] = Parallelpiped();
 init();

}



void Sa::init() // “사”
{
 glm::vec3 p0 = p;
 pipe[0].set(p0, glm::vec3(0.3f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.3f), glm::vec3(0.7f, 1.0f, 0.0f));
 glm::vec3 p1 = p + glm::vec3(1.4f, 0.0f, 0.0f);
 pipe[1].set(p1, glm::vec3(0.3f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.3f), glm::vec3(-0.7f, 1.0f, 0.0f));
 glm::vec3 p2 = p + glm::vec3(2.0f, 0.0f, 0.0f);
 pipe[2].set(p2, glm::vec3(0.3f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.3f), glm::vec3(0.0f, 1.0f,
0.0f));
 glm::vec3 p3 = p + glm::vec3(2.3f, 0.35f, 0.0f);
 pipe[3].set(p3, glm::vec3(0.5f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.3f), glm::vec3(0.0f, 0.3f, 0.0f));
}



void Sa::draw(bool wireframe)
{
 for (int i = 0; i < 4; i++)
  pipe[i].draw();
}

main update animation

// each geometry update
 geoList[g_geometrymode]->update(elapsedTime);
 if (geoList[g_geometrymode]->IsAnimationDone())
 {
  g_geometrymode++;
  if (g_geometrymode == 8)
  {
     g_geometrymode = 0;
     for (int i = 0; i < 8; i++) 
   geoList[i]->reset();
  }
  geoList[g_geometrymode]->activate();
  startTime = glutGet(GLUT_ELAPSED_TIME);
  printf(“geoList[%d] animation is activate\n”, g_geometrymode);
 }