2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-04-18 19:51:05 +02:00
|
|
|
/*
|
|
|
|
* CFrustum is a collection of planes which define a viewing space.
|
2007-05-07 18:33:24 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
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
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "maths/Plane.h"
|
2004-05-29 22:56:24 +02:00
|
|
|
|
|
|
|
//10 planes should be enough
|
|
|
|
#define MAX_NUM_FRUSTUM_PLANES (10)
|
|
|
|
|
2005-09-30 02:59:42 +02:00
|
|
|
class CBound;
|
2004-05-29 22:56:24 +02:00
|
|
|
|
|
|
|
class CFrustum
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CFrustum ();
|
|
|
|
~CFrustum ();
|
|
|
|
|
|
|
|
//Set the number of planes to use for
|
2006-03-26 23:58:48 +02:00
|
|
|
//calculations. This is clipped to
|
2004-05-29 22:56:24 +02:00
|
|
|
//[0,MAX_NUM_FRUSTUM_PLANES]
|
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 20:48:32 +02:00
|
|
|
void SetNumPlanes (size_t num);
|
2004-05-29 22:56:24 +02:00
|
|
|
|
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 20:48:32 +02:00
|
|
|
size_t GetNumPlanes() const { return m_NumPlanes; }
|
2006-03-26 23:58:48 +02:00
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
//The following methods return true if the shape is
|
|
|
|
//partially or completely in front of the frustum planes
|
|
|
|
bool IsPointVisible (const CVector3D &point) const;
|
2006-08-25 08:04:33 +02:00
|
|
|
bool DoesSegmentIntersect(const CVector3D& start, const CVector3D &end);
|
2004-05-29 22:56:24 +02:00
|
|
|
bool IsSphereVisible (const CVector3D ¢er, float radius) const;
|
|
|
|
bool IsBoxVisible (const CVector3D &position,const CBound &bounds) const;
|
|
|
|
|
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 20:48:32 +02:00
|
|
|
CPlane& operator[](size_t idx) { return m_aPlanes[idx]; }
|
|
|
|
const CPlane& operator[](size_t idx) const { return m_aPlanes[idx]; }
|
2006-03-26 23:58:48 +02:00
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
public:
|
|
|
|
//make the planes public for ease of use
|
|
|
|
CPlane m_aPlanes[MAX_NUM_FRUSTUM_PLANES];
|
|
|
|
|
|
|
|
private:
|
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 20:48:32 +02:00
|
|
|
size_t m_NumPlanes;
|
2004-05-29 22:56:24 +02:00
|
|
|
};
|
2006-03-26 23:58:48 +02:00
|
|
|
|
2004-05-29 22:56:24 +02:00
|
|
|
#endif
|