void CCamera::MouseFollow(float mx, float my,double time) { mx = mx/sensitivity * time; my = my/sensitivity * time; float OldXRot = CurrentXRot; CurrentXRot+=my; RotateView(mx * -1, Up.x, Up.y, Up.z); if ( (CurrentXRot <= MaxXRot) && CurrentXRot >= (MaxXRot * -1)) RotateView(my, Side.x,Side.y,Side.z); else { if (CurrentXRot < (MaxXRot * -1))//if(CurrentXRot < 0) { RotateView((MaxXRot * -1) - OldXRot, Side.x,Side.y,Side.z); CurrentXRot = MaxXRot * -1; } else { RotateView(MaxXRot - OldXRot, Side.x,Side.y,Side.z); CurrentXRot = MaxXRot; } } }
void WalkUI::SetViewByMouse() { int middleX = m_iWndWid >> 1; int middleY = m_iWndHet >> 1; float angleY = 0.0f; float angleZ = 0.0f; static float currentRotX = 0.0f; POINT mousePos; GetCursorPos(&mousePos); if( (mousePos.x == middleX) && (mousePos.y == middleY) ) ; //glutSetCursor( GLUT_CURSOR_FULL_CROSSHAIR ); SetCursorPos(middleX, middleY); //ShowCursor(FALSE); angleY = (float)( (middleX - mousePos.x) ) / m_MouseSensitity; angleZ = (float)( (middleY - mousePos.y) ) / m_MouseSensitity; currentRotX -= angleZ; gtl::Vec3f sub = m_vView - m_vPosition; gtl::Vec3f vAxis = sub.cross(m_vUpVector); vAxis.normalize(); RotateView(angleZ, vAxis.x(), vAxis.y(), vAxis.z()); RotateView(angleY, 0, 1, 0); }
void Camera::SetViewByMouse() { POINT mousePos; int middleX = 1600 >> 1; int middleY = 900 >> 1; float angleY = 0.0f; float angleZ = 0.0f; static float currentRotX = 0.0f; //glfwGetCursorPos (GLFWwindow *window, double *xpos, double *ypos);// GetCursorPos(&mousePos); if ((mousePos.x == middleX) && (mousePos.y == middleY)) return; SetCursorPos(middleX, middleY); angleY = (float)((middleX - mousePos.x)) / 1000.0f; angleZ = (float)((middleY - mousePos.y)) / 1000.0f; static float lastRotX = 0.0f; lastRotX = currentRotX; if (currentRotX > 1.0f) { currentRotX = 1.0f; if (lastRotX != 1.0f) { vec3 vAxis = cross(viewVector - position, upVector); vAxis = normalize(vAxis); RotateView(1.0f - lastRotX, vAxis.x, vAxis.y, vAxis.z); } } else if (currentRotX < -1.0f) { currentRotX = -1.0f; if (lastRotX != -1.0f) { vec3 vAxis = cross(viewVector - position, upVector); vAxis = normalize(vAxis); RotateView(-1.0f - lastRotX, vAxis.x, vAxis.y, vAxis.z); } } else { vec3 vAxis = cross(viewVector - position, upVector); vAxis = normalize(vAxis); RotateView(angleZ, vAxis.x, vAxis.y, vAxis.z); } RotateView(angleY, 0, 1, 0); }
////////////////////////////////////////////////////////////////////////// /// Rotate the camera. /// /// @param [in] yaw movement delta on X /// @param [in] pitch movement delta on Y /// /// @remark this version of rotation rotate using floats. /// /// This function doesn't return a value ////////////////////////////////////////////////////////////////////////// void Camera::Rotate(VCNFloat yaw, VCNFloat pitch) { Vector3 vAxis = mFocus - mPosition; vAxis = vAxis.CrossProduct(mUp).Normalized(); RotateView(pitch, vAxis.x, vAxis.y, vAxis.z); // Prevent head and feet angles if ( VCN::Abs(mDir.DotProduct(mUp)) > BLOCK_ANGLE ) { RotateView(-pitch, vAxis.x, vAxis.y, vAxis.z); } RotateView(yaw, mUp.x, mUp.y, mUp.z); }
void CCamera::Mouse() { HWND hWnd = GetActiveWindow(); POINT mousePos = get_cursor_pos(hWnd); RECT rt; GetWindowRect(hWnd, &rt); int mX = (rt.left + rt.right) >> 1; int mY = (rt.top + rt.bottom) >> 1; float angleY = 0.0f; float angleZ = 0.0f; static float currentRotX = 0.0f; if ((mousePos.x == mX) && (mousePos.y == mY)) return; SetCursorPos(mX, mY); angleY = (float)((mX - mousePos.x)) / 1000.0f; angleZ = (float)((mY - mousePos.y)) / 1000.0f; static float lastRotX = 0.0f; lastRotX = currentRotX; if (currentRotX > 1.0f) { currentRotX = 1.0f; if (lastRotX < 1.0f) { fl3 vAxis = norm_ort(m_vView - m_vPosition, m_vUpVector); RotateView(1.0f - lastRotX, vAxis.m[0], vAxis.m[1], vAxis.m[2]); } } else { if (currentRotX < -1.0f) { currentRotX = -1.0f; if (lastRotX < -1.0f) { fl3 vAxis = norm_ort(m_vView - m_vPosition, m_vUpVector); RotateView(-1.0f - lastRotX, vAxis.m[0], vAxis.m[1], vAxis.m[2]); } } else { fl3 vAxis = norm_ort(m_vView - m_vPosition, m_vUpVector); RotateView(angleZ, vAxis.m[0], vAxis.m[1], vAxis.m[2]); } } RotateView(angleY, 0, 1, 0); }
void CCamera::SetViewByMouse() { POINT mousePos; // This is a window structure that holds an X and Y int middleX = SCREEN_WIDTH >> 1; // This is a binary shift to get half the width int middleY = SCREEN_HEIGHT >> 1; // This is a binary shift to get half the height float angleY = 0.0f; // This is the direction for looking up or down float angleZ = 0.0f; // This will be the value we need to rotate around the Y axis (Left and Right) static float currentRotX = 0.0f; // Get the mouse's current X,Y position GetCursorPos(&mousePos); // If our cursor is still in the middle, we never moved... so don't update the screen if( (mousePos.x == middleX) && (mousePos.y == middleY) ) return; // Set the mouse position to the middle of our window SetCursorPos(middleX, middleY); // Get the direction the mouse moved in, but bring the number down to a reasonable amount angleY = (float)( (middleX - mousePos.x) ) / 500.0f; angleZ = (float)( (middleY - mousePos.y) ) / 500.0f; // Here we keep track of the current rotation (for up and down) so that // we can restrict the camera from doing a full 360 loop. currentRotX -= angleZ; // If the current rotation (in radians) is greater than 1.0, we want to cap it. if(currentRotX > 1.0f) currentRotX = 1.0f; // Check if the rotation is below -1.0, if so we want to make sure it doesn't continue else if(currentRotX < -1.0f) currentRotX = -1.0f; // Otherwise, we can rotate the view around our position else { // To find the axis we need to rotate around for up and down // movements, we need to get a perpendicular vector from the // camera's view vector and up vector. This will be the axis. CVector3 vAxis = Cross(m_vView - m_vPosition, m_vUpVector); vAxis = Normalize(vAxis); // Rotate around our perpendicular axis and along the y-axis RotateView(angleZ, vAxis.x, vAxis.y, vAxis.z); } // Rotate around the y axis no matter what the currentRotX is RotateView(angleY, 0, 1, 0); }
void InteractionEventRecorder::CreateQtPartControl( QWidget *parent ) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi( parent ); connect( m_Controls.btnStopRecording, SIGNAL(clicked()), this, SLOT(StopRecording()) ); connect( m_Controls.btnStartRecording, SIGNAL(clicked()), this, SLOT(StartRecording()) ); connect( m_Controls.btnPlay, SIGNAL(clicked()), this, SLOT(Play()) ); connect( m_Controls.btnOpenFile, SIGNAL(clicked()), this, SLOT(OpenFile()) ); connect( m_Controls.rotatePlanes, SIGNAL(clicked()), this, SLOT(RotatePlanes()) ); connect( m_Controls.rotate3D, SIGNAL(clicked()), this, SLOT(RotateView()) ); m_CurrentObserver = new mitk::EventRecorder(); // Register as listener via micro services us::ServiceProperties props; props["name"] = std::string("EventRecorder"); m_ServiceRegistration = us::GetModuleContext()->RegisterService<mitk::InteractionEventObserver>(m_CurrentObserver,props); /* delete m_CurrentObserverDEBUG; m_ServiceRegistrationDEBUG.Unregister(); */ }
//_______________________________________________________________________________________ void MakeFourView(TVirtualPad *pad=0) { // Creates 4 pads view of the pad (or qPad) // ------------------------------ // | | | // | | | // | | | // | Front | Top | // | view | view | // | | | // | | | // | | | // ---------------+------------- // | | | // | | | // | | | // | Side | Spacial | // | view | view | // | | | // | | | // | | | // ------------------------------ // begin_html <P ALIGN=CENTER> <IMG SRC="gif/FourStarView.gif" ></P> end_html // TVirtualPad *thisPad = pad; if (!thisPad) thisPad = qPad(); TView *view = 0; TList *thisPrimitives = 0; if (thisPad && (thisPrimitives = thisPad->GetListOfPrimitives()) && (view = thisPad->GetView()) ) { Double_t min[3],max[3]; view->GetRange(min,max); Int_t system = view->GetSystem(); TCanvas *c = new TCanvas(" 4 views", thisPad->GetTitle(),600,600); c->Divide(2,2); TIter *next= new TIter(thisPrimitives); for (int i =1; i <= 4; i++) { c->cd(i); TList *newPrimitives = qPad()->GetListOfPrimitives(); TObject *obj = 0; while (obj = next->Next()) newPrimitives->Add(obj); TView *newView = new TView(system); newView->SetRange(min,max); next->Reset(); } delete next; // set separate view; // Fron view Int_t j = 1; c->cd(j++); FrontView(); c->cd(j++); TopView(); c->cd(j++); SideView(); c->cd(j++); RotateView(-30.0,60.0,0); c->Modified(); c->Update(); } }
//------------------------------------------------------------------------------ void Example::MouseMove(double x, double y) { y = screen_height-y; if(mouse_left_down) { TranslateView( (mouse_x - x)/screen_width, (mouse_y - y)/screen_height ); UpdateView(); } if(mouse_middle_down) { double v1x = mouse_x - screen_width/2; double v1y = mouse_y - screen_height/2; double v2x = x - screen_width/2; double v2y = y - screen_height/2; double a1 = std::atan2(v1y, v1x); double a2 = std::atan2(v2y, v2x); RotateView((a2-a1)*180.0/3.1415); UpdateView(); } mouse_x = x; mouse_y = y; std::map<double, unsigned> view_tile_dist; for(unsigned i=0, n=view_divs*view_divs; i!=n; ++i) { double tile_x = ((i % view_divs)+0.5)*screen_width/view_divs; double tile_y = ((i / view_divs)+0.5)*screen_height/view_divs; double dist_sq = std::pow(mouse_x-tile_x, 2)+std::pow(mouse_y-tile_y, 2); view_tile_dist[dist_sq] = i; } auto t=view_tile_dist.begin(); unsigned i=0; while(t!=view_tile_dist.end()) { view_tile_index[i] = t->second; ++t; ++i; } }
void Camera::HandleMouse(int deltaX, int deltaY) { float fDeltaY = 0.0f; float fRotateY = 0.0f; fRotateY = (float)( (deltaX) ) / 1000; fDeltaY = (float)( (deltaY) ) / 1000; vView.y += fDeltaY * 15; // Check if the distance of our view exceeds 10 from our position, if so, stop it. (UP) if( (vView.y - vPosition.y) > 10) vView.y = vPosition.y + 10; // Check if the distance of our view exceeds -10 from our position, if so, stop it. (DOWN) if( (vView.y - vPosition.y) < -10) vView.y = vPosition.y - 10; // Here we rotate the view along the X avis depending on the direction (Left of Right) RotateView(0, -fRotateY, 0); }
//_______________________________________________________________________________________ static void TopView(TVirtualPad *pad=0){ RotateView(270.0,0.0,pad); }
//_______________________________________________________________________________________ static void FrontView(TVirtualPad *pad=0){ RotateView(270.0,90.0,pad); }
//_______________________________________________________________________________________ static void SideView(TVirtualPad *pad=0){ RotateView(0,90.0,pad); }