00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "K3dTriangleWork.h"
00034
00035 K3dTriangleWork::K3dTriangleWork(K3dGameData *_pGameData)
00036 {
00037 m_pGameData = _pGameData;
00038
00039 m_pGameData->SetTriangleWork(this);
00040 }
00041
00042 K3dTriangleWork::~K3dTriangleWork(void)
00043 {
00044 }
00045
00047 K3dVector3Obj &K3dTriangleWork::CalcTriangleCentre(const int _iTriangleId)
00048 {
00049
00050 K3dTriangleObj *pTriangle = m_pGameData->GetTriangleObjSP().Get(_iTriangleId);
00051 *pTriangle->GetCentre() = m_pGameData->GetVector3Work()->CalcCentre(*pTriangle->GetVertex(0), *pTriangle->GetVertex(1), *pTriangle->GetVertex(2));
00052
00053 return *pTriangle->GetCentre();
00054 }
00055
00057 void K3dTriangleWork::CalcScale(const int _iTriangleId, const float fDistance)
00058 {
00059
00060 K3dVector3Obj t;
00061
00062 K3dVector3Obj v0dir, v1dir, v2dir;
00063
00064
00065 t = CalcTriangleCentre(_iTriangleId);
00066
00067
00068 K3dTriangle *pTriangle = m_pGameData->GetTriangleObjSP().Get(_iTriangleId);
00069
00070 K3dVector3Obj akV[3];
00071 akV[0] = *pTriangle->GetVertex(0);
00072 akV[1] = *pTriangle->GetVertex(1);
00073 akV[2] = *pTriangle->GetVertex(2);
00074
00075 v0dir = akV[0] - t;
00076 v1dir = akV[1] - t;
00077 v2dir = akV[2] - t;
00078
00079 v0dir = m_pGameData->GetVector3Work()->Normalize(v0dir);
00080 v1dir = m_pGameData->GetVector3Work()->Normalize(v1dir);
00081 v2dir = m_pGameData->GetVector3Work()->Normalize(v2dir);
00082
00083 m_pGameData->GetVector3Work()->Translate(akV[0], v0dir, fDistance);
00084 m_pGameData->GetVector3Work()->Translate(akV[1], v1dir, fDistance);
00085 m_pGameData->GetVector3Work()->Translate(akV[2], v2dir, fDistance);
00086
00087 *pTriangle->GetVertex(0) = akV[0];
00088 *pTriangle->GetVertex(1) = akV[1];
00089 *pTriangle->GetVertex(2) = akV[2];
00090
00091 }
00092
00094 K3dVector3Obj &K3dTriangleWork::CalcNormal(const int _iTriangleId)
00095 {
00096
00097 K3dTriangle *pTriangle = m_pGameData->GetTriangleObjSP().Get(_iTriangleId);
00098 *pTriangle->GetNormal() = m_pGameData->GetVector3Work()->Normal(*pTriangle->GetVertex(0), *pTriangle->GetVertex(1), *pTriangle->GetVertex(2));
00099 return *pTriangle->GetNormal();
00100 }