2012-04-06 00:29:01 +02:00
|
|
|
/* Copyright (C) 2012 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* 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
|
|
|
/*
|
|
|
|
* CBrush, a class representing a convex object
|
2006-03-26 23:58:48 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef maths_brush_h
|
|
|
|
#define maths_brush_h
|
|
|
|
|
|
|
|
#include "Vector3D.h"
|
|
|
|
|
2011-11-25 07:36:13 +01:00
|
|
|
class CBoundingBoxAligned;
|
2006-03-26 23:58:48 +02:00
|
|
|
class CFrustum;
|
|
|
|
class CPlane;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class CBrush: Represents a convex object, supports some CSG operations.
|
|
|
|
*/
|
|
|
|
class CBrush
|
|
|
|
{
|
2012-04-06 00:29:01 +02:00
|
|
|
friend class TestBrush;
|
|
|
|
|
2006-03-26 23:58:48 +02:00
|
|
|
public:
|
|
|
|
CBrush() { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CBrush: Construct a brush from a bounds object.
|
|
|
|
*
|
2011-11-25 07:36:13 +01:00
|
|
|
* @param bounds the CBoundingBoxAligned object to construct the brush from.
|
2006-03-26 23:58:48 +02:00
|
|
|
*/
|
2011-11-25 07:36:13 +01:00
|
|
|
CBrush(const CBoundingBoxAligned& bounds);
|
2006-03-26 23:58:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* IsEmpty: Returns whether the brush is empty.
|
|
|
|
*
|
|
|
|
* @return @c true if the brush is empty, @c false otherwise
|
|
|
|
*/
|
|
|
|
bool IsEmpty() const { return m_Vertices.size() == 0; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bounds: Calculate the axis-aligned bounding box for this brush.
|
|
|
|
*
|
|
|
|
* @param result the resulting bounding box is stored here
|
|
|
|
*/
|
2011-11-25 07:36:13 +01:00
|
|
|
void Bounds(CBoundingBoxAligned& result) const;
|
2006-03-26 23:58:48 +02:00
|
|
|
|
|
|
|
/**
|
2012-04-06 00:29:01 +02:00
|
|
|
* Slice: Cut the object along the given plane, resulting in a smaller (or even empty) brush representing
|
|
|
|
* the part of the object that lies in front of the plane (as defined by the positive direction of its
|
|
|
|
* normal vector).
|
2006-03-26 23:58:48 +02:00
|
|
|
*
|
|
|
|
* @param plane the slicing plane
|
|
|
|
* @param result the resulting brush is stored here
|
|
|
|
*/
|
|
|
|
void Slice(const CPlane& plane, CBrush& result) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Intersect: Intersect the brush with the given frustum.
|
|
|
|
*
|
|
|
|
* @param frustum the frustum to intersect with
|
|
|
|
* @param result the resulting brush is stored here
|
|
|
|
*/
|
|
|
|
void Intersect(const CFrustum& frustum, CBrush& result) const;
|
|
|
|
|
|
|
|
private:
|
2012-04-06 00:29:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a copy of the vertices in this brush. Intended for testing purposes; you should not need to use
|
|
|
|
* this method directly.
|
|
|
|
*/
|
|
|
|
std::vector<CVector3D> GetVertices() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes a vector of the faces in this brush to @p out. Each face is itself a vector, listing the vertex indices
|
|
|
|
* that make up the face, starting and ending with the same index. Intended for testing purposes; you should not
|
|
|
|
* need to use this method directly.
|
|
|
|
*/
|
|
|
|
void GetFaces(std::vector<std::vector<size_t> >& out) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const size_t NO_VERTEX = ~0u;
|
2006-03-26 23:58:48 +02:00
|
|
|
|
|
|
|
typedef std::vector<CVector3D> Vertices;
|
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
|
|
|
typedef std::vector<size_t> FaceIndices;
|
2006-03-26 23:58:48 +02:00
|
|
|
|
2012-04-06 00:29:01 +02:00
|
|
|
/// Collection of unique vertices that make up this shape.
|
2006-03-26 23:58:48 +02:00
|
|
|
Vertices m_Vertices;
|
2012-04-06 00:29:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Holds the face definitions of this brush. Each face is a sequence of indices into m_Vertices that starts and ends with
|
|
|
|
* the same vertex index, completing a loop through all the vertices that make up the face. This vector holds all the face
|
|
|
|
* sequences back-to-back, thus looking something like 'x---xy--------yz--z' in the general case.
|
|
|
|
*/
|
2006-03-26 23:58:48 +02:00
|
|
|
FaceIndices m_Faces;
|
|
|
|
|
|
|
|
struct Helper;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // maths_brush_h
|