class eiObject{public: eiString name;
eiObjectType type;
eiMaterial *material; eiUInt mtl_id;
eiBound box; eiFloat width; //delta x eiFloat height; //delta y eiFloat length; //delta z eiFloat radius; public: eiObject(); ~eiObject();
virtual eiVoid inherit_transform(const eiMatrix &);
virtual eiVoid triangulate();};//-------------------------------------------------class eiPolygon : public eiObject{public: std::vector<eiTri> triList; std::vector<eiVtx> vtxList; std::vector<eiEdge> edgeList;
......public: eiPolygon(); ~eiPolygon();
eiVoid inherit_transform(const eiMatrix &);};//-------------------------------------------------class eiGroup{public: eiString name;
eiVector pos; eiVector x_axis,y_axis,z_axis;
std::list<eiGroup> children; eiGroup *parent; eiObject *object;
public: eiGroup(); ~eiGroup();
virtual eiVoid translate(const eiVector &); virtual eiVoid rotate(const eiVector &); virtual eiVoid scale(const eiVector &);
virtual eiVoid apply_transform(); virtual eiVoid inherit_transform(const eiMatrix &);};
/************************************************************************** Transform **************************************************************************/
#include "stdafx.h"#include "head.h"
//-------------------------------------------------------------------------eiVoid eiObject::inherit_transform(const eiMatrix & mx){ return;}//-------------------------------------------------------------------------eiVoid eiObject::triangulate(){ return;}//-------------------------------------------------------------------------eiVoid eiPolygon::inherit_transform(const eiMatrix & mx){ if( ! vtxList.empty() ) { for(eiInt i = 0 ; i < vtxList.size() ; i++) { vtxList[i].v_pos = mulvm( vtxList[i].pos, inverse( mx ) ); } }}//-------------------------------------------------------------------------eiVoid eiGroup::eiGroup(){ pos = newvec(); x_axis = newvec( 1.0, 0.0, 0.0 ); y_axis = newvec( 0.0, 1.0, 0.0 ); z_axis = newvec( 0.0, 0.0, 1.0 );
parent = NULL; object = NULL;}//-------------------------------------------------------------------------eiVoid eiGroup::apply_transform(){ eiMatrix tm,rm;
tm = newmx( 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, - pos.x, - pos.y, - pos.z, 1.0 );
rm = newmx( x_axis.x, y_axis.x, z_axis.x, 0.0 , x_axis.y, y_axis.y, z_axis.y, 0.0 , x_axis.z, y_axis.z, z_axis.z, 0.0 , 0.0 , 0.0 , 0.0 , 1.0 );
tm = mulmm( tm, rm );
if(object != NULL) { object->inherit_transform( tm ); }
if( ! children.empty() ) { for( std::list<eiGroup>::iterator iter = children.begin() ; iter != children.end() ; ++ iter ) { iter->inherit_transform( tm ); } }}//-------------------------------------------------------------------------eiVoid eiGroup::inherit_transform(const eiMatrix & mx){ eiMatrix tm,rm;
tm = newmx( 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, - pos.x, - pos.y, - pos.z, 1.0 );
rm = newmx( x_axis.x, y_axis.x, z_axis.x, 0.0 , x_axis.y, y_axis.y, z_axis.y, 0.0 , x_axis.z, y_axis.z, z_axis.z, 0.0 , 0.0 , 0.0 , 0.0 , 1.0 );
tm = mulmm( tm, rm ); tm = mulmm( mx, tm );
if(object != NULL) { object->inherit_transform( tm ); }
if( ! children.empty() ) { for( std::list<eiGroup>::iterator iter = children.begin() ; iter != children.end() ; ++ iter ) { iter->inherit_transform( tm ); } }}//-------------------------------------------------------------------------eiVoid eiGroup::translate(const eiVector & vec){ pos = add( pos, vec );}//-------------------------------------------------------------------------eiVoid eiGroup::rotate(const eiVector & vec){ if(vec.y != 0.0f) { x_axis = mulvm( x_axis, roty(vec.y) ); y_axis = mulvm( y_axis, roty(vec.y) ); z_axis = mulvm( z_axis, roty(vec.y) ); }
if(vec.x != 0.0f) { x_axis = mulvm( x_axis, rotx(vec.x) ); y_axis = mulvm( y_axis, rotx(vec.x) ); z_axis = mulvm( z_axis, rotx(vec.x) ); }
if(vec.z != 0.0f) { x_axis = mulvm( x_axis, rotz(vec.z) ); y_axis = mulvm( y_axis, rotz(vec.z) ); z_axis = mulvm( z_axis, rotz(vec.z) ); }}//-------------------------------------------------------------------------eiVoid eiGroup::scale(const eiVector & vec){ x_axis = mulvf( x_axis, vec.x ); y_axis = mulvf( y_axis, vec.y ); z_axis = mulvf( z_axis, vec.z );}
posted on 2005-06-24 23:19 Len3d 阅读( ...) 评论( ...) 编辑 收藏转载于:https://www.cnblogs.com/len3d/archive/2005/06/24/180753.html