Torque3D Documentation / _generateds / containerQuery.cpp

containerQuery.cpp

Engine/source/T3D/containerQuery.cpp

More...

Public Functions

Detailed Description

Public Functions

findRouter(SceneObject * obj, void * key)

physicalZoneFind(SceneObject * obj, void * key)

waterFind(SceneObject * obj, void * key)

  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//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 25// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
 26// Copyright (C) 2015 Faust Logic, Inc.
 27//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 28
 29#include "platform/platform.h"
 30#include "T3D/containerQuery.h"
 31
 32#include "scene/sceneObject.h"
 33#include "environment/waterObject.h"
 34#include "T3D/physicalZone.h"
 35
 36
 37void findRouter( SceneObject *obj, void *key )
 38{
 39   if (obj->getTypeMask() & WaterObjectType)
 40      waterFind(obj, key);
 41   else if (obj->getTypeMask() & PhysicalZoneObjectType)
 42      physicalZoneFind(obj, key);
 43   else {
 44      AssertFatal(false, "Error, must be either water or physical zone here!");
 45   }
 46}
 47
 48void waterFind( SceneObject *obj, void *key )
 49{     
 50   PROFILE_SCOPE( waterFind );
 51
 52   // This is called for each WaterObject the ShapeBase object is overlapping.
 53
 54   ContainerQueryInfo *info = static_cast<ContainerQueryInfo*>(key);
 55   WaterObject *water = dynamic_cast<WaterObject*>(obj);      
 56   AssertFatal( water != NULL, "containerQuery - waterFind(), passed object was not of class WaterObject!");      
 57
 58   // Get point at the bottom/center of the box.
 59   Point3F testPnt = info->box.getCenter();
 60   testPnt.z = info->box.minExtents.z;
 61
 62   F32 coverage = water->getWaterCoverage(info->box);
 63
 64   // Since a WaterObject can have global bounds we may get this call
 65   // even though we have zero coverage.  If so we want to early out and
 66   // not save the water properties.
 67   if ( coverage == 0.0f )
 68      return;
 69
 70   // Add in flow force.  Would be appropriate to try scaling it by coverage
 71   // thought. Or perhaps have getFlow do that internally and take
 72   // the box parameter.
 73   info->appliedForce += water->getFlow( testPnt );
 74
 75   // Only save the following properties for the WaterObject with the
 76   // greatest water coverage for this ShapeBase object.
 77   if ( coverage < info->waterCoverage )
 78      return;
 79   
 80   info->waterCoverage = coverage;
 81   info->liquidType = water->getLiquidType();
 82   info->waterViscosity = water->getViscosity();
 83   info->waterDensity = water->getDensity();
 84   info->waterHeight = water->getSurfaceHeight( Point2F(testPnt.x,testPnt.y) );   
 85   info->waterObject = water;
 86}
 87
 88void physicalZoneFind(SceneObject* obj, void *key)
 89{    
 90   PROFILE_SCOPE( physicalZoneFind );
 91
 92   ContainerQueryInfo *info = static_cast<ContainerQueryInfo*>(key);
 93   PhysicalZone* pz = dynamic_cast<PhysicalZone*>(obj);
 94   AssertFatal(pz != NULL, "Error, not a physical zone!");
 95   if (pz == NULL || pz->testBox(info->box) == false)
 96      return;
 97
 98   if (pz->isActive()) {
 99      info->gravityScale *= pz->getGravityMod();
100      Point3F center; 
101      info->box.getCenter(&center);
102      info->appliedForce += pz->getForce(&center);
103   }
104}
105
106