PDA

View Full Version : Collision Detection using View Matrix of two objects.



MrCybin
12-07-2015, 04:17 AM
Hello,

Given two glViewMatrices for two different objects, is it possible to detect a collision or distance between their centers?

I am using OpenCV's solvepnp to get the OpenGL view matrix from the tvec and rvec with a calibrated camera. I now want to know if these two independantly tracked objects can be located relative to one another.

The viewMatrix created from the results of OpenCV's solvePnp method, and is transposed into the OpenGL co-ordinate system (shown below).



cv::Mat glViewMatrix1 = cv::Mat::zeros(4, 4, CV_64F);
cv::transpose(viewMatrix , glViewMatrix1);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixd(&glViewMatrix1.at<double>(0, 0));


Is it possible to get the distance between the center of two models using the viewMatrix?

The vertices of the hoop are a unit circle (z is 0, centered at (0,0,0)).

The vertices of the ball are a unit sphere (centered at (0,0,0)).

Regards,

Daniel

Raptor2277
12-07-2015, 03:42 PM
Is it possible to get the distance between the center of two models using the viewMatrix?

Daniel

Isn't the view matrix supposed to represent the camera position and orientation? Also the view matrix would be the same for both objects. I think you should be using the a model matrix.

In which case, the position of an object is the 4th column of the model matrix.

1 0 0 x
0 1 0 y
0 0 1 z
0 0 0 1