AnchorPresets.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "AnchorPresets.h"
  9. namespace
  10. {
  11. static AZ::Vector4 presets[ AnchorPresets::PresetIndexCount ] =
  12. {
  13. AZ::Vector4(0.0f, 0.0f, 0.0f, 0.0f),
  14. AZ::Vector4(0.5f, 0.0f, 0.5f, 0.0f),
  15. AZ::Vector4(1.0f, 0.0f, 1.0f, 0.0f),
  16. AZ::Vector4(0.0f, 0.0f, 1.0f, 0.0f),
  17. AZ::Vector4(0.0f, 0.5f, 0.0f, 0.5f),
  18. AZ::Vector4(0.5f, 0.5f, 0.5f, 0.5f),
  19. AZ::Vector4(1.0f, 0.5f, 1.0f, 0.5f),
  20. AZ::Vector4(0.0f, 0.5f, 1.0f, 0.5f),
  21. AZ::Vector4(0.0f, 1.0f, 0.0f, 1.0f),
  22. AZ::Vector4(0.5f, 1.0f, 0.5f, 1.0f),
  23. AZ::Vector4(1.0f, 1.0f, 1.0f, 1.0f),
  24. AZ::Vector4(0.0f, 1.0f, 1.0f, 1.0f),
  25. AZ::Vector4(0.0f, 0.0f, 0.0f, 1.0f),
  26. AZ::Vector4(0.5f, 0.0f, 0.5f, 1.0f),
  27. AZ::Vector4(1.0f, 0.0f, 1.0f, 1.0f),
  28. AZ::Vector4(0.0f, 0.0f, 1.0f, 1.0f)
  29. };
  30. static_assert(AnchorPresets::PresetIndexCount == AZ_ARRAY_SIZE(presets), "presets and PresetIndexCount MUST be the same size.");
  31. } // anonymous namespace.
  32. namespace AnchorPresets
  33. {
  34. const AZ::Vector4& PresetIndexToAnchor(int i)
  35. {
  36. if ((i >= 0) && (i < PresetIndexCount))
  37. {
  38. return presets[ i ];
  39. }
  40. else
  41. {
  42. AZ_Assert(0, "Invalid preset index");
  43. return presets[ 0 ];
  44. }
  45. }
  46. int AnchorToPresetIndex(const AZ::Vector4& v)
  47. {
  48. float x = v.GetX();
  49. float y = v.GetY();
  50. float z = v.GetZ();
  51. float w = v.GetW();
  52. if (x == 0.0f)
  53. {
  54. if (y == 0.0f)
  55. {
  56. if (z == 0.0f)
  57. {
  58. if (w == 0.0f)
  59. {
  60. // 0: AZ::Vector4( 0.0f, 0.0f, 0.0f, 0.0f )
  61. return 0;
  62. }
  63. else if (w == 1.0f)
  64. {
  65. // 12: AZ::Vector4( 0.0f, 0.0f, 0.0f, 1.0f )
  66. return 12;
  67. }
  68. else
  69. {
  70. return -1;
  71. }
  72. }
  73. else if (z == 1.0f)
  74. {
  75. if (w == 0.0f)
  76. {
  77. // 3: AZ::Vector4( 0.0f, 0.0f, 1.0f, 0.0f )
  78. return 3;
  79. }
  80. else if (w == 1.0f)
  81. {
  82. // 15: AZ::Vector4( 0.0f, 0.0f, 1.0f, 1.0f )
  83. return 15;
  84. }
  85. else
  86. {
  87. return -1;
  88. }
  89. }
  90. else
  91. {
  92. return -1;
  93. }
  94. }
  95. else if (y == 0.5f)
  96. {
  97. if (w == 0.5f)
  98. {
  99. if (z == 0.0f)
  100. {
  101. // 4: AZ::Vector4( 0.0f, 0.5f, 0.0f, 0.5f )
  102. return 4;
  103. }
  104. else if (z == 1.0f)
  105. {
  106. // 7: AZ::Vector4( 0.0f, 0.5f, 1.0f, 0.5f )
  107. return 7;
  108. }
  109. else
  110. {
  111. return -1;
  112. }
  113. }
  114. else
  115. {
  116. return -1;
  117. }
  118. }
  119. else if (y == 1.0f)
  120. {
  121. if (w == 1.0f)
  122. {
  123. if (z == 0.0f)
  124. {
  125. // 8: AZ::Vector4( 0.0f, 1.0f, 0.0f, 1.0f )
  126. return 8;
  127. }
  128. else if (z == 1.0f)
  129. {
  130. // 11: AZ::Vector4( 0.0f, 1.0f, 1.0f, 1.0f )
  131. return 11;
  132. }
  133. else
  134. {
  135. return -1;
  136. }
  137. }
  138. else
  139. {
  140. return -1;
  141. }
  142. }
  143. else
  144. {
  145. return -1;
  146. }
  147. }
  148. else if (x == 0.5f)
  149. {
  150. if (y == 0.0f)
  151. {
  152. if (z == 0.5f)
  153. {
  154. if (w == 0.0f)
  155. {
  156. // 1 AZ::Vector4( 0.5f, 0.0f, 0.5f, 0.0f )
  157. return 1;
  158. }
  159. else if (w == 1.0f)
  160. {
  161. // 13 AZ::Vector4( 0.5f, 0.0f, 0.5f, 1.0f )
  162. return 13;
  163. }
  164. else
  165. {
  166. return -1;
  167. }
  168. }
  169. else
  170. {
  171. return -1;
  172. }
  173. }
  174. else if (z == 0.5f)
  175. {
  176. if (y == 0.5f)
  177. {
  178. if (w == 0.5f)
  179. {
  180. // 5 AZ::Vector4( 0.5f, 0.5f, 0.5f, 0.5f )
  181. return 5;
  182. }
  183. else
  184. {
  185. return -1;
  186. }
  187. }
  188. else if (y == 1.0f)
  189. {
  190. if (w == 1.0f)
  191. {
  192. // 9 AZ::Vector4( 0.5f, 1.0f, 0.5f, 1.0f )
  193. return 9;
  194. }
  195. else
  196. {
  197. return -1;
  198. }
  199. }
  200. else
  201. {
  202. return -1;
  203. }
  204. }
  205. else
  206. {
  207. return -1;
  208. }
  209. }
  210. else if (x == 1.0f)
  211. {
  212. if (z == 1.0f)
  213. {
  214. if (y == 0.0f)
  215. {
  216. if (w == 0.0f)
  217. {
  218. // 2: AZ::Vector4( 1.0f, 0.0f, 1.0f, 0.0f )
  219. return 2;
  220. }
  221. else if (w == 1.0f)
  222. {
  223. // 14: AZ::Vector4( 1.0f, 0.0f, 1.0f, 1.0f )
  224. return 14;
  225. }
  226. else
  227. {
  228. return -1;
  229. }
  230. }
  231. else if (y == 0.5f)
  232. {
  233. if (w == 0.5f)
  234. {
  235. // 6: AZ::Vector4( 1.0f, 0.5f, 1.0f, 0.5f )
  236. return 6;
  237. }
  238. else
  239. {
  240. return -1;
  241. }
  242. }
  243. else if (y == 1.0f)
  244. {
  245. if (w == 1.0f)
  246. {
  247. // 10: AZ::Vector4( 1.0f, 1.0f, 1.0f, 1.0f )
  248. return 10;
  249. }
  250. else
  251. {
  252. return -1;
  253. }
  254. }
  255. else
  256. {
  257. return -1;
  258. }
  259. }
  260. else
  261. {
  262. return -1;
  263. }
  264. }
  265. else
  266. {
  267. return -1;
  268. }
  269. }
  270. } // namespace AnchorPresets