Torque3D Documentation / _generateds / afxF_Gravity.cpp

afxF_Gravity.cpp

Engine/source/afx/forces/afxF_Gravity.cpp

More...

Classes:

Public Defines

define
myOffset(field) (field, )

Public Functions

ConsoleDocClass(afxF_GravityData , "@brief A datablock <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> specifiying AFX gravity <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">forces.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxExperimental\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

Detailed Description

Public Defines

myOffset(field) (field, )

Public Functions

ConsoleDocClass(afxF_GravityData , "@brief A datablock <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> specifiying AFX gravity <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">forces.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxExperimental\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

IMPLEMENT_CO_DATABLOCK_V1(afxF_GravityData )

  1
  2
  3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  5// Copyright (C) 2015 Faust Logic, Inc.
  6//
  7// Permission is hereby granted, free of charge, to any person obtaining a copy
  8// of this software and associated documentation files (the "Software"), to
  9// deal in the Software without restriction, including without limitation the
 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 11// sell copies of the Software, and to permit persons to whom the Software is
 12// furnished to do so, subject to the following conditions:
 13//
 14// The above copyright notice and this permission notice shall be included in
 15// all copies or substantial portions of the Software.
 16//
 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 23// IN THE SOFTWARE.
 24//
 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 26
 27#include <typeinfo>
 28#include "afx/arcaneFX.h"
 29
 30#include "afx/forces/afxForce.h"
 31
 32//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 33
 34class afxF_GravityData : public afxForceData
 35{
 36  typedef afxForceData Parent;
 37
 38public:
 39  F32             gravity;
 40
 41public:
 42  /*C*/           afxF_GravityData();
 43  /*C*/           afxF_GravityData(const afxF_GravityData&, bool = false);
 44  
 45  virtual void    packData(BitStream* stream);
 46  virtual void    unpackData(BitStream* stream);
 47  virtual afxForceData* cloneAndPerformSubstitutions(const SimObject*, S32 index=0);
 48
 49  static void     initPersistFields();
 50
 51  DECLARE_CONOBJECT(afxF_GravityData);
 52  DECLARE_CATEGORY("AFX");
 53};
 54
 55//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 56
 57class afxF_Gravity : public afxForce
 58{
 59  typedef afxForce Parent;
 60
 61private:
 62  afxF_GravityData* mDatablock;
 63
 64public:
 65  /*C*/             afxF_Gravity();
 66
 67  virtual bool      onNewDataBlock(afxForceData* dptr, bool reload);
 68
 69  virtual Point3F   evaluate(Point3F pos, Point3F v, F32 mass);
 70};
 71
 72//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 73// afxForceData
 74
 75IMPLEMENT_CO_DATABLOCK_V1(afxF_GravityData);
 76
 77ConsoleDocClass( afxF_GravityData,
 78   "@brief A datablock for specifiying AFX gravity forces.\n\n"
 79
 80   "@ingroup afxExperimental\n"
 81   "@ingroup AFX\n"
 82   "@ingroup Datablocks\n"
 83);
 84
 85afxF_GravityData::afxF_GravityData()
 86{
 87  gravity = 9.807f;
 88}
 89
 90afxF_GravityData::afxF_GravityData(const afxF_GravityData& other, bool temp_clone) : afxForceData(other, temp_clone)
 91{
 92  gravity = other.gravity;
 93}
 94
 95#define myOffset(field) Offset(field, afxF_GravityData)
 96
 97void afxF_GravityData::initPersistFields()
 98{
 99  addField("gravity",   TypeF32,     myOffset(gravity),
100    "...");
101
102  Parent::initPersistFields();
103}
104
105void afxF_GravityData::packData(BitStream* stream)
106{
107   Parent::packData(stream);
108  stream->write(gravity);
109}
110
111void afxF_GravityData::unpackData(BitStream* stream)
112{
113  Parent::unpackData(stream);
114  stream->read(&gravity);
115}
116
117afxForceData* afxF_GravityData::cloneAndPerformSubstitutions(const SimObject* owner, S32 index)
118{
119  afxF_GravityData* grav_data = this;
120
121  // only clone the datablock if there are substitutions
122  if (this->getSubstitutionCount() > 0)
123  {
124    // clone the datablock and perform substitutions
125    afxF_GravityData* orig_db = this;
126    grav_data = new afxF_GravityData(*orig_db, true);
127    orig_db->performSubstitutions(grav_data, owner, index);
128  }
129
130  return grav_data;
131}
132
133//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
134
135afxF_Gravity::afxF_Gravity() : afxForce()
136{
137   mDatablock = NULL;
138}
139
140bool afxF_Gravity::onNewDataBlock(afxForceData* dptr, bool reload)
141{
142   mDatablock = dynamic_cast<afxF_GravityData*>(dptr);
143  if (!mDatablock || !Parent::onNewDataBlock(dptr, reload))
144    return false;
145
146  return true;
147}
148
149Point3F afxF_Gravity::evaluate(Point3F pos, Point3F v, F32 mass)
150{
151  return Point3F(0,0,-mDatablock->gravity)*mass;
152}
153
154
155//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
156
157class afxF_GravityDesc : public afxForceDesc
158{
159  static afxF_GravityDesc desc;
160
161public:
162  virtual bool testForceType(const SimDataBlock*) const;
163  virtual afxForce* create() const { return new afxF_Gravity; }
164};
165
166afxF_GravityDesc afxF_GravityDesc::desc;
167
168bool afxF_GravityDesc::testForceType(const SimDataBlock* db) const
169{
170  return (typeid(afxF_GravityData) == typeid(*db));
171}
172
173//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
174