微软xna数学库里的实现
XMFINLINE XMVECTOR XMVector2Cross
(
FXMVECTOR V1,
FXMVECTOR V2
)
{
#if defined(_XM_NO_INTRINSICS_)
FLOAT fCross = (V1.vector4_f32[0] * V2.vector4_f32[1]) - (V1.vector4_f32[1] * V2.vector4_f32[0]);
XMVECTOR vResult = {
fCross,
fCross,
fCross,
fCross
};
return vResult;
#elif defined(_XM_SSE_INTRINSICS_)
// Swap x and y
XMVECTOR vResult = _mm_shuffle_ps(V2,V2,_MM_SHUFFLE(0,1,0,1));
// Perform the muls
vResult = _mm_mul_ps(vResult,V1);
// Splat y
XMVECTOR vTemp = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(1,1,1,1));
// Sub the values
vResult = _mm_sub_ss(vResult,vTemp);
// Splat the cross product
vResult = _mm_shuffle_ps(vResult,vResult,_MM_SHUFFLE(0,0,0,0));
return vResult;
#else // _XM_VMX128_INTRINSICS_
#endif // _XM_VMX128_INTRINSICS_
}
【 在 xibaomo (xibaomo) 的大作中提到: 】
: 有个非常简单的函数,都是float,
: float cross(Complex& a, Complex& b) {
: float tmp= a.re*b.im - a.im*b.re;
: ...................
--
FROM 120.244.154.*