mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-10 12:52:39 +01:00
ba7eb63941
rwengine + Make renderWorld() take a ViewCamera parameter. + add rotation and getView to ViewCamera + correct directions for vehicle and character movement. rwgame + Remove GenericState + Add State::getCamera() to control the ViewCamera used for rendering + Clean up state camera control + Remove now unused view parameters from main
68 lines
1.2 KiB
C++
68 lines
1.2 KiB
C++
#ifndef _VIEWFRUSTUM_HPP_
|
|
#define _VIEWFRUSTUM_HPP_
|
|
#include <glm/glm.hpp>
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
class ViewFrustum
|
|
{
|
|
public:
|
|
|
|
class ViewPlane
|
|
{
|
|
public:
|
|
glm::vec3 normal;
|
|
float distance;
|
|
};
|
|
|
|
float near;
|
|
float far;
|
|
float fov;
|
|
float aspectRatio;
|
|
|
|
ViewPlane planes[6];
|
|
|
|
ViewFrustum(float near, float far, float fov, float aspect)
|
|
: near(near), far(far), fov(fov), aspectRatio(aspect)
|
|
{
|
|
|
|
}
|
|
|
|
glm::mat4 projection()
|
|
{
|
|
return glm::perspective(fov / aspectRatio, aspectRatio, near, far);
|
|
}
|
|
|
|
void update(const glm::mat4& proj)
|
|
{
|
|
for(size_t i = 0; i < 6; ++i)
|
|
{
|
|
float sign = (i%2==0) ? 1.f : -1.f;
|
|
int r = i / 2;
|
|
planes[i].normal.x = proj[0][3] + proj[0][r] * sign;
|
|
planes[i].normal.y = proj[1][3] + proj[1][r] * sign;
|
|
planes[i].normal.z = proj[2][3] + proj[2][r] * sign;
|
|
planes[i].distance = proj[3][3] + proj[3][r] * sign;
|
|
|
|
auto l = glm::length(planes[i].normal);
|
|
planes[i].normal /= l;
|
|
planes[i].distance /= l;
|
|
}
|
|
}
|
|
|
|
bool intersects(glm::vec3 center, float radius)
|
|
{
|
|
float d;
|
|
bool result = true;
|
|
|
|
for(size_t i = 0; i < 6; ++i)
|
|
{
|
|
d = glm::dot(planes[i].normal, center) + planes[i].distance;
|
|
if( d < -radius ) result = false;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
};
|
|
|
|
#endif
|