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

📄 point2.h

📁 <B>DirectX9.0 3D游戏编程</B>
💻 H
字号:
/*******************************************************************
 *         Advanced 3D Game Programming using DirectX 9.0
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * copyright (c) 2003 by Peter A Walsh and Adrian Perez
 * See license.txt for modification and distribution information
 ******************************************************************/

struct point2
{
	float x, y;

public:

	float Length()
	{
		return (float)sqrt( x*x + y*y );
	}

	point2(){}

	point2( float X, float Y ) : x( X ), y( Y ) {}

	static point2 Midpoint( const point2 &a, const point2 &b )
	{
		point2 out( (a.x + b.x) / 2.f, (a.y + b.y) / 2.f );
		return out;
	}

	static float Dist( const point2 &a, const point2 &b )
	{
		point2 temp( b.x - a.x, b.y - a.y );
		return temp.Length();
	}

	void Normalize(){
		float foo=1/Length();	x*=foo;	y*=foo;
	}
};

//returns point2+point2
inline point2 operator+(point2 const &a, point2 const &b)
{
	return point2(a.x+b.x,a.y+b.y);
}; 


//returns point2-point2
inline point2 operator-(point2 const &a, point2 const &b)
{
	return point2(a.x-b.x,a.y-b.y);
}; 


//returns point2*float
inline point2 operator*(point2 const &a, float const &b)
{
	return point2(a.x*b,a.y*b);
}; 


//returns float*point2
inline point2 operator*(float  const &a, point2 const &b)
{
	return point2(a*b.x,a*b.y);
}; 


//returns point2/float
inline point2 operator/(point2 const &a, float const &b)
{
	return point2(a.x/b,a.y/b);
}; 

// dot product
inline float operator*(point2 const &a, point2 const &b)
{
	return a.x * b.x + a.y * b.y;
}; 

⌨️ 快捷键说明

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