22 #include "precompiled.h"
43 float& tmin,
float& tmax)
const
52 tnear=(float) -FLT_MAX;
56 t1=(
m_Data[0][0]-origin[0])/dir[0];
57 t2=(
m_Data[1][0]-origin[0])/dir[0];
71 if (dir[1]==0 && (origin[1]<
m_Data[0][1] || origin[1]>
m_Data[1][1]))
74 t1=(
m_Data[0][1]-origin[1])/dir[1];
75 t2=(
m_Data[1][1]-origin[1])/dir[1];
89 if (tnear>tfar || tfar<0)
93 if (dir[2]==0 && (origin[2]<
m_Data[0][2] || origin[2]>
m_Data[1][2]))
96 t1=(
m_Data[0][2]-origin[2])/dir[2];
97 t2=(
m_Data[1][2]-origin[2])/dir[2];
111 if (tnear>tfar || tfar<0)
145 for (
int i=0;i<3;++i) {
147 result[0][i]=result[1][i]=m(i,3);
151 for(
int j=0;j<3;j++) {
152 float a=m(i,j)*
m_Data[0][j];
153 float b=m(i,j)*
m_Data[1][j];
180 (pMax.
X - pMin.
X) / 2.f * u.
Length(),
181 (pMax.
Y - pMin.
Y) / 2.f * v.
Length(),
182 (pMax.
Z - pMin.
Z) / 2.f * w.
Length()
226 std::vector<float> data;
228 #define ADD_FACE(x, y, z) \
229 ADD_PT(0, 0, x, y, z); ADD_PT(1, 0, x, y, z); ADD_PT(1, 1, x, y, z); \
230 ADD_PT(1, 1, x, y, z); ADD_PT(0, 1, x, y, z); ADD_PT(0, 0, x, y, z);
231 #define ADD_PT(u_, v_, x, y, z) \
232 STMT(int u = u_; int v = v_; \
235 data.push_back(m_Data[x].X); \
236 data.push_back(m_Data[y].Y); \
237 data.push_back(m_Data[z].Z); \
249 shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*
sizeof(
float), &data[0]);
250 shader->VertexPointer(3, GL_FLOAT, 5*
sizeof(
float), &data[2]);
252 shader->AssertPointersBound();
253 glDrawArrays(GL_TRIANGLES, 0, 6*6);
258 std::vector<float> data;
260 #define ADD_FACE(x, y, z) \
261 ADD_PT(0, 0, x, y, z); ADD_PT(1, 0, x, y, z); \
262 ADD_PT(1, 0, x, y, z); ADD_PT(1, 1, x, y, z); \
263 ADD_PT(1, 1, x, y, z); ADD_PT(0, 1, x, y, z); \
264 ADD_PT(0, 1, x, y, z); ADD_PT(0, 0, x, y, z);
265 #define ADD_PT(u_, v_, x, y, z) \
266 STMT(int u = u_; int v = v_; \
269 data.push_back(m_Data[x].X); \
270 data.push_back(m_Data[y].Y); \
271 data.push_back(m_Data[z].Z); \
283 shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*
sizeof(
float), &data[0]);
284 shader->VertexPointer(3, GL_FLOAT, 5*
sizeof(
float), &data[2]);
286 shader->AssertPointersBound();
287 glDrawArrays(GL_LINES, 0, 6*8);
void Transform(const CMatrix3D &m, CBoundingBoxAligned &result) const
Transforms these bounds according to the specified transformation matrix m, and writes the axis-align...
void RenderOutline(CShaderProgramPtr &shader) const
Render: Render the outline of the bound object as lines.
void Intersect(const CFrustum &frustum, CBrush &result) const
Intersect: Intersect the brush with the given frustum.
static const CBoundingBoxAligned EMPTY
CVector3D Transform(const CVector3D &vector) const
#define ADD_FACE(x, y, z)
CVector3D m_Center
Centroid location of the box.
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Class CBrush: Represents a convex object, supports some CSG operations.
CVector3D m_Basis[3]
Basis vectors (u,v,w) of the sides.
void IntersectFrustumConservative(const CFrustum &frustum)
IntersectFrustumConservative: Approximate the intersection of this bounds object with the given frust...
CVector3D m_HalfSizes
Half the sizes of the box in each dimension (u,v,w).
bool RayIntersect(const CVector3D &origin, const CVector3D &dir, float &tmin, float &tmax) const
Check if a given ray intersects this AABB.
void Bounds(CBoundingBoxAligned &result) const
Bounds: Calculate the axis-aligned bounding box for this brush.
void Expand(float amount)
Expand the bounding box by the given amount in every direction.
void Render(CShaderProgramPtr &shader) const
Render: Render the surfaces of the bound object as triangles.
shared_ptr< CShaderProgram > CShaderProgramPtr