#ifndef ICL_GEOM_DEFS_H #define ICL_GEOM_DEFS_H #include #include #include #include #include namespace icl{ /// color for geometry primitives typedef Color4D32f GeomColor; /// Matrix Typedef of float matrices typedef FixedMatrix Mat4D32f; /// Matrix Typedef of double matrices typedef FixedMatrix Mat4D64f; /// Vector typedef of float vectors typedef FixedColVector Vec4D32f; /// Vector typedef of double vectors typedef FixedColVector Vec4D64f; /// Short typedef for 4D float vectors typedef Vec4D32f Vec; /// Short typedef for 4D float matrices typedef Mat4D32f Mat; /// normalize a vector to length 1 template inline FixedColVector normalize(const FixedMatrix &v) { double l = v.length(); ICLASSERT_RETURN_VAL(l,v); return v/l; } /// normalize a vector to length 1 template inline FixedColVector normalize3(const FixedMatrix &v,const double& h=1) { double l = ::sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]); ICLASSERT_RETURN_VAL(l,v); Vec n = v/l; // XXX n[3]=h; return n; } /// homogenize a vector be normalizing 4th component to 1 template inline FixedColVector homogenize(const FixedMatrix &v){ ICLASSERT_RETURN_VAL(v[3],v); return v/v[3]; } /// perform perspective projection template inline FixedColVector project(FixedMatrix v, T z){ T zz = z*v[2]; v[0]/=zz; v[1]/=zz; v[2]=0; v[3]=1; return v; } /// homogeneous 3D cross-product template inline FixedColVector cross(const FixedMatrix &v1, const FixedMatrix &v2){ return FixedColVector(v1[1]*v2[2]-v1[2]*v2[1], v1[2]*v2[0]-v1[0]*v2[2], v1[0]*v2[1]-v1[1]*v2[0], 1 ); } typedef std::vector VecArray; inline Vec rotate_vector(const Vec &axis, float angle, const Vec &vec){ return create_rot_4x4(axis[0],axis[1],axis[2],angle)*vec; /* angle /= 2; float a = cos(angle); float sa = sin(angle); float b = axis[0] * sa; float c = axis[1] * sa; float d = axis[2] * sa; float a2=a*a, b2=b*b, c2=c*c, d2=d*d; float ab=a*b, ac=a*c, ad=a*d, bc=b*c, bd=b*d, cd=c*d; Mat X(a2+b2-c2-d2, 2*bc-2*ad, 2*ac+2*bd, 0, 2*ad+2*bd, a2-b2+c2-d2, 2*cd-2*ab, 0, 2*bd-2*ac, 2*ab+2*cd, a2-b2-c2+d2, 0, 0, 0, 0, 1); return X * vec; */ } } #endif