Torque3D Documentation / _generateds / afxXM_PivotNodeOffset.cpp

afxXM_PivotNodeOffset.cpp

Engine/source/afx/xm/afxXM_PivotNodeOffset.cpp

More...

Classes:

Public Functions

ConsoleDocClass(afxXM_PivotNodeOffsetData , "@brief An xmod <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXMods\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 Functions

ConsoleDocClass(afxXM_PivotNodeOffsetData , "@brief An xmod <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">datablock.\n\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxXMods\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(afxXM_PivotNodeOffsetData )

  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 "afx/arcaneFX.h"
 28
 29#include "ts/tsShapeInstance.h"
 30
 31#include "afx/afxEffectWrapper.h"
 32#include "afx/afxChoreographer.h"
 33#include "afx/xm/afxXfmMod.h"
 34
 35//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 36
 37class afxXM_PivotNodeOffsetData : public afxXM_BaseData
 38{
 39  typedef afxXM_BaseData Parent;
 40
 41public:
 42  StringTableEntry  node_name;
 43  bool              node_is_static;
 44
 45public:
 46  /*C*/         afxXM_PivotNodeOffsetData();
 47  /*C*/         afxXM_PivotNodeOffsetData(const afxXM_PivotNodeOffsetData&, bool = false);
 48
 49  void          packData(BitStream* stream);
 50  void          unpackData(BitStream* stream);
 51
 52  virtual bool  allowSubstitutions() const { return true; }
 53
 54  static void   initPersistFields();
 55
 56  afxXM_Base*   create(afxEffectWrapper* fx, bool on_server);
 57
 58  DECLARE_CONOBJECT(afxXM_PivotNodeOffsetData);
 59  DECLARE_CATEGORY("AFX");
 60};
 61
 62//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
 63
 64class afxXM_PivotNodeOffset : public afxXM_Base
 65{
 66  typedef afxXM_Base Parent;
 67
 68  StringTableEntry  node_name;
 69  bool              node_is_static;
 70  S32               node_ID;
 71  Point3F           pivot_offset;
 72  bool              offset_calculated;
 73
 74public:
 75  /*C*/         afxXM_PivotNodeOffset(afxXM_PivotNodeOffsetData*, afxEffectWrapper*);
 76
 77  virtual void  updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
 78};
 79
 80//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
 81
 82IMPLEMENT_CO_DATABLOCK_V1(afxXM_PivotNodeOffsetData);
 83
 84ConsoleDocClass( afxXM_PivotNodeOffsetData,
 85   "@brief An xmod datablock.\n\n"
 86
 87   "@ingroup afxXMods\n"
 88   "@ingroup AFX\n"
 89   "@ingroup Datablocks\n"
 90);
 91
 92afxXM_PivotNodeOffsetData::afxXM_PivotNodeOffsetData()
 93{ 
 94  node_name = ST_NULLSTRING;
 95  node_is_static = true;
 96}
 97
 98afxXM_PivotNodeOffsetData::afxXM_PivotNodeOffsetData(const afxXM_PivotNodeOffsetData& other, bool temp_clone) : afxXM_BaseData(other, temp_clone)
 99{
100  node_name = other.node_name;
101  node_is_static = other.node_is_static;
102}
103
104void afxXM_PivotNodeOffsetData::initPersistFields()
105{
106  addField("nodeName",      TypeString,   Offset(node_name, afxXM_PivotNodeOffsetData),
107    "...");
108  addField("nodeIsStatic",  TypeBool, Offset(node_is_static, afxXM_PivotNodeOffsetData),
109    "...");
110
111  Parent::initPersistFields();
112}
113
114void afxXM_PivotNodeOffsetData::packData(BitStream* stream)
115{
116  Parent::packData(stream);
117  stream->writeString(node_name);
118  stream->writeFlag(node_is_static);
119}
120
121void afxXM_PivotNodeOffsetData::unpackData(BitStream* stream)
122{
123  Parent::unpackData(stream);
124  node_name = stream->readSTString();
125  node_is_static = stream->readFlag();
126}
127
128afxXM_Base* afxXM_PivotNodeOffsetData::create(afxEffectWrapper* fx, bool on_server)
129{
130  afxXM_PivotNodeOffsetData* datablock = this;
131
132  if (getSubstitutionCount() > 0)
133  {
134    datablock = new afxXM_PivotNodeOffsetData(*this, true);
135    this->performSubstitutions(datablock, fx->getChoreographer(), fx->getGroupIndex());
136  }
137
138  return new afxXM_PivotNodeOffset(datablock, fx);
139}
140
141//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
142
143afxXM_PivotNodeOffset::afxXM_PivotNodeOffset(afxXM_PivotNodeOffsetData* db, afxEffectWrapper* fxw) 
144: afxXM_Base(db, fxw)
145{ 
146  node_name = db->node_name; 
147  node_is_static = db->node_is_static;
148  node_ID = -1;
149  pivot_offset.set(0,0,0);
150  offset_calculated = false;
151}
152
153void afxXM_PivotNodeOffset::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
154{
155  if (node_ID < 0)
156  {
157    TSShape* ts_shape = fx_wrapper->getTSShape();
158    node_ID = (ts_shape) ? ts_shape->findNode(node_name) : -1;
159  }
160
161  if (node_ID >= 0)
162  {
163    if (!node_is_static || !offset_calculated)
164    {
165      TSShapeInstance* ts_shape_inst = fx_wrapper->getTSShapeInstance();
166      if (ts_shape_inst)
167      {
168        const MatrixF& pivot_xfm = ts_shape_inst->mNodeTransforms[node_ID];
169        pivot_offset = -pivot_xfm.getPosition();
170        offset_calculated = true;
171      }
172    }
173  }
174
175  // re-orient pivot offset then add to position
176  Point3F pivot_offset_temp;
177  params.ori.mulV(pivot_offset, &pivot_offset_temp);
178  params.pos += pivot_offset_temp;
179}
180
181//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
182