share more data structures and code between OpenCL and C/C++ on CPU:
move the setConstraint4/b3ConvertConstraint4 to shared code.
This commit is contained in:
@@ -24,11 +24,18 @@ inline b3Mat3x3 b3AbsoluteMat3x3(b3Mat3x3ConstArg mat)
|
||||
|
||||
#define b3GetRow(m,row) m.getRow(row)
|
||||
|
||||
__inline
|
||||
b3Float4 mtMul3(b3Float4ConstArg a, b3Mat3x3ConstArg b)
|
||||
{
|
||||
return b*a;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float4 m_row[3];
|
||||
b3Float4 m_row[3];
|
||||
}b3Mat3x3;
|
||||
|
||||
#define b3Mat3x3ConstArg const b3Mat3x3
|
||||
@@ -36,7 +43,7 @@ typedef struct
|
||||
|
||||
inline b3Mat3x3 b3QuatGetRotationMatrix(b3Quat quat)
|
||||
{
|
||||
float4 quat2 = (float4)(quat.x*quat.x, quat.y*quat.y, quat.z*quat.z, 0.f);
|
||||
b3Float4 quat2 = (b3Float4)(quat.x*quat.x, quat.y*quat.y, quat.z*quat.z, 0.f);
|
||||
b3Mat3x3 out;
|
||||
|
||||
out.m_row[0].x=1-2*quat2.y-2*quat2.z;
|
||||
@@ -66,10 +73,107 @@ inline b3Mat3x3 b3AbsoluteMat3x3(b3Mat3x3ConstArg matIn)
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
__inline
|
||||
b3Mat3x3 mtZero();
|
||||
|
||||
__inline
|
||||
b3Mat3x3 mtIdentity();
|
||||
|
||||
__inline
|
||||
b3Mat3x3 mtTranspose(b3Mat3x3 m);
|
||||
|
||||
__inline
|
||||
b3Mat3x3 mtMul(b3Mat3x3 a, b3Mat3x3 b);
|
||||
|
||||
__inline
|
||||
b3Float4 mtMul1(b3Mat3x3 a, b3Float4 b);
|
||||
|
||||
__inline
|
||||
b3Float4 mtMul3(b3Float4 a, b3Mat3x3 b);
|
||||
|
||||
__inline
|
||||
b3Mat3x3 mtZero()
|
||||
{
|
||||
b3Mat3x3 m;
|
||||
m.m_row[0] = (b3Float4)(0.f);
|
||||
m.m_row[1] = (b3Float4)(0.f);
|
||||
m.m_row[2] = (b3Float4)(0.f);
|
||||
return m;
|
||||
}
|
||||
|
||||
__inline
|
||||
b3Mat3x3 mtIdentity()
|
||||
{
|
||||
b3Mat3x3 m;
|
||||
m.m_row[0] = (b3Float4)(1,0,0,0);
|
||||
m.m_row[1] = (b3Float4)(0,1,0,0);
|
||||
m.m_row[2] = (b3Float4)(0,0,1,0);
|
||||
return m;
|
||||
}
|
||||
|
||||
__inline
|
||||
b3Mat3x3 mtTranspose(b3Mat3x3 m)
|
||||
{
|
||||
b3Mat3x3 out;
|
||||
out.m_row[0] = (b3Float4)(m.m_row[0].x, m.m_row[1].x, m.m_row[2].x, 0.f);
|
||||
out.m_row[1] = (b3Float4)(m.m_row[0].y, m.m_row[1].y, m.m_row[2].y, 0.f);
|
||||
out.m_row[2] = (b3Float4)(m.m_row[0].z, m.m_row[1].z, m.m_row[2].z, 0.f);
|
||||
return out;
|
||||
}
|
||||
|
||||
__inline
|
||||
b3Mat3x3 mtMul(b3Mat3x3 a, b3Mat3x3 b)
|
||||
{
|
||||
b3Mat3x3 transB;
|
||||
transB = mtTranspose( b );
|
||||
b3Mat3x3 ans;
|
||||
// why this doesn't run when 0ing in the for{}
|
||||
a.m_row[0].w = 0.f;
|
||||
a.m_row[1].w = 0.f;
|
||||
a.m_row[2].w = 0.f;
|
||||
for(int i=0; i<3; i++)
|
||||
{
|
||||
// a.m_row[i].w = 0.f;
|
||||
ans.m_row[i].x = b3Dot3F4(a.m_row[i],transB.m_row[0]);
|
||||
ans.m_row[i].y = b3Dot3F4(a.m_row[i],transB.m_row[1]);
|
||||
ans.m_row[i].z = b3Dot3F4(a.m_row[i],transB.m_row[2]);
|
||||
ans.m_row[i].w = 0.f;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
||||
__inline
|
||||
b3Float4 mtMul1(b3Mat3x3 a, b3Float4 b)
|
||||
{
|
||||
b3Float4 ans;
|
||||
ans.x = b3Dot3F4( a.m_row[0], b );
|
||||
ans.y = b3Dot3F4( a.m_row[1], b );
|
||||
ans.z = b3Dot3F4( a.m_row[2], b );
|
||||
ans.w = 0.f;
|
||||
return ans;
|
||||
}
|
||||
|
||||
__inline
|
||||
b3Float4 mtMul3(b3Float4 a, b3Mat3x3 b)
|
||||
{
|
||||
b3Float4 colx = b3MakeFloat4(b.m_row[0].x, b.m_row[1].x, b.m_row[2].x, 0);
|
||||
b3Float4 coly = b3MakeFloat4(b.m_row[0].y, b.m_row[1].y, b.m_row[2].y, 0);
|
||||
b3Float4 colz = b3MakeFloat4(b.m_row[0].z, b.m_row[1].z, b.m_row[2].z, 0);
|
||||
|
||||
b3Float4 ans;
|
||||
ans.x = b3Dot3F4( a, colx );
|
||||
ans.y = b3Dot3F4( a, coly );
|
||||
ans.z = b3Dot3F4( a, colz );
|
||||
return ans;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //B3_MAT3x3_H
|
||||
|
||||
@@ -46,7 +46,18 @@ inline b3Quat b3QuatMul(b3QuatConstArg a, b3QuatConstArg b)
|
||||
|
||||
inline b3Quat b3QuatNormalize(b3QuatConstArg in)
|
||||
{
|
||||
return b3FastNormalize4(in);
|
||||
//return b3FastNormalize4(in);
|
||||
float len = native_sqrt(dot(q, q));
|
||||
if(len > 0.f)
|
||||
{
|
||||
q *= 1.f / len;
|
||||
}
|
||||
else
|
||||
{
|
||||
q.x = q.y = q.z = 0.f;
|
||||
q.w = 1.f;
|
||||
}
|
||||
return q;
|
||||
}
|
||||
inline float4 b3QuatRotate(b3QuatConstArg q, b3QuatConstArg vec)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user