00001 /****************************************************************************\ 00002 * * 00003 * 16.04.2006 * 00004 * CFlyCamCtrl - Source File * 00005 * * 00006 * (c) Robert Hausmair * 00007 * * 00008 \****************************************************************************/ 00009 00010 /****************************************************************************\ 00011 * REQUIRED HEADERS * 00012 \****************************************************************************/ 00013 #include <Qt> 00014 00015 #include "CSceneCtrl.h" 00016 #include "CCamera.h" 00017 00018 /****************************************************************************\ 00019 * PRIVATE DEFINITIONS * 00020 \****************************************************************************/ 00021 00022 /****************************************************************************\ 00023 * PUBLIC CLASS FUNCTIONS * 00024 \****************************************************************************/ 00025 00026 //Cobstructor 00027 CSceneCtrl::CSceneCtrl() 00028 :ICamCtrl() 00029 { 00030 m_pCamera = NULL; 00031 Reset(); 00032 } 00033 00034 void CSceneCtrl::Reset(){ 00035 m_bActive = false; 00036 m_bDolly = false; 00037 m_bPan = false; 00038 m_bRotate = false; 00039 m_bChangeFov = false; 00040 m_bLButtonDown = false; 00041 m_bRButtonDown = false; 00042 m_bMButtonDown = false; 00043 00044 m_pos.Set(0,0,6); 00045 m_rot.Set(0,0,0); 00046 m_fov = 50; 00047 } 00048 00049 void CSceneCtrl::Enable(const TSmartPointer<CCamera> &pCamera) 00050 { 00051 if(!IsEnabled()) 00052 { 00053 ICamCtrl::Enable(pCamera); 00054 Reset(); 00055 //to avoid Popping 00056 m_pCamera->SetPos(m_pos); 00057 m_pCamera->SetRot(m_rot); 00058 m_pCamera->SetFOV(m_fov); 00059 } 00060 } 00061 00062 void CSceneCtrl::Update() 00063 { 00064 if(IsEnabled()) 00065 { 00066 if(true){//m_bActive){ 00067 m_pCamera->SetTransformOrder(RT); 00068 m_pCamera->SetPos(m_pos); 00069 m_pCamera->SetRot(m_rot); 00070 m_pCamera->SetFOV(m_fov); 00071 } 00072 } 00073 } 00074 00075 void CSceneCtrl::Disable() 00076 { 00077 if(IsEnabled()) 00078 { 00079 ICamCtrl::Disable(); 00080 Reset(); 00081 } 00082 } 00083 00084 CSceneCtrl::~CSceneCtrl() 00085 { 00086 m_pCamera = NULL; 00087 } 00088 00089 /****************************************************************************\ 00090 * PROTECTED CLASS FUNCTIONS * 00091 \****************************************************************************/ 00092 00093 /****************************************************************************\ 00094 * PRIVATE CLASS FUNCTIONS * 00095 \****************************************************************************/ 00096 bool CSceneCtrl::OnMouseMove(sdword sdwX, sdword sdwY, sdword sdwZ) 00097 { 00098 if(!IsEnabled()) 00099 return false; 00100 00101 if(true){//m_bActive){ 00102 if(m_bLButtonDown || m_bMButtonDown || m_bRButtonDown){ 00103 if(m_bRotate){ 00104 m_rot.m_X += (float)sdwY*0.02; 00105 m_rot.m_Y += (float)sdwX*0.02; 00106 } 00107 if(m_bDolly){ 00108 if( (m_pos.m_Z += (float)(sdwY-sdwX)*0.008) < 2 ){ 00109 m_pos.m_Z = 2.0; 00110 } 00111 } 00112 if(m_bPan){ 00113 m_pos.m_X -= (float)sdwX*0.002*m_pos.m_Z; 00114 m_pos.m_Y += (float)sdwY*0.002*m_pos.m_Z; 00115 } 00116 if(m_bChangeFov){ 00117 if( (m_fov += (float)sdwY*0.1) < 10 ){ 00118 m_fov = 10; 00119 } 00120 } 00121 } 00122 } 00123 return true; 00124 } 00125 00126 bool CSceneCtrl::OnKeyDown(dword flag) 00127 { 00128 if(!IsEnabled()) 00129 return false; 00130 00131 if(flag == Qt::Key_Alt){ 00132 m_bActive = true; 00133 return true; 00134 } 00135 return false; 00136 } 00137 00138 bool CSceneCtrl::OnKeyUp(dword dwKey) 00139 { 00140 if(!IsEnabled()) 00141 return false; 00142 00143 if(dwKey == Qt::Key_Alt){ 00144 m_bActive = false; 00145 return true; 00146 } 00147 return false; 00148 } 00149 00150 bool CSceneCtrl::OnMouseKeyDown(byte bKey){ 00151 00152 if(!IsEnabled()) 00153 return false; 00154 00155 switch(bKey){ 00156 00157 case Qt::LeftButton: 00158 00159 m_bLButtonDown = true; 00160 00161 if(m_bMButtonDown == true){ 00162 m_bDolly = true; 00163 m_bRotate = false; 00164 m_bPan = false; 00165 }else{ 00166 m_bRotate = true; 00167 } 00168 break; 00169 00170 case Qt::MidButton : 00171 00172 m_bMButtonDown = true; 00173 00174 if(m_bLButtonDown == false){ 00175 m_bPan = true; 00176 }else{ 00177 m_bDolly = true; 00178 m_bRotate = false; 00179 } 00180 break; 00181 00182 case Qt::RightButton : 00183 m_bChangeFov = true; 00184 m_bRButtonDown = true; 00185 break; 00186 } 00187 return true; 00188 } 00189 00190 bool CSceneCtrl::OnMouseKeyUp(byte bKey){ 00191 00192 if(!IsEnabled()) 00193 return false; 00194 00195 switch(bKey){ 00196 case Qt::LeftButton: 00197 00198 m_bLButtonDown = false; 00199 00200 m_bRotate = false; 00201 m_bDolly = false; 00202 if(m_bMButtonDown) 00203 m_bPan = true; 00204 00205 break; 00206 00207 case Qt::MidButton: 00208 00209 m_bMButtonDown = false; 00210 00211 if(m_bLButtonDown == false){ 00212 m_bPan = false; 00213 m_bMButtonDown = false; 00214 }else{ 00215 m_bRotate = true; 00216 m_bDolly = false; 00217 } 00218 break; 00219 00220 case Qt::RightButton: 00221 m_bChangeFov = false; 00222 m_bRButtonDown = false; 00223 break; 00224 } 00225 return true; 00226 }