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