afxZodiacPlane.cpp 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. INITPERSISTFIELD_IMAGEASSET(Texture, afxZodiacPlaneData, "An image to use as the zodiac's texture.");
  95. addField("radius", TypeF32, myOffset(radius_xy),
  96. "The zodiac's radius in scene units.");
  97. addField("startAngle", TypeF32, myOffset(start_ang),
  98. "The starting angle in degrees of the zodiac's rotation.");
  99. addField("rotationRate", TypeF32, myOffset(ang_per_sec),
  100. "The rate of rotation in degrees-per-second. Zodiacs with a positive rotationRate "
  101. "rotate clockwise, while those with negative values turn counter-clockwise.");
  102. addField("growInTime", TypeF32, myOffset(grow_in_time),
  103. "A duration of time in seconds over which the zodiac grows from a zero size to its "
  104. "full size as specified by the radius.");
  105. addField("shrinkOutTime", TypeF32, myOffset(shrink_out_time),
  106. "A duration of time in seconds over which the zodiac shrinks from full size to "
  107. "invisible.");
  108. addField("growthRate", TypeF32, myOffset(growth_rate),
  109. "A rate in meters-per-second at which the zodiac grows in size. A negative value will "
  110. "shrink the zodiac.");
  111. addField("color", TypeColorF, myOffset(color),
  112. "A color value for the zodiac.");
  113. addField("blend", TYPEID<BlendType>(), myOffset(blend_flags),
  114. "A blending style for the zodiac. Possible values: normal, additive, or subtractive.");
  115. addField("trackOrientConstraint", TypeBool, myOffset(respect_ori_cons),
  116. "Specifies if the zodiac's rotation should be defined by its constrained "
  117. "transformation.");
  118. addField("doubleSided", TypeBool, myOffset(double_sided),
  119. "Controls whether the zodiac-plane's polygons are rendered when viewed from either "
  120. "side. If set to false, the zodiac-plane will only be seen when viewed from the "
  121. "direction it is facing (according to faceDir).");
  122. addField("faceDir", TYPEID<afxZodiacPlaneData::FacingType>(), myOffset(face_dir),
  123. "Specifies which direction the zodiac-plane's polygons face. Possible values: "
  124. "up, down, front, back, right, or left.");
  125. addField("useFullTransform", TypeBool, myOffset(use_full_xfm),
  126. "Normal zodiacs have only one degree of freedom, a rotation around the z-axis. "
  127. "Depending on the setting for trackOrientConstraint, this means that the effect's "
  128. "orientation is either ignored or is limited to influencing the zodiac's angle of "
  129. "rotation. By default, zodiac-plane reproduces this limited behavior in order to "
  130. "match normal zodiacs. When useFullTransform is set to true, the zodiac can be "
  131. "arbitrarily oriented.");
  132. Parent::initPersistFields();
  133. }
  134. void afxZodiacPlaneData::packData(BitStream* stream)
  135. {
  136. Parent::packData(stream);
  137. merge_zflags();
  138. PACKDATA_ASSET(Texture);
  139. stream->write(radius_xy);
  140. stream->write(start_ang);
  141. stream->write(ang_per_sec);
  142. stream->write(grow_in_time);
  143. stream->write(shrink_out_time);
  144. stream->write(growth_rate);
  145. stream->write(color);
  146. stream->write(zflags);
  147. stream->write(double_sided);
  148. stream->writeFlag(use_full_xfm);
  149. stream->writeInt(face_dir, FACES_BITS);
  150. }
  151. void afxZodiacPlaneData::unpackData(BitStream* stream)
  152. {
  153. Parent::unpackData(stream);
  154. UNPACKDATA_ASSET(Texture);
  155. stream->read(&radius_xy);
  156. stream->read(&start_ang);
  157. stream->read(&ang_per_sec);
  158. stream->read(&grow_in_time);
  159. stream->read(&shrink_out_time);
  160. stream->read(&growth_rate);
  161. stream->read(&color);
  162. stream->read(&zflags);
  163. stream->read(&double_sided);
  164. use_full_xfm = stream->readFlag();
  165. face_dir = stream->readInt(FACES_BITS);
  166. expand_zflags();
  167. }
  168. bool afxZodiacPlaneData::preload(bool server, String &errorStr)
  169. {
  170. if (!Parent::preload(server, errorStr))
  171. return false;
  172. return true;
  173. }
  174. F32 afxZodiacPlaneData::calcRotationAngle(F32 elapsed, F32 rate_factor)
  175. {
  176. F32 angle = start_ang + elapsed*ang_per_sec*rate_factor;
  177. angle = mFmod(angle, 360.0f);
  178. return angle;
  179. }
  180. void afxZodiacPlaneData::expand_zflags()
  181. {
  182. blend_flags = (zflags & BLEND_MASK);
  183. respect_ori_cons = ((zflags & RESPECT_ORIENTATION) != 0);
  184. }
  185. void afxZodiacPlaneData::merge_zflags()
  186. {
  187. zflags = (blend_flags & BLEND_MASK);
  188. if (respect_ori_cons)
  189. zflags |= RESPECT_ORIENTATION;
  190. }
  191. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  192. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  193. // afxZodiacPlane
  194. IMPLEMENT_CO_NETOBJECT_V1(afxZodiacPlane);
  195. ConsoleDocClass( afxZodiacPlane,
  196. "@brief A ZodiacPlane effect as defined by an afxZodiacPlaneData datablock.\n\n"
  197. "@ingroup afxEffects\n"
  198. "@ingroup AFX\n"
  199. );
  200. afxZodiacPlane::afxZodiacPlane()
  201. {
  202. mNetFlags.clear();
  203. mNetFlags.set(IsGhost);
  204. mDataBlock = 0;
  205. color.set(1,1,1,1);
  206. radius = 1;
  207. is_visible = true;
  208. }
  209. afxZodiacPlane::~afxZodiacPlane()
  210. {
  211. }
  212. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
  213. bool afxZodiacPlane::onNewDataBlock(GameBaseData* dptr, bool reload)
  214. {
  215. mDataBlock = dynamic_cast<afxZodiacPlaneData*>(dptr);
  216. if (!mDataBlock || !Parent::onNewDataBlock(dptr, reload))
  217. return false;
  218. return true;
  219. }
  220. bool afxZodiacPlane::onAdd()
  221. {
  222. if(!Parent::onAdd())
  223. return false;
  224. F32 len = mDataBlock->radius_xy;
  225. switch (mDataBlock->face_dir)
  226. {
  227. case afxZodiacPlaneData::FACES_UP:
  228. case afxZodiacPlaneData::FACES_DOWN:
  229. mObjBox = Box3F(Point3F(-len, -len, -0.01f), Point3F(len, len, 0.01f));
  230. break;
  231. case afxZodiacPlaneData::FACES_FORWARD:
  232. case afxZodiacPlaneData::FACES_BACK:
  233. mObjBox = Box3F(Point3F(-len, -0.01f, -len), Point3F(len, 0.01f, len));
  234. break;
  235. case afxZodiacPlaneData::FACES_RIGHT:
  236. case afxZodiacPlaneData::FACES_LEFT:
  237. mObjBox = Box3F(Point3F(-0.01f, -len, -len), Point3F(0.01f, len, len));
  238. break;
  239. }
  240. addToScene();
  241. return true;
  242. }
  243. void afxZodiacPlane::onRemove()
  244. {
  245. removeFromScene();
  246. Parent::onRemove();
  247. }
  248. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//