tmp
This commit is contained in:
parent
89e15ab60f
commit
6f52386199
|
@ -75,7 +75,7 @@ int main()
|
|||
sun.ambient = glm::vec3(0.2, 0.2, 0.2);
|
||||
sun.diffuse = glm::vec3(1.0, 1.0, 1.0);
|
||||
sun.specular = glm::vec3(1.0, 1.0, 1.0);
|
||||
sun.direction = glm::vec3(0.0, 0.0, -1.0);
|
||||
sun.direction = glm::vec3(0.0, -1.0, 0.0);
|
||||
|
||||
camera.projection = glm::perspective(45.0f, (float)640 / (float)480, 0.1f, 100.0f);
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "mesh.hpp"
|
||||
|
||||
#include <glm/gtx/vector_angle.hpp>
|
||||
|
||||
void Mesh::add(const glm::vec3 &position, const glm::vec3 &normal)
|
||||
{
|
||||
elements.push_back(positions.size());
|
||||
|
@ -7,3 +9,20 @@ void Mesh::add(const glm::vec3 &position, const glm::vec3 &normal)
|
|||
positions.push_back(position);
|
||||
normals.push_back(normal);
|
||||
}
|
||||
|
||||
void Mesh::add3(const std::array<glm::vec3, 3> &positions, const glm::vec3 &normal)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
add(positions[i], normal);
|
||||
}
|
||||
|
||||
void Mesh::add3_with_auto_normals(const std::array<glm::vec3, 3> &positions, const glm::vec3 &origin)
|
||||
{
|
||||
const glm::vec3 sample = glm::normalize((positions[1] - positions[0]) * (positions[2] - positions[0]));
|
||||
// TODO Handle if direction is zero vector (origin is in vertex 0) - use some other vertex
|
||||
const glm::vec3 direction = glm::normalize(positions[0] - origin);
|
||||
const float angle = glm::angle(direction, sample);
|
||||
const glm::vec3 normal = angle <= glm::radians(90.0f) ? sample : -sample;
|
||||
|
||||
add3(positions, normal);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "../gl.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
@ -15,6 +16,9 @@ struct Mesh
|
|||
std::vector<GLushort> elements;
|
||||
|
||||
void add(const glm::vec3 &position, const glm::vec3 &normal);
|
||||
|
||||
void add3(const std::array<glm::vec3, 3> &positions, const glm::vec3 &normal);
|
||||
void add3_with_auto_normals(const std::array<glm::vec3, 3> &positions, const glm::vec3 &origin = glm::vec3(0.0f, 0.0f, 0.0f));
|
||||
};
|
||||
|
||||
#endif // _MESH_HPP_
|
||||
|
|
|
@ -35,15 +35,12 @@ Raw::Raw(const Adapter &adapter, const std::string &name)
|
|||
|
||||
while (!feof(file))
|
||||
{
|
||||
glm::vec3 v[3];
|
||||
std::array<glm::vec3, 3> v;
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
fscanf(file, "%f %f %f", &v[i].x, &v[i].y, &v[i].z);
|
||||
|
||||
glm::vec3 normal = (v[0] - v[1]) * (v[2] - v[1]);
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
add(v[i], normal);
|
||||
add3_with_auto_normals(v, glm::vec3(0.0f, -10.0f, 0.0f));
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
|
Reference in New Issue