afxXM_GroundConform.cpp
Engine/source/afx/xm/afxXM_GroundConform.cpp
Classes:
Public Functions
ConsoleDocClass(afxXM_GroundConformData , "@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_GroundConformData , "@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_GroundConformData )
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 "afx/afxEffectWrapper.h" 30#include "afx/afxChoreographer.h" 31#include "afx/xm/afxXfmMod.h" 32 33//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 34 35class afxXM_GroundConformData : public afxXM_WeightedBaseData 36{ 37 typedef afxXM_WeightedBaseData Parent; 38 39public: 40 F32 height; 41 bool do_terrain; 42 bool do_interiors; 43 bool do_orientation; 44 45public: 46 /*C*/ afxXM_GroundConformData(); 47 /*C*/ afxXM_GroundConformData(const afxXM_GroundConformData&, 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_GroundConformData); 59 DECLARE_CATEGORY("AFX"); 60}; 61 62class afxXM_GroundConform : public afxXM_WeightedBase 63{ 64 typedef afxXM_WeightedBase Parent; 65 66 afxXM_GroundConformData* db; 67 SceneContainer* container; 68 69public: 70 /*C*/ afxXM_GroundConform(afxXM_GroundConformData*, afxEffectWrapper*, bool on_server); 71 72 virtual void updateParams(F32 dt, F32 elapsed, afxXM_Params& params); 73}; 74 75//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 76 77IMPLEMENT_CO_DATABLOCK_V1(afxXM_GroundConformData); 78 79ConsoleDocClass( afxXM_GroundConformData, 80 "@brief An xmod datablock.\n\n" 81 82 "@ingroup afxXMods\n" 83 "@ingroup AFX\n" 84 "@ingroup Datablocks\n" 85); 86 87afxXM_GroundConformData::afxXM_GroundConformData() 88{ 89 height = 0.0f; 90 do_terrain = true; 91 do_interiors = true; 92 do_orientation = false; 93} 94 95afxXM_GroundConformData::afxXM_GroundConformData(const afxXM_GroundConformData& other, bool temp_clone) : afxXM_WeightedBaseData(other, temp_clone) 96{ 97 height = other.height; 98 do_terrain = other.do_terrain; 99 do_interiors = other.do_interiors; 100 do_orientation = other.do_orientation; 101} 102 103void afxXM_GroundConformData::initPersistFields() 104{ 105 addField("height", TypeF32, Offset(height, afxXM_GroundConformData), 106 "..."); 107 addField("conformToTerrain", TypeBool, Offset(do_terrain, afxXM_GroundConformData), 108 "..."); 109 addField("conformToInteriors", TypeBool, Offset(do_interiors, afxXM_GroundConformData), 110 "..."); 111 addField("conformOrientation", TypeBool, Offset(do_orientation, afxXM_GroundConformData), 112 "..."); 113 114 Parent::initPersistFields(); 115} 116 117void afxXM_GroundConformData::packData(BitStream* stream) 118{ 119 Parent::packData(stream); 120 stream->write(height); 121 stream->write(do_terrain); 122 stream->write(do_interiors); 123 stream->write(do_orientation); 124} 125 126void afxXM_GroundConformData::unpackData(BitStream* stream) 127{ 128 Parent::unpackData(stream); 129 stream->read(&height); 130 stream->read(&do_terrain); 131 stream->read(&do_interiors); 132 stream->read(&do_orientation); 133} 134 135afxXM_Base* afxXM_GroundConformData::create(afxEffectWrapper* fx, bool on_server) 136{ 137 afxXM_GroundConformData* datablock = this; 138 139 if (getSubstitutionCount() > 0) 140 { 141 datablock = new afxXM_GroundConformData(*this, true); 142 this->performSubstitutions(datablock, fx->getChoreographer(), fx->getGroupIndex()); 143 } 144 145 return new afxXM_GroundConform(datablock, fx, on_server); 146} 147 148//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~// 149 150afxXM_GroundConform::afxXM_GroundConform(afxXM_GroundConformData* db, afxEffectWrapper* fxw, bool on_server) 151: afxXM_WeightedBase(db, fxw) 152{ 153 this->db = db; 154 this->container = (on_server) ? &gServerContainer : &gClientContainer; 155} 156 157void afxXM_GroundConform::updateParams(F32 dt, F32 elapsed, afxXM_Params& params) 158{ 159 RayInfo rInfo; 160 bool hit = false; 161 162 if (db->do_interiors) 163 { 164 U32 mask = InteriorLikeObjectType; 165 if (db->do_terrain) 166 { 167 mask |= TerrainObjectType | TerrainLikeObjectType; 168 } 169 170 Point3F above_pos(params.pos); above_pos.z += 0.1f; 171 Point3F below_pos(params.pos); below_pos.z -= 10000; 172 hit = container->castRay(above_pos, below_pos, mask, &rInfo); 173 if (!hit) 174 { 175 above_pos.z = params.pos.z + 10000; 176 below_pos.z = params.pos.z - 0.1f; 177 hit = container->castRay(below_pos, above_pos, mask, &rInfo); 178 } 179 } 180 else if (db->do_terrain) 181 { 182 U32 mask = TerrainObjectType | TerrainLikeObjectType; 183 Point3F above_pos(params.pos); above_pos.z += 10000; 184 Point3F below_pos(params.pos); below_pos.z -= 10000; 185 hit = container->castRay(above_pos, below_pos, mask, &rInfo); 186 } 187 188 if (hit) 189 { 190 F32 terrain_z = rInfo.point.z; 191 F32 wt_factor = calc_weight_factor(elapsed); 192 F32 old_z = params.pos.z; 193 F32 new_z = terrain_z + db->height; 194 params.pos.z = ((1-wt_factor)*old_z) + ((wt_factor)*new_z); 195 196 if (db->do_orientation) 197 { 198 Point3F x,y,z; 199 z = rInfo.normal; 200 z.normalize(); 201 params.ori.getColumn(1,&y); 202 mCross(y,z,&x); 203 x.normalize(); 204 mCross(z,x,&y); 205 params.ori.setColumn(0,x); 206 params.ori.setColumn(1,y); 207 params.ori.setColumn(2,z); 208 } 209 } 210} 211 212//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 213 214