OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
C/OgreArrayAabb.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __C_ArrayAabb_H__
29 #define __C_ArrayAabb_H__
30 
31 #ifndef __ArrayAabb_H__
32  #error "Don't include this file directly. include Math/Array/OgreArrayAabb.h"
33 #endif
34 
35 #include "Math/Array/OgreMathlib.h"
38 #include "Math/Simple/OgreAabb.h"
39 
40 namespace Ogre
41 {
70  {
71  public:
74 
75  ArrayAabb( const ArrayVector3 &center, const ArrayVector3 &halfSize ) :
76  mCenter( center ), mHalfSize( halfSize )
77  {
78  }
79 
80  void getAsAabb( Aabb &out, size_t index ) const
81  {
82  //Be careful of not writing to these regions or else strict aliasing rule gets broken!!!
83  const Real *aliasedReal = reinterpret_cast<const Real*>( &mCenter );
84  out.mCenter.x = aliasedReal[ARRAY_PACKED_REALS * 0 + index]; //X
85  out.mCenter.y = aliasedReal[ARRAY_PACKED_REALS * 1 + index]; //Y
86  out.mCenter.z = aliasedReal[ARRAY_PACKED_REALS * 2 + index]; //Z
87  out.mHalfSize.x = aliasedReal[ARRAY_PACKED_REALS * 3 + index]; //X
88  out.mHalfSize.y = aliasedReal[ARRAY_PACKED_REALS * 4 + index]; //Y
89  out.mHalfSize.z = aliasedReal[ARRAY_PACKED_REALS * 5 + index]; //Z
90  }
91 
94  Aabb getAsAabb( size_t index ) const
95  {
96  Aabb retVal;
97  getAsAabb( retVal, index );
98  return retVal;
99  }
100 
101  void setFromAabb( const Aabb &aabb, size_t index )
102  {
103  Real *aliasedReal = reinterpret_cast<Real*>( &mCenter );
104  aliasedReal[ARRAY_PACKED_REALS * 0 + index] = aabb.mCenter.x; //X
105  aliasedReal[ARRAY_PACKED_REALS * 1 + index] = aabb.mCenter.y; //Y
106  aliasedReal[ARRAY_PACKED_REALS * 2 + index] = aabb.mCenter.z; //Z
107  aliasedReal[ARRAY_PACKED_REALS * 3 + index] = aabb.mHalfSize.x; //X
108  aliasedReal[ARRAY_PACKED_REALS * 4 + index] = aabb.mHalfSize.y; //Y
109  aliasedReal[ARRAY_PACKED_REALS * 5 + index] = aabb.mHalfSize.z; //Z
110  }
111 
112  void setAll( const Aabb &aabb )
113  {
114  mCenter.setAll( aabb.mCenter );
115  mHalfSize.setAll( aabb.mHalfSize );
116  }
117 
119  inline ArrayVector3 getMinimum() const;
120 
122  inline ArrayVector3 getMaximum() const;
123 
127  inline void merge( const ArrayAabb& rhs );
128 
130  inline void merge( const ArrayVector3& points );
131 
143  inline void transformAffine( const ArrayMatrix4 &matrix );
144 
146  inline ArrayMaskR intersects( const ArrayAabb& b2 ) const;
147 
149  inline ArrayAabb intersection( const ArrayAabb& b2 ) const;
150 
152  inline ArrayReal volume(void) const;
153 
155  inline ArrayMaskR contains( const ArrayAabb &other ) const;
156 
158  inline ArrayMaskR contains( const ArrayVector3 &v ) const;
159 
161  inline ArrayReal distance( const ArrayVector3 &v ) const;
162 
163  static const ArrayAabb BOX_INFINITE;
164 
165  //Contains all zeroes. Used for inactive objects to avoid causing unnecessary NaNs
166  static const ArrayAabb BOX_ZERO;
167  };
171 }
172 
173 #include "OgreArrayAabb.inl"
174 
175 #endif
Aabb getAsAabb(size_t index) const
Prefer using.
bool ArrayMaskR
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:255
Ogre::Vector3 mHalfSize
Definition: C/OgreAabb.h:81
Cache-friendly container of 4x4 matrices represented as a SoA array.
static const ArrayAabb BOX_INFINITE
Real ArrayReal
void setFromAabb(const Aabb &aabb, size_t index)
ArrayVector3 mCenter
void getAsAabb(Aabb &out, size_t index) const
void setAll(const Aabb &aabb)
Cache-friendly array of 3-dimensional represented as a SoA array.
static const ArrayAabb BOX_ZERO
AoS (array of structures) version of ArrayAabb.
Definition: C/OgreAabb.h:78
Ogre::Vector3 mCenter
Definition: C/OgreAabb.h:80
#define ARRAY_PACKED_REALS
ArrayAabb(const ArrayVector3 &center, const ArrayVector3 &halfSize)
Cache-friendly array of Aabb represented as a SoA array.
ArrayVector3 mHalfSize