Calculate normals if there aren't any, texture store file path

This commit is contained in:
SeanOMik 2022-09-27 14:43:24 -04:00
parent ab09107d23
commit e0049c61ba
Signed by: SeanOMik
GPG Key ID: 568F326C7EB33ACB
3 changed files with 17 additions and 9 deletions

View File

@ -63,19 +63,19 @@ namespace simpleengine {
} }
if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS) { if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS) {
rotation.z += camera_speed; rotation.z += camera_speed * .3;
} }
if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS) { if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS) {
rotation.z -= camera_speed; rotation.z -= camera_speed * .3;
} }
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS) { if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS) {
rotation.y -= camera_speed; rotation.y -= camera_speed * .3;
} }
if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS) { if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS) {
rotation.y += camera_speed; rotation.y += camera_speed * .3;
} }
// Limit the pitch of the camera. // Limit the pitch of the camera.

View File

@ -73,8 +73,10 @@ namespace simpleengine::gfx {
simpleengine::Vectorf position(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z); simpleengine::Vectorf position(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z);
vertex.position = position; vertex.position = position;
if (mesh->HasNormals()) {
glm::vec3 normal(mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z); glm::vec3 normal(mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z);
vertex.normal = normal; vertex.normal = normal;
}
if (mesh->mTextureCoords[0]) { if (mesh->mTextureCoords[0]) {
glm::vec2 tex_coord(mesh->mTextureCoords[0][i].x, mesh->mTextureCoords[0][i].y); glm::vec2 tex_coord(mesh->mTextureCoords[0][i].x, mesh->mTextureCoords[0][i].y);
@ -142,7 +144,13 @@ namespace simpleengine::gfx {
} }
} }
return Mesh(vertices, indices, mat); Mesh se_mesh(vertices, indices, mat);
if (!mesh->HasNormals()) {
se_mesh.calculate_normals();
}
return se_mesh;
} }
std::unordered_map<aiTextureType, std::vector<Texture>> load_all_textures(aiMaterial* material) { std::unordered_map<aiTextureType, std::vector<Texture>> load_all_textures(aiMaterial* material) {

View File

@ -4,7 +4,7 @@
#include <stb_image.h> #include <stb_image.h>
namespace simpleengine::gfx { namespace simpleengine::gfx {
Texture::Texture(const char* path, aiTextureType type, int flags): type(type) { Texture::Texture(const char* path, aiTextureType type, int flags): type(type), path(path) {
bool img_2d = flags & TextureFlags::TexFlags_IMG_2D; bool img_2d = flags & TextureFlags::TexFlags_IMG_2D;
bool flip_vertically = flags & TextureFlags::TexFlags_FLIP_VERTICALLY; bool flip_vertically = flags & TextureFlags::TexFlags_FLIP_VERTICALLY;
bool mipmap = flags & TextureFlags::TexFlags_MIPMAP; bool mipmap = flags & TextureFlags::TexFlags_MIPMAP;