K3dTriangleWork.cpp

Go to the documentation of this file.
00001 
00012 /***************************************************************************
00013  *   Copyright (C) 2007 by Jan Koci   *
00014  *   honza.koci@email.cz   *
00015  *   http://kengine.sourceforge.net/tutorial/
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  *   This program is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00025  *   GNU General Public License for more details.                          *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU General Public License     *
00028  *   along with this program; if not, write to the                         *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00031  ***************************************************************************/
00032 
00033 #include "K3dTriangleWork.h"
00034 
00035 K3dTriangleWork::K3dTriangleWork(K3dGameData *_pGameData)
00036 {
00037         m_pGameData = _pGameData;
00038         // Set this pointer to the game data
00039         m_pGameData->SetTriangleWork(this);
00040 }
00041 
00042 K3dTriangleWork::~K3dTriangleWork(void)
00043 {
00044 }
00045 
00047 K3dVector3Obj &K3dTriangleWork::CalcTriangleCentre(const int _iTriangleId)
00048 {
00049         // Get triangle from global data
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         // Triangle center
00060         K3dVector3Obj t;
00061         // Directional vectors
00062         K3dVector3Obj v0dir, v1dir, v2dir;
00063 
00064         // Calculate triangle centre
00065         t = CalcTriangleCentre(_iTriangleId);
00066 
00067         // Get triangle from global data
00068         K3dTriangle *pTriangle =  m_pGameData->GetTriangleObjSP().Get(_iTriangleId);
00069         // Get triangle vertices from global data
00070         K3dVector3Obj akV[3];
00071         akV[0] = *pTriangle->GetVertex(0);
00072         akV[1] = *pTriangle->GetVertex(1);
00073         akV[2] = *pTriangle->GetVertex(2);
00074         // Calculate directional vectors
00075         v0dir = akV[0] - t;
00076         v1dir = akV[1] - t;
00077         v2dir = akV[2] - t;
00078         // Normalize directional vectors
00079         v0dir = m_pGameData->GetVector3Work()->Normalize(v0dir);
00080         v1dir = m_pGameData->GetVector3Work()->Normalize(v1dir);
00081         v2dir = m_pGameData->GetVector3Work()->Normalize(v2dir);
00082         // Translate current vectors by directional vectors
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         // Get triangle from global data
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 }

Generated on Thu Aug 16 23:53:29 2007 for K3dEngine by  doxygen 1.5.0