afxXM_Offset.cpp
Engine/source/afx/xm/afxXM_Offset.cpp
Classes:
Public Functions
ConsoleDocClass(afxXM_LocalOffsetData , "@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>" )
ConsoleDocClass(afxXM_WorldOffsetData , "@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_LocalOffsetData , "@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>" )
ConsoleDocClass(afxXM_WorldOffsetData , "@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_LocalOffsetData )
IMPLEMENT_CO_DATABLOCK_V1(afxXM_WorldOffsetData )
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#include "afx/util/afxPath3D.h" 36#include "afx/util/afxPath.h" 37 38//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 39// LOCAL OFFSET 40 41class afxXM_LocalOffsetData : public afxXM_WeightedBaseData 42{ 43 typedef afxXM_WeightedBaseData Parent; 44 45public: 46 Point3F local_offset; 47 bool offset_pos2; 48 49public: 50 /*C*/ afxXM_LocalOffsetData(); 51 /*C*/ afxXM_LocalOffsetData(const afxXM_LocalOffsetData&, bool = false); 52 53 void packData(BitStream* stream); 54 void unpackData(BitStream* stream); 55 56 virtual bool allowSubstitutions() const { return true; } 57 58 static void initPersistFields(); 59 60 afxXM_Base* create(afxEffectWrapper* fx, bool on_server); 61 62 DECLARE_CONOBJECT(afxXM_LocalOffsetData); 63 DECLARE_CATEGORY("AFX"); 64}; 65 66//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 67 68class afxXM_LocalOffset_weighted : public afxXM_WeightedBase 69{ 70 typedef afxXM_WeightedBase Parent; 71 72 Point3F local_offset; 73 74public: 75 /*C*/ afxXM_LocalOffset_weighted(afxXM_LocalOffsetData*, afxEffectWrapper*); 76 virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& params); 77}; 78 79//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 80 81// this fixed variation is used when 82// the weight factors are constant. 83 84class afxXM_LocalOffset_fixed : public afxXM_Base 85{ 86 typedef afxXM_Base Parent; 87 88 Point3F local_offset; 89 90public: 91 /*C*/ afxXM_LocalOffset_fixed(afxXM_LocalOffsetData*, afxEffectWrapper*); 92 virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& params); 93}; 94 95//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 96 97class afxXM_LocalOffset2_weighted : public afxXM_WeightedBase 98{ 99 typedef afxXM_WeightedBase Parent; 100 101 Point3F local_offset; 102 103public: 104 /*C*/ afxXM_LocalOffset2_weighted(afxXM_LocalOffsetData*, afxEffectWrapper*); 105 virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& params); 106}; 107 108//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 109 110// this fixed variation is used when 111// the weight factors are constant. 112 113class afxXM_LocalOffset2_fixed : public afxXM_Base 114{ 115 typedef afxXM_Base Parent; 116 117 Point3F local_offset; 118 119public: 120 /*C*/ afxXM_LocalOffset2_fixed(afxXM_LocalOffsetData*, afxEffectWrapper*); 121 virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& params); 122}; 123 124//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 125// WORLD OFFSET 126 127class afxXM_WorldOffsetData : public afxXM_WeightedBaseData 128{ 129 typedef afxXM_WeightedBaseData Parent; 130 131public: 132 Point3F world_offset; 133 bool offset_pos2; 134 135public: 136 /*C*/ afxXM_WorldOffsetData(); 137 /*C*/ afxXM_WorldOffsetData(const afxXM_WorldOffsetData&, bool = false); 138 139 void packData(BitStream* stream); 140 void unpackData(BitStream* stream); 141 142 virtual bool allowSubstitutions() const { return true; } 143 144 static void initPersistFields(); 145 146 afxXM_Base* create(afxEffectWrapper* fx, bool on_server); 147 148 DECLARE_CONOBJECT(afxXM_WorldOffsetData); 149 DECLARE_CATEGORY("AFX"); 150}; 151 152//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 153 154class afxXM_WorldOffset_weighted : public afxXM_WeightedBase 155{ 156 typedef afxXM_WeightedBase Parent; 157 Point3F world_offset; 158 159public: 160 /*C*/ afxXM_WorldOffset_weighted(afxXM_WorldOffsetData*, afxEffectWrapper*); 161 162 virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& params); 163}; 164 165//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 166 167// this fixed variation is used when 168// the weight factors are constant. 169 170class afxXM_WorldOffset_fixed : public afxXM_Base 171{ 172 typedef afxXM_WeightedBase Parent; 173 Point3F world_offset; 174 175public: 176 /*C*/ afxXM_WorldOffset_fixed(afxXM_WorldOffsetData*, afxEffectWrapper*); 177 virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& params); 178}; 179 180//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 181 182class afxXM_WorldOffset2_weighted : public afxXM_WeightedBase 183{ 184 typedef afxXM_WeightedBase Parent; 185 Point3F world_offset; 186 187public: 188 /*C*/ afxXM_WorldOffset2_weighted(afxXM_WorldOffsetData*, afxEffectWrapper*); 189 190 virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& params); 191}; 192 193//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 194 195// this fixed variation is used when 196// the weight factors are constant. 197 198class afxXM_WorldOffset2_fixed : public afxXM_Base 199{ 200 typedef afxXM_WeightedBase Parent; 201 Point3F world_offset; 202 203public: 204 /*C*/ afxXM_WorldOffset2_fixed(afxXM_WorldOffsetData*, afxEffectWrapper*); 205 virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& params); 206}; 207 208//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 209// LOCAL OFFSET 210 211IMPLEMENT_CO_DATABLOCK_V1(afxXM_LocalOffsetData); 212 213ConsoleDocClass( afxXM_LocalOffsetData, 214 "@brief An xmod datablock.\n\n" 215 216 "@ingroup afxXMods\n" 217 "@ingroup AFX\n" 218 "@ingroup Datablocks\n" 219); 220 221afxXM_LocalOffsetData::afxXM_LocalOffsetData() 222{ 223 local_offset.zero(); 224 offset_pos2 = false; 225} 226 227afxXM_LocalOffsetData::afxXM_LocalOffsetData(const afxXM_LocalOffsetData& other, bool temp_clone) : afxXM_WeightedBaseData(other, temp_clone) 228{ 229 local_offset = other.local_offset; 230 offset_pos2 = other.offset_pos2; 231} 232 233void afxXM_LocalOffsetData::initPersistFields() 234{ 235 addField("localOffset", TypePoint3F, Offset(local_offset, afxXM_LocalOffsetData), 236 "..."); 237 addField("offsetPos2", TypeBool, Offset(offset_pos2, afxXM_LocalOffsetData), 238 "..."); 239 240 Parent::initPersistFields(); 241} 242 243void afxXM_LocalOffsetData::packData(BitStream* stream) 244{ 245 Parent::packData(stream); 246 mathWrite(*stream, local_offset); 247 stream->writeFlag(offset_pos2); 248} 249 250void afxXM_LocalOffsetData::unpackData(BitStream* stream) 251{ 252 Parent::unpackData(stream); 253 mathRead(*stream, &local_offset); 254 offset_pos2 = stream->readFlag(); 255} 256 257afxXM_Base* afxXM_LocalOffsetData::create(afxEffectWrapper* fx, bool on_server) 258{ 259 afxXM_LocalOffsetData* datablock = this; 260 261 if (getSubstitutionCount() > 0) 262 { 263 datablock = new afxXM_LocalOffsetData(*this, true); 264 this->performSubstitutions(datablock, fx->getChoreographer(), fx->getGroupIndex()); 265 } 266 267 if (datablock->offset_pos2) 268 { 269 if (datablock->hasFixedWeight()) 270 return new afxXM_LocalOffset2_fixed(datablock, fx); 271 else 272 return new afxXM_LocalOffset2_weighted(datablock, fx); 273 } 274 else 275 { 276 if (datablock->hasFixedWeight()) 277 return new afxXM_LocalOffset_fixed(datablock, fx); 278 else 279 return new afxXM_LocalOffset_weighted(datablock, fx); 280 } 281} 282 283//~~~~~~~~~~~~~~~~~~~~// 284 285afxXM_LocalOffset_weighted::afxXM_LocalOffset_weighted(afxXM_LocalOffsetData* db, afxEffectWrapper* fxw) 286: afxXM_WeightedBase(db, fxw) 287{ 288 local_offset = db->local_offset*db->getWeightFactor(); 289} 290 291void afxXM_LocalOffset_weighted::updateParams(F32 dt, F32 elapsed, afxXM_Params& params) 292{ 293 F32 wt_factor = calc_weight_factor(elapsed); 294 Point3F offset(local_offset*wt_factor); 295 params.ori.mulV(offset); 296 params.pos += offset; 297} 298 299//~~~~~~~~~~~~~~~~~~~~// 300 301afxXM_LocalOffset_fixed::afxXM_LocalOffset_fixed(afxXM_LocalOffsetData* db, afxEffectWrapper* fxw) 302: afxXM_Base(db, fxw) 303{ 304 local_offset = db->local_offset*db->getWeightFactor(); 305} 306 307void afxXM_LocalOffset_fixed::updateParams(F32 dt, F32 elapsed, afxXM_Params& params) 308{ 309 Point3F offset(local_offset); 310 params.ori.mulV(offset); 311 params.pos += offset; 312} 313 314//~~~~~~~~~~~~~~~~~~~~// 315 316afxXM_LocalOffset2_weighted::afxXM_LocalOffset2_weighted(afxXM_LocalOffsetData* db, afxEffectWrapper* fxw) 317: afxXM_WeightedBase(db, fxw) 318{ 319 local_offset = db->local_offset*db->getWeightFactor(); 320} 321 322void afxXM_LocalOffset2_weighted::updateParams(F32 dt, F32 elapsed, afxXM_Params& params) 323{ 324 F32 wt_factor = calc_weight_factor(elapsed); 325 Point3F offset(local_offset*wt_factor); 326 327 afxConstraint* pos2_cons = fx_wrapper->getAimConstraint(); 328 if (pos2_cons) 329 { 330 MatrixF ori2; 331 pos2_cons->getTransform(ori2); 332 ori2.mulV(offset); 333 } 334 335 params.pos2 += offset; 336} 337 338//~~~~~~~~~~~~~~~~~~~~// 339 340afxXM_LocalOffset2_fixed::afxXM_LocalOffset2_fixed(afxXM_LocalOffsetData* db, afxEffectWrapper* fxw) 341: afxXM_Base(db, fxw) 342{ 343 local_offset = db->local_offset*db->getWeightFactor(); 344} 345 346void afxXM_LocalOffset2_fixed::updateParams(F32 dt, F32 elapsed, afxXM_Params& params) 347{ 348 Point3F offset(local_offset); 349 350 afxConstraint* pos2_cons = fx_wrapper->getAimConstraint(); 351 if (pos2_cons) 352 { 353 MatrixF ori2; 354 pos2_cons->getTransform(ori2); 355 ori2.mulV(offset); 356 } 357 358 params.pos2 += offset; 359} 360 361//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 362// WORLD OFFSET 363 364IMPLEMENT_CO_DATABLOCK_V1(afxXM_WorldOffsetData); 365 366ConsoleDocClass( afxXM_WorldOffsetData, 367 "@brief An xmod datablock.\n\n" 368 369 "@ingroup afxXMods\n" 370 "@ingroup AFX\n" 371 "@ingroup Datablocks\n" 372); 373 374afxXM_WorldOffsetData::afxXM_WorldOffsetData() 375{ 376 world_offset.zero(); 377 offset_pos2 = false; 378} 379 380afxXM_WorldOffsetData::afxXM_WorldOffsetData(const afxXM_WorldOffsetData& other, bool temp_clone) : afxXM_WeightedBaseData(other, temp_clone) 381{ 382 world_offset = other.world_offset; 383 offset_pos2 = other.offset_pos2; 384} 385 386void afxXM_WorldOffsetData::initPersistFields() 387{ 388 addField("worldOffset", TypePoint3F, Offset(world_offset, afxXM_WorldOffsetData), 389 "..."); 390 addField("offsetPos2", TypeBool, Offset(offset_pos2, afxXM_WorldOffsetData), 391 "..."); 392 393 Parent::initPersistFields(); 394} 395 396void afxXM_WorldOffsetData::packData(BitStream* stream) 397{ 398 Parent::packData(stream); 399 mathWrite(*stream, world_offset); 400 stream->writeFlag(offset_pos2); 401} 402 403void afxXM_WorldOffsetData::unpackData(BitStream* stream) 404{ 405 Parent::unpackData(stream); 406 mathRead(*stream, &world_offset); 407 offset_pos2 = stream->readFlag(); 408} 409 410afxXM_Base* afxXM_WorldOffsetData::create(afxEffectWrapper* fx, bool on_server) 411{ 412 afxXM_WorldOffsetData* datablock = this; 413 414 if (getSubstitutionCount() > 0) 415 { 416 datablock = new afxXM_WorldOffsetData(*this, true); 417 this->performSubstitutions(datablock, fx->getChoreographer(), fx->getGroupIndex()); 418 } 419 420 if (datablock->offset_pos2) 421 { 422 if (datablock->hasFixedWeight()) 423 return new afxXM_WorldOffset2_fixed(datablock, fx); 424 else 425 return new afxXM_WorldOffset2_weighted(datablock, fx); 426 } 427 else 428 { 429 if (datablock->hasFixedWeight()) 430 return new afxXM_WorldOffset_fixed(datablock, fx); 431 else 432 return new afxXM_WorldOffset_weighted(datablock, fx); 433 } 434} 435 436//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 437 438afxXM_WorldOffset_weighted::afxXM_WorldOffset_weighted(afxXM_WorldOffsetData* db, afxEffectWrapper* fxw) 439: afxXM_WeightedBase(db, fxw) 440{ 441 world_offset = db->world_offset*db->getWeightFactor(); 442} 443 444void afxXM_WorldOffset_weighted::updateParams(F32 dt, F32 elapsed, afxXM_Params& params) 445{ 446 F32 wt_factor = calc_weight_factor(elapsed); 447 params.pos += world_offset*wt_factor; 448} 449 450//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 451 452afxXM_WorldOffset_fixed::afxXM_WorldOffset_fixed(afxXM_WorldOffsetData* db, afxEffectWrapper* fxw) 453: afxXM_Base(db, fxw) 454{ 455 world_offset = db->world_offset*db->getWeightFactor(); 456} 457 458void afxXM_WorldOffset_fixed::updateParams(F32 dt, F32 elapsed, afxXM_Params& params) 459{ 460 params.pos += world_offset; 461} 462 463//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 464 465afxXM_WorldOffset2_weighted::afxXM_WorldOffset2_weighted(afxXM_WorldOffsetData* db, afxEffectWrapper* fxw) 466: afxXM_WeightedBase(db, fxw) 467{ 468 world_offset = db->world_offset*db->getWeightFactor(); 469} 470 471void afxXM_WorldOffset2_weighted::updateParams(F32 dt, F32 elapsed, afxXM_Params& params) 472{ 473 F32 wt_factor = calc_weight_factor(elapsed); 474 params.pos2 += world_offset*wt_factor; 475} 476 477//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 478 479afxXM_WorldOffset2_fixed::afxXM_WorldOffset2_fixed(afxXM_WorldOffsetData* db, afxEffectWrapper* fxw) 480: afxXM_Base(db, fxw) 481{ 482 world_offset = db->world_offset*db->getWeightFactor(); 483} 484 485void afxXM_WorldOffset2_fixed::updateParams(F32 dt, F32 elapsed, afxXM_Params& params) 486{ 487 params.pos2 += world_offset; 488} 489 490//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 491