Torque3D Documentation / _generateds / afxXM_BoxAdapt.cpp

afxXM_BoxAdapt.cpp

Engine/source/afx/xm/afxXM_BoxAdapt.cpp

More...

Classes:

Public Functions

ConsoleDocClass(afxXM_BoxAdaptData , "@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_BoxAdaptData , "@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_BoxAdaptData )

  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 "math/mathIO.h"
 30#include "math/mathUtils.h"
 31
 32#include "afx/afxEffectWrapper.h"
 33#include "afx/xm/afxXfmMod.h"
 34
 35//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 36
 37class afxXM_BoxAdaptData : public afxXM_WeightedBaseData
 38{
 39  typedef afxXM_WeightedBaseData Parent;
 40
 41public:
 42  F32           scale_factor;
 43  Point2F       dim_range;
 44
 45public:
 46  /*C*/         afxXM_BoxAdaptData();
 47  /*C*/         afxXM_BoxAdaptData(const afxXM_BoxAdaptData&, bool = false);
 48
 49  void          packData(BitStream* stream);
 50  void          unpackData(BitStream* stream);
 51  static void   initPersistFields();
 52
 53  afxXM_Base*   create(afxEffectWrapper* fx, bool on_server);
 54
 55  DECLARE_CONOBJECT(afxXM_BoxAdaptData);
 56  DECLARE_CATEGORY("AFX");
 57};
 58
 59//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
 60
 61class afxConstraint;
 62
 63class afxXM_BoxAdapt : public afxXM_WeightedBase
 64{
 65  typedef afxXM_WeightedBase Parent;
 66
 67  F32             scale_factor;
 68  Point2F         dim_range;
 69
 70public:
 71  /*C*/           afxXM_BoxAdapt(afxXM_BoxAdaptData*, afxEffectWrapper*);
 72
 73  virtual void    updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
 74};
 75
 76//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 77
 78IMPLEMENT_CO_DATABLOCK_V1(afxXM_BoxAdaptData);
 79
 80ConsoleDocClass( afxXM_BoxAdaptData,
 81   "@brief An xmod datablock.\n\n"
 82
 83   "@ingroup afxXMods\n"
 84   "@ingroup AFX\n"
 85   "@ingroup Datablocks\n"
 86);
 87
 88afxXM_BoxAdaptData::afxXM_BoxAdaptData()
 89{
 90  scale_factor = 1.0f;
 91  dim_range.set(0.1f, 1000.0f);
 92}
 93
 94afxXM_BoxAdaptData::afxXM_BoxAdaptData(const afxXM_BoxAdaptData& other, bool temp_clone) 
 95  : afxXM_WeightedBaseData(other, temp_clone)
 96{
 97  scale_factor = other.scale_factor;
 98  dim_range = other.dim_range;
 99}
100
101void afxXM_BoxAdaptData::initPersistFields()
102{
103  addField("scaleFactor",     TypeF32,        Offset(scale_factor, afxXM_BoxAdaptData),
104    "...");
105  addField("dimensionRange",  TypePoint2F,    Offset(dim_range, afxXM_BoxAdaptData),
106    "...");
107
108  Parent::initPersistFields();
109}
110
111void afxXM_BoxAdaptData::packData(BitStream* stream)
112{
113  Parent::packData(stream);
114  stream->write(scale_factor);
115  mathWrite(*stream, dim_range);
116}
117
118void afxXM_BoxAdaptData::unpackData(BitStream* stream)
119{
120  Parent::unpackData(stream);
121  stream->read(&scale_factor);
122  mathRead(*stream, &dim_range);
123}
124
125afxXM_Base* afxXM_BoxAdaptData::create(afxEffectWrapper* fx, bool on_server)
126{
127  return new afxXM_BoxAdapt(this, fx);
128}
129
130
131//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
132
133afxXM_BoxAdapt::afxXM_BoxAdapt(afxXM_BoxAdaptData* db, afxEffectWrapper* fxw) 
134: afxXM_WeightedBase(db, fxw)
135{ 
136  scale_factor = db->scale_factor;
137
138  dim_range = db->dim_range;
139
140  dim_range.x = getMax(0.001f, dim_range.x);
141  dim_range.y = getMax(0.001f, dim_range.y);
142
143  if (dim_range.x > dim_range.y)
144  {
145    F32 tmp = dim_range.y;
146    dim_range.y = dim_range.x;
147    dim_range.x = tmp;
148  }
149}
150
151void afxXM_BoxAdapt::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
152{
153  afxConstraint* pos_cons = fx_wrapper->getPosConstraint();
154  if (!pos_cons)
155    return;
156      
157  SceneObject* obj = pos_cons->getSceneObject();
158  if (!obj)
159    return;
160
161  F32 wt_factor = calc_weight_factor(elapsed);
162
163  const Box3F& obj_box = obj->getObjBox();
164  const VectorF obj_scale = obj->getScale();
165
166  F32 x_dim = obj_box.len_x()*obj_scale.x;
167  F32 y_dim = obj_box.len_y()*obj_scale.y;
168
169  F32 dim = mClampF(getMax(x_dim, y_dim), dim_range.x, dim_range.y);
170  dim *= scale_factor*wt_factor*0.5f;
171
172  //Con::printf("SET liveScaleFactor=%g x_dim=%g, y_dim=%g", dim, obj_box.len_x(), obj_box.len_y());
173  fx_wrapper->setField("liveScaleFactor", avar("%g", dim));
174}
175
176//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
177