123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include "AnchorPresets.h"
- namespace
- {
- static AZ::Vector4 presets[ AnchorPresets::PresetIndexCount ] =
- {
- AZ::Vector4(0.0f, 0.0f, 0.0f, 0.0f),
- AZ::Vector4(0.5f, 0.0f, 0.5f, 0.0f),
- AZ::Vector4(1.0f, 0.0f, 1.0f, 0.0f),
- AZ::Vector4(0.0f, 0.0f, 1.0f, 0.0f),
- AZ::Vector4(0.0f, 0.5f, 0.0f, 0.5f),
- AZ::Vector4(0.5f, 0.5f, 0.5f, 0.5f),
- AZ::Vector4(1.0f, 0.5f, 1.0f, 0.5f),
- AZ::Vector4(0.0f, 0.5f, 1.0f, 0.5f),
- AZ::Vector4(0.0f, 1.0f, 0.0f, 1.0f),
- AZ::Vector4(0.5f, 1.0f, 0.5f, 1.0f),
- AZ::Vector4(1.0f, 1.0f, 1.0f, 1.0f),
- AZ::Vector4(0.0f, 1.0f, 1.0f, 1.0f),
- AZ::Vector4(0.0f, 0.0f, 0.0f, 1.0f),
- AZ::Vector4(0.5f, 0.0f, 0.5f, 1.0f),
- AZ::Vector4(1.0f, 0.0f, 1.0f, 1.0f),
- AZ::Vector4(0.0f, 0.0f, 1.0f, 1.0f)
- };
- static_assert(AnchorPresets::PresetIndexCount == AZ_ARRAY_SIZE(presets), "presets and PresetIndexCount MUST be the same size.");
- } // anonymous namespace.
- namespace AnchorPresets
- {
- const AZ::Vector4& PresetIndexToAnchor(int i)
- {
- if ((i >= 0) && (i < PresetIndexCount))
- {
- return presets[ i ];
- }
- else
- {
- AZ_Assert(0, "Invalid preset index");
- return presets[ 0 ];
- }
- }
- int AnchorToPresetIndex(const AZ::Vector4& v)
- {
- float x = v.GetX();
- float y = v.GetY();
- float z = v.GetZ();
- float w = v.GetW();
- if (x == 0.0f)
- {
- if (y == 0.0f)
- {
- if (z == 0.0f)
- {
- if (w == 0.0f)
- {
- // 0: AZ::Vector4( 0.0f, 0.0f, 0.0f, 0.0f )
- return 0;
- }
- else if (w == 1.0f)
- {
- // 12: AZ::Vector4( 0.0f, 0.0f, 0.0f, 1.0f )
- return 12;
- }
- else
- {
- return -1;
- }
- }
- else if (z == 1.0f)
- {
- if (w == 0.0f)
- {
- // 3: AZ::Vector4( 0.0f, 0.0f, 1.0f, 0.0f )
- return 3;
- }
- else if (w == 1.0f)
- {
- // 15: AZ::Vector4( 0.0f, 0.0f, 1.0f, 1.0f )
- return 15;
- }
- else
- {
- return -1;
- }
- }
- else
- {
- return -1;
- }
- }
- else if (y == 0.5f)
- {
- if (w == 0.5f)
- {
- if (z == 0.0f)
- {
- // 4: AZ::Vector4( 0.0f, 0.5f, 0.0f, 0.5f )
- return 4;
- }
- else if (z == 1.0f)
- {
- // 7: AZ::Vector4( 0.0f, 0.5f, 1.0f, 0.5f )
- return 7;
- }
- else
- {
- return -1;
- }
- }
- else
- {
- return -1;
- }
- }
- else if (y == 1.0f)
- {
- if (w == 1.0f)
- {
- if (z == 0.0f)
- {
- // 8: AZ::Vector4( 0.0f, 1.0f, 0.0f, 1.0f )
- return 8;
- }
- else if (z == 1.0f)
- {
- // 11: AZ::Vector4( 0.0f, 1.0f, 1.0f, 1.0f )
- return 11;
- }
- else
- {
- return -1;
- }
- }
- else
- {
- return -1;
- }
- }
- else
- {
- return -1;
- }
- }
- else if (x == 0.5f)
- {
- if (y == 0.0f)
- {
- if (z == 0.5f)
- {
- if (w == 0.0f)
- {
- // 1 AZ::Vector4( 0.5f, 0.0f, 0.5f, 0.0f )
- return 1;
- }
- else if (w == 1.0f)
- {
- // 13 AZ::Vector4( 0.5f, 0.0f, 0.5f, 1.0f )
- return 13;
- }
- else
- {
- return -1;
- }
- }
- else
- {
- return -1;
- }
- }
- else if (z == 0.5f)
- {
- if (y == 0.5f)
- {
- if (w == 0.5f)
- {
- // 5 AZ::Vector4( 0.5f, 0.5f, 0.5f, 0.5f )
- return 5;
- }
- else
- {
- return -1;
- }
- }
- else if (y == 1.0f)
- {
- if (w == 1.0f)
- {
- // 9 AZ::Vector4( 0.5f, 1.0f, 0.5f, 1.0f )
- return 9;
- }
- else
- {
- return -1;
- }
- }
- else
- {
- return -1;
- }
- }
- else
- {
- return -1;
- }
- }
- else if (x == 1.0f)
- {
- if (z == 1.0f)
- {
- if (y == 0.0f)
- {
- if (w == 0.0f)
- {
- // 2: AZ::Vector4( 1.0f, 0.0f, 1.0f, 0.0f )
- return 2;
- }
- else if (w == 1.0f)
- {
- // 14: AZ::Vector4( 1.0f, 0.0f, 1.0f, 1.0f )
- return 14;
- }
- else
- {
- return -1;
- }
- }
- else if (y == 0.5f)
- {
- if (w == 0.5f)
- {
- // 6: AZ::Vector4( 1.0f, 0.5f, 1.0f, 0.5f )
- return 6;
- }
- else
- {
- return -1;
- }
- }
- else if (y == 1.0f)
- {
- if (w == 1.0f)
- {
- // 10: AZ::Vector4( 1.0f, 1.0f, 1.0f, 1.0f )
- return 10;
- }
- else
- {
- return -1;
- }
- }
- else
- {
- return -1;
- }
- }
- else
- {
- return -1;
- }
- }
- else
- {
- return -1;
- }
- }
- } // namespace AnchorPresets
|