vector2d.h
来自「一个自己写的游戏引擎,用DirectX 写成」· C头文件 代码 · 共 58 行
H
58 行
//--------------------------------------------------
// Desc: 2D Vector
// Date: 2006.11.9 /update
// Author: artsylee
//
// Copyright (C) 2006 artsylee
//
//--------------------------------------------------
#ifndef _VECTOR2D_
#define _VECTOR2D_
#include <math.h>
#ifdef __cplusplus
extern "C"
{
#endif
ASE_DLL float __stdcall InvSqrt(const float x);
#ifdef __cplusplus
}
#endif
class ASE_DLL Vector2D
{
public:
float x;
float y;
Vector2D(float fx, float fy) { x = fx; y = fy; }
Vector2D() { x = 0; y = 0; }
Vector2D operator-(const Vector2D &v) { return Vector2D(x - v.x, y - v.y); }
Vector2D operator+(const Vector2D &v) { return Vector2D(x + v.x, y + v.y); }
Vector2D operator*(float scale) { return Vector2D(x*scale, y*scale); }
Vector2D& operator-=(const Vector2D &v) { x -= v.x; y -= v.y; return *this; }
Vector2D& operator+=(const Vector2D &v) { x += v.x; y += v.y; return *this; }
Vector2D& operator*=(float scale) { x*=scale; y*=scale; return *this; }
Vector2D operator-() { return Vector2D(-x, -y); }
Vector2D operator+() { return Vector2D(x, y); }
bool operator==(const Vector2D &v) { return (x == v.x && y == v.y); }
bool operator!=(const Vector2D &v) { return (x != v.x || y != v.y); }
float Length(void);
float Dot(const Vector2D *v);
float Angle(const Vector2D *v = 0);
Vector2D* Normalize(void);
Vector2D* Rotate(float a);
};
inline Vector2D operator*(const Vector2D &v, float s) { return Vector2D(s * v.x, s * v.y); }
inline Vector2D operator*(float s, const Vector2D &v) { return Vector2D(s * v.x, s * v.y); }
#endif // _VECTOR2D_
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?