From 14a3a08bf6c6c10431ddee88f525d6e90c889253 Mon Sep 17 00:00:00 2001 From: ayachi3 <1592757525@qq.com> Date: Tue, 13 Dec 2022 16:42:44 +0800 Subject: [PATCH] add check_boundary --- FinalProject/model.cpp | 32 ++++++++++---- FinalProject/model.h | 5 ++- .../253395836ff6e468d34a6e0bb41a535/model.h | 42 ------------------- 3 files changed, 28 insertions(+), 51 deletions(-) delete mode 100644 enc_temp_folder/253395836ff6e468d34a6e0bb41a535/model.h diff --git a/FinalProject/model.cpp b/FinalProject/model.cpp index f8ae923..6a313d9 100644 --- a/FinalProject/model.cpp +++ b/FinalProject/model.cpp @@ -66,15 +66,15 @@ Mesh Model::processMesh(aiMesh* mesh, const aiScene* scene) { // Process vertex positions // 使用循环避免代码重复,如果可行的话,可以在此循环中确定法向量等信息 - for (int j = 0; j < 3; j++) { - vertexPosition[j] = mesh->mVertices[i][j]; - _left_down_back[j] = _left_down_back[j] < vertexPosition[j] ? _left_down_back[j] : vertexPosition[j]; - _right_up_front[j] = _right_up_front[j] > vertexPosition[j] ? _right_up_front[j] : vertexPosition[j]; - } + //for (int j = 0; j < 3; j++) { + // vertexPosition[j] = mesh->mVertices[i][j]; + // _left_down_back[j] = _left_down_back[j] < vertexPosition[j] ? _left_down_back[j] : vertexPosition[j]; + // _right_up_front[j] = _right_up_front[j] > vertexPosition[j] ? _right_up_front[j] : vertexPosition[j]; + //} - //vertexPosition.x = mesh->mVertices[i].x; - //vertexPosition.y = mesh->mVertices[i].y; - //vertexPosition.z = mesh->mVertices[i].z; + vertexPosition.x = mesh->mVertices[i].x; + vertexPosition.y = mesh->mVertices[i].y; + vertexPosition.z = mesh->mVertices[i].z; // Process vertex normals if (mesh->mNormals) { @@ -184,3 +184,19 @@ void Model::render(const ShaderProgram& shader) const { _meshes[i].render(shader); } } + +void Model::check_boundary() { + for (int i = 0; i < _meshes.size(); i++) { + for (int j = 0; j < _meshes[i].vertices().size();j++) { + // 0,1,2 for x,y,z + for (int k = 0; k < 3; k++) { + _left_down_back[k] = _left_down_back[k] < _meshes[i].vertices()[j]._position[k] ? + _left_down_back[k] : _meshes[i].vertices()[j]._position[k]; + + _right_up_front[k] = _right_up_front[k] > _meshes[i].vertices()[j]._position[k] ? + _right_up_front[k] : _meshes[i].vertices()[j]._position[k]; + } + } + } + +} \ No newline at end of file diff --git a/FinalProject/model.h b/FinalProject/model.h index 951bde1..9a22193 100644 --- a/FinalProject/model.h +++ b/FinalProject/model.h @@ -20,7 +20,7 @@ private: MODELSTATUS _status = LOADING; // smallest point - glm::vec3 _left_down_back = glm::vec3(3e37f, 3e37f, 3e37f); + glm::vec3 _left_down_back = glm::vec3(3e36f, 3e36f, 3e36f); // largest point glm::vec3 _right_up_front = -_left_down_back; @@ -31,6 +31,8 @@ public: public: inline MODELSTATUS status() const { return _status; } + + // maybe we can check if boundary has not been set yet inline glm::vec3 get_upper_bound() { return _right_up_front; } @@ -46,4 +48,5 @@ private: public: void render(const ShaderProgram& shader) const; + void check_boundary(); }; \ No newline at end of file diff --git a/enc_temp_folder/253395836ff6e468d34a6e0bb41a535/model.h b/enc_temp_folder/253395836ff6e468d34a6e0bb41a535/model.h deleted file mode 100644 index 636253b..0000000 --- a/enc_temp_folder/253395836ff6e468d34a6e0bb41a535/model.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "mesh.h" -#include "shader.h" -#include -class Model { -public: - enum MODELSTATUS { LOADING, LOADED, ERR }; - -private: - std::vector _meshes; - std::vector _texturesLoaded; - std::string _directory; - MODELSTATUS _status = LOADING; - - // smallest point - glm::vec3 left_down_back = glm::vec3(3e37f, 3e37f, 3e37f); - // largest point - glm::vec3 right_up_front = -left_down_back; - -public: - Model(std::string path); - ~Model(); - -public: - inline MODELSTATUS status() const { return _status; } - -private: - void loadModel(std::string path); - void processNode(aiNode* node, const aiScene* scene); - Mesh processMesh(aiMesh* mesh, const aiScene* scene); - std::vector loadMaterialTextures(aiMaterial* mat, aiTextureType type, TextureType textureType); - -public: - void render(const ShaderProgram& shader) const; -}; \ No newline at end of file