Skip to content
Snippets Groups Projects
Commit dd450f18 authored by Martin Štourač's avatar Martin Štourač
Browse files

added cube vertices with normals (indexed)

parent b412bf65
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,7 @@ void gfx_draw(Shader &myShader,
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
ASSUMPTION(glGetError() == GL_NO_ERROR);
Frame lightPos(glm::vec3(1.2f, 1.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f));
Frame lightPos(glm::vec3(1.2f, 10.0f, 10.0f), glm::vec3(0.0f, 0.0f, 0.0f));
myShader.use();
myShader.setVec3("objectColor", glm::vec3(1.0f, 0.5f, 0.31f));
......@@ -70,8 +70,9 @@ void gfx_draw(Shader &myShader,
/* ---------------------------------------------------------------- */
glm::mat4 model = glm::mat4(1.0f);
model = obj_frame.getRotationMat() * model;
model = glm::translate(model, obj_frame.getPosition());
glm::mat4 rotated = obj_frame.getRotationMat() * model;
glm::mat4 translated = glm::translate(model, obj_frame.getPosition());
model = translated * rotated;
glm::mat4 view;
......
......@@ -12,7 +12,7 @@ VAO::~VAO()
Delete();
}
void VAO::LinkVBO(unsigned int layout_loc)
void VAO::LinkVBO(unsigned int layout_loc) // TO DO: change to getUniform
{
ASSUMPTION(ID != 0);
glVertexAttribPointer(layout_loc, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
......
......@@ -41,60 +41,84 @@ std::vector<unsigned int> obj_indices =
1, 2, 5, 2, 5, 6
};
std::vector<float> lit_cube_vertices =
{
-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, // +Y
-1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, // -Y
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, // +X
-1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, // -X
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, // +Z
-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f // -Z
};
std::vector<unsigned int> lit_cube_indices =
{
8, 9, 10, 9, 11, 10,
14, 13, 12, 14, 15, 13,
1, 2, 0, 3, 2, 1,
4, 6, 5, 5, 6, 7,
17, 18, 16, 19, 18, 17,
20, 22, 21, 21, 22, 23
};
std::vector<float> lit_cube_normals =
{
0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f,
1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f
};
std::vector<float> getnormals(std::vector<unsigned int> &indices, std::vector<float> &vertices)
{
std::vector<float> normals;
for (int i = 0; i < indices.size(); i += 3)
{
glm::vec3 v1(vertices[indices[i]*3], vertices[indices[i]*3+1], vertices[indices[i]*3+2]);
glm::vec3 v2(vertices[indices[i+1]*3], vertices[indices[i+1]*3+1], vertices[indices[i+1]*3+2]);
glm::vec3 v3(vertices[indices[i+2]*3], vertices[indices[i+2]*3+1], vertices[indices[i+2]*3+2]);
glm::vec3 normal = glm::normalize(glm::cross(v2 - v1, v3 - v1));
for (int j = 0; j < 3; j++)
{
normals.push_back(normal.x);
normals.push_back(normal.y);
normals.push_back(normal.z);
}
}
return normals;
}
Simulator::Simulator()
: osi::Simulator()
// camera frame, object frame, camera, object
, myShader{"./data/shaders/lightshader.vert",
"./data/shaders/lightshader.frag"}
, camera{60.0f}
, object{{
0, 0, 0, 1, -0.2f, 0, 1, 0.2f, 0,
0, 0, 0, -0.2f, 2, 0, 0.2f, 2, 0,
0, 0, 0, -0.2f, 0, 3, 0.2f, 0, 3,
},
{
0, 1, 2,
3, 4, 5,
6, 7, 8
},
{
0, 1, 1, 0, 0, -1, 0, 0, -1,
0, 1, 1, 0, 0, -1, 0, 0, -1,
0, 1, 1, 1, 0, 0, 1, 0, 0
}
}
, object{lit_cube_vertices, lit_cube_indices, lit_cube_normals}
// , object{{
// 0, 0, 0, 1, -0.2f, 0, 1, 0.2f, 0,
// 0, 0, 0, -0.2f, 2, 0, 0.2f, 2, 0,
// 0, 0, 0, -0.2f, 0, 3, 0.2f, 0, 3,
// },
// {
// 0, 1, 2,
// 3, 4, 5,
// 6, 7, 8
// },
// {
// 0, 0, -1, 0, 0, -1, 0, 0, -1,
// 0, 0, -1, 0, 0, -1, 0, 0, -1,
// 0, 1, 0, 0, 1, 0, 0, 1, 0
// }
// }
, cam_frame{{0.0f, 0.0f, 3.0f}, {0.0f, -90.0f, 0.0f}} // Setting camera rotation currently does nothing
, obj_frame{{ 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }}
, cam_control{cam_frame}
, obj_control{obj_frame}
// , object{{ 1.0f, -1.0f, 0.0f },
// {
// // positions
// //front
// 0.2f, 0.2f, 0.2f, // top right
// 0.2f, -0.2f, 0.2f, // bottom right
// -0.2f, -0.2f, 0.2f, // bottom left
// -0.2f, 0.2f, 0.2f, // top left
// //back
// 0.2f, 0.2f, -0.2f, // top right
// 0.2f, -0.2f, -0.2f, // bottom right
// -0.2f, -0.2f, -0.2f, // bottom left
// -0.2f, 0.2f, -0.2f // top left
// },
// {
// // front
// 0, 1, 3, 1, 2, 3,
// // back
// 4, 5, 7, 5, 6, 7,
// // right
// 0, 1, 4, 1, 4, 5,
// // left
// 2, 3, 7, 2, 6, 7,
// // top
// 0, 3, 4, 3, 4, 7,
// // bottom
// 1, 2, 5, 2, 5, 6
// }}
{
camera.setWindowSize(window().size());
//obj_control.rotate(glm::vec3(0.0f, 50.0f, 0.0f));
......@@ -108,7 +132,7 @@ void Simulator::update()
process_input();
process_mouse();
//obj_control.rotate(glm::vec3(1.0f, 0.0f, 0.0f)); // Rotation around x-axis demo
// obj_control.rotate(glm::vec3(1.0f, 0.0f, 0.0f)); // Rotation around x-axis demo
}
void Simulator::present()
......@@ -144,7 +168,7 @@ void Simulator::process_input()
cam_control.move(keyboard().down());
}
int fill_mode = keyboard().down().contains("X") ? GL_FILL : GL_LINE; // TO DO: change
int fill_mode = keyboard().down().contains("X") ? GL_LINE : GL_FILL; // TO DO: change
glPolygonMode(GL_FRONT_AND_BACK, fill_mode);
ASSUMPTION(glGetError() == GL_NO_ERROR);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment