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