therealcain

12-04-2017, 06:01 AM

Hello, I'm trying to create a function that check if my camera is touching one of the cubes ( array ).

I thought about doing distance between MVP / View Matrix and Model and if it's equal to "0 + scale" / "0 - scale" it's overlapping.

but somehow it doesn't work...

Camera Update Source:

void Camera::Update(glm::vec3 const& Cube_scale,

glm::vec3 const& Cube_position)

{

Camera::computeMatricesFromInputs();

glm::mat4 Model = glm::mat4();

Model = glm::scale(Model, Cube_scale);

Model = glm::translate(Model, Cube_position);

glm::mat4 mvp = ProjectionMatrix * ViewMatrix * Model;

glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &mvp[0][0]);

// Overlap Detection - will moved to function

float dist = Distance3D(Model[3][0], mvp[3][0], Model[3][1], mvp[3][1], Model[3][2], mvp[3][2]);

std::cout << dist << std::endl;

}

but the values aren't correct.

by the way, I've seen something about "extracting" translation from matrices, so i guess i need to do something with that, but not sure how.

can anyone direct me to the correct path ? or give me an example ? ( it would be great ).

I thought about doing distance between MVP / View Matrix and Model and if it's equal to "0 + scale" / "0 - scale" it's overlapping.

but somehow it doesn't work...

Camera Update Source:

void Camera::Update(glm::vec3 const& Cube_scale,

glm::vec3 const& Cube_position)

{

Camera::computeMatricesFromInputs();

glm::mat4 Model = glm::mat4();

Model = glm::scale(Model, Cube_scale);

Model = glm::translate(Model, Cube_position);

glm::mat4 mvp = ProjectionMatrix * ViewMatrix * Model;

glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &mvp[0][0]);

// Overlap Detection - will moved to function

float dist = Distance3D(Model[3][0], mvp[3][0], Model[3][1], mvp[3][1], Model[3][2], mvp[3][2]);

std::cout << dist << std::endl;

}

but the values aren't correct.

by the way, I've seen something about "extracting" translation from matrices, so i guess i need to do something with that, but not sure how.

can anyone direct me to the correct path ? or give me an example ? ( it would be great ).