Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AxisAlignedBox.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010, The Cinder Project: http://libcinder.org
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
6  the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and
9  the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
11  the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
15  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
17  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20  POSSIBILITY OF SUCH DAMAGE.
21 */
22 
23 #pragma once
24 
25 #include "cinder/Matrix.h"
26 #include "cinder/Ray.h"
27 #include "cinder/Vector.h"
28 
29 namespace cinder {
30 
32  public:
34  AxisAlignedBox3f( const Vec3f &aMin, const Vec3f &aMax );
35 
36  bool intersects( const Ray &ray );
37  int intersect( const Ray &ray, float intersections[2] );
38 
39  Vec3f getCenter() const { return ( mExtents[1] + mExtents[0] ) * 0.5f; }
40  Vec3f getSize() const { return mExtents[1] - mExtents[0]; }
41 
43  void include( const AxisAlignedBox3f &box );
44 
45  const Vec3f& getMin() const { return mExtents[0]; }
46  const Vec3f& getMax() const { return mExtents[1]; }
47 
49  Vec3f getNegative( const Vec3f &normal ) const;
50  Vec3f getPositive( const Vec3f &normal ) const;
51 
54 
55  static bool calcTriangleIntersection( const Ray &ray, const Vec3f &vert0, const Vec3f &vert1, const Vec3f &vert2, float *result );
56 
57  protected:
60 };
61 
62 } // namespace cinder
Vec3f mVerts[8]
Definition: AxisAlignedBox.h:59
void include(const AxisAlignedBox3f &box)
Expands the box so that it contains box.
Definition: AxisAlignedBox.cpp:72
Definition: Ray.h:29
static bool calcTriangleIntersection(const Ray &ray, const Vec3f &vert0, const Vec3f &vert1, const Vec3f &vert2, float *result)
void normal(float x, float y, float z)
Sets the current normal.
Definition: dx.cpp:848
AxisAlignedBox3f transformed(const Matrix44f &transform) const
converts axis-aligned box to another coordinate space
Definition: AxisAlignedBox.cpp:181
AxisAlignedBox3f()
Definition: AxisAlignedBox.h:33
Vec3f getCenter() const
Definition: AxisAlignedBox.h:39
const Vec3f & getMin() const
Definition: AxisAlignedBox.h:45
Vec3f getSize() const
Definition: AxisAlignedBox.h:40
GLuint GLenum GLenum transform
Definition: GLee.h:10032
Vec3f getPositive(const Vec3f &normal) const
Definition: AxisAlignedBox.cpp:147
Vec3f mExtents[2]
Definition: AxisAlignedBox.h:58
int intersect(const Ray &ray, float intersections[2])
Definition: AxisAlignedBox.cpp:97
bool intersects(const Ray &ray)
Definition: AxisAlignedBox.cpp:46
Definition: AxisAlignedBox.h:31
Vec3f getNegative(const Vec3f &normal) const
for use in frustum culling
Definition: AxisAlignedBox.cpp:164
const Vec3f & getMax() const
Definition: AxisAlignedBox.h:46