projection = perspective(yFov, xyRatio, zNear, zFar);
}
-Camera::FC_stat Camera::frustum_sphere(vec3 _center, float _radius)
+Camera::FC_stat Camera::frustum_sphere(vec3 _center, float _radius) const
{
+
+ FC_stat result = FC_INSIDE;
+
vec3 v(_center - cCenter);
vec3 pVCam(dot(v,cRight), dot(v,cUpVector), dot(v,cFront));
- if (_radius != 0) {
+ float h2 = pVCam.z * tan(yFov/2);
+ float w2 = h2 * xyRatio;
+ //float d = _radius * cos
+
+ if (_radius == 0) {
if (pVCam.z > zFar || pVCam.z < zNear)
return FC_OUTSIDE;
+
+ if (pVCam.y > h2 || pVCam.y < -h2)
+ return FC_OUTSIDE;
+
+ if (pVCam.x > w2 || pVCam.x < -w2)
+ return FC_OUTSIDE;
}
else
{
return FC_OUTSIDE;
if (pVCam.z > zFar - _radius || pVCam.z < zNear + _radius)
- return FC_INTERSECT;
+ result = FC_INTERSECT;
}
- return FC_INSIDE;
+ return result;
}
void Camera::updateVectors()
for (auto i = SceneObjects.cbegin(); i != SceneObjects.cend(); ++i)
{
- (*i)->draw(_target);
+ auto result = camera.frustum_sphere((*i)->getPosition());
+ if (result == camera.FC_OUTSIDE)
+ continue;
+ (*i)->draw(_target);
}
}