All this culling must be done in application side.
From Demo:
m_objectsInFrustum.clear();
for (int i = 0; i < 100; ++i)
{
if (m_GUICheckRotate->m_isChecked)
{
float M = float(i + 1) * 0.01;
m_objects[i]->RotateX(slMath::DegToRad((30.f * M) * (*m_app->m_dt)));
m_objects[i]->RotateY(slMath::DegToRad((25.f * M) * (*m_app->m_dt)));
m_objects[i]->RotateZ(slMath::DegToRad((21.f * M) * (*m_app->m_dt)));
m_objects[i]->RecalculateWorldMatrix();
m_objects[i]->UpdateBV();
}
if (m_GUIRadioBVMethodSphere->m_isChecked)
{
if(m_camera->m_frust.SphereInFrustum(m_objects[i]->GetBVRadius(), m_objects[i]->GetPosition()))
m_objectsInFrustum.push_back(m_objects[i]);
}
else
{
if (m_camera->m_frust.AABBInFrustum(m_objects[i]->GetAabbTransformed()))
m_objectsInFrustum.push_back(m_objects[i]);
}
}
m_objectsInFrustum is array slArray. After this work with objects in m_objectsInFrustum
Object rotation
I not implemented object rotation. Because I don't know how to do it in right way.
But I done something, and this is best thing that I've ever done before.
Add this things into Object class
// only rotation matrix
slMat4 m_matrixRotation;
// also add scale
slVec3 m_scale = slVec3(1.0);
// Order for rotation will be X Y Z
slQuaternion m_qX;
slQuaternion m_qY;
slQuaternion m_qZ;
slQuaternion m_qOrientation;
Update RecalculateWorldMatrix.
virtual void RecalculateWorldMatrix()
{
m_matrixWorld.identity();
m_matrixWorld.m_data[0].x = m_scale.x;
m_matrixWorld.m_data[1].y = m_scale.y;
m_matrixWorld.m_data[2].z = m_scale.z;
// I don't know how to do it fast and better
slQuaternion Q;
Q = Q * m_qX;
Q = Q * m_qY;
Q = Q * m_qZ;
if(m_axisAlignedRotation)
m_qOrientation = m_qOrientation * Q;
else
m_qOrientation = Q * m_qOrientation; // like a airplane
m_qX.identity();
m_qY.identity();
m_qZ.identity();
m_matrixRotation.set_rotation(m_qOrientation);
m_matrixWorld = m_matrixWorld * m_matrixRotation;
m_matrixWorld.m_data[3].x = m_position.x;
m_matrixWorld.m_data[3].y = m_position.y;
m_matrixWorld.m_data[3].z = m_position.z;
slSceneObject* parent = dynamic_cast(m_parent);
if (parent)
m_matrixWorld = m_matrixWorld * parent->m_matrixWorld;
}
// I don't know how to call it.
// if false then object will rotates like airplane
bool m_axisAlignedRotation = false;
And now I can rotate object like airplane, or not like, I call it m_axisAlignedRotation.
I don't know how to store angles, if you try to save angles, and then
set rotation by this angles, you will(or can) get wrong result.
Better to save angles by yourself.
slSceneObject is just basic object for more complex game object.