📄 oasisvector3.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 : oasisVector3.h
* DESCRIPTION : Vector
* AUTHOR : Zephie Greyvenstein
*****************************************************************************/
/// Avoid double inclusion
#ifndef __VECTOR3_H__
#define __VECTOR3_H__
/// Include common stuff
#include "oasisCommon.h"
namespace Oasis {
/// Vector class for oasis
class _oasisExport vector3 {
public:
/// Axis value for X
real x;
/// Axis value for Y
real y;
/// Axis value for Z
real z;
/// Zero vector
static const vector3 ZERO;
/// Unit X vector
static const vector3 UNITX;
/// Unit Y vector
static const vector3 UNITY;
/// Unit Z vector
static const vector3 UNITZ;
/// Unit scale vector
static const vector3 UNITSCALE;
/// Constructor
inline vector3( ) {}
/// Real constructor
inline vector3( real fx, real fy, real fz ) {
x = fx;
y = fy;
z = fz;
}
/// Integer constructor
inline vector3( int fx, int fy, int fz ) {
x = ( real )fx;
y = ( real )fy;
z = ( real )fz;
}
/// Addition operator
inline vector3 operator + ( const vector3& rkVector ) const {
vector3 kSum;
kSum.x = x + rkVector.x;
kSum.y = y + rkVector.y;
kSum.z = z + rkVector.z;
return kSum;
}
/// Subtration operator
inline vector3 operator - ( const vector3& rkVector ) const {
vector3 kDiff;
kDiff.x = x - rkVector.x;
kDiff.y = y - rkVector.y;
kDiff.z = z - rkVector.z;
return kDiff;
}
/// Negative operator
inline vector3 operator - ( ) const {
vector3 kNeg;
kNeg.x = -x;
kNeg.y = -y;
kNeg.z = -z;
return kNeg;
}
/// Scalar multiplication operator
inline vector3 operator * ( real fScalar ) const {
vector3 kProd;
kProd.x = fScalar*x;
kProd.y = fScalar*y;
kProd.z = fScalar*z;
return kProd;
}
/// Multiplication operator
inline vector3 operator * ( const vector3& rhs) const {
vector3 kProd;
kProd.x = rhs.x * x;
kProd.y = rhs.y * y;
kProd.z = rhs.z * z;
return kProd;
}
/// Scalar division operator
inline vector3 operator / ( real fScalar ) const {
assert( fScalar != 0.0 );
vector3 kDiv;
real fInv = ( real )( 1.0 / fScalar );
kDiv.x = x * fInv;
kDiv.y = y * fInv;
kDiv.z = z * fInv;
return kDiv;
}
/// Addition update operator
inline vector3& operator += ( const vector3& rkVector ) {
x += rkVector.x;
y += rkVector.y;
z += rkVector.z;
return *this;
}
/// Subtraction update operator
inline vector3& operator -= ( const vector3& rkVector ) {
x -= rkVector.x;
y -= rkVector.y;
z -= rkVector.z;
return *this;
}
/// Multiplication update operator
inline vector3& operator *= ( real fScalar ) {
x *= fScalar;
y *= fScalar;
z *= fScalar;
return *this;
}
/// Division update operator
inline vector3& operator /= ( real fScalar ) {
assert( fScalar != 0.0 );
real fInv = ( real )( 1.0 / fScalar );
x *= fInv;
y *= fInv;
z *= fInv;
return *this;
}
/// Get the squared length of the vector
inline const real squaredLength( void ) const {
return x * x + y * y + z * z;
}
/// Get the cross product of 2 vectors
inline vector3 crossProduct( const vector3 &rkVector ) const {
return vector3( y * rkVector.z - z * rkVector.y,
z * rkVector.x - x * rkVector.z,
x * rkVector.y - y * rkVector.x );
}
};
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -