Change variable names

This commit is contained in:
Linloir 2022-12-17 13:19:55 +08:00
parent 849da430e9
commit bef49b7499
No known key found for this signature in database
GPG Key ID: 58EEB209A0F2C366
4 changed files with 25 additions and 31 deletions

View File

@ -76,8 +76,8 @@ Mesh Model::processMesh(aiMesh* mesh, const aiScene* scene) {
//使用循环避免代码重复,如果可行的话,可以在此循环中确定法向量等信息 //使用循环避免代码重复,如果可行的话,可以在此循环中确定法向量等信息
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]; _leftBackBottomVex[j] = _leftBackBottomVex[j] < vertexPosition[j] ? _leftBackBottomVex[j] : vertexPosition[j];
_right_up_front[j] = _right_up_front[j] > vertexPosition[j] ? _right_up_front[j] : vertexPosition[j]; _rightFrontTopVex[j] = _rightFrontTopVex[j] > vertexPosition[j] ? _rightFrontTopVex[j] : vertexPosition[j];
} }
//vertexPosition.x = mesh->mVertices[i].x; //vertexPosition.x = mesh->mVertices[i].x;
@ -198,11 +198,11 @@ void Model::checkBoundary() {
for (int j = 0; j < _meshes[i].vertices().size();j++) { for (int j = 0; j < _meshes[i].vertices().size();j++) {
// 0,1,2 for x,y,z // 0,1,2 for x,y,z
for (int k = 0; k < 3; k++) { for (int k = 0; k < 3; k++) {
_left_down_back[k] = _left_down_back[k] < _meshes[i].vertices()[j]._position[k] ? _leftBackBottomVex[k] = _leftBackBottomVex[k] < _meshes[i].vertices()[j]._position[k] ?
_left_down_back[k] : _meshes[i].vertices()[j]._position[k]; _leftBackBottomVex[k] : _meshes[i].vertices()[j]._position[k];
_right_up_front[k] = _right_up_front[k] > _meshes[i].vertices()[j]._position[k] ? _rightFrontTopVex[k] = _rightFrontTopVex[k] > _meshes[i].vertices()[j]._position[k] ?
_right_up_front[k] : _meshes[i].vertices()[j]._position[k]; _rightFrontTopVex[k] : _meshes[i].vertices()[j]._position[k];
} }
} }
} }

View File

@ -20,9 +20,9 @@ private:
MODELSTATUS _status = LOADING; MODELSTATUS _status = LOADING;
// smallest point // smallest point
glm::vec3 _left_down_back = glm::vec3(3e36f, 3e36f, 3e36f); glm::vec3 _leftBackBottomVex = glm::vec3(3e36f, 3e36f, 3e36f);
// largest point // largest point
glm::vec3 _right_up_front = -_left_down_back; glm::vec3 _rightFrontTopVex = -_leftBackBottomVex;
public: public:
Model(std::string path); Model(std::string path);
@ -42,13 +42,13 @@ public:
// maybe we can check if boundary has not been set yet // maybe we can check if boundary has not been set yet
// Do remember to ensure you have called checkBoundary // Do remember to ensure you have called checkBoundary
inline glm::vec3 get_upper_bound() { inline glm::vec3 upperBoundVex() {
return _right_up_front; return _rightFrontTopVex;
} }
// Do remember to ensure you have called checkBoundary // Do remember to ensure you have called checkBoundary
inline glm::vec3 get_lower_bound() { inline glm::vec3 lowerBoundVex() {
return _left_down_back; return _leftBackBottomVex;
} }
private: private:
@ -56,14 +56,8 @@ private:
void processNode(aiNode* node, const aiScene* scene); void processNode(aiNode* node, const aiScene* scene);
Mesh processMesh(aiMesh* mesh, const aiScene* scene); Mesh processMesh(aiMesh* mesh, const aiScene* scene);
std::vector<Texture> loadMaterialTextures(aiMaterial* mat, aiTextureType type, TextureType textureType); std::vector<Texture> loadMaterialTextures(aiMaterial* mat, aiTextureType type, TextureType textureType);
// Since these are loacl position, this function should be called just once.
void checkBoundary(); void checkBoundary();
public: public:
void render(const ShaderProgram& shader) const; void render(const ShaderProgram& shader) const;
// maybe we can encapsure a function to get both upper and lower bound?
}; };

