Hey all,
I have been working on creating an AABB class that can recompute the AABB of an object with the original AABB points when the model is first loaded in. I have been using the book "Real Time Collision Detection to try and create this function but I'm running into an error.
When rotating the my object I first use Euler angles which I then turn into a quaternion which from then I use the quaternion to create a 4x4 matrix for my Model matrix and I turn it into a 3x3 matrix to recompute the Min/Max. If I only change one element of rotation (say I just change the pitch to 90 to my model is facing up) then the new value are correct but as soon as I change two elements of the Euler angles (say pitch 90 and yaw 90) then values become incorrect. (I should note that though debugging I have noticed that the values become worst when both pitch and yaw are around 90 though the values still don't seem accurate if say pitch was 90 and yaw is 45.)
Below I will post the code for the player changing the Euler angles, the taking of the Euler angles into a quad and the function that does the recomputing of the min/max. (note the Euler is in radians )
code for the changing of the angle
if(turnkeys[0] == true && rotation.x < glm::radians(78.0f) || rotation.x > glm::radians(270.0f) && turnkeys[0] == true)
{
rotation.x += 1.0f * deltaTs; //change the pitch
}
else if(turnkeys[1] == true && !(rotation.x < glm::radians(280.0f) && (rotation.x > glm::radians(90.0f))))
{
rotation.x -= 1.0f * deltaTs;
}
if(turnkeys[2] == true)
{
rotation.y += 1.0f * deltaTs;; //change the roll
}
else if(turnkeys[3] == true)
{
rotation.y -= 1.0f * deltaTs;
}
how I change the Euler angles into a quaternion (glm)
myquat = glm::quat(rotation);
and lastly the code that i use to recompute the min/max (with help from real time collision detection)
glm::mat3 rotationmatrix = glm::toMat3(rotation);
for(int i = 0; i < 3; i++)
{
currentmin[i] = 0.0f;
currentmax[i] = 0.0f;
for(int j = 0; j < 3; j++)
{
float e = rotationmatrix[i][j] * orimin[j];
float f = rotationmatrix[i][j] * origmax[j];
if(e < f)
{
currentmin[i] += e;
currentmax[i] += f;
}
else
{
currentmin[i] += f;
currentmax[i] += e;
}
}
}
Any help you can provide will be greatly appropriated and any additional information on the maths side will be greatly welcomed.
Thanks for your guys time and help in advance
PS: sorry if it would have been better if i posted this in the open gl part i was not sure which place would be better considering its both maths based and with open gl functions