Torque3D Documentation / _generateds / afxXM_HeightSampler.cpp

afxXM_HeightSampler.cpp

Engine/source/afx/xm/afxXM_HeightSampler.cpp

More...

Classes:

Public Functions

ConsoleDocClass(afxXM_HeightSamplerData , "@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_HeightSamplerData , "@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_HeightSamplerData )

  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/afxChoreographer.h"
 34#include "afx/xm/afxXfmMod.h"
 35
 36//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 37
 38class afxXM_HeightSamplerData : public afxXM_WeightedBaseData
 39{
 40  typedef afxXM_WeightedBaseData Parent;
 41
 42public:
 43  /*C*/         afxXM_HeightSamplerData();
 44  /*C*/         afxXM_HeightSamplerData(const afxXM_HeightSamplerData&, bool = false);
 45
 46  void          packData(BitStream* stream);
 47  void          unpackData(BitStream* stream);
 48
 49  virtual bool  allowSubstitutions() const { return true; }
 50
 51  static void   initPersistFields();
 52
 53  afxXM_Base*   create(afxEffectWrapper* fx, bool on_server);
 54
 55  DECLARE_CONOBJECT(afxXM_HeightSamplerData);
 56  DECLARE_CATEGORY("AFX");
 57};
 58
 59//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
 60
 61class afxConstraint;
 62
 63class afxXM_HeightSampler : public afxXM_WeightedBase
 64{
 65  typedef afxXM_WeightedBase Parent;
 66
 67public:
 68  /*C*/           afxXM_HeightSampler(afxXM_HeightSamplerData*, afxEffectWrapper*);
 69
 70  virtual void    updateParams(F32 dt, F32 elapsed, afxXM_Params& params);
 71};
 72
 73//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 74
 75IMPLEMENT_CO_DATABLOCK_V1(afxXM_HeightSamplerData);
 76
 77ConsoleDocClass( afxXM_HeightSamplerData,
 78   "@brief An xmod datablock.\n\n"
 79
 80   "@ingroup afxXMods\n"
 81   "@ingroup AFX\n"
 82   "@ingroup Datablocks\n"
 83);
 84
 85afxXM_HeightSamplerData::afxXM_HeightSamplerData()
 86{
 87}
 88
 89afxXM_HeightSamplerData::afxXM_HeightSamplerData(const afxXM_HeightSamplerData& other, bool temp_clone) : afxXM_WeightedBaseData(other, temp_clone)
 90{
 91}
 92
 93void afxXM_HeightSamplerData::initPersistFields()
 94{
 95  Parent::initPersistFields();
 96}
 97
 98void afxXM_HeightSamplerData::packData(BitStream* stream)
 99{
100  Parent::packData(stream);
101}
102
103void afxXM_HeightSamplerData::unpackData(BitStream* stream)
104{
105  Parent::unpackData(stream);
106}
107
108afxXM_Base* afxXM_HeightSamplerData::create(afxEffectWrapper* fx, bool on_server)
109{
110  afxXM_HeightSamplerData* datablock = this;
111
112  if (getSubstitutionCount() > 0)
113  {
114    datablock = new afxXM_HeightSamplerData(*this, true);
115    this->performSubstitutions(datablock, fx->getChoreographer(), fx->getGroupIndex());
116  }
117
118  return new afxXM_HeightSampler(datablock, fx);
119}
120
121
122//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
123
124afxXM_HeightSampler::afxXM_HeightSampler(afxXM_HeightSamplerData* db, afxEffectWrapper* fxw) 
125: afxXM_WeightedBase(db, fxw)
126{ 
127}
128
129void afxXM_HeightSampler::updateParams(F32 dt, F32 elapsed, afxXM_Params& params)
130{
131  afxConstraint* pos_cons = fx_wrapper->getPosConstraint();
132  if (!pos_cons)
133    return;
134      
135  Point3F base_pos;
136  pos_cons->getPosition(base_pos);
137  
138  F32 range = 0.5f;
139  F32 height = (base_pos.z > params.pos.z) ? (base_pos.z - params.pos.z) : 0.0f;
140  F32 factor = mClampF(1.0f - (height/range), 0.0f, 1.0f);
141
142  //Con::printf("SET height=%g liveScaleFactor=%g", height, factor);
143  fx_wrapper->setField("liveScaleFactor", avar("%g", factor));
144  fx_wrapper->setField("liveFadeFactor", avar("%g", factor));
145}
146
147//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
148