www.pudn.com > VISC_LFS.rar > visc.h


//_VISC_H 
#include  
#include  
using namespace std; 
 
 
//颜色 
struct Color 
{ 
	int r; 
	int g; 
	int b; 
}; 
 
 
//点 
class Point 
{ 
public: 
	double x,y,z; 
	Point(double xx = 0,double yy = 0,double zz = 0) 
	{ 
		x = xx; 
		y = yy; 
		z = zz; 
	} 
	Point operator+(const Point &p) 
	{ 
		Point pp; 
		pp.x = x + p.x; 
		pp.y = y + p.y; 
		pp.z = z + p.z; 
		return pp; 
	} 
	/*Point& operator*(const double &d) 
	{ 
		x = x*d; 
		y = y*d; 
		z = z*d; 
		return *this; 
	}*/ 
	Point operator*(const double &d) 
	{ 
		Point temp; 
		temp.x = x*d; 
		temp.y = y*d; 
		temp.z = z*d; 
		return temp; 
	} 
}; 
//向量 
class Normal 
{ 
public: 
	double nx,ny,nz; 
public: 
	Normal(double x=0,double y=0,double z=0) 
	{ 
		nx = x ; 
		ny = y; 
		nz = z; 
	} 
	Normal(Point& p1,Point& p2) 
	{ 
		nx = p2.x - p1.x; 
		ny = p2.y - p1.y; 
		nz = p2.z - p1.z; 
	} 
	Point operator+(const Point &p) 
	{ 
		Point pp; 
		pp.x = p.x + nx; 
		pp.y = p.y + ny; 
		pp.z = p.z + nz; 
		return pp; 
	} 
	/*Normal& operator*(const double &d)  //错误的根源 
	{ 
		nx = d*nx; 
		ny = d*ny; 
		nz = d*nz; 
		return *this; 
	}*/ 
	Normal operator*(const double &d) 
	{ 
		Normal temp; 
		temp.nx = d*nx; 
		temp.ny = d*ny; 
		temp.nz = d*nz; 
		return temp; 
	} 
	Normal Cross(Normal &n2) //向量叉乘 
	{ 
		Normal n; 
		n.nx = ny*n2.nz - nz*n2.ny; 
		n.ny = nz*n2.nx - nx*n2.nz; 
		n.nz = nx*n2.ny - ny*n2.nx; 
		Normalizing(); 
		return n; 
	} 
	double Dot(Normal &n2)//向量点乘 
	{ 
		return nx*n2.nx + ny*n2.ny + nz*n2.nz; 
	} 
	void Normalizing() //归一化 
	{ 
		double temp = sqrt(nx*nx+ny*ny+nz*nz); 
		if(temp == 0.0) 
		{ 
			cout<<"error"<RADIUS ||p.x<-RADIUS ||p.y>RADIUS||p.y<-RADIUS||p.z>RADIUS||p.z<-RADIUS) 
		{ 
			return false; 
		} 
		return true; 
	} 
	//-------------------------------------------------------
	//bool intersect(Line &l,double &t,Point& ispoint)
	//该函数是表示射线和面的求交.
	//------------------------------------------------------- 
	bool intersect(Ray &l,double &t,Point& ispoint) 
	{ 
		Normal n(normal.nx,normal.ny,normal.nz); 
		double denominator = Dot(n,l.n); 
		if(abs(denominator)