1
0
forked from 0ad/0ad
0ad/source/graphics/Frustum.h
janwas c0ed950657 had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).

it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.

after several hours, the code now requires fewer casts and less
guesswork.

other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.

This was SVN commit r5942.
2008-05-11 18:48:32 +00:00

58 lines
1.5 KiB
C++

/**
* =========================================================================
* File : Frustum.cpp
* Project : 0 A.D.
* Description : CFrustum is a collection of planes which define
* a viewing space.
* =========================================================================
*/
/*
Usually associated with the camera, there are 6 planes which define the
view pyramid. But we allow more planes per frustum which may be used for
portal rendering, where a portal may have 3 or more edges.
*/
#ifndef INCLUDED_FRUSTUM
#define INCLUDED_FRUSTUM
#include "maths/Plane.h"
//10 planes should be enough
#define MAX_NUM_FRUSTUM_PLANES (10)
class CBound;
class CFrustum
{
public:
CFrustum ();
~CFrustum ();
//Set the number of planes to use for
//calculations. This is clipped to
//[0,MAX_NUM_FRUSTUM_PLANES]
void SetNumPlanes (size_t num);
size_t GetNumPlanes() const { return m_NumPlanes; }
//The following methods return true if the shape is
//partially or completely in front of the frustum planes
bool IsPointVisible (const CVector3D &point) const;
bool DoesSegmentIntersect(const CVector3D& start, const CVector3D &end);
bool IsSphereVisible (const CVector3D &center, float radius) const;
bool IsBoxVisible (const CVector3D &position,const CBound &bounds) const;
CPlane& operator[](size_t idx) { return m_aPlanes[idx]; }
const CPlane& operator[](size_t idx) const { return m_aPlanes[idx]; }
public:
//make the planes public for ease of use
CPlane m_aPlanes[MAX_NUM_FRUSTUM_PLANES];
private:
size_t m_NumPlanes;
};
#endif