View File

@ -49,10 +49,10 @@ void Renderable::render(ShaderProgram shader) {
// check here to get global boundary // check here to get global boundary
// must check before get boundary // must check before get boundary
void Renderable::checkBoundary() { void Renderable::checkBoundary() {
std::vector<glm::vec3> temp = {_model->get_upper_bound(),_model->get_lower_bound()}; std::vector<glm::vec3> temp = {_model->upperBoundVex(),_model->lowerBoundVex()};
_lower_bound = glm::vec3(3e36, 3e36, 3e36); _lowerBoundVex = glm::vec3(3e36, 3e36, 3e36);
_upper_bound = -_lower_bound; _upperBoundVex = -_lowerBoundVex;
auto model = this->modelMatrix(); // transform matrix auto model = this->modelMatrix(); // transform matrix
@ -61,8 +61,8 @@ void Renderable::checkBoundary() {
glm::vec4 vx = glm::vec4(temp[(i & 4) >> 2][0], temp[(i & 2)>>1][1], temp[i & 1][2], 1.0f); glm::vec4 vx = glm::vec4(temp[(i & 4) >> 2][0], temp[(i & 2)>>1][1], temp[i & 1][2], 1.0f);
auto vex = model * vx; // Transformed vertex position auto vex = model * vx; // Transformed vertex position
for (int j = 0; j < 3; j++) { for (int j = 0; j < 3; j++) {
_lower_bound[j] = _lower_bound[j] < vex[j] ? _lower_bound[j] : vex[j]; _lowerBoundVex[j] = _lowerBoundVex[j] < vex[j] ? _lowerBoundVex[j] : vex[j];
_upper_bound[j] = _upper_bound[j] > vex[j] ? _upper_bound[j] : vex[j]; _upperBoundVex[j] = _upperBoundVex[j] > vex[j] ? _upperBoundVex[j] : vex[j];
} }
} }
} }

View File

@ -20,8 +20,8 @@ private:
glm::vec3 _position = glm::vec3(0.0f); glm::vec3 _position = glm::vec3(0.0f);
glm::mat4 _rotation = glm::mat4(1.0f); glm::mat4 _rotation = glm::mat4(1.0f);
glm::vec3 _scale = glm::vec3(1.0f); glm::vec3 _scale = glm::vec3(1.0f);
glm::vec3 _lower_bound; glm::vec3 _lowerBoundVex;
glm::vec3 _upper_bound; glm::vec3 _upperBoundVex;
public: public:
Renderable(Model* model); Renderable(Model* model);
@ -38,8 +38,8 @@ public:
inline glm::mat4 modelMatrix() const; inline glm::mat4 modelMatrix() const;
inline glm::vec3 get_upper_boundary()const; inline glm::vec3 upperBoundVex()const;
inline glm::vec3 get_lower_boundary()const; inline glm::vec3 lowerBoundVex()const;
public: public:
void render(ShaderProgram shader); void render(ShaderProgram shader);
@ -55,9 +55,9 @@ inline glm::mat4 Renderable::modelMatrix() const {
return model; return model;
} }
inline glm::vec3 Renderable::get_lower_boundary()const { inline glm::vec3 Renderable::lowerBoundVex() const {
return _lower_bound; return _lowerBoundVex;
} }
inline glm::vec3 Renderable::get_upper_boundary()const { inline glm::vec3 Renderable::upperBoundVex() const {
return _upper_bound; return _upperBoundVex;
} }