Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Camera and Cube Overlapping

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Newbie
    Join Date
    Dec 2017

    Camera and Cube Overlapping

    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:
    Code :
    void Camera::Update(glm::vec3 const& Cube_scale,
    					glm::vec3 const& Cube_position)
    	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 ).
    Last edited by therealcain; 12-04-2017 at 07:42 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts