00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "K3dBoxBuild.h"
00034
00035 K3dBoxBuild::K3dBoxBuild(K3dGameData *_pGameData):
00036 K3dBoxWork(_pGameData)
00037 {
00038 m_pGameData = _pGameData;
00039
00040 m_pGameData->SetBoxBuild(this);
00041 m_pIntersection = m_pGameData->GetIntersection();
00042 m_pPolyPlaneBuild = m_pGameData->GetPolyPlaneBuild();
00043 m_pLineBuild = m_pGameData->GetLineBuild();
00044 m_pVertexBuild = m_pGameData->GetVertexBuild();
00045 }
00046
00047 K3dBoxBuild::~K3dBoxBuild()
00048 {
00049 DeleteBoxes();
00050 }
00051
00055 K3dLineObj *K3dBoxBuild::CreateEdge(K3dVector3Obj *_pOrigin,K3dVector3Obj *_pDirection)
00056 {
00057 K3dLineObj *pEdge = m_pLineBuild->CreateNewLineObj();
00058 pEdge->SetOrigin(_pOrigin);
00059 pEdge->SetDirection(_pDirection);
00060 pEdge->GetIsVisible() = m_bIsVisible;
00061 pEdge->Init();
00062 return pEdge;
00063 }
00064
00066 K3dPolyPlane *K3dBoxBuild::CreatePlane(const K3dVector3Obj *_pV0,const K3dVector3Obj *_pV1,const K3dVector3Obj *_pV2)
00067 {
00068 K3dPolyPlane *pPlane = m_pPolyPlaneBuild->CreateNewPolyPlaneObj(*_pV0,*_pV1,*_pV2);
00069 pPlane->GetWidth() = K3D_PLANE_SIZE;
00070 pPlane->GetHeight() = K3D_PLANE_SIZE;
00071 pPlane->GetIsVisible() = m_bIsVisible;
00072
00073 m_pPolyPlaneBuild->CalcVertsOnPlane(pPlane);
00074 return pPlane;
00075 }
00076
00079 K3dPolyObj *K3dBoxBuild::CreateSceneBox()
00080 {
00081 m_pPoly = m_pGameData->GetPolyObjSP().New();
00082
00083 float fMaxAxis = (float) K_MAX_SCENE_LENGTH * (float)0.5;
00084
00085 K3dVertexObj *pVertex0 = m_pVertexBuild->CreateNewVertexObj();
00086 pVertex0->GetPosition()->Set(fMaxAxis, fMaxAxis, fMaxAxis);
00087 m_pPoly->AddVertex(pVertex0);
00088
00089 K3dVertexObj *pVertex1 = m_pVertexBuild->CreateNewVertexObj();
00090 pVertex1->GetPosition()->Set(-fMaxAxis, fMaxAxis, fMaxAxis);
00091 m_pPoly->AddVertex(pVertex1);
00092
00093 K3dVertexObj *pVertex2 = m_pVertexBuild->CreateNewVertexObj();
00094 pVertex2->GetPosition()->Set(-fMaxAxis, -fMaxAxis, fMaxAxis);
00095 m_pPoly->AddVertex(pVertex2);
00096
00097 K3dVertexObj *pVertex3 = m_pVertexBuild->CreateNewVertexObj();
00098 pVertex3->GetPosition()->Set(fMaxAxis, -fMaxAxis, fMaxAxis);
00099 m_pPoly->AddVertex(pVertex3);
00100
00101 K3dVertexObj *pVertex4 = m_pVertexBuild->CreateNewVertexObj();
00102 pVertex4->GetPosition()->Set(fMaxAxis, -fMaxAxis, -fMaxAxis);
00103 m_pPoly->AddVertex(pVertex4);
00104
00105 K3dVertexObj *pVertex5 = m_pVertexBuild->CreateNewVertexObj();
00106 pVertex5->GetPosition()->Set(fMaxAxis, fMaxAxis, -fMaxAxis);
00107 m_pPoly->AddVertex(pVertex5);
00108
00109 K3dVertexObj *pVertex6 = m_pVertexBuild->CreateNewVertexObj();
00110 pVertex6->GetPosition()->Set(-fMaxAxis, fMaxAxis, -fMaxAxis);
00111 m_pPoly->AddVertex(pVertex6);
00112
00113 K3dVertexObj *pVertex7 = m_pVertexBuild->CreateNewVertexObj();
00114 pVertex7->GetPosition()->Set(-fMaxAxis, -fMaxAxis, -fMaxAxis);
00115 m_pPoly->AddVertex(pVertex7);
00116
00117
00118 K3dLineObj *pEdge;
00119 pEdge = CreateEdge(pVertex0->GetPosition(), pVertex1->GetPosition());
00120 m_pPoly->AddEdge(pEdge);
00121 pEdge = CreateEdge(pVertex1->GetPosition(), pVertex2->GetPosition());
00122 m_pPoly->AddEdge(pEdge);
00123 pEdge = CreateEdge(pVertex2->GetPosition(), pVertex3->GetPosition());
00124 m_pPoly->AddEdge(pEdge);
00125 pEdge = CreateEdge(pVertex3->GetPosition(), pVertex0->GetPosition());
00126 m_pPoly->AddEdge(pEdge);
00127 pEdge = CreateEdge(pVertex4->GetPosition(), pVertex5->GetPosition());
00128 m_pPoly->AddEdge(pEdge);
00129 pEdge = CreateEdge(pVertex5->GetPosition(), pVertex6->GetPosition());
00130 m_pPoly->AddEdge(pEdge);
00131 pEdge = CreateEdge(pVertex6->GetPosition(), pVertex7->GetPosition());
00132 m_pPoly->AddEdge(pEdge);
00133 pEdge = CreateEdge(pVertex7->GetPosition(), pVertex4->GetPosition());
00134 m_pPoly->AddEdge(pEdge);
00135 pEdge = CreateEdge(pVertex0->GetPosition(), pVertex5->GetPosition());
00136 m_pPoly->AddEdge(pEdge);
00137 pEdge = CreateEdge(pVertex1->GetPosition(), pVertex6->GetPosition());
00138 m_pPoly->AddEdge(pEdge);
00139 pEdge = CreateEdge(pVertex2->GetPosition(), pVertex7->GetPosition());
00140 m_pPoly->AddEdge(pEdge);
00141 pEdge = CreateEdge(pVertex3->GetPosition(), pVertex4->GetPosition());
00142 m_pPoly->AddEdge(pEdge);
00143
00144
00145 K3dPolyPlane *pPolyPlane = NULL;
00146 pPolyPlane = CreatePlane(pVertex0->GetPosition(), pVertex1->GetPosition(), pVertex2->GetPosition());
00147 m_pPoly->AddPlane(pPolyPlane);
00148 pPolyPlane = CreatePlane(pVertex5->GetPosition(), pVertex0->GetPosition(), pVertex3->GetPosition());
00149 m_pPoly->AddPlane(pPolyPlane);
00150 pPolyPlane = CreatePlane(pVertex6->GetPosition(), pVertex5->GetPosition(), pVertex4->GetPosition());
00151 m_pPoly->AddPlane(pPolyPlane);
00152 pPolyPlane = CreatePlane(pVertex1->GetPosition(), pVertex6->GetPosition(), pVertex7->GetPosition());
00153 m_pPoly->AddPlane(pPolyPlane);
00154 pPolyPlane = CreatePlane(pVertex5->GetPosition(), pVertex6->GetPosition(), pVertex1->GetPosition());
00155 m_pPoly->AddPlane(pPolyPlane);
00156 pPolyPlane = CreatePlane(pVertex7->GetPosition(), pVertex4->GetPosition(), pVertex3->GetPosition());
00157 m_pPoly->AddPlane(pPolyPlane);
00158
00159
00160 m_pPoly->GetIsVisible() = m_bIsVisible;
00161 m_pPoly->GetId() = m_pGameData->GetPolyObjSP().GetNum();
00162 return m_pPoly;
00163 }
00164
00166 void K3dBoxBuild::DeleteBoxes()
00167 {
00168
00169 while(m_pGameData->GetPolyObjSP().GetNum())
00170 {
00171 K3dPolyObj *p = m_pGameData->GetPolyObjSP().Get(0);
00172 p = m_pGameData->GetPolyObjSP().Delete(p);
00173 }
00174 }
00175