00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "K3dObjectWork.h"
00034
00035 K3dObjectWork::K3dObjectWork(K3dGameData *_pGameData):
00036 K3dCameraWork(_pGameData),
00037 K3dRayWork(_pGameData),
00038 K3dLineWork(_pGameData),
00039 K3dSphereWork(_pGameData)
00040 {
00041 m_pGameData = _pGameData;
00042 m_pIntersection = m_pGameData->GetIntersection();
00043 m_pVertexBuild = m_pGameData->GetVertexBuild();
00044 }
00045
00046 K3dObjectWork::~K3dObjectWork()
00047 {
00048 }
00049
00054 int K3dObjectWork::FindObjectId(const char* _strName, const int _iObjType )
00055 {
00056 int iId = -1;
00057 switch (_iObjType)
00058 {
00059 case K3D_IMAGE_OBJ:
00060 break;
00061 case K3D_VERTEX_OBJ:
00062 iId = m_pVertexBuild->FindVertexId(_strName);
00063 break;
00064 case K3D_SPHERE_OBJ:
00065 iId = FindSphereId(_strName);
00066 break;
00067 case K3D_CAMERA_OBJ:
00068 iId = FindCameraId( _strName);
00069 break;
00070 case K3D_LINE_OBJ:
00071 iId = FindLineId(_strName);
00072 break;
00073 case K3D_RAY_OBJ:
00074 iId = FindRayId(_strName);
00075 break;
00076 case K3D_PLANE_OBJ:
00077 iId = m_pGameData->GetPlaneWork()->FindPlaneId(_strName);
00078 break;
00079 default:
00080 break;
00081 }
00082 return iId;
00083 }
00084
00091 float K3dObjectWork::GetDistance(const int _iObjId0, const int _iObjId1, const int _iObjType0, const int _iObjType1)
00092 {
00093 float fDistance = -1;
00094 K3dCameraObj *pCamera;
00095 K3dSphereObj *pSphere;
00096 switch (_iObjType0)
00097 {
00098 case K3D_IMAGE_OBJ:
00099 break;
00100 case K3D_VERTEX_OBJ:
00101 break;
00102 case K3D_SPHERE_OBJ:
00103 if(_iObjType1 == K3D_CAMERA_OBJ)
00104 {
00105 pSphere = m_pGameData->GetSphereObjSP().Get(_iObjId0);
00106 pCamera = m_pGameData->GetCameraObjSP().Get(_iObjId1);
00107
00108 return m_pIntersection->Points(pCamera->GetCameraPos(), *pSphere->GetPosition());
00109 }
00110 break;
00111 case K3D_CAMERA_OBJ:
00112 if(_iObjType1 == K3D_SPHERE_OBJ)
00113 {
00114 pCamera = m_pGameData->GetCameraObjSP().Get(_iObjId0);
00115 pSphere = m_pGameData->GetSphereObjSP().Get(_iObjId1);
00116
00117 return m_pIntersection->Points(pCamera->GetCameraPos(), *pSphere->GetPosition());
00118 }
00119 break;
00120 case K3D_LINE_OBJ:
00121 break;
00122 case K3D_RAY_OBJ:
00123 break;
00124 case K3D_PLANE_OBJ:
00125 break;
00126 default:
00127 break;
00128 }
00129 return fDistance;
00130 }
00131
00138 bool K3dObjectWork::GetIntersection(const int _iObjId0, const int _iObjId1, const int _iObjType0, const int _iObjType1)
00139 {
00140 K3dRay *pRay;
00141 K3dSphere *pSphere;
00142 K3dPlane *pPlane;
00143 switch (_iObjType0)
00144 {
00145 case K3D_IMAGE_OBJ:
00146 break;
00147 case K3D_VERTEX_OBJ:
00148 break;
00149 case K3D_SPHERE_OBJ:
00150 if(_iObjType1 == K3D_SPHERE_OBJ)
00151 {
00152 pSphere = m_pGameData->GetSphereObjSP().Get(_iObjId0);
00153 pRay = m_pGameData->GetRayObjSP().Get(_iObjId1);
00154 return m_pIntersection->RaySphere(*pRay, *pSphere);
00155 }
00156 break;
00157 case K3D_CAMERA_OBJ:
00158 break;
00159 case K3D_LINE_OBJ:
00160 pRay = m_pGameData->GetLineObjSP().Get(_iObjId0);
00161 pPlane = m_pGameData->GetPlaneObjSP().Get(_iObjId1);
00162 return m_pIntersection->LinePlane(*pRay, *pPlane);
00163 break;
00164 case K3D_RAY_OBJ:
00165 if(_iObjType1 == K3D_SPHERE_OBJ)
00166 {
00167 pRay = m_pGameData->GetRayObjSP().Get(_iObjId0);
00168 pSphere = m_pGameData->GetSphereObjSP().Get(_iObjId1);
00169 return m_pIntersection->RaySphere(*pRay, *pSphere);
00170 }
00171 break;
00172 case K3D_PLANE_OBJ:
00173 pPlane = m_pGameData->GetPlaneObjSP().Get(_iObjId0);
00174 pRay = m_pGameData->GetRayObjSP().Get(_iObjId1);
00175 return m_pIntersection->LinePlane(*pRay, *pPlane);
00176 break;
00177 default:
00178 break;
00179 }
00180 return false;
00181 }
00182
00190 bool K3dObjectWork::GetIntersection(const int _iObjId0, const int _iObjId1, const int _iObjType0, const int _iObjType1, K3dVector3 &_rkInrPoint)
00191 {
00192 if(GetIntersection( _iObjId0, _iObjId1, _iObjType0, _iObjType1))
00193 {
00194 switch (_iObjType0)
00195 {
00196 case K3D_IMAGE_OBJ:
00197 break;
00198 case K3D_VERTEX_OBJ:
00199 break;
00200 case K3D_SPHERE_OBJ:
00201 break;
00202 case K3D_CAMERA_OBJ:
00203 break;
00204 case K3D_LINE_OBJ:
00205 _rkInrPoint = m_pIntersection->GetIntrPoint();
00206 return true;
00207 break;
00208 case K3D_RAY_OBJ:
00209 break;
00210 case K3D_PLANE_OBJ:
00211 _rkInrPoint = m_pIntersection->GetIntrPoint();
00212 return true;
00213 break;
00214 default:
00215 break;
00216 }
00217 }
00218 return false;
00219 }
00220
00227 void K3dObjectWork::SetColor(const int _iObjId, const int _iObjType, const char _r,const char _g,const char _b)
00228 {
00229 K3dSphereVis *pSphere;
00230 switch (_iObjType)
00231 {
00232 case K3D_IMAGE_OBJ:
00233 break;
00234 case K3D_VERTEX_OBJ:
00235 break;
00236 case K3D_SPHERE_OBJ:
00237 pSphere = m_pGameData->GetSphereObjSP().Get(_iObjId);
00238 pSphere->GetColor()->GetR() = (GLubyte) _r;
00239 pSphere->GetColor()->GetG() = (GLubyte) _g;
00240 pSphere->GetColor()->GetB() = (GLubyte) _b;
00241 break;
00242 case K3D_CAMERA_OBJ:
00243 break;
00244 case K3D_LINE_OBJ:
00245 break;
00246 case K3D_RAY_OBJ:
00247 break;
00248 case K3D_PLANE_OBJ:
00249 break;
00250 default:
00251 break;
00252 }
00253 }
00254
00260 void K3dObjectWork::Link(const int _iObjId0, const int _iObjId1, const int _iObjType0, const int _iObjType1)
00261 {
00262 switch (_iObjType1)
00263 {
00264 case K3D_IMAGE_OBJ:
00265 break;
00266 case K3D_VERTEX_OBJ:
00267 break;
00268 case K3D_SPHERE_OBJ:
00269 LinkObject(_iObjId1, _iObjId0, _iObjType0);
00270 break;
00271 case K3D_CAMERA_OBJ:
00272 break;
00273 case K3D_LINE_OBJ:
00274 LinkObject(_iObjId0, _iObjId1, _iObjType1);
00275 break;
00276 case K3D_RAY_OBJ:
00277 break;
00278 case K3D_PLANE_OBJ:
00279 LinkObject(_iObjId0, _iObjId1, _iObjType1);
00280 break;
00281 default:
00282 break;
00283 }
00284 }
00285
00290 void K3dObjectWork::Hide(const int _iObjId, const int _iObjType, const bool _bHide)
00291 {
00292 switch (_iObjType)
00293 {
00294 case K3D_IMAGE_OBJ:
00295 break;
00296 case K3D_VERTEX_OBJ:
00297 if(_bHide)
00298 {
00299 m_pGameData->GetVertexObjSP().Get(_iObjId)->GetIsVisible() = false;
00300 }
00301 else
00302 {
00303 m_pGameData->GetVertexObjSP().Get(_iObjId)->GetIsVisible() = true;
00304 }
00305 break;
00306 case K3D_SPHERE_OBJ:
00307 break;
00308 case K3D_CAMERA_OBJ:
00309 break;
00310 case K3D_LINE_OBJ:
00311 if(_bHide)
00312 {
00313 m_pGameData->GetLineObjSP().Get(_iObjId)->GetIsVisible() = false;
00314 }
00315 else
00316 {
00317 m_pGameData->GetLineObjSP().Get(_iObjId)->GetIsVisible() = true;
00318 }
00319 break;
00320 case K3D_RAY_OBJ:
00321 break;
00322 case K3D_PLANE_OBJ:
00323 if(_bHide)
00324 {
00325 m_pGameData->GetPlaneObjSP().Get(_iObjId)->GetIsVisible() = false;
00326 }
00327 else
00328 {
00329 m_pGameData->GetPlaneObjSP().Get(_iObjId)->GetIsVisible() = true;
00330 }
00331 break;
00332 default:
00333 break;
00334 }
00335 }