afxZodiacPlane.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  2. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  3. // Copyright (C) 2015 Faust Logic, Inc.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //
  23. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  24. #include "afx/arcaneFX.h"
  25. #include "math/mathIO.h"
  26. #include "renderInstance/renderPassManager.h"
  27. #include "afx/afxChoreographer.h"
  28. #include "afx/ce/afxZodiac.h"
  29. #include "afx/ce/afxZodiacPlane.h"
  30. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  31. // afxZodiacPlaneData
  32. IMPLEMENT_CO_DATABLOCK_V1(afxZodiacPlaneData);
  33. ConsoleDocClass( afxZodiacPlaneData,
  34. "@brief A datablock that specifies a Zodiac Plane effect.\n\n"
  35. "afxZodiacData describes a zodiac-like effect called a zodiac plane. It reproduces most of the behavior of normal zodiacs "
  36. "but unlike zodiac decals, it is represented as a flat plane of geometry that can be more flexibly positioned and oriented."
  37. "\n\n"
  38. "@ingroup afxEffects\n"
  39. "@ingroup AFX\n"
  40. "@ingroup Datablocks\n"
  41. );
  42. afxZodiacPlaneData::afxZodiacPlaneData()
  43. {
  44. txr_name = ST_NULLSTRING;
  45. radius_xy = 1;
  46. start_ang = 0;
  47. ang_per_sec = 0;
  48. grow_in_time = 0.0f;
  49. shrink_out_time = 0.0f;
  50. growth_rate = 0.0f;
  51. color.set(1,1,1,1);
  52. blend_flags = BLEND_NORMAL;
  53. respect_ori_cons = false;
  54. double_sided = true;
  55. face_dir = FACES_UP;
  56. use_full_xfm = false;
  57. }
  58. afxZodiacPlaneData::afxZodiacPlaneData(const afxZodiacPlaneData& other, bool temp_clone)
  59. : GameBaseData(other, temp_clone)
  60. {
  61. txr_name = other.txr_name;
  62. txr = other.txr;
  63. radius_xy = other.radius_xy;
  64. start_ang = other.start_ang;
  65. ang_per_sec = other.ang_per_sec;
  66. grow_in_time = other.grow_in_time;
  67. shrink_out_time = other.shrink_out_time;
  68. growth_rate = other.growth_rate;
  69. color = other.color;
  70. double_sided = other.double_sided;
  71. face_dir = other.face_dir;
  72. use_full_xfm = other.use_full_xfm;
  73. zflags = other.zflags;
  74. expand_zflags();
  75. }
  76. ImplementEnumType( afxZodiacPlane_BlendType, "Possible zodiac blend types.\n" "@ingroup afxZodiacPlane\n\n" )
  77. { afxZodiacData::BLEND_NORMAL, "normal", "..." },
  78. { afxZodiacData::BLEND_ADDITIVE, "additive", "..." },
  79. { afxZodiacData::BLEND_SUBTRACTIVE, "subtractive", "..." },
  80. EndImplementEnumType;
  81. ImplementEnumType( afxZodiacPlane_FacingType, "Possible zodiac plane facing types.\n" "@ingroup afxZodiacPlane\n\n" )
  82. { afxZodiacPlaneData::FACES_UP, "up", "..." },
  83. { afxZodiacPlaneData::FACES_DOWN, "down", "..." },
  84. { afxZodiacPlaneData::FACES_FORWARD, "forward", "..." },
  85. { afxZodiacPlaneData::FACES_BACK, "backward", "..." },
  86. { afxZodiacPlaneData::FACES_RIGHT, "right", "..." },
  87. { afxZodiacPlaneData::FACES_LEFT, "left", "..." },
  88. { afxZodiacPlaneData::FACES_FORWARD, "front", "..." },
  89. { afxZodiacPlaneData::FACES_BACK, "back", "..." },
  90. EndImplementEnumType;
  91. #define myOffset(field) Offset(field, afxZodiacPlaneData)
  92. void afxZodiacPlaneData::initPersistFields()
  93. {
  94. addField("texture", TypeFilename, myOffset(txr_name),
  95. "An image to use as the zodiac's texture.");
  96. addField("radius", TypeF32, myOffset(radius_xy),
  97. "The zodiac's radius in scene units.");
  98. addField("startAngle", TypeF32, myOffset(start_ang),
  99. "The starting angle in degrees of the zodiac's rotation.");
  100. addField("rotationRate", TypeF32, myOffset(ang_per_sec),
  101. "The rate of rotation in degrees-per-second. Zodiacs with a positive rotationRate "
  102. "rotate clockwise, while those with negative values turn counter-clockwise.");
  103. addField("growInTime", TypeF32, myOffset(grow_in_time),
  104. "A duration of time in seconds over which the zodiac grows from a zero size to its "
  105. "full size as specified by the radius.");
  106. addField("shrinkOutTime", TypeF32, myOffset(shrink_out_time),
  107. "A duration of time in seconds over which the zodiac shrinks from full size to "
  108. "invisible.");
  109. addField("growthRate", TypeF32, myOffset(growth_rate),
  110. "A rate in meters-per-second at which the zodiac grows in size. A negative value will "
  111. "shrink the zodiac.");
  112. addField("color", TypeColorF, myOffset(color),
  113. "A color value for the zodiac.");
  114. addField("blend", TYPEID<BlendType>(), myOffset(blend_flags),
  115. "A blending style for the zodiac. Possible values: normal, additive, or subtractive.");
  116. addField("trackOrientConstraint", TypeBool, myOffset(respect_ori_cons),
  117. "Specifies if the zodiac's rotation should be defined by its constrained "
  118. "transformation.");
  119. addField("doubleSided", TypeBool, myOffset(double_sided),
  120. "Controls whether the zodiac-plane's polygons are rendered when viewed from either "
  121. "side. If set to false, the zodiac-plane will only be seen when viewed from the "
  122. "direction it is facing (according to faceDir).");
  123. addField("faceDir", TYPEID<afxZodiacPlaneData::FacingType>(), myOffset(face_dir),
  124. "Specifies which direction the zodiac-plane's polygons face. Possible values: "
  125. "up, down, front, back, right, or left.");
  126. addField("useFullTransform", TypeBool, myOffset(use_full_xfm),
  127. "Normal zodiacs have only one degree of freedom, a rotation around the z-axis. "
  128. "Depending on the setting for trackOrientConstraint, this means that the effect's "
  129. "orientation is either ignored or is limited to influencing the zodiac's angle of "
  130. "rotation. By default, zodiac-plane reproduces this limited behavior in order to "
  131. "match normal zodiacs. When useFullTransform is set to true, the zodiac can be "
  132. "arbitrarily oriented.");
  133. Parent::initPersistFields();
  134. }
  135. void afxZodiacPlaneData::packData(BitStream* stream)
  136. {
  137. Parent::packData(stream);
  138. merge_zflags();
  139. stream->writeString(txr_name);
  140. stream->write(radius_xy);
  141. stream->write(start_ang);
  142. stream->write(ang_per_sec);
  143. stream->write(grow_in_time);
  144. stream->write(shrink_out_time);
  145. stream->write(growth_rate);
  146. stream->write(color);
  147. stream->write(zflags);
  148. stream->write(double_sided);
  149. stream->writeFlag(use_full_xfm);
  150. stream->writeInt(face_dir, FACES_BITS);
  151. }
  152. void afxZodiacPlaneData::unpackData(BitStream* stream)
  153. {
  154. Parent::unpackData(stream);
  155. txr_name = stream->readSTString();
  156. txr = GFXTexHandle();
  157. stream->read(&radius_xy);
  158. stream->read(&start_ang);
  159. stream->read(&ang_per_sec);
  160. stream->read(&grow_in_time);
  161. stream->read(&shrink_out_time);
  162. stream->read(&growth_rate);
  163. stream->read(&color);
  164. stream->read(&zflags);
  165. stream->read(&double_sided);
  166. use_full_xfm = stream->readFlag();
  167. face_dir = stream->readInt(FACES_BITS);
  168. expand_zflags();
  169. }
  170. bool afxZodiacPlaneData::preload(bool server, String &errorStr)
  171. {
  172. if (!Parent::preload(server, errorStr))
  173. return false;
  174. if (!server)
  175. {
  176. if (txr_name && txr_name[0] != '\0')
  177. {
  178. txr.set(txr_name, &AFX_GFXZodiacTextureProfile, "Zodiac Texture");
  179. }
  180. }
  181. return true;
  182. }
  183. F32 afxZodiacPlaneData::calcRotationAngle(F32 elapsed, F32 rate_factor)
  184. {
  185. F32 angle = start_ang + elapsed*ang_per_sec*rate_factor;
  186. angle = mFmod(angle, 360.0f);
  187. return angle;
  188. }
  189. void afxZodiacPlaneData::expand_zflags()
  190. {
  191. blend_flags = (zflags & BLEND_MASK);
  192. respect_ori_cons = ((zflags & RESPECT_ORIENTATION) != 0);
  193. }
  194. void afxZodiacPlaneData::merge_zflags()
  195. {
  196. zflags = (blend_flags & BLEND_MASK);
  197. if (respect_ori_cons)
  198. zflags |= RESPECT_ORIENTATION;
  199. }
  200. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  201. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  202. // afxZodiacPlane
  203. IMPLEMENT_CO_NETOBJECT_V1(afxZodiacPlane);
  204. ConsoleDocClass( afxZodiacPlane,
  205. "@brief A ZodiacPlane effect as defined by an afxZodiacPlaneData datablock.\n\n"
  206. "@ingroup afxEffects\n"
  207. "@ingroup AFX\n"
  208. );
  209. afxZodiacPlane::afxZodiacPlane()
  210. {
  211. mNetFlags.clear();
  212. mNetFlags.set(IsGhost);
  213. mDataBlock = 0;
  214. color.set(1,1,1,1);
  215. radius = 1;
  216. is_visible = true;
  217. }
  218. afxZodiacPlane::~afxZodiacPlane()
  219. {
  220. }
  221. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  222. bool afxZodiacPlane::onNewDataBlock(GameBaseData* dptr, bool reload)
  223. {
  224. mDataBlock = dynamic_cast<afxZodiacPlaneData*>(dptr);
  225. if (!mDataBlock || !Parent::onNewDataBlock(dptr, reload))
  226. return false;
  227. return true;
  228. }
  229. bool afxZodiacPlane::onAdd()
  230. {
  231. if(!Parent::onAdd())
  232. return false;
  233. F32 len = mDataBlock->radius_xy;
  234. switch (mDataBlock->face_dir)
  235. {
  236. case afxZodiacPlaneData::FACES_UP:
  237. case afxZodiacPlaneData::FACES_DOWN:
  238. mObjBox = Box3F(Point3F(-len, -len, -0.01f), Point3F(len, len, 0.01f));
  239. break;
  240. case afxZodiacPlaneData::FACES_FORWARD:
  241. case afxZodiacPlaneData::FACES_BACK:
  242. mObjBox = Box3F(Point3F(-len, -0.01f, -len), Point3F(len, 0.01f, len));
  243. break;
  244. case afxZodiacPlaneData::FACES_RIGHT:
  245. case afxZodiacPlaneData::FACES_LEFT:
  246. mObjBox = Box3F(Point3F(-0.01f, -len, -len), Point3F(0.01f, len, len));
  247. break;
  248. }
  249. addToScene();
  250. return true;
  251. }
  252. void afxZodiacPlane::onRemove()
  253. {
  254. removeFromScene();
  255. Parent::onRemove();
  256. }
  257. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//