2
0

containerQuery.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  23. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  24. // Copyright (C) 2015 Faust Logic, Inc.
  25. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  26. #include "platform/platform.h"
  27. #include "T3D/containerQuery.h"
  28. #include "scene/sceneObject.h"
  29. #include "environment/waterObject.h"
  30. #include "T3D/physicalZone.h"
  31. void findRouter( SceneObject *obj, void *key )
  32. {
  33. if (obj->getTypeMask() & WaterObjectType)
  34. waterFind(obj, key);
  35. else if (obj->getTypeMask() & PhysicalZoneObjectType)
  36. physicalZoneFind(obj, key);
  37. else {
  38. AssertFatal(false, "Error, must be either water or physical zone here!");
  39. }
  40. }
  41. void waterFind( SceneObject *obj, void *key )
  42. {
  43. PROFILE_SCOPE( waterFind );
  44. // This is called for each WaterObject the ShapeBase object is overlapping.
  45. ContainerQueryInfo *info = static_cast<ContainerQueryInfo*>(key);
  46. WaterObject *water = dynamic_cast<WaterObject*>(obj);
  47. AssertFatal( water != NULL, "containerQuery - waterFind(), passed object was not of class WaterObject!");
  48. // Get point at the bottom/center of the box.
  49. Point3F testPnt = info->box.getCenter();
  50. testPnt.z = info->box.minExtents.z;
  51. F32 coverage = water->getWaterCoverage(info->box);
  52. // Since a WaterObject can have global bounds we may get this call
  53. // even though we have zero coverage. If so we want to early out and
  54. // not save the water properties.
  55. if ( coverage == 0.0f )
  56. return;
  57. // Add in flow force. Would be appropriate to try scaling it by coverage
  58. // thought. Or perhaps have getFlow do that internally and take
  59. // the box parameter.
  60. info->appliedForce += water->getFlow( testPnt );
  61. // Only save the following properties for the WaterObject with the
  62. // greatest water coverage for this ShapeBase object.
  63. if ( coverage < info->waterCoverage )
  64. return;
  65. info->waterCoverage = coverage;
  66. info->liquidType = water->getLiquidType();
  67. info->waterViscosity = water->getViscosity();
  68. info->waterDensity = water->getDensity();
  69. info->waterHeight = water->getSurfaceHeight( Point2F(testPnt.x,testPnt.y) );
  70. info->waterObject = water;
  71. }
  72. void physicalZoneFind(SceneObject* obj, void *key)
  73. {
  74. PROFILE_SCOPE( physicalZoneFind );
  75. ContainerQueryInfo *info = static_cast<ContainerQueryInfo*>(key);
  76. PhysicalZone* pz = dynamic_cast<PhysicalZone*>(obj);
  77. AssertFatal(pz != NULL, "Error, not a physical zone!");
  78. if (pz == NULL || pz->testBox(info->box) == false)
  79. return;
  80. if (pz->isActive()) {
  81. info->gravityScale *= pz->getGravityMod();
  82. Point3F center;
  83. info->box.getCenter(&center);
  84. info->appliedForce += pz->getForce(&center);
  85. }
  86. }