Changed how we track a models position.

In learning more about linear algebra I've figured out that if we have
the model matrix of an object, for the most part the objects position is
0,0,0 multiplied through the model matrix.
This commit is contained in:
Warwick 2022-07-26 11:33:33 +01:00
parent 811e949def
commit 2eabd78ed5
5 changed files with 17 additions and 3 deletions

View file

@ -10,7 +10,7 @@ Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Bump wooden box and barrel/boxes_DefaultMaterial_Normal.png
norm wooden box and barrel/boxes_DefaultMaterial_Normal.png
map_Kd wooden box and barrel/boxes_DefaultMaterial_BaseColor.png
map_Pr wooden box and barrel/boxes_DefaultMaterial_Roughness.jpg
map_Pm wooden box and barrel/boxes_DefaultMaterial_Metallic.jpg

View file

@ -126,5 +126,9 @@ void main()
float metallic = texture(texture_rma1, ourTexCoord).g;
float ao = texture(texture_rma1, ourTexCoord).b;
// Normals
// load and invert normal
vec3 normal = normalize(texture(texture_normal1, ourTexCoord).rgb * 2.0 - 1.0);
FragColor = vec4(PBR(albedo, roughness, metallic, ao), 1.0);
}

View file

@ -8,8 +8,13 @@ uniform mat4 Model;
out vec2 ourTexCoord;
out vec3 ourNormCoord;
//Pbr
out vec3 WorldPos;
//Normals
out mat3 TBN;
void main()
{
gl_Position = MVP * Model * vec4(aPos, 1.0);

View file

@ -15,10 +15,14 @@ void Model::translate(glm::vec3 translation) {
// set worldspace postition
glm::mat4 trans = glm::mat4(1.0f);
trans = glm::translate(trans, translation);
this->position = trans * this->position;
glm::vec3 position = trans * this->position;
// set model transform
this->model = glm::translate(glm::mat4(1.0f), glm::vec3(this->position));
this->model = glm::translate(glm::mat4(1.0f), glm::vec3(position));
// set position based on the current model
// TODO: turn this into a function if readability becomes an issue
this->position = model * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
}
void Model::resize(glm::vec3 scale) {
// set worldspace postition

View file

@ -79,6 +79,7 @@ int main(int argc, char **argv) {
// Model gun(ROOT_DIR "data/models/gun/Cerberus_LP.FBX");
Model boxbarrel(ROOT_DIR
"data/models/wooden_boxbarrel/wooden_box_and_barrel.obj");
boxbarrel.translate(glm::vec3(0.0f, -1.0f, 0.0f));
// cube.translate(glm::vec3(3.0f, 0.0f, -1.0f));
// backpack.translate(glm::vec3(-3.0f, 0.0f, 0.0f));
// gun.translate(glm::vec3(0.0f, 1.0f, 0.0f));