From 23311c4ef582826dea218fab5ce2c32e4514d57d Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Thu, 19 May 2016 13:46:34 +0200 Subject: [PATCH] frustum Fixed --- Weave/GLM.h | 4 ++++ Weave/Scene/Camera.cpp | 14 ++++++-------- Weave/Scene/Scene.cpp | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Weave/GLM.h b/Weave/GLM.h index 9b82470..cefa069 100644 --- a/Weave/GLM.h +++ b/Weave/GLM.h @@ -11,6 +11,10 @@ using glm::vec3; using glm::mat4; using glm::vec4; +#ifdef GLM_FORCE_RADIANS ; +hello +#endif // GLM_FORCE_RADIANS ; + using glm::translate; using glm::rotate; //using glm::scale; diff --git a/Weave/Scene/Camera.cpp b/Weave/Scene/Camera.cpp index da5dc8e..e091d77 100644 --- a/Weave/Scene/Camera.cpp +++ b/Weave/Scene/Camera.cpp @@ -16,7 +16,7 @@ Camera::Camera(float _yFov, float _xyRatio, float _zNear, float _zFar) : xyRatio(_xyRatio), zNear(_zNear), zFar(_zFar), - projection(perspective(yFov, xyRatio, zNear, zFar)), + projection(perspective(yFov* (float)M_D2R, xyRatio, zNear, zFar)), pitch(0.f), yaw(0.f), dist(2.f), //DIST @@ -98,7 +98,7 @@ void Camera::updateProjection(float _xyRatio) xyRatio = _xyRatio; - projection = perspective(yFov, xyRatio, zNear, zFar); + projection = perspective(yFov * (float)M_D2R, xyRatio, zNear, zFar); } void Camera::updateProjection(float _yFov, float _xyRatio, float _zNear, float _zFar) @@ -111,23 +111,21 @@ void Camera::updateProjection(float _yFov, float _xyRatio, float _zNear, float _ zNear = _zNear; zFar = _zFar; - tan_alphaY = tan(yFov / 2.f); - Icos_alphaX = 1.f / cos(yFov / 2.f*xyRatio); - Icos_alphaY = 1.f / cos(yFov / 2.f); + tan_alphaY = tan(yFov * (float)M_D2R * .5f); + Icos_alphaX = 1.f / cos(atan(tan_alphaY*xyRatio)); + Icos_alphaY = 1.f / cos(yFov * (float)M_D2R * .5f); - projection = perspective(yFov, xyRatio, zNear, zFar); + projection = perspective(yFov * (float)M_D2R, xyRatio, zNear, zFar); } Camera::FC_stat Camera::frustum_sphere(vec3 _center, float _radius) const { FC_stat result = FC_INSIDE; - //return result; vec3 v(_center - cCenter); vec3 pVCam(dot(v,cRight), dot(v,cUpVector), dot(v,cFront)); float h2 = pVCam.z * tan_alphaY; float w2 = h2 * xyRatio; - //float d = _radius * cos if (_radius == 0) { if (pVCam.z > zFar || pVCam.z < zNear) diff --git a/Weave/Scene/Scene.cpp b/Weave/Scene/Scene.cpp index 68cdca4..4876350 100644 --- a/Weave/Scene/Scene.cpp +++ b/Weave/Scene/Scene.cpp @@ -340,7 +340,7 @@ void Scene::drawSceneObjects(drawTarget _target) const for (auto i = SceneObjects.cbegin(); i != SceneObjects.cend(); ++i) { - auto result = camera.frustum_sphere((*i)->getPosition() + (*i)->gModel()->getBox().center());// , (*i)->gModel()->getBox().radius()); + auto result = camera.frustum_sphere((*i)->getPosition() +(*i)->gModel()->getBox().center() , (*i)->gModel()->getBox().radius()); if (result == camera.FC_OUTSIDE) continue; (*i)->draw(_target); -- 2.47.3