Changeset 459
- Timestamp:
- 08/18/15 14:26:33 (10 years ago)
- Location:
- trunk/nv
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/interface/interpolation_raw.hh
r451 r459 150 150 { 151 151 quat& r = *( reinterpret_cast<quat*>( data ) ); 152 r = quat_cast( r33 * mat3_cast( r ) * ri33 );152 r = math::quat_cast( r33 * mat3_cast( r ) * ri33 ); 153 153 } 154 154 inline void transform_key_scale( void* data, float scale ) … … 162 162 t = transform( 163 163 r33 * t.get_position() * scale, 164 quat_cast( r33 *mat3_cast( t.get_orientation() ) * ri33 )164 math::quat_cast( r33 * math::mat3_cast( t.get_orientation() ) * ri33 ) 165 165 ); 166 166 } -
trunk/nv/stl/math/common.hh
r454 r459 25 25 #include <nv/base/cmath.hh> 26 26 #include <glm/glm.hpp> 27 #include <glm/gtc/quaternion.hpp>28 #include <glm/gtx/vector_angle.hpp>29 27 30 28 namespace nv … … 67 65 template < typename T > using tmat3 = ::glm::detail::tmat3x3<T, glm::precision::highp>; 68 66 template < typename T > using tmat4 = ::glm::detail::tmat4x4<T, glm::precision::highp>; 69 template < typename T > using tquat = ::glm::detail::tmat4x4<T, glm::precision::highp>;70 67 #else 71 68 template < typename T > using tvec2 = ::glm::tvec2<T>; … … 75 72 template < typename T > using tmat3 = ::glm::tmat3x3<T>; 76 73 template < typename T > using tmat4 = ::glm::tmat4x4<T>; 77 template < typename T > using tquat = ::glm::tquat<T, glm::highp>;78 74 #endif 79 80 typedef glm::quat quat;81 75 82 76 template < typename T > struct is_vec : false_type {}; 83 77 template < typename T > struct is_mat : false_type {}; 84 template < typename T > struct is_quat : false_type {};85 78 86 79 template < typename T > struct is_fp : is_floating_point< T > {}; 87 80 template < typename T > struct is_fp_vec : false_type {}; 88 81 template < typename T > struct is_fp_mat : false_type {}; 89 template < typename T > struct is_fp_quat : false_type {};90 82 91 83 template < typename T > struct is_bool_vec : false_type {}; … … 97 89 template < typename T > struct is_mat < tmat3< T > > : true_type {}; 98 90 template < typename T > struct is_mat < tmat4< T > > : true_type {}; 99 template < typename T > struct is_quat< tquat< T > > : true_type {};100 91 101 92 template < typename T > struct is_fp < tvec2< T > > : is_floating_point< T > {}; … … 108 99 template < typename T > struct is_fp_mat < tmat3< T > > : is_floating_point< T > {}; 109 100 template < typename T > struct is_fp_mat < tmat4< T > > : is_floating_point< T > {}; 110 template < typename T > struct is_fp_quat< tquat< T > > : is_floating_point< T > {};111 101 112 102 template <> struct is_bool_vec < tvec2< bool > > : true_type {}; … … 232 222 typedef math::tmat4< float > mat4; 233 223 234 typedef math::quat quat;235 236 237 238 224 template < typename T > 239 225 struct make_unsigned< math::tvec2< T > > -
trunk/nv/stl/math/quaternion.hh
r454 r459 24 24 namespace math 25 25 { 26 27 template <typename T> 28 struct tquat 29 { 30 typedef tquat<T> type; 31 typedef T value_type; 32 public: 33 T x, y, z, w; 34 35 typedef int length_type; 36 37 constexpr length_type length() const { return 4; } 38 inline T& operator[]( length_type i ) 39 { 40 NV_ASSERT( i >= 0 && i < 4, "index out of range" ); 41 return ( &x )[i] 42 } 43 inline const T& operator[]( length_type i ) const 44 { 45 NV_ASSERT( i >= 0 && i < 4, "index out of range" ); 46 return ( &x )[i] 47 } 48 49 constexpr tquat() 50 : x( 0 ), y( 0 ), z( 0 ), w( 0 ) {}; 51 constexpr tquat( const tquat<T>& q ) 52 : x( q.x ), y( q.y ), z( q.z ), w( q.w ) {} 53 54 inline explicit tquat( ctor ) {} 55 constexpr explicit tquat( const T& s, const tvec3<T>& v ) 56 : x( v.x ), y( v.y ), z( v.z ), w( s ) {} 57 constexpr tquat( const T& aw, const T& ax, const T& ay, const T& az ) 58 : x( ax ), y( ay ), z( az ), w( aw ) {} 59 60 inline explicit operator tmat3<T>(); 61 inline explicit operator tmat4<T>(); 62 inline explicit tquat( const tvec3<T>& u, const tvec3<T>& v ); 63 inline explicit tquat( const tvec3<T>& euler ); 64 inline explicit tquat( const tmat3<T>& m ); 65 inline explicit tquat( const tmat4<T>& m ); 66 67 inline tquat<T>& operator=( const tquat<T>& q ) 68 { 69 this->w = q.w; 70 this->x = q.x; 71 this->y = q.y; 72 this->z = q.z; 73 return *this; 74 } 75 inline tquat<T>& operator+=( const tquat<T>& q ) 76 { 77 this->w += q.w; 78 this->x += q.x; 79 this->y += q.y; 80 this->z += q.z; 81 return *this; 82 } 83 inline tquat<T>& operator*=( const tquat<T>& q ) 84 { 85 this->w = w * q.w - x * q.x - y * q.y - z * q.z; 86 this->x = w * q.x + x * q.w + y * q.z - z * q.y; 87 this->y = w * q.y + y * q.w + z * q.x - x * q.z; 88 this->z = w * q.z + z * q.w + x * q.y - y * q.x; 89 return *this; 90 } 91 inline tquat<T>& operator*=( T s ) 92 { 93 this->w *= s; 94 this->x *= s; 95 this->y *= s; 96 this->z *= s; 97 return *this; 98 } 99 100 inline tquat<T>& operator/=( T s ) 101 { 102 this->w /= s; 103 this->x /= s; 104 this->y /= s; 105 this->z /= s; 106 return *this; 107 } 108 109 }; 110 111 typedef tquat< f32 > quat; 112 113 template < typename T > struct is_fp_quat : false_type {}; 114 template < typename T > struct is_quat : false_type {}; 115 116 template < typename T > struct is_quat< tquat< T > > : true_type {}; 117 template < typename T > struct is_fp_quat< tquat< T > > : is_floating_point< T > {}; 118 26 119 namespace detail 27 120 { … … 39 132 } 40 133 134 template < typename T, typename enable_if< is_fp_quat<T>::value >::type* = nullptr > 135 inline value_type_t<T> dot( const T& a, const T& b ) 136 { 137 return detail::dot_impl< T >::get( a, b ); 138 } 41 139 42 140 template < typename T > … … 355 453 } 356 454 455 template < typename T > 456 inline tquat<T>::operator tmat3<T>() 457 { 458 return mat3_cast( *this ); 459 } 460 461 template < typename T > 462 inline tquat<T>::operator tmat4<T>() 463 { 464 return mat4_cast( *this ); 465 } 466 467 template < typename T > 468 inline tquat<T>::tquat( const tvec3<T>& u, const tvec3<T>& v ) 469 { 470 const tvec3<T> lw( cross( u, v ) ); 471 T dot_result = detail::dot_impl< tvec3<T> >::get( u, v ); 472 tquat<T> q( T( 1 ) + dot_result, lw.x, lw.y, lw.z ); 473 *this = normalize( q ); 474 } 475 476 template < typename T > 477 inline tquat<T>::tquat( const tvec3<T>& euler ) 478 { 479 tvec3<T> c = math::cos( euler * T( 0.5 ) ); 480 tvec3<T> s = math::sin( euler * T( 0.5 ) ); 481 482 w = c.x * c.y * c.z + s.x * s.y * s.z; 483 x = s.x * c.y * c.z - c.x * s.y * s.z; 484 y = c.x * s.y * c.z + s.x * c.y * s.z; 485 z = c.x * c.y * s.z - s.x * s.y * c.z; 486 } 487 488 template < typename T > 489 inline tquat<T>::tquat( const tmat3<T>& m ) 490 { 491 *this = quat_cast( m ); 492 } 493 494 template < typename T > 495 inline tquat<T>::tquat( const tmat4<T>& m ) 496 { 497 *this = quat_cast( m ); 498 } 499 500 template < typename T > 501 inline tquat<T> operator-( const tquat<T>& q ) 502 { 503 return tquat<T>( -q.w, -q.x, -q.y, -q.z ); 504 } 505 506 template < typename T > 507 inline tquat<T> operator+( const tquat<T>& q, const tquat<T>& p ) 508 { 509 return tquat<T>( q ) += p; 510 } 511 512 template < typename T > 513 inline tquat<T> operator*( const tquat<T>& q, const tquat<T>& p ) 514 { 515 return tquat<T>( q ) *= p; 516 } 517 518 template < typename T > 519 inline tvec3<T> operator*( const tquat<T>& q, const tvec3<T>& v ) 520 { 521 tvec3<T> qvec( q.x, q.y, q.z ); 522 tvec3<T> uv( math::cross( qvec, v ) ); 523 tvec3<T> uuv( math::cross( qvec, uv ) ); 524 525 return v + ( ( uv * q.w ) + uuv ) * static_cast<T>( 2 ); 526 } 527 528 template < typename T > 529 inline tvec3<T> operator*( const tvec3<T> & v, const tquat<T>& q ) 530 { 531 return math::inverse( q ) * v; 532 } 533 534 template < typename T > 535 inline tvec4<T> operator*( const tquat<T>& q, const tvec4<T>& v ) 536 { 537 return tvec4<T>( q * tvec3<T>( v ), v.w ); 538 } 539 540 template < typename T > 541 inline tvec4<T> operator*( const tvec4<T>& v, const tquat<T>& q ) 542 { 543 return math::inverse( q ) * v; 544 } 545 546 template < typename T > 547 inline tquat<T> operator*( const tquat<T>& q, T s ) 548 { 549 return tquat<T>( q.w * s, q.x * s, q.y * s, q.z * s ); 550 } 551 552 template < typename T > 553 inline tquat<T> operator*( T s, const tquat<T>& q ) 554 { 555 return q * s; 556 } 557 558 template < typename T > 559 inline tquat<T> operator/( const tquat<T>& q, T s ) 560 { 561 return tquat<T>( q.w / s, q.x / s, q.y / s, q.z / s ); 562 } 563 564 template < typename T > 565 inline bool operator==( const tquat<T>& q1, const tquat<T>& q2 ) 566 { 567 return ( q1.x == q2.x ) && ( q1.y == q2.y ) && ( q1.z == q2.z ) && ( q1.w == q2.w ); 568 } 569 570 template < typename T > 571 inline bool operator!=( const tquat<T>& q1, const tquat<T>& q2 ) 572 { 573 return ( q1.x != q2.x ) || ( q1.y != q2.y ) || ( q1.z != q2.z ) || ( q1.w != q2.w ); 574 } 575 357 576 } 358 577 578 typedef math::quat quat; 579 359 580 } 360 581
Note: See TracChangeset
for help on using the changeset viewer.