|
|
@@ -67,22 +67,22 @@ void Camera::calcLSpaceFrustumPlanes()
|
|
|
{
|
|
|
float c, s; // cos & sine
|
|
|
|
|
|
- sinCos(PI+fovX/2, s, c);
|
|
|
+ sinCos(PI + fovX / 2, s, c);
|
|
|
// right
|
|
|
- lspaceFrustumPlanes[FP_RIGHT] = plane_t(Vec3(c, 0.0, s), 0.0);
|
|
|
+ lspaceFrustumPlanes[FP_RIGHT] = Plane(Vec3(c, 0.0, s), 0.0);
|
|
|
// left
|
|
|
- lspaceFrustumPlanes[FP_LEFT] = plane_t(Vec3(-c, 0.0, s), 0.0);
|
|
|
+ lspaceFrustumPlanes[FP_LEFT] = Plane(Vec3(-c, 0.0, s), 0.0);
|
|
|
|
|
|
- sinCos((3*PI-fovY)*0.5, s, c);
|
|
|
+ sinCos((3 * PI - fovY) * 0.5, s, c);
|
|
|
// top
|
|
|
- lspaceFrustumPlanes[FP_TOP] = plane_t(Vec3(0.0, s, c), 0.0);
|
|
|
+ lspaceFrustumPlanes[FP_TOP] = Plane(Vec3(0.0, s, c), 0.0);
|
|
|
// bottom
|
|
|
- lspaceFrustumPlanes[FP_BOTTOM] = plane_t(Vec3(0.0, -s, c), 0.0);
|
|
|
+ lspaceFrustumPlanes[FP_BOTTOM] = Plane(Vec3(0.0, -s, c), 0.0);
|
|
|
|
|
|
// near
|
|
|
- lspaceFrustumPlanes[FP_NEAR] = plane_t(Vec3(0.0, 0.0, -1.0), zNear);
|
|
|
+ lspaceFrustumPlanes[FP_NEAR] = Plane(Vec3(0.0, 0.0, -1.0), zNear);
|
|
|
// far
|
|
|
- lspaceFrustumPlanes[FP_FAR] = plane_t(Vec3(0.0, 0.0, 1.0), -zFar);
|
|
|
+ lspaceFrustumPlanes[FP_FAR] = Plane(Vec3(0.0, 0.0, 1.0), -zFar);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -93,9 +93,9 @@ void Camera::updateWSpaceFrustumPlanes()
|
|
|
{
|
|
|
for(uint i=0; i<6; i++)
|
|
|
{
|
|
|
- wspaceFrustumPlanes[i] = lspaceFrustumPlanes[i].Transformed(getWorldTransform().origin,
|
|
|
- getWorldTransform().rotation,
|
|
|
- getWorldTransform().scale);
|
|
|
+ wspaceFrustumPlanes[i] = lspaceFrustumPlanes[i].getTransformed(getWorldTransform().origin,
|
|
|
+ getWorldTransform().rotation,
|
|
|
+ getWorldTransform().scale);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -104,11 +104,15 @@ void Camera::updateWSpaceFrustumPlanes()
|
|
|
// insideFrustum =
|
|
|
//======================================================================================================================
|
|
|
/// Check if the volume is inside the frustum cliping planes
|
|
|
-bool Camera::insideFrustum(const bvolume_t& bvol) const
|
|
|
+bool Camera::insideFrustum(const CollisionShape& bvol) const
|
|
|
{
|
|
|
for(uint i=0; i<6; i++)
|
|
|
- if(bvol.PlaneTest(wspaceFrustumPlanes[i]) < 0.0)
|
|
|
+ {
|
|
|
+ if(bvol.testPlane(wspaceFrustumPlanes[i]) < 0.0)
|
|
|
+ {
|
|
|
return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
@@ -119,12 +123,12 @@ bool Camera::insideFrustum(const bvolume_t& bvol) const
|
|
|
//======================================================================================================================
|
|
|
bool Camera::insideFrustum(const Camera& cam) const
|
|
|
{
|
|
|
- //** get five points. These points are the tips of the given camera **
|
|
|
+ // get five points. These points are the tips of the given camera
|
|
|
Vec3 points[5];
|
|
|
|
|
|
// get 3 sample floats
|
|
|
- float x = cam.getZFar() / tan((PI-cam.getFovX())/2);
|
|
|
- float y = tan(cam.getFovY()/2) * cam.getZFar();
|
|
|
+ float x = cam.getZFar() / tan((PI - cam.getFovX())/2);
|
|
|
+ float y = tan(cam.getFovY() / 2) * cam.getZFar();
|
|
|
float z = -cam.getZFar();
|
|
|
|
|
|
// the actual points in local space
|
|
|
@@ -136,20 +140,26 @@ bool Camera::insideFrustum(const Camera& cam) const
|
|
|
|
|
|
// transform them to the given camera's world space (exept the eye)
|
|
|
for(uint i=0; i<4; i++)
|
|
|
+ {
|
|
|
points[i].transform(getWorldTransform());
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- //** the collision code **
|
|
|
+ // the collision code
|
|
|
for(uint i=0; i<6; i++) // for the 6 planes
|
|
|
{
|
|
|
int failed = 0;
|
|
|
|
|
|
for(uint j=0; j<5; j++) // for the 5 points
|
|
|
{
|
|
|
- if(wspaceFrustumPlanes[i].Test(points[j]) < 0.0)
|
|
|
+ if(wspaceFrustumPlanes[i].test(points[j]) < 0.0)
|
|
|
+ {
|
|
|
++failed;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(failed == 5)
|
|
|
+ {
|
|
|
+ return false; // if all points are behind the plane then the cam is not in frustum
|
|
|
}
|
|
|
- if(failed == 5) return false; // if all points are behind the plane then the cam is not in frustum
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
@@ -161,9 +171,9 @@ bool Camera::insideFrustum(const Camera& cam) const
|
|
|
//======================================================================================================================
|
|
|
void Camera::calcProjectionMatrix()
|
|
|
{
|
|
|
- float f = 1.0/tan(fovY*0.5f); // f = cot(fovY/2)
|
|
|
+ float f = 1.0 / tan(fovY * 0.5); // f = cot(fovY/2)
|
|
|
|
|
|
- projectionMat(0, 0) = f*fovY/fovX; // = f/aspectRatio;
|
|
|
+ projectionMat(0, 0) = f * fovY / fovX; // = f/aspectRatio;
|
|
|
projectionMat(0, 1) = 0.0;
|
|
|
projectionMat(0, 2) = 0.0;
|
|
|
projectionMat(0, 3) = 0.0;
|
|
|
@@ -173,8 +183,8 @@ void Camera::calcProjectionMatrix()
|
|
|
projectionMat(1, 3) = 0.0;
|
|
|
projectionMat(2, 0) = 0.0;
|
|
|
projectionMat(2, 1) = 0.0;
|
|
|
- projectionMat(2, 2) = (zFar+zNear) / (zNear-zFar);
|
|
|
- projectionMat(2, 3) = (2.0f*zFar*zNear) / (zNear-zFar);
|
|
|
+ projectionMat(2, 2) = (zFar + zNear) / ( zNear - zFar);
|
|
|
+ projectionMat(2, 3) = (2.0f * zFar * zNear) / (zNear - zFar);
|
|
|
projectionMat(3, 0) = 0.0;
|
|
|
projectionMat(3, 1) = 0.0;
|
|
|
projectionMat(3, 2) = -1.0;
|
|
|
@@ -213,5 +223,3 @@ void Camera::updateTrf()
|
|
|
updateWSpaceFrustumPlanes();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|