Torque3D Documentation / _generateds / physicsEvents.cpp

physicsEvents.cpp

Engine/source/T3D/physics/physicsEvents.cpp

More...

Public Functions

ConsoleDocClass(RadialImpulseEvent , "@brief Creates <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> physics-based impulse effect from <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> defined central point and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">magnitude.\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">RadialImpulseEvent::send\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Physics\n</a>" )
DefineEngineStaticMethod(RadialImpulseEvent , send , void , (const char *inPosition, F32 radius, F32 magnitude) , ("1.0 1.0 1.0", 10.0f, 20.0f) , "@brief Applies <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> radial impulse <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> any SceneObjects within the area of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">effect.\n\n</a>" "This event is performed both server and client-<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">side.\n\n</a>" "@param position Center point <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this radial <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">impulse.\n</a>" "@param radius Distance from the position <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this radial impulse <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">affect.\n</a>" "@param magnitude The force applied <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> objects within the radius from the position of this radial impulse <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">effect.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Define the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Position\n</a>" "% position)

Detailed Description

Public Functions

ConsoleDocClass(RadialImpulseEvent , "@brief Creates <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> physics-based impulse effect from <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> defined central point and <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">magnitude.\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">RadialImpulseEvent::send\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Physics\n</a>" )

DefineEngineStaticMethod(RadialImpulseEvent , send , void , (const char *inPosition, F32 radius, F32 magnitude) , ("1.0 1.0 1.0", 10.0f, 20.0f) , "@brief Applies <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> radial impulse <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> any SceneObjects within the area of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">effect.\n\n</a>" "This event is performed both server and client-<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">side.\n\n</a>" "@param position Center point <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this radial <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">impulse.\n</a>" "@param radius Distance from the position <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this radial impulse <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">affect.\n</a>" "@param magnitude The force applied <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> objects within the radius from the position of this radial impulse <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">effect.\n\n</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Define the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Position\n</a>" "% position)

IMPLEMENT_CO_NETEVENT_V1(RadialImpulseEvent )

  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/physics/physicsEvents.h"
 26
 27#include "math/mathIO.h"
 28#include "core/stream/bitStream.h"
 29#include "T3D/physics/physicsPlugin.h"
 30#include "T3D/physics/physicsWorld.h"
 31#include "scene/sceneObject.h"
 32#include "T3D/gameBase/gameConnection.h"
 33#include "console/engineAPI.h"
 34
 35
 36RadialImpulseEvent::RadialImpulseEvent()
 37 : mPosition( 0, 0, 0 ),
 38   mRadius( 0 ),
 39   mMagnitude( 0 )
 40{            
 41}
 42
 43RadialImpulseEvent::RadialImpulseEvent( const Point3F &pos, F32 radius, F32 magnitude )
 44 :  mPosition( pos ),
 45    mRadius( radius ),
 46    mMagnitude( magnitude )
 47{
 48}
 49
 50RadialImpulseEvent::~RadialImpulseEvent()
 51{ 
 52}
 53
 54void RadialImpulseEvent::pack( NetConnection* /*ps*/, BitStream *bstream )
 55{       
 56   mathWrite( *bstream, mPosition );
 57   bstream->write( mRadius );
 58   bstream->write( mMagnitude );
 59}
 60
 61void RadialImpulseEvent::write( NetConnection*, BitStream *bstream )
 62{ 
 63   mathWrite( *bstream, mPosition );
 64   bstream->write( mRadius );
 65   bstream->write( mMagnitude );
 66}
 67   
 68void RadialImpulseEvent::unpack( NetConnection *ps, BitStream *bstream )
 69{      
 70   mathRead( *bstream, &mPosition );
 71   bstream->read( &mRadius );
 72   bstream->read( &mMagnitude );
 73}
 74   
 75void RadialImpulseEvent::process(NetConnection *con)
 76{ 
 77   impulse( &gClientContainer, mPosition, mRadius, mMagnitude );   
 78}
 79
 80void RadialImpulseEvent::_impulseCallback( SceneObject *obj, void *key )
 81{
 82   ImpulseInfo *info = (ImpulseInfo*)key; 
 83   obj->applyRadialImpulse( info->pos, info->radius, info->magnitude );
 84}
 85
 86void RadialImpulseEvent::impulse( SceneContainer *con, const Point3F &position, F32 radius, F32 magnitude )
 87{
 88   Point3F offset( radius, radius, radius );   
 89   Box3F bounds( position - offset, position + offset );      
 90   
 91   ImpulseInfo info;
 92   info.pos = position;
 93   info.radius = radius;
 94   info.magnitude = magnitude;
 95
 96   con->findObjects( bounds, -1, _impulseCallback, &info );
 97}
 98
 99IMPLEMENT_CO_NETEVENT_V1( RadialImpulseEvent );
100
101ConsoleDocClass( RadialImpulseEvent,
102   "@brief Creates a physics-based impulse effect from a defined central point and magnitude.\n\n"
103   "@see RadialImpulseEvent::send\n"
104   "@ingroup Physics\n"
105);
106
107
108DefineEngineStaticMethod(RadialImpulseEvent, send, void, (const char* inPosition, F32 radius, F32 magnitude), ("1.0 1.0 1.0", 10.0f, 20.0f),
109                "@brief Applies a radial impulse to any SceneObjects within the area of effect.\n\n"
110                "This event is performed both server and client-side.\n\n"
111                "@param position Center point for this radial impulse.\n"
112                "@param radius Distance from the position for this radial impulse to affect.\n"
113                "@param magnitude The force applied to objects within the radius from the position of this radial impulse effect.\n\n"
114                "@tsexample\n"
115                  "// Define the Position\n"
116                  "%position = \"10.0 15.0 10.0\";\n\n"
117                  "// Define the Radius\n"
118                  "%radius = \"25.0\";\n\n"
119                  "// Define the Magnitude\n"
120                  "%magnitude = \"30.0\"\n\n"
121                  "// Create a globalRadialImpulse physics effect.\n"
122                  "RadialImpulseEvent::send(%position,%radius,%magnitude);\n"
123                "@endtsexample\n\n")
124{
125   // Scan out arguments...
126   Point3F position;
127
128   dSscanf( inPosition, "%f %f %f", &position.x, &position.y, &position.z );
129
130   // Apply server-side.
131   RadialImpulseEvent::impulse( &gServerContainer, position, radius, magnitude );
132
133   // Transmit event to each client to perform client-side...
134
135   SimGroup *pClientGroup = Sim::getClientGroup();
136   if ( !pClientGroup )
137   {
138      Con::errorf( "globalRadialImpulse() - Client group not found!" );
139      return;
140   }
141   
142   SimGroup::iterator itr = pClientGroup->begin();
143   for ( ; itr != pClientGroup->end(); itr++ )
144   {
145      GameConnection* gc = static_cast<GameConnection*>(*itr);
146      if ( gc )
147         gc->postNetEvent( new RadialImpulseEvent( position, radius, magnitude ) );
148   }
149}
150