diff --git a/FinalProject/model.cpp b/FinalProject/model.cpp index 3f3ee94..e1db286 100644 --- a/FinalProject/model.cpp +++ b/FinalProject/model.cpp @@ -35,7 +35,7 @@ void Model::loadModel(std::string path) { _status = LOADED; Logger::info("Model loaded"); // 仅检查一次即可 - check_boundary(); + //check_boundary(); } void Model::processNode(aiNode* node, const aiScene* scene) { @@ -67,16 +67,16 @@ Mesh Model::processMesh(aiMesh* mesh, const aiScene* scene) { glm::vec3 vertexBitangent = glm::vec3(0.0f); // 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) { diff --git a/FinalProject/renderable.cpp b/FinalProject/renderable.cpp index a022be4..11e1459 100644 --- a/FinalProject/renderable.cpp +++ b/FinalProject/renderable.cpp @@ -4,15 +4,9 @@ // 极值点一定在model包围盒的顶点出取到 -Renderable::Renderable(Model* model) : _model(model) { - _upper_bound = model->get_upper_bound(); - _lower_bound = model->get_lower_bound(); -} +Renderable::Renderable(Model* model) : _model(model) {} -Renderable::Renderable(Model* model, glm::vec3 position) : _model(model), _position(position) { - _upper_bound = model->get_upper_bound(); - _lower_bound = model->get_lower_bound(); -} +Renderable::Renderable(Model* model, glm::vec3 position) : _model(model), _position(position) {} void Renderable::move(glm::vec3 deltaVec) { _position += deltaVec; @@ -47,5 +41,18 @@ void Renderable::render(ShaderProgram shader) { // check here to get global boundary void Renderable::check_boundary() { - + std::vector temp = { _lower_bound,_upper_bound }; + _lower_bound = glm::vec3(3e36, 3e36, 3e36); + _upper_bound = -_lower_bound; + auto model = this->modelMatrix();// 变换矩阵 + // 位运算 从000到111的每一种组合 + for (int i = 0; i < 7; i++) { + //遍历每一个顶点 + glm::vec4 vex = glm::vec4(temp[i & 4][0], temp[i & 2][1], temp[i & 1][2],1.0f); + vex = model * vex; // 经过变化之后的点的坐标 + for (int j = 0; j < 3; j++) { + _lower_bound[j] = _lower_bound[j] < vex[j] ? _lower_bound[j] : vex[j]; + _upper_bound[j] = _upper_bound[j] > vex[j] ? _upper_bound[j] : vex[j]; + } + } } \ No newline at end of file