vector3d.h

来自「3D游戏展示程序」· C头文件 代码 · 共 53 行

H
53
字号
//--------------------------------------------------
//  Desc: 3D Vector
//  Date: 2007.4.2 /update
//  Author: artsylee
//
//  Copyright (C) 2007 artsylee
//
//--------------------------------------------------

#ifndef _VECTOR3D_
#define _VECTOR3D_

#include <math.h>

class Vector3D
{
public:
	float	x;
	float	y;
	float	z;

	Vector3D();	
	Vector3D(float fx, float fy, float fz);							
	Vector3D(const Vector3D &v);

	Vector3D	operator-(const Vector3D &v) const;
	Vector3D	operator+(const Vector3D &v) const;
	Vector3D	operator*(float scale) const;
	Vector3D	operator/(float scale) const;
	float		operator*(const Vector3D &v) const;
	Vector3D	operator%(const Vector3D &v) const;

	Vector3D&   operator=(const Vector3D &v);
	Vector3D&	operator+=(const Vector3D &v);
	Vector3D&	operator-=(const Vector3D &v);
	Vector3D&	operator*=(float scale);

	float		LengthSquared() const;
	float		Length() const;
	Vector3D&	Normalize();
	Vector3D	operator~() const;

	operator	float*()	{	return (float*)this;	}
	bool		operator==(const Vector3D &v)	{ return (x == v.x && y == v.y && z == v.z); }
	bool		operator!=(const Vector3D &v)	{ return (x != v.x || y != v.y || z != v.z); }
};

__forceinline Vector3D operator*(float d, const Vector3D& v)	{ v*d;	}
//__forceinline Vector3D operator*(const Vector3D& v, float d)	{ v*d;	}


#endif // _VECTOR3D_

⌨️ 快捷键说明

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