📄 oasisquaternion.h
字号:
/******************************************************************************
* This source file is part of Bad Camel Gaming
* Copyright (C) 2003 Zephie Greyvenstein
* See Readme.html for acknowledgements
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
/******************************************************************************
* FILENAME : oasisQuaternion.h
* DESCRIPTION : Quaternion
* AUTHOR : Zephie Greyvenstein
*****************************************************************************/
/// Avoid double inclusion
#ifndef __QUATERNION_H__
#define __QUATERNION_H__
/// Include common stuff
#include "oasisCommon.h"
/// Include the rest of the needed oasis stuff
#include "oasisVector3.h"
namespace Oasis {
/** Quaternion class for oasis
@remarks
This exposes a basic quaternion class for use with oasis. Once passed
into the framework for use, it is usually converted to the quat format of
an internal library which provides more powerful functionality in order
for it to perform it's functions.
All quaternion type information passed out the engine will also be in
this format, again, usually converted from an internal quat format.
*/
class _oasisExport quaternion {
public:
/// W value
real w;
/// X value
real x;
/// Y value
real y;
/// Z value
real z;
/// Zero quaternion
static const quaternion ZERO;
/// Identity quaternion
static const quaternion IDENTITY;
/// Constructor
inline quaternion( ) {}
/// Real constructor
inline quaternion( real fw, real fx, real fy, real fz ) {
w = fw;
x = fx;
y = fy;
z = fz;
}
/// Integer constructor
inline quaternion( int fw, int fx, int fy, int fz ) {
w = ( real )fw;
x = ( real )fx;
y = ( real )fy;
z = ( real ) fz;
}
/// Addition operator
inline quaternion operator + ( const quaternion &rk ) const {
return quaternion( w + rk.w, x + rk.x, y + rk.y, z + rk.z );
}
/// Subtration operator
inline quaternion operator - ( const quaternion &rk ) const {
return quaternion( w - rk.w, x - rk.x, y - rk.y, z - rk.z );
}
/// Negative operator
inline quaternion operator - ( ) const {
return quaternion( -w, -x, -y, -z );
}
/// Scalar multiplication operator
inline quaternion operator * ( real scalar ) const {
return quaternion( w * scalar, x * scalar, y * scalar, z * scalar );
}
/// Multiplication operator
inline quaternion operator * ( const quaternion &rk ) const {
return quaternion( w * rk.w - x * rk.x - y * rk.y - z * rk.z,
w * rk.x + x * rk.w + y * rk.z - z * rk.y,
w * rk.y + y * rk.w + z * rk.x - x * rk.z,
w * rk.z + z * rk.w + x * rk.y - y * rk.x );
}
/// Vector multiplication operator
inline vector3 operator * ( const vector3 &rk ) const {
// Nvidia did this
vector3 uv, uuv;
vector3 qvec( x, y, z );
uv = qvec.crossProduct( rk );
uuv = qvec.crossProduct( uv );
uv *= ( real )( 2.0 * w );
uuv *= 2.0;
return rk + uv + uuv;
}
/// Creates a quat from an axis and an angle
void fromAxisAndAngle( const vector3 &axis, const real angle );
};
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -