Torque3D Documentation / _generateds / scenePolyhedralZone.cpp

scenePolyhedralZone.cpp

Engine/source/scene/zones/scenePolyhedralZone.cpp

More...

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "platform/platform.h"
 25#include "scene/zones/scenePolyhedralZone.h"
 26
 27#include "scene/mixin/scenePolyhedralObject.impl.h"
 28
 29
 30//-----------------------------------------------------------------------------
 31
 32ScenePolyhedralZone::ScenePolyhedralZone( const PolyhedronType& polyhedron )
 33   : Parent( polyhedron )
 34{
 35}
 36
 37//-----------------------------------------------------------------------------
 38
 39bool ScenePolyhedralZone::onAdd()
 40{
 41   if( !Parent::onAdd() )
 42      return false;
 43
 44   // Precompute polyhedron/AABB intersection data, if not
 45   // a trivial box polyhedron.
 46
 47   if( !mIsBox )
 48   {
 49      _updateIntersector();
 50
 51      // Also need to update OBB.
 52      _updateOrientedWorldBox();
 53   }
 54      
 55   return true;
 56}
 57
 58//-----------------------------------------------------------------------------
 59
 60void ScenePolyhedralZone::setTransform( const MatrixF& mat )
 61{
 62   Parent::setTransform( mat );
 63
 64   // Recompute intersection data.
 65
 66   if( !mIsBox )
 67      _updateIntersector();
 68}
 69
 70//-----------------------------------------------------------------------------
 71
 72void ScenePolyhedralZone::_updateOrientedWorldBox()
 73{
 74   if( mIsBox )
 75      Parent::_updateOrientedWorldBox();
 76   else
 77       mOrientedWorldBox.set( getTransform(), mObjBox.getExtents() * getScale() );
 78}
 79
 80//-----------------------------------------------------------------------------
 81
 82bool ScenePolyhedralZone::getOverlappingZones( const Box3F& aabb, U32* outZones, U32& outNumZones )
 83{
 84   // If a trivial box, let parent handle this.
 85
 86   if( mIsBox )
 87      return Parent::getOverlappingZones( aabb, outZones, outNumZones );
 88
 89   // Otherwise, use the intersector.
 90
 91   OverlapTestResult overlap = mIntersector.test( aabb );
 92   
 93   if( overlap == GeometryOutside )
 94   {
 95      outNumZones = 0;
 96      return true;
 97   }
 98
 99   outZones[ 0 ] = getZoneRangeStart();
100   outNumZones = 1;
101
102   return ( overlap != GeometryInside );
103}
104