void Camera::useView() const
{
- Shader::getShader(SH_ACTIVE)->setUniformLocation("uView", lookAt(cPosition - dist* cFront,cPosition, cUpVector));
+ Shader::getShader(SH_ACTIVE)->setUniformLocation("uView", lookAt(cCenter,cPosition, cUpVector));
}
void Camera::useProjection() const
return;
cPosition = _target;
+ cCenter = _target - dist* cFront;
}
void Camera::updateView_pitch(float _pitch)
projection = perspective(yFov, xyRatio, zNear, zFar);
}
-bool Camera::frustum_sphere(vec3 center, float radius)
+Camera::FC_stat Camera::frustum_sphere(vec3 _center, float _radius)
{
- return false;
+ vec3 v(_center - cCenter);
+ vec3 pVCam(dot(v,cRight), dot(v,cUpVector), dot(v,cFront));
+
+ if (_radius != 0) {
+ if (pVCam.z > zFar || pVCam.z < zNear)
+ return FC_OUTSIDE;
+ }
+ else
+ {
+ if (pVCam.z > zFar + _radius || pVCam.z < zNear - _radius)
+ return FC_OUTSIDE;
+
+ if (pVCam.z > zFar - _radius || pVCam.z < zNear + _radius)
+ return FC_INTERSECT;
+ }
+
+
+ return FC_INSIDE;
}
void Camera::updateVectors()
cFront.z = sin(yaw*(float)M_PI_2) * cos(pitch*(float)M_2_PI);
cFront = normalize(cFront);
-
cRight = normalize(cross(cFront, WORLD_UP));
cUpVector = normalize(cross(cRight, cFront));
+
+ cCenter = cPosition - dist* cFront;
}
\ No newline at end of file
vec3 getWorldDirection() { return normalize(vec3(cFront.x, 0.f, cFront.z)); }
vec3 getWorldRight() { return normalize(vec3(cRight.x, 0.f, cRight.z)); }
- bool frustum_sphere(vec3 center, float radius = 0.f);
+ enum FC_stat {
+ FC_OUTSIDE,
+ FC_INTERSECT,
+ FC_INSIDE
+ };
+ FC_stat frustum_sphere(vec3 center, float radius = 0.f);
protected:
mat4 projection = mat4(1.f);
/*View*/
- vec3 cPosition, cFront, cUpVector, cRight;
+ vec3 cPosition, cCenter, cFront, cUpVector, cRight;
float pitch, yaw;
float dist;