📄 vector2d.h
字号:
//--------------------------------------------------
// 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -