00001 00011 /*************************************************************************** 00012 * Copyright (C) 2007 by Jan Koci * 00013 * honza.koci@email.cz * 00014 * http://kengine.sourceforge.net/tutorial/ 00015 * * 00016 * This program is free software; you can redistribute it and/or modify * 00017 * it under the terms of the GNU General Public License as published by * 00018 * the Free Software Foundation; either version 2 of the License, or * 00019 * (at your option) any later version. * 00020 * * 00021 * This program is distributed in the hope that it will be useful, * 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00024 * GNU General Public License for more details. * 00025 * * 00026 * You should have received a copy of the GNU General Public License * 00027 * along with this program; if not, write to the * 00028 * Free Software Foundation, Inc., * 00029 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00030 00031 ***************************************************************************/ 00032 #include "K3dCutEdge.h" 00033 00034 K3dCutEdge::K3dCutEdge(K3dGameData *_pGameData) 00035 { 00036 m_pGameData = _pGameData; 00037 m_pIntersection = m_pGameData->GetIntersection(); 00038 } 00039 00040 K3dCutEdge::~K3dCutEdge() 00041 { 00042 } 00043 00048 K3dLineObj *K3dCutEdge::CutEdge(K3dLineObj *_pEdge, K3dPlaneObj *_pPlane) 00049 { 00050 cout << "K3dLineObj *K3dCutEdge::CutEdge(K3dLineObj *_pEdge, K3dPlaneObj *_pPlane)" << endl; 00051 K3dLineObj *pBackEdge = NULL; 00052 if(m_pIntersection->LinePlane( *_pEdge, *_pPlane)==true) 00053 { 00054 // Store edge origin and direction vector 00055 K3dVector3Obj kOrigin = *_pEdge->GetOrigin(); 00056 K3dVector3Obj kDirection = *_pEdge->GetDirection(); 00057 // Set front of plane edge and create new back of plane edge 00058 K3dLineObj *pFrongEdge = _pEdge; 00059 pBackEdge = m_pGameData->GetLineBuild()->CreateNewLineObj(); 00060 // Test distance between edge origin and plane 00061 float fDistance = m_pIntersection->PointPlane(*_pPlane, kOrigin); 00062 if(fDistance > (float) 0) 00063 { 00064 // Set intersection point as front edge direction vector 00065 *pFrongEdge->GetDirection() = m_pIntersection->GetIntrPoint(); 00066 // Set back edge origin and direction vector 00067 *pBackEdge->GetOrigin() = kDirection; 00068 *pBackEdge->GetDirection() = m_pIntersection->GetIntrPoint(); 00069 } 00070 else if(fDistance < (float) 0) 00071 { 00072 // Set intersection point as front edge origin vector 00073 *pFrongEdge->GetOrigin() = m_pIntersection->GetIntrPoint(); 00074 // Set back edge origin and direction vector 00075 *pBackEdge->GetOrigin() = kOrigin; 00076 *pBackEdge->GetDirection() = m_pIntersection->GetIntrPoint(); 00077 } 00078 else 00079 { 00080 // If distance is zero, then vertex intersect the plane 00081 return NULL; 00082 } 00083 } 00084 return pBackEdge; 00085 } 00086 00087