afVec3.cpp
资源名称:AirForce.rar [点击查看]
上传用户:kaiguan
上传日期:2007-10-28
资源大小:1074k
文件大小:1k
源码类别:
其他游戏
开发平台:
Visual C++
- #include "afVec3.h"
- #include "afPlane.h"
- #include <math.h>
- #pragma warning(disable: 4514)
- #define MAX3(x,y,z) ( ((x>y)&&(x>z)) ? x :( ((y>x)&&(y>z))? y : z) )
- #define MID3(x,y,z) ( ((x>y)&&(x<z)) ? x :( ((y>x)&&(y<z))? y : z) )
- #define MIN3(x,y,z) ( ((x<y)&&(x<z)) ? x :( ((y<x)&&(y<z))? y : z) )
- float afVec3::length() const
- {
- return (float)sqrt( x*x + y*y + z*z );
- }
- float afVec3::distance(const afVec3& left, const afVec3& right)
- {
- return (float)sqrt(pow(left.x-right.x,2) + pow(left.y-right.y,2) + pow(left.z-right.z,2));
- }
- float afVec3::normalize()
- {
- float l = length(), il;
- if (l!=0.0f)
- {
- il = 1.0f / l;
- x *= il;
- y *= il;
- z *= il;
- }
- return ( l );
- }
- afVec3& afVec3::cross( const afVec3& v1, const afVec3& v2 )
- {
- x = v1.y*v2.z - v1.z*v2.y;
- y = v1.z*v2.x - v1.x*v2.z;
- z = v1.x*v2.y - v1.y*v2.x;
- return *this;
- }
- float afVec3::cosine(const afVec3& left,const afVec3& right)
- {
- float dif = (right-left).length() * 0.5f;
- if (dif<0.00001f)
- return 0.0f;
- return 2.0f*(float)asin(dif);
- }
- afVec3 afVec3::normal()
- {
- float rx,ry;
- rx = MAX3(x,y,z);
- ry = MID3(x,y,z);
- return afVec3(-ry,rx,0);
- }
- float afVec3::dot(const afVec3& nV) const
- {
- return x*nV.x + y*nV.y + z*nV.z;
- }
- bool afVec3::isInfrontOf(const afPlane& nPlane) const
- {
- return nPlane.x*x + nPlane.y*y + nPlane.z*z > nPlane.d;
- }