void draw_real_map(t_map *map, t_img *img) { int x; t_raycaster r; x = 0; while (x < img->width) { init_ray(&r, map, img, x); ray_cast(&r, map); draw_column(&r, map, img, x); x++; } }
void MainGameState::HandleUpdate(Urho3D::StringHash eventType, Urho3D::VariantMap &eventData) { float m_time_step = eventData[Urho3D::Update::P_TIMESTEP].GetFloat(); // Movement speed as world units per second float MOVE_SPEED = 10.0f; // Mouse sensitivity as degrees per pixel // const float MOUSE_SENSITIVITY = 0.1f; // Rotate the box thingy. // A much nicer way of doing this would be with a LogicComponent. // With LogicComponents it is easy to control things like movement // and animation from some IDE, console or just in game. // Alas, it is out of the scope for our simple example. // boxNode_->Rotate(Quaternion(8*timeStep,16*timeStep,0)); Urho3D::Input *input = GetSubsystem<Urho3D::Input>(); if (m_right_mouse_button_down && !m_context_menu_open) { m_right_click_pressed_time += m_time_step; if (m_right_click_pressed_time > 0.2 && !m_context_menu_open) { Urho3D::PODVector<Urho3D::RayQueryResult> results; if (ray_cast(results)) { m_context_menu->create_context_buttons(results[0].drawable_->GetNode()); std::cout << "ShowPopupening context menu" << std::endl; } m_systems.update<TestSystem>(m_time_step); m_context_menu_open = true; m_right_click_pressed_time = 0.0; } } Urho3D::String lol = "FPS: "; Urho3D::String rofl = Urho3D::String(1 / m_time_step); text_->SetText(lol + rofl); if (input->GetQualifierDown(1)) // 1 is shift, 2 is ctrl, 4 is alt MOVE_SPEED *= 10; if (input->GetKeyDown('W')) cameraNode_->Translate(Urho3D::Vector3(0, 0.5, 0.5) * MOVE_SPEED * m_time_step); if (input->GetKeyDown('S')) cameraNode_->Translate(Urho3D::Vector3(0, -0.5, -0.5) * MOVE_SPEED * m_time_step); if (input->GetKeyDown('A')) cameraNode_->Translate(Urho3D::Vector3(-1, 0, 0) * MOVE_SPEED * m_time_step); if (input->GetKeyDown('D')) cameraNode_->Translate(Urho3D::Vector3(1, 0, 0) * MOVE_SPEED * m_time_step); if (!GetSubsystem<Urho3D::Input>()->IsMouseVisible()) { // Use this frame's mouse motion to adjust camera node yaw and pitch. Clamp the // pitch // between -90 and 90 degrees /* Urho3D::IntVector2 mouseMove = input->GetMouseMove(); // avoid the weird extrem values before moving the mouse if (mouseMove.x_ > -2000000000 && mouseMove.y_ > -2000000000) { static float yaw_ = 0; static float pitch_ = 0; yaw_ += MOUSE_SENSITIVITY * mouseMove.x_; pitch_ += MOUSE_SENSITIVITY * mouseMove.y_; pitch_ = Urho3D::Clamp(pitch_, -90.0f, 90.0f); // Reset rotation and set yaw and pitch again cameraNode_->SetDirection(Urho3D::Vector3::FORWARD); cameraNode_->Yaw(yaw_); cameraNode_->Pitch(pitch_); }*/ } }
void wxGL_PMFCanvas::OnMouseEvt(wxMouseEvent& event) { bool update_omnipoints = false; if(event.Leaving() || event.ButtonUp()){ mainpanel->control_panel->push_undo(); } //if(!event.Leaving()){ // if(this != FindFocus()){ // previus_focus = FindFocus(); // SetFocus(); // } //}else{ // if(previus_focus)previus_focus->SetFocus(); //} if (!model.GetSOBJCount()) { event.Skip(); return; } //glsz if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_RIGHT_DOWN ) { mouse_start = wxPoint(event.GetX(), event.GetY()); } else if (event.GetEventType() == wxEVT_MOTION && event.Dragging()) { //########################start mouse movement code########################// if(event.m_controlDown){ //------------------------start omnipoint code------------------------// //if control is down we move the selected omnipoint if(omni.point.size() > 0 && omni_selected_list >-1 && omni_selected_list < (int)omni.point.size() && omni_selected_item >-1 && omni_selected_item < (int)omni.point[omni_selected_list].size()){ //but only if we have omnipoints and our selected coords are valid omnipoint&point = omni.point[omni_selected_list][omni_selected_item]; double M[16], P[16]; int v[4]; glGetDoublev(GL_MODELVIEW_MATRIX, M); glGetDoublev(GL_PROJECTION_MATRIX, P); glGetIntegerv(GL_VIEWPORT, v); vector3d start; vector3d start_dir; vector3d end; vector3d end_dir; ray_cast(event.GetX(), event.GetY(), end, end_dir); ray_cast(mouse_start.x, mouse_start.y, start, start_dir); vector3d global_point = point.pos+model.get_model_offset(point.model); bool s = true, s2 = true; vector3d delta(0,0,0); if(event.m_leftDown){ delta = filter_movement_delta( plane_line_intersect(global_point, get_movement_plane_norm(),end, end_dir, &s) - plane_line_intersect(global_point, get_movement_plane_norm(),start, start_dir, &s2)); //if left button is down we move along x and y }else if(event.m_rightDown){ //if right is down we move along y delta = closest_point_between_lines(global_point, get_movement_plane_norm(), end, end_dir) -closest_point_between_lines(global_point, get_movement_plane_norm(), start, start_dir); } if(s &&s2 && !null_vec(delta)){ point.pos = point.pos + delta; update_omnipoints = true; } } //------------------------end omnipoint code------------------------// } else if(event.m_altDown){ //------------------------start transform code------------------------// if(event.m_leftDown){ //if left button is down we move along x and y bool s = true, s2 = true; vector3d start; vector3d start_dir; vector3d end; vector3d end_dir; ray_cast(event.GetX(), event.GetY(), end, end_dir); ray_cast(mouse_start.x, mouse_start.y, start, start_dir); // XXX: Should this have a value? vector3d global_point = vector3d(); vector3d delta; delta = filter_movement_delta( plane_line_intersect(global_point, get_movement_plane_norm(),end, end_dir, &s) - plane_line_intersect(global_point, get_movement_plane_norm(),start, start_dir, &s2)); if(s &&s2 && !null_vec(delta)){ mainpanel->control_panel->transform(matrix(), delta); } }else if(event.m_rightDown){ //if right is down we rotate about z float angle = (mouse_start.y - event.GetY()); matrix transform(get_movement_plane_norm()); if(angle){ mainpanel->control_panel->transform(transform.invert() % matrix(angle) % transform, vector3d()); } } //------------------------end transform code------------------------// }else{ //++++++++++++++++++++++++start view code++++++++++++++++++++++++// if (!event.m_shiftDown) { //if shift is not down we rotate if (event.m_leftDown) { //we rotate about x and y when the left button is down rotation.y -= (mouse_start.x - event.GetX()); rotation.x -= (mouse_start.y - event.GetY()); } else { //we rotate about z when the right is down rotation.z -= (mouse_start.y - event.GetY()); } } else { //if shift is down them we move the position if (event.m_leftDown) { //we move x and y when the left is down position.x -= model.SOBJ(0).radius * (float(mouse_start.x - event.GetX())/100.0) ; position.y += model.SOBJ(0).radius * (float(mouse_start.y - event.GetY())/100.0); } else { //we move along z when the right is down position.z -= model.SOBJ(0).radius * (float(mouse_start.y - event.GetY())/100.0); } } //++++++++++++++++++++++++end view code++++++++++++++++++++++++// } mouse_start = wxPoint(event.GetX(), event.GetY()); Render(); //########################end mouse movement code########################// } if (event.GetEventType() == wxEVT_MOUSEWHEEL){ //************************start scroll code************************// if(event.m_controlDown){ //------------------------start omnipoint code------------------------// //if control is down we scale the selected omnipoint if(omni.flags & OMNIPOINT_RAD && omni.point.size() > 0 && omni_selected_list >-1 && omni_selected_list < (int)omni.point.size() && omni_selected_item >-1 && omni_selected_item < (int)omni.point[omni_selected_list].size()){ //if the omnipoint has a radius //and the coords are valid if(omni.point[omni_selected_list][omni_selected_item].rad < 0.000001)omni.point[omni_selected_list][omni_selected_item].rad = model.get_avg_dimintion()/61.80f; if(event.GetWheelRotation()>0) omni.point[omni_selected_list][omni_selected_item].rad *= float(event.GetWheelRotation()/event.GetWheelDelta())*1.15; else omni.point[omni_selected_list][omni_selected_item].rad /= float(-event.GetWheelRotation()/event.GetWheelDelta())*1.15; update_omnipoints=true; } //------------------------end omnipoint code------------------------// } else if(event.m_altDown){ //------------------------start transform code------------------------// float scale; if(event.GetWheelRotation()>0) { scale = float(event.GetWheelRotation()/event.GetWheelDelta())*1.15; } else { scale = 1 / (float(-event.GetWheelRotation()/event.GetWheelDelta())*1.15); } matrix transform; for (int i = 0; i < 3; i++) { transform.a2d[i][i] = scale; } if(scale != 1.0f){ mainpanel->control_panel->transform(transform, vector3d()); } //------------------------end transform code------------------------// }else{ //++++++++++++++++++++++++start view code++++++++++++++++++++++++// position.z -= float( event.GetWheelRotation()/event.GetWheelDelta() ) * position.z/50.0f; //++++++++++++++++++++++++end view code++++++++++++++++++++++++// } //************************end scroll code************************// Render(); } else event.Skip(); if(update_omnipoints){ mainpanel->control_panel->set_omnipoints(omni); set_omnipoints(mainpanel->control_panel->get_omnipoints()); } // Render(); }
void wxGL_PMFCanvas::on_click(wxMouseEvent& event){ vector3d ray_start, ray_dir; ray_cast(event.GetX(), event.GetY(), ray_start, ray_dir); ray_pick(ray_start, ray_dir); }