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();
}