Sunny:tpoint4.h

/**/ ///
// tpoint4.h
// Sunny:2007-2-7
// Author:cheungmine-cheungmine@gmail.com
// Copyrightbycheungmine
/**/ ///
#ifndef_tpoint4_h_
#define _tpoint4_h_

#include
" geomdef.h "

#include
" tpoint3.h "

template
< typenameT >
struct GEOM_EXPt_point4
... {
union
...{
struct
...{
Tx,y,z,w;
//3realcomponentsofthevector
}
;
Tv[
4];//Arrayaccessusefulinloops
}
;

//Defaultconstructor,definedfortemplateclasses
t_point4()
...{}

//Constructapointwith3giveninputs
t_point4(T_x,T_y,T_z,T_w=1.f):x(_x),y(_y),z(_z),w(_w)
...{}

t_point4(
constt_point4&in):x(in.x),y(in.y),z(in.z),w(in.w)
...{
}


t_point4(
constt_point3<T>&in):x(in.x),y(in.y),z(in.z),w(1.f)
...{
}


//Reassignapointwithoutmakingatemporarystructure
voidassign(T_x,T_y,T_z,T_w)
...{
x
=_x;y=_y;z=_z;w=_w;
}


//Negateavector
voidneg()
...{
x
=-x;y=-y;z=-z;w=-w;
}


//Returnthemagnitudeofapoint
Tmag()
...{
return(T)sqrt(x*x+y*y+z*z+w*w);
}


//Normalizesavector(makesit'slength1)
voidnorm()
...{
Tinv
=1/mag();
x
*=inv;
y
*=inv;
z
*=inv;
w
*=inv;
}

}
;

// Addstwopointstogether:ret=a+b
template < typenameT >
inline
const t_point4 < T > operator + ( const t_point4 < T >& a, const t_point4 < T >& b)
... {
returnt_point4<T>(a.x+b.x,a.y+b.y,a.z+b.z,a.w+b.w);
}
;

// Subtractstopoints:ret=a-b
template < typenameT >
inline
const t_point4 < T > operator - ( const t_point4 < T >& a, const t_point4 < T >& b)
... {
returnt_point4<T>(a.x-b.x,a.y-b.y,a.z-b.z,a.w-b.w);
}
;

// Scalesavectorbyascalar:ret=a*s
template < typenameT >
inline
const t_point4 < T > operator * ( const t_point4 < T >& a, const T & s)
... {
returnt_point4<T>(a.x*s,a.y*s,a.z*s,a.w*s);
}
;

// Scalesavectorbyascalar:ret=s*a
template < typenameT >
inline
const t_point4 < T > operator * ( const T & s, const t_point4 < T >& a)
... {
returnt_point4<T>(s*a.x,s*a.y,s*a.z,s*a.w);
}
;

// Dividesavectorbyascalar:ret=a/s
template < typenameT >
inline
const t_point4 < T > operator / ( const t_point4 < T > & a, const T & s)
... {
returnt_point4<T>(a.x/s,a.y/s,a.z/s,a.w/s);
}
;

// VectorEquality,epsilonusedduetonumericalimprecision
template < typenameT >
inline
bool operator == ( const t_point4 < T >& a, const t_point4 < T >& b)
... {
if(fabs(a.x-b.x)<EPSILON&&fabs(a.y-b.y)<EPSILON&&fabs(a.z-b.z)<EPSILON&&fabs(a.w-b.w)<EPSILON)
returntrue;
returnfalse;
}
;

// Performsavectordotproduct:ret=adotb
template < typenameT >
inlineT
operator * ( const t_point4 < T >& a, const t_point4 < T >& b)
... {
return(T)(a.x*b.x+a.y*b.y+a.z*b.z+a.w*b.w);
}



#endif // _tpoint4_h_
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值