/** ******************************************************************************* @file /gui/engine/MapCamera.cpp @brief Kamera mapy @author Pavel @version 0.1 ******************************************************************************/ #include "gui/engine/MapCamera.h" #include "common/Log.h" // #include #include namespace gui{ /*MainCamera*********************************************************************************/ void TMainCamera::calculateCameraLook() { float r2, temp; p4fPos.z = sin(height) * radius + centre.z; r2 = cos(height) * radius; p4fPos.x = sin(width) * r2 + centre.x; p4fPos.y = cos(width) * r2 + centre.y; // pokud je oko kamery pod povrchem, tak ji zvednu if (guiMap->altitude(p4fPos.x, p4fPos.y, &temp) && (temp + CAM_ABOVE_MAP > p4fPos.z) ) { temp += CAM_ABOVE_MAP - centre.z; if (temp > radius) temp = radius; float _height = asin(temp / radius); p4fPos.z = sin(_height) * radius + centre.z; r2 = cos(_height) * radius; p4fPos.x = sin(width) * r2 + centre.x; p4fPos.y = cos(width) * r2 + centre.y; } // pokud je spodni cast kamery pod povrchem, tak ji take zvednu P3F bot; float _radius; float rel = (radius - fNear) / radius; CopyV3(bot.p, p4fPos.p); SubV3(bot.p, centre.p); MulV3(bot.p, rel); AddV3(bot.p, centre.p); if (guiMap->altitude(bot.x, bot.y, &temp) && (temp + CAM_ABOVE_MAP > bot.z) ) { temp += CAM_ABOVE_MAP - centre.z; _radius = rel * radius; if (temp > _radius) temp = _radius; float _height = asin(temp / _radius); p4fPos.z = sin(_height) * radius + centre.z; r2 = cos(_height) * radius; p4fPos.x = sin(width) * r2 + centre.x; p4fPos.y = cos(width) * r2 + centre.y; } p4fPos.u = 1; SETP4(p4fUp, 0, 0, 1, 1); CopyV3(p4fDir.p, centre.p); SubV3(p4fDir.p, p4fPos.p) p4fDir.u = 1; calculateMatrix(); } void TMainCamera::base() { radius = CAM_BASE_RADIUS; width = CAM_BASE_WIDTH; height = CAM_BASE_HEIGHT; // calculateCameraLook(); } void TMainCamera::turn(double dw,double dh) { float newh; width += (float)dw; while (width < 0) width += (float)(2*M_PI); while (width >= 2*M_PI) width -= (float)(2*M_PI); newh = height + (float)dh; if (newh < CAM_MIN_HEIGHT) newh = CAM_MIN_HEIGHT; if (newh > CAM_MAX_HEIGHT) newh = CAM_MAX_HEIGHT; height = newh; // calculateCameraLook(); } void TMainCamera::scroll(float _dx, float _dy) { float tmp; float dx = -( _dx*cos(width)+_dy*sin(width) ); float dy = ( -_dy*cos(width)+_dx*sin(width) ); tmp = centre.x+dx; if ( (tmp >= xmin) && ( tmp <= xmax) ) { centre.x = tmp; guiMap->altitude(tmp, centre.y, ¢re.z); } tmp = centre.y+dy; if ( (tmp >= ymin) && ( tmp <= ymax) ) { centre.y = tmp; guiMap->altitude(centre.x, tmp, ¢re.z); } // calculateCameraLook(); } void TMainCamera::setCentre(float _x, float _y) { if ( (_x >= xmin) && (_x <= xmax) && (_y >= ymin) && (_y <= ymax) ) { centre.x = _x; centre.y = _y; guiMap->altitude(_x, _y, ¢re.z); } // calculateCameraLook(); } void TMainCamera::incRadius(float dr) { float _radius = radius + dr; if (_radius < CAM_MIN_RADIUS) _radius = CAM_MIN_RADIUS; if (_radius > CAM_MAX_RADIUS) _radius = CAM_MAX_RADIUS; radius = _radius; // calculateCameraLook(); } TMainCamera::TMainCamera(TguiMap *_map) :TCamera(VIEW_ANGLE, ASPECT_RATIO, NEAR_CLIP, FAR_CLIP) { editing = false; guiMap = _map; SETV2(startEdit,0,0); SETV3(centre.p, 0,0,0); width = 0; height = 0; radius = 0; } void TMainCamera::initCam() { guiMap->getExtents(&xmin, &xmax, &ymin,&ymax); base(); // calculateCameraLook(); } /******************************************************************************/ }//namespace /******************************************************************************/