float4::float4(const float3 &xyz, float w_) #if !defined(MATH_AUTOMATIC_SSE) || !defined(MATH_SSE) // Best: 5.761 nsecs / 15.872 ticks, Avg: 6.237 nsecs, Worst: 7.681 nsecs :x(xyz.x), y(xyz.y), z(xyz.z), w(w_) #endif { #if defined(MATH_AUTOMATIC_SSE) && defined(MATH_SSE) // Best: 1.536 nsecs / 4.032 ticks, Avg: 1.540 nsecs, Worst: 1.920 nsecs v = load_vec3(xyz.ptr(), w_); #endif }
float3 MUST_USE_RESULT Quat::Transform(const float3 &vec) const { assume2(this->IsNormalized(), *this, this->LengthSq()); #if defined(MATH_AUTOMATIC_SSE) && defined(MATH_SSE) return float4(quat_transform_vec4(q, load_vec3(vec.ptr(), 0.f))).xyz(); #else ///\todo Optimize/benchmark the scalar path not to generate a matrix! float3x3 mat = this->ToFloat3x3(); return mat * vec; #endif }
/** dst = A x B - Apply the diagonal rule to derive the standard cross product formula: \code |a cross b| = |a||b|sin(alpha) i j k i j k units (correspond to x,y,z) a.x a.y a.z a.x a.y a.z vector a (this) b.x b.y b.z b.x b.y b.z vector b -a.z*b.y*i -a.x*b.z*j -a.y*b.x*k a.y*b.z*i a.z*b.x*j a.x*b.y*k result Add up the results: x = a.y*b.z - a.z*b.y y = a.z*b.x - a.x*b.z z = a.x*b.y - a.y*b.x \endcode Cross product is anti-commutative, i.e. a x b == -b x a. It distributes over addition, meaning that a x (b + c) == a x b + a x c, and combines with scalar multiplication: (sa) x b == a x (sb). i x j == -(j x i) == k, (j x k) == -(k x j) == i, (k x i) == -(i x k) == j. */ float4 float4::Cross3(const float3 &rhs) const { #if defined(MATH_AUTOMATIC_SSE) && defined(MATH_SSE) return float4(cross_ps(v, load_vec3(rhs.ptr(), 0.f))); #else float4 dst; dst.x = y * rhs.z - z * rhs.y; dst.y = z * rhs.x - x * rhs.z; dst.z = x * rhs.y - y * rhs.x; dst.w = 0.f; return dst; #endif }
void Quat::SetFromAxisAngle(const float3 &axis, float angle) { #if defined(MATH_AUTOMATIC_SSE) && defined(MATH_SSE) SetFromAxisAngle(load_vec3(axis.ptr(), 0.f), angle); #else assume1(axis.IsNormalized(), axis); assume1(MATH_NS::IsFinite(angle), angle); float sinz, cosz; SinCos(angle*0.5f, sinz, cosz); x = axis.x * sinz; y = axis.y * sinz; z = axis.z * sinz; w = cosz; #endif }