/* * * * * * * * * * * * * Author's note * * * * * * * * * * * *\ * _ _ _ _ _ _ _ _ _ _ _ _ * * |_| |_| |_| |_| |_|_ _|_| |_| |_| _|_|_|_|_| * * |_|_ _ _|_| |_| |_| |_|_|_|_|_| |_| |_| |_|_ _ _ * * |_|_|_|_|_| |_| |_| |_| |_| |_| |_| |_| |_|_|_|_ * * |_| |_| |_|_ _ _|_| |_| |_| |_|_ _ _|_| _ _ _ _|_| * * |_| |_| |_|_|_| |_| |_| |_|_|_| |_|_|_|_| * * * * http://www.humus.name * * * * This file is a part of the work done by Humus. You are free to * * use the code in any way you like, modified, unmodified or copied * * into your own work. However, I expect you to respect these points: * * - If you use this file and its contents unmodified, or use a major * * part of this file, please credit the author and leave this note. * * - For use in anything commercial, please request my approval. * * - Share your work and ideas too as much as you can. * * * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ // I would like to thank Humus for giving away this code, it // is very generous and makes my life easier. // - Bill Whitacre #ifndef _FRUSTUM_H #define _FRUSTUM_H #include "vector.h" #define _FRUSTUM_LEFT 0 #define _FRUSTUM_RIGHT 1 #define _FRUSTUM_TOP 2 #define _FRUSTUM_BOTTOM 3 #define _FRUSTUM_FAR 4 #define _FRUSTUM_NEAR 5 // this one's mine struct Projection { Projection(){} Projection(float aspect,float yfov,float znear,float zfar) { this->aspect=aspect; this->yfov=yfov; this->znear=znear; this->zfar=zfar; } void ToMatrix(Matrix4x4 &mat); float aspect,yfov,znear,zfar; }; struct Plane { Plane(){} Plane(const float x, const float y, const float z, const float o) { normal = Vector3(x, y, z); float invLen = 1.0f / length(normal); normal *= invLen; offset = o * invLen; } float dist(const Vector3 &pos) const { return dot(normal, pos) + offset; } Vector3 normal; float offset; }; class Frustum { public: void LoadFrustum(const Matrix4x4 &mvp); bool PointInFrustum(const Vector3 &pos) const; bool SphereInFrustum(const Vector3 &pos, const float radius) const; bool CubeInFrustum(const float minX, const float maxX, const float minY, const float maxY, const float minZ, const float maxZ) const; const Plane &GetPlane(const int plane) const {return planes[plane];} protected: Plane planes[6]; }; #endif // _FRUSTUM_H_