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

📄 math.h

📁 mpq文件查看器
💻 H
字号:
/********************************************************************************
    Warcraft 3 Viewer - Utility to view models and textures from Warcraft 3
    Copyright (C) 2002  David GRIMBICHLER (theprophet@wanadoo.Fr)
	http://www.xeberon.net

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
********************************************************************************/

/////////////////////////////////
// MATH STUFF
typedef float vec;

class Vec2
{     
	friend class Vec3;

private:
    vec				v[2];

public:
	inline 			Vec2		( void )						{ set( 0, 0 );		 }
	inline 			Vec2		( vec x, vec y )				{ set( x, y);		 } 
        
	inline void		set			( vec x, vec y )				{ v[0] = x; v[1] = y; }
    inline void		set			( const vec *vP )				{ v[0] = vP[0]; v[1] = vP[1]; }
	
	inline vec&		operator[]	( int i )						{ return v[i]; }
    inline vec*		raw			( void )						{ return v;    }

	inline operator const vec*	( void ) const					{ return v; }
	
	inline Vec2&	operator+=	( const Vec2& v2 )				{ v[0] += v2.v[0]; v[1] += v2.v[1]; return *this; }
	inline Vec2&	operator-=	( const Vec2& v2 )				{ v[0] -= v2.v[0]; v[1] -= v2.v[1]; return *this; }
    inline Vec2		operator+	( const Vec2& v2 ) const		{ return Vec2( v[0] + v2.v[0], v[1] + v2.v[1] ); }
    inline Vec2		operator-	( const Vec2& v2 ) const		{ return Vec2( v[0] - v2.v[0], v[1] - v2.v[1] ); }
    inline Vec2		operator*	( vec s ) const					{ return Vec2( v[0] * s, v[1] * s ); }
	inline void		normalize	( void )						{ vec l = length(); v[0] /= l; v[1] /= l; }

	inline float	length		(void)
	{
		return (float)sqrt(v[0]*v[0]+v[1]*v[1]);
	}
};

class Vec3
{
	friend class Vec2;       
	friend class Mat4;

private:
	vec				v[3];

public:
					Vec3		( void )						{ set( 0, 0, 0);   }
					Vec3		( vec x, vec y, vec z )			{ set( x, y, z );  }
	inline void		set			( vec x, vec y, vec z )			{ v[0] = x; v[1] = y; v[2] = z; }
	inline void		set			( const vec *vP )				{ v[0] = vP[0]; v[1] = vP[1]; v[2] = vP[2]; }
    
    inline vec&		operator[]	( int i )						{ return v[i]; }
	inline vec*		raw			( void )						{ return v; }                

	inline operator const vec*	( void ) const					{ return v; }
    
    inline Vec3&	operator+=	( const Vec3& v3 )				{ v[0] += v3.v[0]; v[1] += v3.v[1]; v[2] += v3.v[2]; return *this; }
	inline Vec3&	operator-=	( const Vec3& v3 )				{ v[0] -= v3.v[0]; v[1] -= v3.v[1]; v[2] -= v3.v[2]; return *this; }
    inline Vec3		operator+	( const Vec3& v3 ) const		{ return Vec3( v[0] + v3.v[0] , v[1] + v3.v[1] , v[2] + v3.v[2] ); }
    inline Vec3		operator-	( const Vec3& v3 ) const		{ return Vec3( v[0] - v3.v[0] , v[1] - v3.v[1] , v[2] - v3.v[2] ); }
	inline Vec3		operator*	( vec s ) const					{ return Vec3( v[0] * s , v[1] * s , v[2] * s ); }
	inline float	operator*	( const Vec3& v3 ) const		{ return ( v[0] * v3[0] + v[1] * v3[1] + v[2] * v3[2] ); } 
	inline Vec3		operator~	( void ) const					{ return Vec3( -v[0] , -v[1], -v[2] ); }
    inline Vec3		operator^	( const Vec3& v3 ) const		{ return Vec3( v[1]*v3.v[2] - v3.v[1]*v[2], -v[0]*v3.v[2] + v3.v[0]*v[2], v[0]*v3.v[1] - v3.v[0]*v[1] ); }

	inline vec		length		( void ) const					{ return (vec)sqrt( v[0] * v[0] + v[1] * v[1] + v[2] * v[2] ); }
    inline void		normalize	( void )						{ vec l = length(); v[0] /= l; v[1] /= l; v[2] /= l; }
};

// END OF MATH STUFF
/////////////////////////////////

⌨️ 快捷键说明

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