afxZodiacPlane.cpp 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. INIT_ASSET(Texture);
  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. zflags = 0;
  55. double_sided = true;
  56. face_dir = FACES_UP;
  57. use_full_xfm = false;
  58. }
  59. afxZodiacPlaneData::afxZodiacPlaneData(const afxZodiacPlaneData& other, bool temp_clone)
  60. : GameBaseData(other, temp_clone)
  61. {
  62. CLONE_ASSET(Texture);
  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. docsURL;
  95. INITPERSISTFIELD_IMAGEASSET(Texture, afxZodiacPlaneData, "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. PACKDATA_ASSET(Texture);
  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. UNPACKDATA_ASSET(Texture);
  156. stream->read(&radius_xy);
  157. stream->read(&start_ang);
  158. stream->read(&ang_per_sec);
  159. stream->read(&grow_in_time);
  160. stream->read(&shrink_out_time);
  161. stream->read(&growth_rate);
  162. stream->read(&color);
  163. stream->read(&zflags);
  164. stream->read(&double_sided);
  165. use_full_xfm = stream->readFlag();
  166. face_dir = stream->readInt(FACES_BITS);
  167. expand_zflags();
  168. }
  169. bool afxZodiacPlaneData::preload(bool server, String &errorStr)
  170. {
  171. if (!Parent::preload(server, errorStr))
  172. return false;
  173. return true;
  174. }
  175. F32 afxZodiacPlaneData::calcRotationAngle(F32 elapsed, F32 rate_factor)
  176. {
  177. F32 angle = start_ang + elapsed*ang_per_sec*rate_factor;
  178. angle = mFmod(angle, 360.0f);
  179. return angle;
  180. }
  181. void afxZodiacPlaneData::expand_zflags()
  182. {
  183. blend_flags = (zflags & BLEND_MASK);
  184. respect_ori_cons = ((zflags & RESPECT_ORIENTATION) != 0);
  185. }
  186. void afxZodiacPlaneData::merge_zflags()
  187. {
  188. zflags = (blend_flags & BLEND_MASK);
  189. if (respect_ori_cons)
  190. zflags |= RESPECT_ORIENTATION;
  191. }
  192. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  193. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  194. // afxZodiacPlane
  195. IMPLEMENT_CO_NETOBJECT_V1(afxZodiacPlane);
  196. ConsoleDocClass( afxZodiacPlane,
  197. "@brief A ZodiacPlane effect as defined by an afxZodiacPlaneData datablock.\n\n"
  198. "@ingroup afxEffects\n"
  199. "@ingroup AFX\n"
  200. );
  201. afxZodiacPlane::afxZodiacPlane()
  202. {
  203. mNetFlags.clear();
  204. mNetFlags.set(IsGhost);
  205. mDataBlock = 0;
  206. color.set(1,1,1,1);
  207. radius = 1;
  208. is_visible = true;
  209. }
  210. afxZodiacPlane::~afxZodiacPlane()
  211. {
  212. }
  213. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  214. bool afxZodiacPlane::onNewDataBlock(GameBaseData* dptr, bool reload)
  215. {
  216. mDataBlock = dynamic_cast<afxZodiacPlaneData*>(dptr);
  217. if (!mDataBlock || !Parent::onNewDataBlock(dptr, reload))
  218. return false;
  219. return true;
  220. }
  221. bool afxZodiacPlane::onAdd()
  222. {
  223. if(!Parent::onAdd())
  224. return false;
  225. F32 len = mDataBlock->radius_xy;
  226. switch (mDataBlock->face_dir)
  227. {
  228. case afxZodiacPlaneData::FACES_UP:
  229. case afxZodiacPlaneData::FACES_DOWN:
  230. mObjBox = Box3F(Point3F(-len, -len, -0.01f), Point3F(len, len, 0.01f));
  231. break;
  232. case afxZodiacPlaneData::FACES_FORWARD:
  233. case afxZodiacPlaneData::FACES_BACK:
  234. mObjBox = Box3F(Point3F(-len, -0.01f, -len), Point3F(len, 0.01f, len));
  235. break;
  236. case afxZodiacPlaneData::FACES_RIGHT:
  237. case afxZodiacPlaneData::FACES_LEFT:
  238. mObjBox = Box3F(Point3F(-0.01f, -len, -len), Point3F(0.01f, len, len));
  239. break;
  240. }
  241. addToScene();
  242. return true;
  243. }
  244. void afxZodiacPlane::onRemove()
  245. {
  246. removeFromScene();
  247. Parent::onRemove();
  248. }
  249. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//