Vector3.cpp
资源名称:虚拟地形建模.rar [点击查看]
上传用户:dfjhuyju
上传日期:2013-03-13
资源大小:11035k
文件大小:1k
源码类别:
OpenGL
开发平台:
Visual C++
- // Vector3.cpp: implementation of the CVector3 class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "LiFeng.h"
- #include "Vector3.h"
- #include <math.h>
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CVector3::CVector3()
- {
- }
- CVector3::~CVector3()
- {
- }
- CVector3 Cross(CVector3 vVector1, CVector3 vVector2)
- {
- CVector3 vNormal;
- vNormal.x = ((vVector1.y * vVector2.z) - (vVector1.z * vVector2.y));
- vNormal.y = ((vVector1.z * vVector2.x) - (vVector1.x * vVector2.z));
- vNormal.z = ((vVector1.x * vVector2.y) - (vVector1.y * vVector2.x));
- return vNormal;
- }
- float Magnitude(CVector3 vNormal)
- {
- return (float)sqrt( (vNormal.x * vNormal.x) +
- (vNormal.y * vNormal.y) +
- (vNormal.z * vNormal.z) );
- }
- CVector3 Normalize(CVector3 vVector)
- {
- float magnitude = Magnitude(vVector);
- vVector = vVector / magnitude;
- return vVector;
- }