⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glvector.h

📁 实战粒子系统例程
💻 H
字号:
/*
	glvector.h - Vector class
	Copyright (c) HalfLucifer, 2001.6.12
*/#ifndef __GLVECTORH__#define __GLVECTORH__#include "glmathlib.h"typedef float GLvector2[2];
typedef float GLvector4[4];class GLvector{

public:
	// Constructor	GLvector()							   { v[0]=v[1]=v[2]=0; }	GLvector(float tx, float ty, float tz) { v[0]=tx; v[1]=ty; v[2]=tz; }	GLvector(const GLvector &pVec)		   { v[0]=pVec.v[0]; v[1]=pVec.v[1]; v[2]=pVec.v[2]; }	GLvector(const float *pVec)			   { v[0]=pVec[0]; v[1]=pVec[1]; v[2]=pVec[2]; }
	// Operators overloading	GLvector operator=(const GLvector &pVec)   { return GLvector( v[0]=pVec.v[0], v[1]=pVec.v[1], v[2]=pVec.v[2]); }	GLvector operator=(const float *ptr)	   { return GLvector( v[0]=ptr[0], v[1]=ptr[1], v[2]=ptr[2]); }
	GLvector operator+(const GLvector &pVec)   { return GLvector( v[0]+pVec.v[0], v[1]+pVec.v[1], v[2]+pVec.v[2] ); }
	GLvector operator-(const GLvector &pVec)   { return GLvector( v[0]-pVec.v[0], v[1]-pVec.v[1], v[2]-pVec.v[2] ); }
	GLvector operator*(const GLvector &pVec)   { return GLvector( v[0]*pVec.v[0], v[1]*pVec.v[1], v[2]*pVec.v[2] ); }
	GLvector operator*(float val)			   { return GLvector( v[0]*val, v[1]*val, v[2]*val ); }
	GLvector operator/(const GLvector &pVec)   { return GLvector( v[0]/pVec.v[0], v[1]/pVec.v[1], v[2]/pVec.v[2] ); }
	GLvector operator/(float val)			   { return GLvector( v[0]/val, v[1]/val, v[2]/val ); }
	GLvector operator-(void)				   { return GLvector( -v[0], -v[1], -v[2] ); }
	GLvector &operator+=(const GLvector &pVec) { *this = *this + pVec; return *this; }
	GLvector &operator-=(const GLvector &pVec) { *this = *this - pVec; return *this; }
	GLvector &operator*=(const GLvector &pVec) { *this = *this * pVec; return *this; }
	GLvector &operator*=(float val)            { *this = *this * val; return *this; }
	GLvector &operator/=(const GLvector &pVec) { *this = *this / pVec; return *this; }
	GLvector &operator/=(float val)            { *this = *this / val; return *this; }
	bool operator==(const GLvector &pVec) { return ( v[0]==pVec.v[0] && v[1]==pVec.v[1] && v[2]==pVec.v[2] ); }	bool operator==(const float *pVec)	  { return ( v[0]==pVec[0] && v[1]==pVec[1] && v[2]==pVec[2] ); }	bool operator!=(const GLvector &pVec) { return !((*this) == pVec ); }	bool operator!=(const float *pVec)    { return !(pVec == (*this) ); }	bool operator<(const GLvector vec)	  { return ( (v[0]<vec[0]) && (v[1]<vec[1]) && (v[2]<vec[2]) ); }	bool operator<=(const GLvector vec)   { return ( (v[0]<=vec[0]) && (v[1]<=vec[1]) && (v[2]<=vec[2]) ); }	bool operator>(const GLvector vec)    { return ( (v[0]>vec[0]) && (v[1]>vec[1]) && (v[2]>vec[2]) ); }	bool operator>=(const GLvector vec)   { return ( (v[0]>=vec[0]) && (v[1]>=vec[1]) && (v[2]>=vec[2]) ); }	// Indexing into the array	const float &operator[](int ndx) const { return v[ndx]; }	float &operator[](int ndx)             { return v[ndx]; }	operator float*(void)                  { return v; }
	// Member functions
	void Clear(void)						{ v[0]=v[1]=v[2]=0; }	void Set(float x, float y, float z)		{ v[0]=x; v[1]=y; v[2]=z; }	void Set(GLvector &p)					{ v[0]=p[0]; v[1]=p[1]; v[2]=p[2]; }	void Add(GLvector &a, GLvector &b)		{ v[0]=a.v[0]+b.v[0]; v[1]=a.v[1]+b.v[1]; v[2]=a.v[2]+b.v[2]; }	void Add(GLvector &a)					{ v[0]+=a.v[0]; v[1]+=a.v[1]; v[2]+=a.v[2]; }	void Subtract(GLvector &a, GLvector &b) { v[0]=a.v[0]-b.v[0]; v[1]=a.v[1]-b.v[1]; v[2]=a.v[2]-b.v[2]; }	void Subtract(GLvector &a)		        { v[0]-=a.v[0]; v[1]-=a.v[1]; v[2]-=a.v[2]; }	void Multiply(GLvector &a, GLvector &b) { v[0]=a.v[0]*b.v[0]; v[1]=a.v[1]*b.v[1]; v[2]=a.v[2]*b.v[2]; }	void Multiply(GLvector &a)				{ v[0]*=a.v[0]; v[1]*=a.v[1]; v[2]*=a.v[2]; }	void Divide(GLvector &a, GLvector &b)   { v[0]=a.v[0]/b.v[0]; v[1]=a.v[1]/b.v[1]; v[2]=a.v[2]/b.v[2]; }	void Divide(GLvector &a)				{ v[0]/=a.v[0]; v[1]/=a.v[1]; v[2]/=a.v[2]; }	void Scale(float val)	 { v[0]*=val; v[1]*=val; v[2]*=val; }	void Fabs(GLvector &src) { v[0]=(float)fabs(src.v[0]); v[1]=(float)fabs(src.v[1]); v[2]=(float)fabs(src.v[2]); }	float DotProduct(const GLvector &pVec) { return v[0]*pVec.v[0]+v[1]*pVec.v[1]+v[2]*pVec.v[2]; }
	float Length();	void Normalize();	void CrossProduct(const GLvector &p, const GLvector &q);	void Clamp(float min, float max);	void RotateX(float amnt, GLvector &dest);	void RotateY(float amnt, GLvector &dest);	void RotateZ(float amnt, GLvector &dest);
protected:
	float v[3];
};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -