

Divide-Dependencies
This repository has no backups
This repository's network speed is throttled to 100KB/sec
Upgrade your account to fix these warnings, or use backups.vc for automated backups
@ 70
Divide-Dependencies / debug-draw / samples / vectormath / SSE / cpp / vectormath_aos.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 |
/* Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Sony Computer Entertainment Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _VECTORMATH_AOS_CPP_SSE_H #define _VECTORMATH_AOS_CPP_SSE_H #include "defines.h" #include <math.h> #include <xmmintrin.h> #include <emmintrin.h> #include <assert.h> typedef __m128 vec_float4; typedef __m128 vec_uint4; typedef __m128 vec_int4; typedef __m128i vec_uchar16; typedef __m128i vec_ushort8; #define _mm_ror_ps(vec, i) (((i)%4) ? (_mm_shuffle_ps(vec,vec, _MM_SHUFFLE((unsigned char)(i+3)%4,(unsigned char)(i+2)%4,(unsigned char)(i+1)%4,(unsigned char)(i+0)%4))) : (vec)) #define _mm_rol_ps(vec, i) (((i)%4) ? (_mm_shuffle_ps(vec,vec, _MM_SHUFFLE((unsigned char)(7-i)%4,(unsigned char)(6-i)%4,(unsigned char)(5-i)%4,(unsigned char)(4-i)%4))) : (vec)) #define _mm_abs_ps(vec) _mm_andnot_ps(_MASKSIGN_,vec) #define _mm_neg_ps(vec) _mm_xor_ps(_MASKSIGN_,vec) #define vec_splat(x, e) _mm_shuffle_ps(x, x, _MM_SHUFFLE(e, e, e, e)) #define vec_madd(a, b, c) _mm_add_ps(c, _mm_mul_ps(a, b) ) #define vec_sld(vec, vec2, x) _mm_ror_ps(vec, ((x)/4)) union SSEFloat { __m128 m128; float f[4]; }; static inline __m128 vec_sel(__m128 a, __m128 b, __m128 mask) { return _mm_or_ps(_mm_and_ps(mask, b), _mm_andnot_ps(mask, a)); } static inline __m128 vec_sel(__m128 a, __m128 b, const unsigned int *_mask) { return vec_sel(a, b, _mm_load_ps((float *)_mask)); } static inline __m128 vec_sel(__m128 a, __m128 b, unsigned int _mask) { return vec_sel(a, b, _mm_set1_ps(*(float *)&_mask)); } static inline __m128 toM128(unsigned int x) { return _mm_set1_ps( *(float *)&x ); } static inline __m128 fabsf4(__m128 x) { return _mm_and_ps(x, toM128(0x7fffffff)); } /* union SSE64 { __m128 m128; struct { __m64 m01; __m64 m23; } m64; }; static inline __m128 vec_cts(__m128 x, int a) { assert(a == 0); // Only 2^0 supported (void)a; SSE64 sse64; sse64.m64.m01 = _mm_cvttps_pi32(x); sse64.m64.m23 = _mm_cvttps_pi32(_mm_ror_ps(x,2)); _mm_empty(); return sse64.m128; } static inline __m128 vec_ctf(__m128 x, int a) { assert(a == 0); // Only 2^0 supported (void)a; SSE64 sse64; sse64.m128 = x; __m128 result =_mm_movelh_ps( _mm_cvt_pi2ps(_mm_setzero_ps(), sse64.m64.m01), _mm_cvt_pi2ps(_mm_setzero_ps(), sse64.m64.m23)); _mm_empty(); return result; } */ static inline __m128 vec_cts(__m128 x, int a) { assert(a == 0); // Only 2^0 supported (void)a; __m128i result = _mm_cvtps_epi32(x); return (__m128 &)result; } static inline __m128 vec_ctf(__m128 x, int a) { assert(a == 0); // Only 2^0 supported (void)a; return _mm_cvtepi32_ps((__m128i &)x); } #define vec_nmsub(a, b, c) _mm_sub_ps( c, _mm_mul_ps( a, b ) ) #define vec_sub(a, b) _mm_sub_ps( a, b ) #define vec_add(a, b) _mm_add_ps( a, b ) #define vec_mul(a, b) _mm_mul_ps( a, b ) #define vec_xor(a, b) _mm_xor_ps( a, b ) #define vec_and(a, b) _mm_and_ps( a, b ) #define vec_cmpeq(a, b) _mm_cmpeq_ps( a, b ) #define vec_cmpgt(a, b) _mm_cmpgt_ps( a, b ) #define vec_mergeh(a, b) _mm_unpacklo_ps( a, b ) #define vec_mergel(a, b) _mm_unpackhi_ps( a, b ) #define vec_andc(a, b) _mm_andnot_ps( b, a ) #define sqrtf4(x) _mm_sqrt_ps( x ) #define rsqrtf4(x) _mm_rsqrt_ps( x ) #define recipf4(x) _mm_rcp_ps( x ) #define negatef4(x) _mm_sub_ps( _mm_setzero_ps(), x ) static inline __m128 newtonrapson_rsqrt4( const __m128 v ) { #define _half4 _mm_setr_ps(0.5f, 0.5f, 0.5f, 0.5f) #define _three _mm_setr_ps(3.0f, 3.0f, 3.0f, 3.0f) const __m128 approx = _mm_rsqrt_ps(v); const __m128 muls = _mm_mul_ps(_mm_mul_ps(v, approx), approx); return _mm_mul_ps(_mm_mul_ps(_half4, approx), _mm_sub_ps(_three, muls) ); } static inline __m128 acosf4(__m128 x) { __m128 xabs = fabsf4(x); __m128 select = _mm_cmplt_ps( x, _mm_setzero_ps() ); __m128 t1 = sqrtf4(vec_sub(_mm_set1_ps(1.0f), xabs)); /* Instruction counts can be reduced if the polynomial was * computed entirely from nested (dependent) fma's. However, * to reduce the number of pipeline stalls, the polygon is evaluated * in two halves (hi and lo). */ __m128 xabs2 = _mm_mul_ps(xabs, xabs); __m128 xabs4 = _mm_mul_ps(xabs2, xabs2); __m128 hi = vec_madd(vec_madd(vec_madd(_mm_set1_ps(-0.0012624911f), xabs, _mm_set1_ps(0.0066700901f)), xabs, _mm_set1_ps(-0.0170881256f)), xabs, _mm_set1_ps( 0.0308918810f)); __m128 lo = vec_madd(vec_madd(vec_madd(_mm_set1_ps(-0.0501743046f), xabs, _mm_set1_ps(0.0889789874f)), xabs, _mm_set1_ps(-0.2145988016f)), xabs, _mm_set1_ps( 1.5707963050f)); __m128 result = vec_madd(hi, xabs4, lo); // Adjust the result if x is negative. return vec_sel( vec_mul(t1, result), // Positive vec_nmsub(t1, result, _mm_set1_ps(3.1415926535898f)), // Negative select); } static inline __m128 sinf4(vec_float4 x) { // // Common constants used to evaluate sinf4/cosf4/tanf4 // #define _SINCOS_CC0 -0.0013602249f #define _SINCOS_CC1 0.0416566950f #define _SINCOS_CC2 -0.4999990225f #define _SINCOS_SC0 -0.0001950727f #define _SINCOS_SC1 0.0083320758f #define _SINCOS_SC2 -0.1666665247f #define _SINCOS_KC1 1.57079625129f #define _SINCOS_KC2 7.54978995489e-8f vec_float4 xl,xl2,xl3,res; // Range reduction using : xl = angle * TwoOverPi; // xl = vec_mul(x, _mm_set1_ps(0.63661977236f)); // Find the quadrant the angle falls in // using: q = (int) (ceil(abs(xl))*sign(xl)) // vec_int4 q = vec_cts(xl,0); // Compute an offset based on the quadrant that the angle falls in // vec_int4 offset = _mm_and_ps(q,toM128(0x3)); // Remainder in range [-pi/4..pi/4] // vec_float4 qf = vec_ctf(q,0); xl = vec_nmsub(qf,_mm_set1_ps(_SINCOS_KC2),vec_nmsub(qf,_mm_set1_ps(_SINCOS_KC1),x)); // Compute x^2 and x^3 // xl2 = vec_mul(xl,xl); xl3 = vec_mul(xl2,xl); // Compute both the sin and cos of the angles // using a polynomial expression: // cx = 1.0f + xl2 * ((C0 * xl2 + C1) * xl2 + C2), and // sx = xl + xl3 * ((S0 * xl2 + S1) * xl2 + S2) // vec_float4 cx = vec_madd( vec_madd( vec_madd(_mm_set1_ps(_SINCOS_CC0),xl2,_mm_set1_ps(_SINCOS_CC1)),xl2,_mm_set1_ps(_SINCOS_CC2)),xl2,_mm_set1_ps(1.0f)); vec_float4 sx = vec_madd( vec_madd( vec_madd(_mm_set1_ps(_SINCOS_SC0),xl2,_mm_set1_ps(_SINCOS_SC1)),xl2,_mm_set1_ps(_SINCOS_SC2)),xl3,xl); // Use the cosine when the offset is odd and the sin // when the offset is even // res = vec_sel(cx,sx,vec_cmpeq(vec_and(offset, toM128(0x1)), _mm_setzero_ps())); // Flip the sign of the result when (offset mod 4) = 1 or 2 // return vec_sel( vec_xor(toM128(0x80000000U), res), // Negative res, // Positive vec_cmpeq(vec_and(offset,toM128(0x2)),_mm_setzero_ps())); } static inline void sincosf4(vec_float4 x, vec_float4* s, vec_float4* c) { vec_float4 xl,xl2,xl3; vec_int4 offsetSin, offsetCos; // Range reduction using : xl = angle * TwoOverPi; // xl = vec_mul(x, _mm_set1_ps(0.63661977236f)); // Find the quadrant the angle falls in // using: q = (int) (ceil(abs(xl))*sign(xl)) // //vec_int4 q = vec_cts(vec_add(xl,vec_sel(_mm_set1_ps(0.5f),xl,(0x80000000))),0); vec_int4 q = vec_cts(xl,0); // Compute the offset based on the quadrant that the angle falls in. // Add 1 to the offset for the cosine. // offsetSin = vec_and(q,toM128((int)0x3)); __m128i temp = _mm_add_epi32(_mm_set1_epi32(1),(__m128i &)offsetSin); offsetCos = (__m128 &)temp; // Remainder in range [-pi/4..pi/4] // vec_float4 qf = vec_ctf(q,0); xl = vec_nmsub(qf,_mm_set1_ps(_SINCOS_KC2),vec_nmsub(qf,_mm_set1_ps(_SINCOS_KC1),x)); // Compute x^2 and x^3 // xl2 = vec_mul(xl,xl); xl3 = vec_mul(xl2,xl); // Compute both the sin and cos of the angles // using a polynomial expression: // cx = 1.0f + xl2 * ((C0 * xl2 + C1) * xl2 + C2), and // sx = xl + xl3 * ((S0 * xl2 + S1) * xl2 + S2) // vec_float4 cx = vec_madd( vec_madd( vec_madd(_mm_set1_ps(_SINCOS_CC0),xl2,_mm_set1_ps(_SINCOS_CC1)),xl2,_mm_set1_ps(_SINCOS_CC2)),xl2,_mm_set1_ps(1.0f)); vec_float4 sx = vec_madd( vec_madd( vec_madd(_mm_set1_ps(_SINCOS_SC0),xl2,_mm_set1_ps(_SINCOS_SC1)),xl2,_mm_set1_ps(_SINCOS_SC2)),xl3,xl); // Use the cosine when the offset is odd and the sin // when the offset is even // vec_uint4 sinMask = (vec_uint4)vec_cmpeq(vec_and(offsetSin,toM128(0x1)),_mm_setzero_ps()); vec_uint4 cosMask = (vec_uint4)vec_cmpeq(vec_and(offsetCos,toM128(0x1)),_mm_setzero_ps()); *s = vec_sel(cx,sx,sinMask); *c = vec_sel(cx,sx,cosMask); // Flip the sign of the result when (offset mod 4) = 1 or 2 // sinMask = vec_cmpeq(vec_and(offsetSin,toM128(0x2)),_mm_setzero_ps()); cosMask = vec_cmpeq(vec_and(offsetCos,toM128(0x2)),_mm_setzero_ps()); *s = vec_sel((vec_float4)vec_xor(toM128(0x80000000),(vec_uint4)*s),*s,sinMask); *c = vec_sel((vec_float4)vec_xor(toM128(0x80000000),(vec_uint4)*c),*c,cosMask); } #include "vecidx_aos.h" #include "floatInVec.h" #include "boolInVec.h" #ifdef _VECTORMATH_DEBUG #include <stdio.h> #endif namespace Vectormath { namespace Aos { //----------------------------------------------------------------------------- // Forward Declarations // class Vector3; class Vector4; class Point3; class Quat; class Matrix3; class Matrix4; class Transform3; // A 3-D vector in array-of-structures format // _VECTORMATH_ALIGNED_TYPE_1 class Vector3 { private: __m128 mVec128; public: // Default constructor; does no initialization // inline Vector3( ) { }; // Construct a 3-D vector from x, y, and z elements // inline Vector3( float x, float y, float z ); // Construct a 3-D vector from x, y, and z elements (scalar data contained in vector data type) // inline Vector3( const floatInVec &x, const floatInVec &y, const floatInVec &z ); // Copy elements from a 3-D point into a 3-D vector // explicit inline Vector3( const Point3 &pnt ); // Set all elements of a 3-D vector to the same scalar value // explicit inline Vector3( float scalar ); // Set all elements of a 3-D vector to the same scalar value (scalar data contained in vector data type) // explicit inline Vector3( const floatInVec &scalar ); // Set vector float data in a 3-D vector // explicit inline Vector3( __m128 vf4 ); // Get vector float data from a 3-D vector // inline __m128 get128( ) const; // Assign one 3-D vector to another // inline Vector3 & operator =( const Vector3 &vec ); // Set the x element of a 3-D vector // inline Vector3 & setX( float x ); // Set the y element of a 3-D vector // inline Vector3 & setY( float y ); // Set the z element of a 3-D vector // inline Vector3 & setZ( float z ); // Set the x element of a 3-D vector (scalar data contained in vector data type) // inline Vector3 & setX( const floatInVec &x ); // Set the y element of a 3-D vector (scalar data contained in vector data type) // inline Vector3 & setY( const floatInVec &y ); // Set the z element of a 3-D vector (scalar data contained in vector data type) // inline Vector3 & setZ( const floatInVec &z ); // Get the x element of a 3-D vector // inline const floatInVec getX( ) const; // Get the y element of a 3-D vector // inline const floatInVec getY( ) const; // Get the z element of a 3-D vector // inline const floatInVec getZ( ) const; // Set an x, y, or z element of a 3-D vector by index // inline Vector3 & setElem( int idx, float value ); // Set an x, y, or z element of a 3-D vector by index (scalar data contained in vector data type) // inline Vector3 & setElem( int idx, const floatInVec &value ); // Get an x, y, or z element of a 3-D vector by index // inline const floatInVec getElem( int idx ) const; // Subscripting operator to set or get an element // inline VecIdx operator []( int idx ); // Subscripting operator to get an element // inline const floatInVec operator []( int idx ) const; // Add two 3-D vectors // inline const Vector3 operator +( const Vector3 &vec ) const; // Subtract a 3-D vector from another 3-D vector // inline const Vector3 operator -( const Vector3 &vec ) const; // Add a 3-D vector to a 3-D point // inline const Point3 operator +( const Point3 &pnt ) const; // Multiply a 3-D vector by a scalar // inline const Vector3 operator *( float scalar ) const; // Divide a 3-D vector by a scalar // inline const Vector3 operator /( float scalar ) const; // Multiply a 3-D vector by a scalar (scalar data contained in vector data type) // inline const Vector3 operator *( const floatInVec &scalar ) const; // Divide a 3-D vector by a scalar (scalar data contained in vector data type) // inline const Vector3 operator /( const floatInVec &scalar ) const; // Perform compound assignment and addition with a 3-D vector // inline Vector3 & operator +=( const Vector3 &vec ); // Perform compound assignment and subtraction by a 3-D vector // inline Vector3 & operator -=( const Vector3 &vec ); // Perform compound assignment and multiplication by a scalar // inline Vector3 & operator *=( float scalar ); // Perform compound assignment and division by a scalar // inline Vector3 & operator /=( float scalar ); // Perform compound assignment and multiplication by a scalar (scalar data contained in vector data type) // inline Vector3 & operator *=( const floatInVec &scalar ); // Perform compound assignment and division by a scalar (scalar data contained in vector data type) // inline Vector3 & operator /=( const floatInVec &scalar ); // Negate all elements of a 3-D vector // inline const Vector3 operator -( ) const; // Construct x axis // static inline const Vector3 xAxis( ); // Construct y axis // static inline const Vector3 yAxis( ); // Construct z axis // static inline const Vector3 zAxis( ); } _VECTORMATH_ALIGNED_TYPE_2 ; // Multiply a 3-D vector by a scalar // inline const Vector3 operator *( float scalar, const Vector3 &vec ); // Multiply a 3-D vector by a scalar (scalar data contained in vector data type) // inline const Vector3 operator *( const floatInVec &scalar, const Vector3 &vec ); // Multiply two 3-D vectors per element // inline const Vector3 mulPerElem( const Vector3 &vec0, const Vector3 &vec1 ); // Divide two 3-D vectors per element // NOTE: // Floating-point behavior matches standard library function divf4. // inline const Vector3 divPerElem( const Vector3 &vec0, const Vector3 &vec1 ); // Compute the reciprocal of a 3-D vector per element // NOTE: // Floating-point behavior matches standard library function recipf4. // inline const Vector3 recipPerElem( const Vector3 &vec ); // Compute the absolute value of a 3-D vector per element // inline const Vector3 absPerElem( const Vector3 &vec ); // Copy sign from one 3-D vector to another, per element // inline const Vector3 copySignPerElem( const Vector3 &vec0, const Vector3 &vec1 ); // Maximum of two 3-D vectors per element // inline const Vector3 maxPerElem( const Vector3 &vec0, const Vector3 &vec1 ); // Minimum of two 3-D vectors per element // inline const Vector3 minPerElem( const Vector3 &vec0, const Vector3 &vec1 ); // Maximum element of a 3-D vector // inline const floatInVec maxElem( const Vector3 &vec ); // Minimum element of a 3-D vector // inline const floatInVec minElem( const Vector3 &vec ); // Compute the sum of all elements of a 3-D vector // inline const floatInVec sum( const Vector3 &vec ); // Compute the dot product of two 3-D vectors // inline const floatInVec dot( const Vector3 &vec0, const Vector3 &vec1 ); // Compute the square of the length of a 3-D vector // inline const floatInVec lengthSqr( const Vector3 &vec ); // Compute the length of a 3-D vector // inline const floatInVec length( const Vector3 &vec ); // Normalize a 3-D vector // NOTE: // The result is unpredictable when all elements of vec are at or near zero. // inline const Vector3 normalize( const Vector3 &vec ); // Compute cross product of two 3-D vectors // inline const Vector3 cross( const Vector3 &vec0, const Vector3 &vec1 ); // Outer product of two 3-D vectors // inline const Matrix3 outer( const Vector3 &vec0, const Vector3 &vec1 ); // Pre-multiply a row vector by a 3x3 matrix // NOTE: // Slower than column post-multiply. // inline const Vector3 rowMul( const Vector3 &vec, const Matrix3 & mat ); // Cross-product matrix of a 3-D vector // inline const Matrix3 crossMatrix( const Vector3 &vec ); // Create cross-product matrix and multiply // NOTE: // Faster than separately creating a cross-product matrix and multiplying. // inline const Matrix3 crossMatrixMul( const Vector3 &vec, const Matrix3 & mat ); // Linear interpolation between two 3-D vectors // NOTE: // Does not clamp t between 0 and 1. // inline const Vector3 lerp( float t, const Vector3 &vec0, const Vector3 &vec1 ); // Linear interpolation between two 3-D vectors (scalar data contained in vector data type) // NOTE: // Does not clamp t between 0 and 1. // inline const Vector3 lerp( const floatInVec &t, const Vector3 &vec0, const Vector3 &vec1 ); // Spherical linear interpolation between two 3-D vectors // NOTE: // The result is unpredictable if the vectors point in opposite directions. // Does not clamp t between 0 and 1. // inline const Vector3 slerp( float t, const Vector3 &unitVec0, const Vector3 &unitVec1 ); // Spherical linear interpolation between two 3-D vectors (scalar data contained in vector data type) // NOTE: // The result is unpredictable if the vectors point in opposite directions. // Does not clamp t between 0 and 1. // inline const Vector3 slerp( const floatInVec &t, const Vector3 &unitVec0, const Vector3 &unitVec1 ); // Conditionally select between two 3-D vectors // NOTE: // This function uses a conditional select instruction to avoid a branch. // However, the transfer of select1 to a VMX register may use more processing time than a branch. // Use the boolInVec version for better performance. // inline const Vector3 select( const Vector3 &vec0, const Vector3 &vec1, bool select1 ); // Conditionally select between two 3-D vectors (scalar data contained in vector data type) // NOTE: // This function uses a conditional select instruction to avoid a branch. // inline const Vector3 select( const Vector3 &vec0, const Vector3 &vec1, const boolInVec &select1 ); // Store x, y, and z elements of 3-D vector in first three words of a quadword, preserving fourth word // inline void storeXYZ( const Vector3 &vec, __m128 * quad ); // Load four three-float 3-D vectors, stored in three quadwords // inline void loadXYZArray( Vector3 & vec0, Vector3 & vec1, Vector3 & vec2, Vector3 & vec3, const __m128 * threeQuads ); // Store four 3-D vectors in three quadwords // inline void storeXYZArray( const Vector3 &vec0, const Vector3 &vec1, const Vector3 &vec2, const Vector3 &vec3, __m128 * threeQuads ); // Store eight 3-D vectors as half-floats // inline void storeHalfFloats( const Vector3 &vec0, const Vector3 &vec1, const Vector3 &vec2, const Vector3 &vec3, const Vector3 &vec4, const Vector3 &vec5, const Vector3 &vec6, const Vector3 &vec7, vec_ushort8 * threeQuads ); #ifdef _VECTORMATH_DEBUG // Print a 3-D vector // NOTE: // Function is only defined when _VECTORMATH_DEBUG is defined. // inline void print( const Vector3 &vec ); // Print a 3-D vector and an associated string identifier // NOTE: // Function is only defined when _VECTORMATH_DEBUG is defined. // inline void print( const Vector3 &vec, const char * name ); #endif // A 4-D vector in array-of-structures format // _VECTORMATH_ALIGNED_TYPE_1 class Vector4 { private: __m128 mVec128; public: // Default constructor; does no initialization // inline Vector4( ) { }; // Construct a 4-D vector from x, y, z, and w elements // inline Vector4( float x, float y, float z, float w ); // Construct a 4-D vector from x, y, z, and w elements (scalar data contained in vector data type) // inline Vector4( const floatInVec &x, const floatInVec &y, const floatInVec &z, const floatInVec &w ); // Construct a 4-D vector from a 3-D vector and a scalar // inline Vector4( const Vector3 &xyz, float w ); // Construct a 4-D vector from a 3-D vector and a scalar (scalar data contained in vector data type) // inline Vector4( const Vector3 &xyz, const floatInVec &w ); // Copy x, y, and z from a 3-D vector into a 4-D vector, and set w to 0 // explicit inline Vector4( const Vector3 &vec ); // Copy x, y, and z from a 3-D point into a 4-D vector, and set w to 1 // explicit inline Vector4( const Point3 &pnt ); // Copy elements from a quaternion into a 4-D vector // explicit inline Vector4( const Quat &quat ); // Set all elements of a 4-D vector to the same scalar value // explicit inline Vector4( float scalar ); // Set all elements of a 4-D vector to the same scalar value (scalar data contained in vector data type) // explicit inline Vector4( const floatInVec &scalar ); // Set vector float data in a 4-D vector // explicit inline Vector4( __m128 vf4 ); // Get vector float data from a 4-D vector // inline __m128 get128( ) const; // Assign one 4-D vector to another // inline Vector4 & operator =( const Vector4 &vec ); // Set the x, y, and z elements of a 4-D vector // NOTE: // This function does not change the w element. // inline Vector4 & setXYZ( const Vector3 &vec ); // Get the x, y, and z elements of a 4-D vector // inline const Vector3 getXYZ( ) const; // Set the x element of a 4-D vector // inline Vector4 & setX( float x ); // Set the y element of a 4-D vector // inline Vector4 & setY( float y ); // Set the z element of a 4-D vector // inline Vector4 & setZ( float z ); // Set the w element of a 4-D vector // inline Vector4 & setW( float w ); // Set the x element of a 4-D vector (scalar data contained in vector data type) // inline Vector4 & setX( const floatInVec &x ); // Set the y element of a 4-D vector (scalar data contained in vector data type) // inline Vector4 & setY( const floatInVec &y ); // Set the z element of a 4-D vector (scalar data contained in vector data type) // inline Vector4 & setZ( const floatInVec &z ); // Set the w element of a 4-D vector (scalar data contained in vector data type) // inline Vector4 & setW( const floatInVec &w ); // Get the x element of a 4-D vector // inline const floatInVec getX( ) const; // Get the y element of a 4-D vector // inline const floatInVec getY( ) const; // Get the z element of a 4-D vector // inline const floatInVec getZ( ) const; // Get the w element of a 4-D vector // inline const floatInVec getW( ) const; // Set an x, y, z, or w element of a 4-D vector by index // inline Vector4 & setElem( int idx, float value ); // Set an x, y, z, or w element of a 4-D vector by index (scalar data contained in vector data type) // inline Vector4 & setElem( int idx, const floatInVec &value ); // Get an x, y, z, or w element of a 4-D vector by index // inline const floatInVec getElem( int idx ) const; // Subscripting operator to set or get an element // inline VecIdx operator []( int idx ); // Subscripting operator to get an element // inline const floatInVec operator []( int idx ) const; // Add two 4-D vectors // inline const Vector4 operator +( const Vector4 &vec ) const; // Subtract a 4-D vector from another 4-D vector // inline const Vector4 operator -( const Vector4 &vec ) const; // Multiply a 4-D vector by a scalar // inline const Vector4 operator *( float scalar ) const; // Divide a 4-D vector by a scalar // inline const Vector4 operator /( float scalar ) const; // Multiply a 4-D vector by a scalar (scalar data contained in vector data type) // inline const Vector4 operator *( const floatInVec &scalar ) const; // Divide a 4-D vector by a scalar (scalar data contained in vector data type) // inline const Vector4 operator /( const floatInVec &scalar ) const; // Perform compound assignment and addition with a 4-D vector // inline Vector4 & operator +=( const Vector4 &vec ); // Perform compound assignment and subtraction by a 4-D vector // inline Vector4 & operator -=( const Vector4 &vec ); // Perform compound assignment and multiplication by a scalar // inline Vector4 & operator *=( float scalar ); // Perform compound assignment and division by a scalar // inline Vector4 & operator /=( float scalar ); // Perform compound assignment and multiplication by a scalar (scalar data contained in vector data type) // inline Vector4 & operator *=( const floatInVec &scalar ); // Perform compound assignment and division by a scalar (scalar data contained in vector data type) // inline Vector4 & operator /=( const floatInVec &scalar ); // Negate all elements of a 4-D vector // inline const Vector4 operator -( ) const; // Construct x axis // static inline const Vector4 xAxis( ); // Construct y axis // static inline const Vector4 yAxis( ); // Construct z axis // static inline const Vector4 zAxis( ); // Construct w axis // static inline const Vector4 wAxis( ); } _VECTORMATH_ALIGNED_TYPE_2 ; // Multiply a 4-D vector by a scalar // inline const Vector4 operator *( float scalar, const Vector4 &vec ); // Multiply a 4-D vector by a scalar (scalar data contained in vector data type) // inline const Vector4 operator *( const floatInVec &scalar, const Vector4 &vec ); // Multiply two 4-D vectors per element // inline const Vector4 mulPerElem( const Vector4 &vec0, const Vector4 &vec1 ); // Divide two 4-D vectors per element // NOTE: // Floating-point behavior matches standard library function divf4. // inline const Vector4 divPerElem( const Vector4 &vec0, const Vector4 &vec1 ); // Compute the reciprocal of a 4-D vector per element // NOTE: // Floating-point behavior matches standard library function recipf4. // inline const Vector4 recipPerElem( const Vector4 &vec ); // Compute the absolute value of a 4-D vector per element // inline const Vector4 absPerElem( const Vector4 &vec ); // Copy sign from one 4-D vector to another, per element // inline const Vector4 copySignPerElem( const Vector4 &vec0, const Vector4 &vec1 ); // Maximum of two 4-D vectors per element // inline const Vector4 maxPerElem( const Vector4 &vec0, const Vector4 &vec1 ); // Minimum of two 4-D vectors per element // inline const Vector4 minPerElem( const Vector4 &vec0, const Vector4 &vec1 ); // Maximum element of a 4-D vector // inline const floatInVec maxElem( const Vector4 &vec ); // Minimum element of a 4-D vector // inline const floatInVec minElem( const Vector4 &vec ); // Compute the sum of all elements of a 4-D vector // inline const floatInVec sum( const Vector4 &vec ); // Compute the dot product of two 4-D vectors // inline const floatInVec dot( const Vector4 &vec0, const Vector4 &vec1 ); // Compute the square of the length of a 4-D vector // inline const floatInVec lengthSqr( const Vector4 &vec ); // Compute the length of a 4-D vector // inline const floatInVec length( const Vector4 &vec ); // Normalize a 4-D vector // NOTE: // The result is unpredictable when all elements of vec are at or near zero. // inline const Vector4 normalize( const Vector4 &vec ); // Outer product of two 4-D vectors // inline const Matrix4 outer( const Vector4 &vec0, const Vector4 &vec1 ); // Linear interpolation between two 4-D vectors // NOTE: // Does not clamp t between 0 and 1. // inline const Vector4 lerp( float t, const Vector4 &vec0, const Vector4 &vec1 ); // Linear interpolation between two 4-D vectors (scalar data contained in vector data type) // NOTE: // Does not clamp t between 0 and 1. // inline const Vector4 lerp( const floatInVec &t, const Vector4 &vec0, const Vector4 &vec1 ); // Spherical linear interpolation between two 4-D vectors // NOTE: // The result is unpredictable if the vectors point in opposite directions. // Does not clamp t between 0 and 1. // inline const Vector4 slerp( float t, const Vector4 &unitVec0, const Vector4 &unitVec1 ); // Spherical linear interpolation between two 4-D vectors (scalar data contained in vector data type) // NOTE: // The result is unpredictable if the vectors point in opposite directions. // Does not clamp t between 0 and 1. // inline const Vector4 slerp( const floatInVec &t, const Vector4 &unitVec0, const Vector4 &unitVec1 ); // Conditionally select between two 4-D vectors // NOTE: // This function uses a conditional select instruction to avoid a branch. // However, the transfer of select1 to a VMX register may use more processing time than a branch. // Use the boolInVec version for better performance. // inline const Vector4 select( const Vector4 &vec0, const Vector4 &vec1, bool select1 ); // Conditionally select between two 4-D vectors (scalar data contained in vector data type) // NOTE: // This function uses a conditional select instruction to avoid a branch. // inline const Vector4 select( const Vector4 &vec0, const Vector4 &vec1, const boolInVec &select1 ); // Store four 4-D vectors as half-floats // inline void storeHalfFloats( const Vector4 &vec0, const Vector4 &vec1, const Vector4 &vec2, const Vector4 &vec3, vec_ushort8 * twoQuads ); #ifdef _VECTORMATH_DEBUG // Print a 4-D vector // NOTE: // Function is only defined when _VECTORMATH_DEBUG is defined. // inline void print( const Vector4 &vec ); // Print a 4-D vector and an associated string identifier // NOTE: // Function is only defined when _VECTORMATH_DEBUG is defined. // inline void print( const Vector4 &vec, const char * name ); #endif // A 3-D point in array-of-structures format // _VECTORMATH_ALIGNED_TYPE_1 class Point3 { private: __m128 mVec128; public: // Default constructor; does no initialization // inline Point3( ) { }; // Construct a 3-D point from x, y, and z elements // inline Point3( float x, float y, float z ); // Construct a 3-D point from x, y, and z elements (scalar data contained in vector data type) // inline Point3( const floatInVec &x, const floatInVec &y, const floatInVec &z ); // Copy elements from a 3-D vector into a 3-D point // explicit inline Point3( const Vector3 &vec ); // Set all elements of a 3-D point to the same scalar value // explicit inline Point3( float scalar ); // Set all elements of a 3-D point to the same scalar value (scalar data contained in vector data type) // explicit inline Point3( const floatInVec &scalar ); // Set vector float data in a 3-D point // explicit inline Point3( __m128 vf4 ); // Get vector float data from a 3-D point // inline __m128 get128( ) const; // Assign one 3-D point to another // inline Point3 & operator =( const Point3 &pnt ); // Set the x element of a 3-D point // inline Point3 & setX( float x ); // Set the y element of a 3-D point // inline Point3 & setY( float y ); // Set the z element of a 3-D point // inline Point3 & setZ( float z ); // Set the x element of a 3-D point (scalar data contained in vector data type) // inline Point3 & setX( const floatInVec &x ); // Set the y element of a 3-D point (scalar data contained in vector data type) // inline Point3 & setY( const floatInVec &y ); // Set the z element of a 3-D point (scalar data contained in vector data type) // inline Point3 & setZ( const floatInVec &z ); // Get the x element of a 3-D point // inline const floatInVec getX( ) const; // Get the y element of a 3-D point // inline const floatInVec getY( ) const; // Get the z element of a 3-D point // inline const floatInVec getZ( ) const; // Set an x, y, or z element of a 3-D point by index // inline Point3 & setElem( int idx, float value ); // Set an x, y, or z element of a 3-D point by index (scalar data contained in vector data type) // inline Point3 & setElem( int idx, const floatInVec &value ); // Get an x, y, or z element of a 3-D point by index // inline const floatInVec getElem( int idx ) const; // Subscripting operator to set or get an element // inline VecIdx operator []( int idx ); // Subscripting operator to get an element // inline const floatInVec operator []( int idx ) const; // Subtract a 3-D point from another 3-D point // inline const Vector3 operator -( const Point3 &pnt ) const; // Add a 3-D point to a 3-D vector // inline const Point3 operator +( const Vector3 &vec ) const; // Subtract a 3-D vector from a 3-D point // inline const Point3 operator -( const Vector3 &vec ) const; // Perform compound assignment and addition with a 3-D vector // inline Point3 & operator +=( const Vector3 &vec ); // Perform compound assignment and subtraction by a 3-D vector // inline Point3 & operator -=( const Vector3 &vec ); } _VECTORMATH_ALIGNED_TYPE_2 ; // Multiply two 3-D points per element // inline const Point3 mulPerElem( const Point3 &pnt0, const Point3 &pnt1 ); // Divide two 3-D points per element // NOTE: // Floating-point behavior matches standard library function divf4. // inline const Point3 divPerElem( const Point3 &pnt0, const Point3 &pnt1 ); // Compute the reciprocal of a 3-D point per element // NOTE: // Floating-point behavior matches standard library function recipf4. // inline const Point3 recipPerElem( const Point3 &pnt ); // Compute the absolute value of a 3-D point per element // inline const Point3 absPerElem( const Point3 &pnt ); // Copy sign from one 3-D point to another, per element // inline const Point3 copySignPerElem( const Point3 &pnt0, const Point3 &pnt1 ); // Maximum of two 3-D points per element // inline const Point3 maxPerElem( const Point3 &pnt0, const Point3 &pnt1 ); // Minimum of two 3-D points per element // inline const Point3 minPerElem( const Point3 &pnt0, const Point3 &pnt1 ); // Maximum element of a 3-D point // inline const floatInVec maxElem( const Point3 &pnt ); // Minimum element of a 3-D point // inline const floatInVec minElem( const Point3 &pnt ); // Compute the sum of all elements of a 3-D point // inline const floatInVec sum( const Point3 &pnt ); // Apply uniform scale to a 3-D point // inline const Point3 scale( const Point3 &pnt, float scaleVal ); // Apply uniform scale to a 3-D point (scalar data contained in vector data type) // inline const Point3 scale( const Point3 &pnt, const floatInVec &scaleVal ); // Apply non-uniform scale to a 3-D point // inline const Point3 scale( const Point3 &pnt, const Vector3 &scaleVec ); // Scalar projection of a 3-D point on a unit-length 3-D vector // inline const floatInVec projection( const Point3 &pnt, const Vector3 &unitVec ); // Compute the square of the distance of a 3-D point from the coordinate-system origin // inline const floatInVec distSqrFromOrigin( const Point3 &pnt ); // Compute the distance of a 3-D point from the coordinate-system origin // inline const floatInVec distFromOrigin( const Point3 &pnt ); // Compute the square of the distance between two 3-D points // inline const floatInVec distSqr( const Point3 &pnt0, const Point3 &pnt1 ); // Compute the distance between two 3-D points // inline const floatInVec dist( const Point3 &pnt0, const Point3 &pnt1 ); // Linear interpolation between two 3-D points // NOTE: // Does not clamp t between 0 and 1. // inline const Point3 lerp( float t, const Point3 &pnt0, const Point3 &pnt1 ); // Linear interpolation between two 3-D points (scalar data contained in vector data type) // NOTE: // Does not clamp t between 0 and 1. // inline const Point3 lerp( const floatInVec &t, const Point3 &pnt0, const Point3 &pnt1 ); // Conditionally select between two 3-D points // NOTE: // This function uses a conditional select instruction to avoid a branch. // However, the transfer of select1 to a VMX register may use more processing time than a branch. // Use the boolInVec version for better performance. // inline const Point3 select( const Point3 &pnt0, const Point3 &pnt1, bool select1 ); // Conditionally select between two 3-D points (scalar data contained in vector data type) // NOTE: // This function uses a conditional select instruction to avoid a branch. // inline const Point3 select( const Point3 &pnt0, const Point3 &pnt1, const boolInVec &select1 ); // Store x, y, and z elements of 3-D point in first three words of a quadword, preserving fourth word // inline void storeXYZ( const Point3 &pnt, __m128 * quad ); // Load four three-float 3-D points, stored in three quadwords // inline void loadXYZArray( Point3 & pnt0, Point3 & pnt1, Point3 & pnt2, Point3 & pnt3, const __m128 * threeQuads ); // Store four 3-D points in three quadwords // inline void storeXYZArray( const Point3 &pnt0, const Point3 &pnt1, const Point3 &pnt2, const Point3 &pnt3, __m128 * threeQuads ); // Store eight 3-D points as half-floats // inline void storeHalfFloats( const Point3 &pnt0, const Point3 &pnt1, const Point3 &pnt2, const Point3 &pnt3, const Point3 &pnt4, const Point3 &pnt5, const Point3 &pnt6, const Point3 &pnt7, vec_ushort8 * threeQuads ); #ifdef _VECTORMATH_DEBUG // Print a 3-D point // NOTE: // Function is only defined when _VECTORMATH_DEBUG is defined. // inline void print( const Point3 &pnt ); // Print a 3-D point and an associated string identifier // NOTE: // Function is only defined when _VECTORMATH_DEBUG is defined. // inline void print( const Point3 &pnt, const char * name ); #endif // A quaternion in array-of-structures format // _VECTORMATH_ALIGNED_TYPE_1 class Quat { private: __m128 mVec128; public: // Default constructor; does no initialization // inline Quat( ) { }; // Construct a quaternion from x, y, z, and w elements // inline Quat( float x, float y, float z, float w ); // Construct a quaternion from x, y, z, and w elements (scalar data contained in vector data type) // inline Quat( const floatInVec &x, const floatInVec &y, const floatInVec &z, const floatInVec &w ); // Construct a quaternion from a 3-D vector and a scalar // inline Quat( const Vector3 &xyz, float w ); // Construct a quaternion from a 3-D vector and a scalar (scalar data contained in vector data type) // inline Quat( const Vector3 &xyz, const floatInVec &w ); // Copy elements from a 4-D vector into a quaternion // explicit inline Quat( const Vector4 &vec ); // Convert a rotation matrix to a unit-length quaternion // explicit inline Quat( const Matrix3 & rotMat ); // Set all elements of a quaternion to the same scalar value // explicit inline Quat( float scalar ); // Set all elements of a quaternion to the same scalar value (scalar data contained in vector data type) // explicit inline Quat( const floatInVec &scalar ); // Set vector float data in a quaternion // explicit inline Quat( __m128 vf4 ); // Get vector float data from a quaternion // inline __m128 get128( ) const; // Assign one quaternion to another // inline Quat & operator =( const Quat &quat ); // Set the x, y, and z elements of a quaternion // NOTE: // This function does not change the w element. // inline Quat & setXYZ( const Vector3 &vec ); // Get the x, y, and z elements of a quaternion // inline const Vector3 getXYZ( ) const; // Set the x element of a quaternion // inline Quat & setX( float x ); // Set the y element of a quaternion // inline Quat & setY( float y ); // Set the z element of a quaternion // inline Quat & setZ( float z ); // Set the w element of a quaternion // inline Quat & setW( float w ); // Set the x element of a quaternion (scalar data contained in vector data type) // inline Quat & setX( const floatInVec &x ); // Set the y element of a quaternion (scalar data contained in vector data type) // inline Quat & setY( const floatInVec &y ); // Set the z element of a quaternion (scalar data contained in vector data type) // inline Quat & setZ( const floatInVec &z ); // Set the w element of a quaternion (scalar data contained in vector data type) // inline Quat & setW( const floatInVec &w ); // Get the x element of a quaternion // inline const floatInVec getX( ) const; // Get the y element of a quaternion // inline const floatInVec getY( ) const; // Get the z element of a quaternion // inline const floatInVec getZ( ) const; // Get the w element of a quaternion // inline const floatInVec getW( ) const; // Set an x, y, z, or w element of a quaternion by index // inline Quat & setElem( int idx, float value ); // Set an x, y, z, or w element of a quaternion by index (scalar data contained in vector data type) // inline Quat & setElem( int idx, const floatInVec &value ); // Get an x, y, z, or w element of a quaternion by index // inline const floatInVec getElem( int idx ) const; // Subscripting operator to set or get an element // inline VecIdx operator []( int idx ); // Subscripting operator to get an element // inline const floatInVec operator []( int idx ) const; // Add two quaternions // inline const Quat operator +( const Quat &quat ) const; // Subtract a quaternion from another quaternion // inline const Quat operator -( const Quat &quat ) const; // Multiply two quaternions // inline const Quat operator *( const Quat &quat ) const; // Multiply a quaternion by a scalar // inline const Quat operator *( float scalar ) const; // Divide a quaternion by a scalar // inline const Quat operator /( float scalar ) const; // Multiply a quaternion by a scalar (scalar data contained in vector data type) // inline const Quat operator *( const floatInVec &scalar ) const; // Divide a quaternion by a scalar (scalar data contained in vector data type) // inline const Quat operator /( const floatInVec &scalar ) const; // Perform compound assignment and addition with a quaternion // inline Quat & operator +=( const Quat &quat ); // Perform compound assignment and subtraction by a quaternion // inline Quat & operator -=( const Quat &quat ); // Perform compound assignment and multiplication by a quaternion // inline Quat & operator *=( const Quat &quat ); // Perform compound assignment and multiplication by a scalar // inline Quat & operator *=( float scalar ); // Perform compound assignment and division by a scalar // inline Quat & operator /=( float scalar ); // Perform compound assignment and multiplication by a scalar (scalar data contained in vector data type) // inline Quat & operator *=( const floatInVec &scalar ); // Perform compound assignment and division by a scalar (scalar data contained in vector data type) // inline Quat & operator /=( const floatInVec &scalar ); // Negate all elements of a quaternion // inline const Quat operator -( ) const; // Construct an identity quaternion // static inline const Quat identity( ); // Construct a quaternion to rotate between two unit-length 3-D vectors // NOTE: // The result is unpredictable if unitVec0 and unitVec1 point in opposite directions. // static inline const Quat rotation( const Vector3 &unitVec0, const Vector3 &unitVec1 ); // Construct a quaternion to rotate around a unit-length 3-D vector // static inline const Quat rotation( float radians, const Vector3 &unitVec ); // Construct a quaternion to rotate around a unit-length 3-D vector (scalar data contained in vector data type) // static inline const Quat rotation( const floatInVec &radians, const Vector3 &unitVec ); // Construct a quaternion to rotate around the x axis // static inline const Quat rotationX( float radians ); // Construct a quaternion to rotate around the y axis // static inline const Quat rotationY( float radians ); // Construct a quaternion to rotate around the z axis // static inline const Quat rotationZ( float radians ); // Construct a quaternion to rotate around the x axis (scalar data contained in vector data type) // static inline const Quat rotationX( const floatInVec &radians ); // Construct a quaternion to rotate around the y axis (scalar data contained in vector data type) // static inline const Quat rotationY( const floatInVec &radians ); // Construct a quaternion to rotate around the z axis (scalar data contained in vector data type) // static inline const Quat rotationZ( const floatInVec &radians ); } _VECTORMATH_ALIGNED_TYPE_2 ; // Multiply a quaternion by a scalar // inline const Quat operator *( float scalar, const Quat &quat ); // Multiply a quaternion by a scalar (scalar data contained in vector data type) // inline const Quat operator *( const floatInVec &scalar, const Quat &quat ); // Compute the conjugate of a quaternion // inline const Quat conj( const Quat &quat ); // Use a unit-length quaternion to rotate a 3-D vector // inline const Vector3 rotate( const Quat &unitQuat, const Vector3 &vec ); // Compute the dot product of two quaternions // inline const floatInVec dot( const Quat &quat0, const Quat &quat1 ); // Compute the norm of a quaternion // inline const floatInVec norm( const Quat &quat ); // Compute the length of a quaternion // inline const floatInVec length( const Quat &quat ); // Normalize a quaternion // NOTE: // The result is unpredictable when all elements of quat are at or near zero. // inline const Quat normalize( const Quat &quat ); // Linear interpolation between two quaternions // NOTE: // Does not clamp t between 0 and 1. // inline const Quat lerp( float t, const Quat &quat0, const Quat &quat1 ); // Linear interpolation between two quaternions (scalar data contained in vector data type) // NOTE: // Does not clamp t between 0 and 1. // inline const Quat lerp( const floatInVec &t, const Quat &quat0, const Quat &quat1 ); // Spherical linear interpolation between two quaternions // NOTE: // Interpolates along the shortest path between orientations. // Does not clamp t between 0 and 1. // inline const Quat slerp( float t, const Quat &unitQuat0, const Quat &unitQuat1 ); // Spherical linear interpolation between two quaternions (scalar data contained in vector data type) // NOTE: // Interpolates along the shortest path between orientations. // Does not clamp t between 0 and 1. // inline const Quat slerp( const floatInVec &t, const Quat &unitQuat0, const Quat &unitQuat1 ); // Spherical quadrangle interpolation // inline const Quat squad( float t, const Quat &unitQuat0, const Quat &unitQuat1, const Quat &unitQuat2, const Quat &unitQuat3 ); // Spherical quadrangle interpolation (scalar data contained in vector data type) // inline const Quat squad( const floatInVec &t, const Quat &unitQuat0, const Quat &unitQuat1, const Quat &unitQuat2, const Quat &unitQuat3 ); // Conditionally select between two quaternions // NOTE: // This function uses a conditional select instruction to avoid a branch. // However, the transfer of select1 to a VMX register may use more processing time than a branch. // Use the boolInVec version for better performance. // inline const Quat select( const Quat &quat0, const Quat &quat1, bool select1 ); // Conditionally select between two quaternions (scalar data contained in vector data type) // NOTE: // This function uses a conditional select instruction to avoid a branch. // inline const Quat select( const Quat &quat0, const Quat &quat1, const boolInVec &select1 ); #ifdef _VECTORMATH_DEBUG // Print a quaternion // NOTE: // Function is only defined when _VECTORMATH_DEBUG is defined. // inline void print( const Quat &quat ); // Print a quaternion and an associated string identifier // NOTE: // Function is only defined when _VECTORMATH_DEBUG is defined. // inline void print( const Quat &quat, const char * name ); #endif // A 3x3 matrix in array-of-structures format // _VECTORMATH_ALIGNED_TYPE_1 class Matrix3 { private: Vector3 mCol0; Vector3 mCol1; Vector3 mCol2; public: // Default constructor; does no initialization // inline Matrix3( ) { }; // Copy a 3x3 matrix // inline Matrix3( const Matrix3 & mat ); // Construct a 3x3 matrix containing the specified columns // inline Matrix3( const Vector3 &col0, const Vector3 &col1, const Vector3 &col2 ); // Construct a 3x3 rotation matrix from a unit-length quaternion // explicit inline Matrix3( const Quat &unitQuat ); // Set all elements of a 3x3 matrix to the same scalar value // explicit inline Matrix3( float scalar ); // Set all elements of a 3x3 matrix to the same scalar value (scalar data contained in vector data type) // explicit inline Matrix3( const floatInVec &scalar ); // Assign one 3x3 matrix to another // inline Matrix3 & operator =( const Matrix3 & mat ); // Set column 0 of a 3x3 matrix // inline Matrix3 & setCol0( const Vector3 &col0 ); // Set column 1 of a 3x3 matrix // inline Matrix3 & setCol1( const Vector3 &col1 ); // Set column 2 of a 3x3 matrix // inline Matrix3 & setCol2( const Vector3 &col2 ); // Get column 0 of a 3x3 matrix // inline const Vector3 getCol0( ) const; // Get column 1 of a 3x3 matrix // inline const Vector3 getCol1( ) const; // Get column 2 of a 3x3 matrix // inline const Vector3 getCol2( ) const; // Set the column of a 3x3 matrix referred to by the specified index // inline Matrix3 & setCol( int col, const Vector3 &vec ); // Set the row of a 3x3 matrix referred to by the specified index // inline Matrix3 & setRow( int row, const Vector3 &vec ); // Get the column of a 3x3 matrix referred to by the specified index // inline const Vector3 getCol( int col ) const; // Get the row of a 3x3 matrix referred to by the specified index // inline const Vector3 getRow( int row ) const; // Subscripting operator to set or get a column // inline Vector3 & operator []( int col ); // Subscripting operator to get a column // inline const Vector3 operator []( int col ) const; // Set the element of a 3x3 matrix referred to by column and row indices // inline Matrix3 & setElem( int col, int row, float val ); // Set the element of a 3x3 matrix referred to by column and row indices (scalar data contained in vector data type) // inline Matrix3 & setElem( int col, int row, const floatInVec &val ); // Get the element of a 3x3 matrix referred to by column and row indices // inline const floatInVec getElem( int col, int row ) const; // Add two 3x3 matrices // inline const Matrix3 operator +( const Matrix3 & mat ) const; // Subtract a 3x3 matrix from another 3x3 matrix // inline const Matrix3 operator -( const Matrix3 & mat ) const; // Negate all elements of a 3x3 matrix // inline const Matrix3 operator -( ) const; // Multiply a 3x3 matrix by a scalar // inline const Matrix3 operator *( float scalar ) const; // Multiply a 3x3 matrix by a scalar (scalar data contained in vector data type) // inline const Matrix3 operator *( const floatInVec &scalar ) const; // Multiply a 3x3 matrix by a 3-D vector // inline const Vector3 operator *( const Vector3 &vec ) const; // Multiply two 3x3 matrices // inline const Matrix3 operator *( const Matrix3 & mat ) const; // Perform compound assignment and addition with a 3x3 matrix // inline Matrix3 & operator +=( const Matrix3 & mat ); // Perform compound assignment and subtraction by a 3x3 matrix // inline Matrix3 & operator -=( const Matrix3 & mat ); // Perform compound assignment and multiplication by a scalar // inline Matrix3 & operator *=( float scalar ); // Perform compound assignment and multiplication by a scalar (scalar data contained in vector data type) // inline Matrix3 & operator *=( const floatInVec &scalar ); // Perform compound assignment and multiplication by a 3x3 matrix // inline Matrix3 & operator *=( const Matrix3 & mat ); // Construct an identity 3x3 matrix // static inline const Matrix3 identity( ); // Construct a 3x3 matrix to rotate around the x axis // static inline const Matrix3 rotationX( float radians ); // Construct a 3x3 matrix to rotate around the y axis // static inline const Matrix3 rotationY( float radians ); // Construct a 3x3 matrix to rotate around the z axis // static inline const Matrix3 rotationZ( float radians ); // Construct a 3x3 matrix to rotate around the x axis (scalar data contained in vector data type) // static inline const Matrix3 rotationX( const floatInVec &radians ); // Construct a 3x3 matrix to rotate around the y axis (scalar data contained in vector data type) // static inline const Matrix3 rotationY( const floatInVec &radians ); // Construct a 3x3 matrix to rotate around the z axis (scalar data contained in vector data type) // static inline const Matrix3 rotationZ( const floatInVec &radians ); // Construct a 3x3 matrix to rotate around the x, y, and z axes // static inline const Matrix3 rotationZYX( const Vector3 &radiansXYZ ); // Construct a 3x3 matrix to rotate around a unit-length 3-D vector // static inline const Matrix3 rotation( float radians, const Vector3 &unitVec ); // Construct a 3x3 matrix to rotate around a unit-length 3-D vector (scalar data contained in vector data type) // static inline const Matrix3 rotation( const floatInVec &radians, const Vector3 &unitVec ); // Construct a rotation matrix from a unit-length quaternion // static inline const Matrix3 rotation( const Quat &unitQuat ); // Construct a 3x3 matrix to perform scaling // static inline const Matrix3 scale( const Vector3 &scaleVec ); } _VECTORMATH_ALIGNED_TYPE_2 ; // Multiply a 3x3 matrix by a scalar // inline const Matrix3 operator *( float scalar, const Matrix3 & mat ); // Multiply a 3x3 matrix by a scalar (scalar data contained in vector data type) // inline const Matrix3 operator *( const floatInVec &scalar, const Matrix3 & mat ); // Append (post-multiply) a scale transformation to a 3x3 matrix // NOTE: // Faster than creating and multiplying a scale transformation matrix. // inline const Matrix3 appendScale( const Matrix3 & mat, const Vector3 &scaleVec ); // Prepend (pre-multiply) a scale transformation to a 3x3 matrix // NOTE: // Faster than creating and multiplying a scale transformation matrix. // inline const Matrix3 prependScale( const Vector3 &scaleVec, const Matrix3 & mat ); // Multiply two 3x3 matrices per element // inline const Matrix3 mulPerElem( const Matrix3 & mat0, const Matrix3 & mat1 ); // Compute the absolute value of a 3x3 matrix per element // inline const Matrix3 absPerElem( const Matrix3 & mat ); // Transpose of a 3x3 matrix // inline const Matrix3 transpose( const Matrix3 & mat ); // Compute the inverse of a 3x3 matrix // NOTE: // Result is unpredictable when the determinant of mat is equal to or near 0. // inline const Matrix3 inverse( const Matrix3 & mat ); // Determinant of a 3x3 matrix // inline const floatInVec determinant( const Matrix3 & mat ); // Conditionally select between two 3x3 matrices // NOTE: // This function uses a conditional select instruction to avoid a branch. // However, the transfer of select1 to a VMX register may use more processing time than a branch. // Use the boolInVec version for better performance. // inline const Matrix3 select( const Matrix3 & mat0, const Matrix3 & mat1, bool select1 ); // Conditionally select between two 3x3 matrices (scalar data contained in vector data type) // NOTE: // This function uses a conditional select instruction to avoid a branch. // inline const Matrix3 select( const Matrix3 & mat0, const Matrix3 & mat1, const boolInVec &select1 ); #ifdef _VECTORMATH_DEBUG // Print a 3x3 matrix // NOTE: // Function is only defined when _VECTORMATH_DEBUG is defined. // inline void print( const Matrix3 & mat ); // Print a 3x3 matrix and an associated string identifier // NOTE: // Function is only defined when _VECTORMATH_DEBUG is defined. // inline void print( const Matrix3 & mat, const char * name ); #endif // A 4x4 matrix in array-of-structures format // _VECTORMATH_ALIGNED_TYPE_1 class Matrix4 { private: Vector4 mCol0; Vector4 mCol1; Vector4 mCol2; Vector4 mCol3; public: // Default constructor; does no initialization // inline Matrix4( ) { }; // Copy a 4x4 matrix // inline Matrix4( const Matrix4 & mat ); // Construct a 4x4 matrix containing the specified columns // inline Matrix4( const Vector4 &col0, const Vector4 &col1, const Vector4 &col2, const Vector4 &col3 ); // Construct a 4x4 matrix from a 3x4 transformation matrix // explicit inline Matrix4( const Transform3 & mat ); // Construct a 4x4 matrix from a 3x3 matrix and a 3-D vector // inline Matrix4( const Matrix3 & mat, const Vector3 &translateVec ); // Construct a 4x4 matrix from a unit-length quaternion and a 3-D vector // inline Matrix4( const Quat &unitQuat, const Vector3 &translateVec ); // Set all elements of a 4x4 matrix to the same scalar value // explicit inline Matrix4( float scalar ); // Set all elements of a 4x4 matrix to the same scalar value (scalar data contained in vector data type) // explicit inline Matrix4( const floatInVec &scalar ); // Assign one 4x4 matrix to another // inline Matrix4 & operator =( const Matrix4 & mat ); // Set the upper-left 3x3 submatrix // NOTE: // This function does not change the bottom row elements. // inline Matrix4 & setUpper3x3( const Matrix3 & mat3 ); // Get the upper-left 3x3 submatrix of a 4x4 matrix // inline const Matrix3 getUpper3x3( ) const; // Set translation component // NOTE: // This function does not change the bottom row elements. // inline Matrix4 & setTranslation( const Vector3 &translateVec ); // Get the translation component of a 4x4 matrix // inline const Vector3 getTranslation( ) const; // Set column 0 of a 4x4 matrix // inline Matrix4 & setCol0( const Vector4 &col0 ); // Set column 1 of a 4x4 matrix // inline Matrix4 & setCol1( const Vector4 &col1 ); // Set column 2 of a 4x4 matrix // inline Matrix4 & setCol2( const Vector4 &col2 ); // Set column 3 of a 4x4 matrix // inline Matrix4 & setCol3( const Vector4 &col3 ); // Get column 0 of a 4x4 matrix // inline const Vector4 getCol0( ) const; // Get column 1 of a 4x4 matrix // inline const Vector4 getCol1( ) const; // Get column 2 of a 4x4 matrix // inline const Vector4 getCol2( ) const; // Get column 3 of a 4x4 matrix // inline const Vector4 getCol3( ) const; // Set the column of a 4x4 matrix referred to by the specified index // inline Matrix4 & setCol( int col, const Vector4 &vec ); // Set the row of a 4x4 matrix referred to by the specified index // inline Matrix4 & setRow( int row, const Vector4 &vec ); // Get the column of a 4x4 matrix referred to by the specified index // inline const Vector4 getCol( int col ) const; // Get the row of a 4x4 matrix referred to by the specified index // inline const Vector4 getRow( int row ) const; // Subscripting operator to set or get a column // inline Vector4 & operator []( int col ); // Subscripting operator to get a column // inline const Vector4 operator []( int col ) const; // Set the element of a 4x4 matrix referred to by column and row indices // inline Matrix4 & setElem( int col, int row, float val ); // Set the element of a 4x4 matrix referred to by column and row indices (scalar data contained in vector data type) // inline Matrix4 & setElem( int col, int row, const floatInVec &val ); // Get the element of a 4x4 matrix referred to by column and row indices // inline const floatInVec getElem( int col, int row ) const; // Add two 4x4 matrices // inline const Matrix4 operator +( const Matrix4 & mat ) const; // Subtract a 4x4 matrix from another 4x4 matrix // inline const Matrix4 operator -( const Matrix4 & mat ) const; // Negate all elements of a 4x4 matrix // inline const Matrix4 operator -( ) const; // Multiply a 4x4 matrix by a scalar // inline const Matrix4 operator *( float scalar ) const; // Multiply a 4x4 matrix by a scalar (scalar data contained in vector data type) // inline const Matrix4 operator *( const floatInVec &scalar ) const; // Multiply a 4x4 matrix by a 4-D vector // inline const Vector4 operator *( const Vector4 &vec ) const; // Multiply a 4x4 matrix by a 3-D vector // inline const Vector4 operator *( const Vector3 &vec ) const; // Multiply a 4x4 matrix by a 3-D point // inline const Vector4 operator *( const Point3 &pnt ) const; // Multiply two 4x4 matrices // inline const Matrix4 operator *( const Matrix4 & mat ) const; // Multiply a 4x4 matrix by a 3x4 transformation matrix // inline const Matrix4 operator *( const Transform3 & tfrm ) const; // Perform compound assignment and addition with a 4x4 matrix // inline Matrix4 & operator +=( const Matrix4 & mat ); // Perform compound assignment and subtraction by a 4x4 matrix // inline Matrix4 & operator -=( const Matrix4 & mat ); // Perform compound assignment and multiplication by a scalar // inline Matrix4 & operator *=( float scalar ); // Perform compound assignment and multiplication by a scalar (scalar data contained in vector data type) // inline Matrix4 & operator *=( const floatInVec &scalar ); // Perform compound assignment and multiplication by a 4x4 matrix // inline Matrix4 & operator *=( const Matrix4 & mat ); // Perform compound assignment and multiplication by a 3x4 transformation matrix // inline Matrix4 & operator *=( const Transform3 & tfrm ); // Construct an identity 4x4 matrix // static inline const Matrix4 identity( ); // Construct a 4x4 matrix to rotate around the x axis // static inline const Matrix4 rotationX( float radians ); // Construct a 4x4 matrix to rotate around the y axis // static inline const Matrix4 rotationY( float radians ); // Construct a 4x4 matrix to rotate around the z axis // static inline const Matrix4 rotationZ( float radians ); // Construct a 4x4 matrix to rotate around the x axis (scalar data contained in vector data type) // static inline const Matrix4 rotationX( const floatInVec &radians ); // Construct a 4x4 matrix to rotate around the y axis (scalar data contained in vector data type) // static inline const Matrix4 rotationY( const floatInVec &radians ); // Construct a 4x4 matrix to rotate around the z axis (scalar data contained in vector data type) // static inline const Matrix4 rotationZ( const floatInVec &radians ); // Construct a 4x4 matrix to rotate around the x, y, and z axes // static inline const Matrix4 rotationZYX( const Vector3 &radiansXYZ ); // Construct a 4x4 matrix to rotate around a unit-length 3-D vector // static inline const Matrix4 rotation( float radians, const Vector3 &unitVec ); // Construct a 4x4 matrix to rotate around a unit-length 3-D vector (scalar data contained in vector data type) // static inline const Matrix4 rotation( const floatInVec &radians, const Vector3 &unitVec ); // Construct a rotation matrix from a unit-length quaternion // static inline const Matrix4 rotation( const Quat &unitQuat ); // Construct a 4x4 matrix to perform scaling // static inline const Matrix4 scale( const Vector3 &scaleVec ); // Construct a 4x4 matrix to perform translation // static inline const Matrix4 translation( const Vector3 &translateVec ); // Construct viewing matrix based on eye, position looked at, and up direction // static inline const Matrix4 lookAt( const Point3 &eyePos, const Point3 &lookAtPos, const Vector3 &upVec ); // Construct a perspective projection matrix // static inline const Matrix4 perspective( float fovyRadians, float aspect, float zNear, float zFar ); // Construct a perspective projection matrix based on frustum // static inline const Matrix4 frustum( float left, float right, float bottom, float top, float zNear, float zFar ); // Construct an orthographic projection matrix // static inline const Matrix4 orthographic( float left, float right, float bottom, float top, float zNear, float zFar ); } _VECTORMATH_ALIGNED_TYPE_2 ; // Multiply a 4x4 matrix by a scalar // inline const Matrix4 operator *( float scalar, const Matrix4 & mat ); // Multiply a 4x4 matrix by a scalar (scalar data contained in vector data type) // inline const Matrix4 operator *( const floatInVec &scalar, const Matrix4 & mat ); // Append (post-multiply) a scale transformation to a 4x4 matrix // NOTE: // Faster than creating and multiplying a scale transformation matrix. // inline const Matrix4 appendScale( const Matrix4 & mat, const Vector3 &scaleVec ); // Prepend (pre-multiply) a scale transformation to a 4x4 matrix // NOTE: // Faster than creating and multiplying a scale transformation matrix. // inline const Matrix4 prependScale( const Vector3 &scaleVec, const Matrix4 & mat ); // Multiply two 4x4 matrices per element // inline const Matrix4 mulPerElem( const Matrix4 & mat0, const Matrix4 & mat1 ); // Compute the absolute value of a 4x4 matrix per element // inline const Matrix4 absPerElem( const Matrix4 & mat ); // Transpose of a 4x4 matrix // inline const Matrix4 transpose( const Matrix4 & mat ); // Compute the inverse of a 4x4 matrix // NOTE: // Result is unpredictable when the determinant of mat is equal to or near 0. // inline const Matrix4 inverse( const Matrix4 & mat ); // Compute the inverse of a 4x4 matrix, which is expected to be an affine matrix // NOTE: // This can be used to achieve better performance than a general inverse when the specified 4x4 matrix meets the given restrictions. // The result is unpredictable when the determinant of mat is equal to or near 0. // inline const Matrix4 affineInverse( const Matrix4 & mat ); // Compute the inverse of a 4x4 matrix, which is expected to be an affine matrix with an orthogonal upper-left 3x3 submatrix // NOTE: // This can be used to achieve better performance than a general inverse when the specified 4x4 matrix meets the given restrictions. // inline const Matrix4 orthoInverse( const Matrix4 & mat ); // Determinant of a 4x4 matrix // inline const floatInVec determinant( const Matrix4 & mat ); // Conditionally select between two 4x4 matrices // NOTE: // This function uses a conditional select instruction to avoid a branch. // However, the transfer of select1 to a VMX register may use more processing time than a branch. // Use the boolInVec version for better performance. // inline const Matrix4 select( const Matrix4 & mat0, const Matrix4 & mat1, bool select1 ); // Conditionally select between two 4x4 matrices (scalar data contained in vector data type) // NOTE: // This function uses a conditional select instruction to avoid a branch. // inline const Matrix4 select( const Matrix4 & mat0, const Matrix4 & mat1, const boolInVec &select1 ); #ifdef _VECTORMATH_DEBUG // Print a 4x4 matrix // NOTE: // Function is only defined when _VECTORMATH_DEBUG is defined. // inline void print( const Matrix4 & mat ); // Print a 4x4 matrix and an associated string identifier // NOTE: // Function is only defined when _VECTORMATH_DEBUG is defined. // inline void print( const Matrix4 & mat, const char * name ); #endif // A 3x4 transformation matrix in array-of-structures format // _VECTORMATH_ALIGNED_TYPE_1 class Transform3 { private: Vector3 mCol0; Vector3 mCol1; Vector3 mCol2; Vector3 mCol3; public: // Default constructor; does no initialization // inline Transform3( ) { }; // Copy a 3x4 transformation matrix // inline Transform3( const Transform3 & tfrm ); // Construct a 3x4 transformation matrix containing the specified columns // inline Transform3( const Vector3 &col0, const Vector3 &col1, const Vector3 &col2, const Vector3 &col3 ); // Construct a 3x4 transformation matrix from a 3x3 matrix and a 3-D vector // inline Transform3( const Matrix3 & tfrm, const Vector3 &translateVec ); // Construct a 3x4 transformation matrix from a unit-length quaternion and a 3-D vector // inline Transform3( const Quat &unitQuat, const Vector3 &translateVec ); // Set all elements of a 3x4 transformation matrix to the same scalar value // explicit inline Transform3( float scalar ); // Set all elements of a 3x4 transformation matrix to the same scalar value (scalar data contained in vector data type) // explicit inline Transform3( const floatInVec &scalar ); // Assign one 3x4 transformation matrix to another // inline Transform3 & operator =( const Transform3 & tfrm ); // Set the upper-left 3x3 submatrix // inline Transform3 & setUpper3x3( const Matrix3 & mat3 ); // Get the upper-left 3x3 submatrix of a 3x4 transformation matrix // inline const Matrix3 getUpper3x3( ) const; // Set translation component // inline Transform3 & setTranslation( const Vector3 &translateVec ); // Get the translation component of a 3x4 transformation matrix // inline const Vector3 getTranslation( ) const; // Set column 0 of a 3x4 transformation matrix // inline Transform3 & setCol0( const Vector3 &col0 ); // Set column 1 of a 3x4 transformation matrix // inline Transform3 & setCol1( const Vector3 &col1 ); // Set column 2 of a 3x4 transformation matrix // inline Transform3 & setCol2( const Vector3 &col2 ); // Set column 3 of a 3x4 transformation matrix // inline Transform3 & setCol3( const Vector3 &col3 ); // Get column 0 of a 3x4 transformation matrix // inline const Vector3 getCol0( ) const; // Get column 1 of a 3x4 transformation matrix // inline const Vector3 getCol1( ) const; // Get column 2 of a 3x4 transformation matrix // inline const Vector3 getCol2( ) const; // Get column 3 of a 3x4 transformation matrix // inline const Vector3 getCol3( ) const; // Set the column of a 3x4 transformation matrix referred to by the specified index // inline Transform3 & setCol( int col, const Vector3 &vec ); // Set the row of a 3x4 transformation matrix referred to by the specified index // inline Transform3 & setRow( int row, const Vector4 &vec ); // Get the column of a 3x4 transformation matrix referred to by the specified index // inline const Vector3 getCol( int col ) const; // Get the row of a 3x4 transformation matrix referred to by the specified index // inline const Vector4 getRow( int row ) const; // Subscripting operator to set or get a column // inline Vector3 & operator []( int col ); // Subscripting operator to get a column // inline const Vector3 operator []( int col ) const; // Set the element of a 3x4 transformation matrix referred to by column and row indices // inline Transform3 & setElem( int col, int row, float val ); // Set the element of a 3x4 transformation matrix referred to by column and row indices (scalar data contained in vector data type) // inline Transform3 & setElem( int col, int row, const floatInVec &val ); // Get the element of a 3x4 transformation matrix referred to by column and row indices // inline const floatInVec getElem( int col, int row ) const; // Multiply a 3x4 transformation matrix by a 3-D vector // inline const Vector3 operator *( const Vector3 &vec ) const; // Multiply a 3x4 transformation matrix by a 3-D point // inline const Point3 operator *( const Point3 &pnt ) const; // Multiply two 3x4 transformation matrices // inline const Transform3 operator *( const Transform3 & tfrm ) const; // Perform compound assignment and multiplication by a 3x4 transformation matrix // inline Transform3 & operator *=( const Transform3 & tfrm ); // Construct an identity 3x4 transformation matrix // static inline const Transform3 identity( ); // Construct a 3x4 transformation matrix to rotate around the x axis // static inline const Transform3 rotationX( float radians ); // Construct a 3x4 transformation matrix to rotate around the y axis // static inline const Transform3 rotationY( float radians ); // Construct a 3x4 transformation matrix to rotate around the z axis // static inline const Transform3 rotationZ( float radians ); // Construct a 3x4 transformation matrix to rotate around the x axis (scalar data contained in vector data type) // static inline const Transform3 rotationX( const floatInVec &radians ); // Construct a 3x4 transformation matrix to rotate around the y axis (scalar data contained in vector data type) // static inline const Transform3 rotationY( const floatInVec &radians ); // Construct a 3x4 transformation matrix to rotate around the z axis (scalar data contained in vector data type) // static inline const Transform3 rotationZ( const floatInVec &radians ); // Construct a 3x4 transformation matrix to rotate around the x, y, and z axes // static inline const Transform3 rotationZYX( const Vector3 &radiansXYZ ); // Construct a 3x4 transformation matrix to rotate around a unit-length 3-D vector // static inline const Transform3 rotation( float radians, const Vector3 &unitVec ); // Construct a 3x4 transformation matrix to rotate around a unit-length 3-D vector (scalar data contained in vector data type) // static inline const Transform3 rotation( const floatInVec &radians, const Vector3 &unitVec ); // Construct a rotation matrix from a unit-length quaternion // static inline const Transform3 rotation( const Quat &unitQuat ); // Construct a 3x4 transformation matrix to perform scaling // static inline const Transform3 scale( const Vector3 &scaleVec ); // Construct a 3x4 transformation matrix to perform translation // static inline const Transform3 translation( const Vector3 &translateVec ); } _VECTORMATH_ALIGNED_TYPE_2 ; // Append (post-multiply) a scale transformation to a 3x4 transformation matrix // NOTE: // Faster than creating and multiplying a scale transformation matrix. // inline const Transform3 appendScale( const Transform3 & tfrm, const Vector3 &scaleVec ); // Prepend (pre-multiply) a scale transformation to a 3x4 transformation matrix // NOTE: // Faster than creating and multiplying a scale transformation matrix. // inline const Transform3 prependScale( const Vector3 &scaleVec, const Transform3 & tfrm ); // Multiply two 3x4 transformation matrices per element // inline const Transform3 mulPerElem( const Transform3 & tfrm0, const Transform3 & tfrm1 ); // Compute the absolute value of a 3x4 transformation matrix per element // inline const Transform3 absPerElem( const Transform3 & tfrm ); // Inverse of a 3x4 transformation matrix // NOTE: // Result is unpredictable when the determinant of the left 3x3 submatrix is equal to or near 0. // inline const Transform3 inverse( const Transform3 & tfrm ); // Compute the inverse of a 3x4 transformation matrix, expected to have an orthogonal upper-left 3x3 submatrix // NOTE: // This can be used to achieve better performance than a general inverse when the specified 3x4 transformation matrix meets the given restrictions. // inline const Transform3 orthoInverse( const Transform3 & tfrm ); // Conditionally select between two 3x4 transformation matrices // NOTE: // This function uses a conditional select instruction to avoid a branch. // However, the transfer of select1 to a VMX register may use more processing time than a branch. // Use the boolInVec version for better performance. // inline const Transform3 select( const Transform3 & tfrm0, const Transform3 & tfrm1, bool select1 ); // Conditionally select between two 3x4 transformation matrices (scalar data contained in vector data type) // NOTE: // This function uses a conditional select instruction to avoid a branch. // inline const Transform3 select( const Transform3 & tfrm0, const Transform3 & tfrm1, const boolInVec &select1 ); #ifdef _VECTORMATH_DEBUG // Print a 3x4 transformation matrix // NOTE: // Function is only defined when _VECTORMATH_DEBUG is defined. // inline void print( const Transform3 & tfrm ); // Print a 3x4 transformation matrix and an associated string identifier // NOTE: // Function is only defined when _VECTORMATH_DEBUG is defined. // inline void print( const Transform3 & tfrm, const char * name ); #endif } // namespace Aos } // namespace Vectormath #include "vec_aos.h" #include "quat_aos.h" #include "mat_aos.h" #endif |
Commits for Divide-Dependencies/debug-draw/samples/vectormath/SSE/cpp/vectormath_aos.h
Revision | Author | Commited | Message |
---|---|---|---|
70 |
|
Wed 26 Jul, 2017 20:21:42 +0000 | [Ionut] |