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

📄 gpoint.h

📁 一个自己写的游戏引擎,用DirectX 写成
💻 H
字号:
//--------------------------------------------------
//  Desc: POINT and RECT
//  Date: 2006.8.25 /update
//  Author: artsylee
//
//  Copyright (C) 2006 artsylee
//
//  扩展: InvSqrt, Dot, Normalize, Length, Angle, Rotate
//		  On (2006_11_09)
//		  GRect提供一个SetRectWH函数
//--------------------------------------------------

#ifndef _GPOINT_
#define _GPOINT_

#include <windows.h>
#include <math.h>

//----------------------------------------
//----------------------------------------
// GPoint class
//----------------------------------------
//----------------------------------------

// 2006_11_09---------
/*
** Fast 1.0/sqrtf(float) routine
*/
//float InvSqrt(float x);
//--------------------

class ASE_DLL GPoint : public POINT
{
public:
	// Constructors
	GPoint()						{ x = 0; y = 0; }
	GPoint(int argX, int argY)		{ x = argX; y = argY; }
	GPoint(POINT const &pt)			{ *(POINT*)this = pt; }
	GPoint(SIZE const &size)		{ *(SIZE*)this = size;}

	// Member functions
	void Offset(int xOffset, int yOffset);
	void Offset(POINT point);
	void Offset(SIZE size);

	// 2006_11_09---------
	LONG	Dot(POINT *v)		{ return x * v->x + y * v->y; }
//	POINT*	Normalize()			{ float rc=InvSqrt((float)Dot(this)); x=(LONG)(x*rc); y=(LONG)(y*rc); return this; }
	float	Length()			{ return sqrtf((float)Dot(this)); }
//	float	Angle(GPoint *v = 0);
//	POINT*	Rotate(float a);
	//--------------------

	// Operators
	GPoint & operator+=(POINT const &pt)	{ x += pt.x; y += pt.y; return *this; }
	GPoint & operator-=(POINT const &pt)   { x -= pt.x; y -= pt.y; return *this; }
	GPoint & operator*=(int i)				{ x *= i; y *= i; return *this;	}
	GPoint & operator/=(int i)				
	{ if(i==0) return *this; x /= i; y /=i; return *this; }
	GPoint & operator%=(int i)				{ x %= i; y %= i; return *this;	}
	GPoint & operator<<=(int i)				{ x <<= i; y <<= i; return *this; }
	GPoint & operator>>=(int i)				{ x >>= i; y >>= i; return *this; }

	bool operator==(POINT const &pt) const;
	bool operator!=(POINT const &pt) const;

	GPoint operator+();
	GPoint operator-();

	GPoint operator+(POINT const &pt);
	GPoint operator-(POINT const &pt);
	GPoint operator*(int i);
	GPoint operator/(int i);
	GPoint operator%(int i);
    GPoint operator<<(int i);
	GPoint operator>>(int i);	
};

//----------------------------------------
//----------------------------------------
// GRect class
//----------------------------------------
//----------------------------------------
class ASE_DLL GRect : public RECT
{
public:
	// Constructors
	GRect()								{ left = right = top = bottom = 0; }
	GRect(int l, int t, int r, int b)	{ left = l; top = t; right = r, bottom = b; }

	GRect(POINT const &pt_lt, POINT const &pt_rb)  
	{ left = pt_lt.x; top = pt_lt.y; right = pt_rb.x; bottom = pt_rb.y; }
	GRect(GPoint const &pt_lt, GPoint const &pt_rb)		
	{ left = pt_lt.x; top = pt_lt.y; right = pt_rb.x; bottom = pt_rb.y; }
	GRect(POINT const &pt, SIZE const &size) 
	{ right = (left = pt.x) + size.cx; bottom = (top = pt.y) + size.cy; }

	GRect(const RECT &srcRect)			{ ::CopyRect(this, &srcRect); }

	// Member functions
	int Width() const;
	int Height() const;
	void ZeroRect();
	void NormalizeRect();

	void SetRect(int x1, int y1, int x2, int y2);
	void SetRect(POINT topLeft, POINT bottomRight);
	void SetRectWH(int x1, int y1, int x2, int y2);

	GPoint &LeftTop() const;
	GPoint &RightBottom() const;
	GPoint CenterPoint() const;

	bool PtInRect(POINT point) const;

	void InflateRect(int x, int y);
	void InflateRect(POINT pt);
	void InflateRect(int l, int t, int r, int b);
	void DeflateRect(int x, int y);
	void DeflateRect(POINT pt);
	void DeflateRect(int l, int t, int r, int b);
	void OffsetRect(int x, int y);
	void OffsetRect(POINT pt);

	void make_extern(RECT const &rect);
	void make_clipper(RECT const &rect);

	// Operators
	void operator=(const RECT &srcRect);
	bool operator==(const RECT &rect);
	bool operator!=(const RECT &rect);
	void operator+=(POINT point);
	void operator-=(POINT point);

	GRect operator+(POINT point);
	GRect operator-(POINT point);
};

#endif // _GPOINT_

⌨️ 快捷键说明

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