implement check_boundary

This commit is contained in:
ayachi3 2022-12-13 19:02:44 +08:00
parent 5ec0a5718e
commit 13bd34973c
2 changed files with 26 additions and 19 deletions

View File

@ -35,7 +35,7 @@ void Model::loadModel(std::string path) {
_status = LOADED; _status = LOADED;
Logger::info("Model loaded"); Logger::info("Model loaded");
// 仅检查一次即可 // 仅检查一次即可
check_boundary(); //check_boundary();
} }
void Model::processNode(aiNode* node, const aiScene* scene) { void Model::processNode(aiNode* node, const aiScene* scene) {
@ -68,15 +68,15 @@ Mesh Model::processMesh(aiMesh* mesh, const aiScene* scene) {
// Process vertex positions // Process vertex positions
//使用循环避免代码重复,如果可行的话,可以在此循环中确定法向量等信息 //使用循环避免代码重复,如果可行的话,可以在此循环中确定法向量等信息
//for (int j = 0; j < 3; j++) { for (int j = 0; j < 3; j++) {
// vertexPosition[j] = mesh->mVertices[i][j]; vertexPosition[j] = mesh->mVertices[i][j];
// _left_down_back[j] = _left_down_back[j] < vertexPosition[j] ? _left_down_back[j] : vertexPosition[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]; _right_up_front[j] = _right_up_front[j] > vertexPosition[j] ? _right_up_front[j] : vertexPosition[j];
//} }
vertexPosition.x = mesh->mVertices[i].x; //vertexPosition.x = mesh->mVertices[i].x;
vertexPosition.y = mesh->mVertices[i].y; //vertexPosition.y = mesh->mVertices[i].y;
vertexPosition.z = mesh->mVertices[i].z; //vertexPosition.z = mesh->mVertices[i].z;
// Process vertex normals // Process vertex normals
if (mesh->mNormals) { if (mesh->mNormals) {

View File

@ -4,15 +4,9 @@
// 极值点一定在model包围盒的顶点出取到 // 极值点一定在model包围盒的顶点出取到
Renderable::Renderable(Model* model) : _model(model) { Renderable::Renderable(Model* model) : _model(model) {}
_upper_bound = model->get_upper_bound();
_lower_bound = model->get_lower_bound();
}
Renderable::Renderable(Model* model, glm::vec3 position) : _model(model), _position(position) { Renderable::Renderable(Model* model, glm::vec3 position) : _model(model), _position(position) {}
_upper_bound = model->get_upper_bound();
_lower_bound = model->get_lower_bound();
}
void Renderable::move(glm::vec3 deltaVec) { void Renderable::move(glm::vec3 deltaVec) {
_position += deltaVec; _position += deltaVec;
@ -47,5 +41,18 @@ void Renderable::render(ShaderProgram shader) {
// check here to get global boundary // check here to get global boundary
void Renderable::check_boundary() { void Renderable::check_boundary() {
std::vector<glm::vec3> 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];
}
}
} }