void VoxelEditor::update_hit() { has_hit = hit_floor = false; vec3 dir, pos; vec2 win_pos(last_pos.x(), height() - last_pos.y()); get_window_ray(win_pos, inverse_mvp, viewport, pos, dir); btCollisionObject * obj = get_collision_object(); btTransform from_trans; btVector3 from_vec = convert_vec(pos); from_trans.setIdentity(); from_trans.setOrigin(from_vec); btTransform to_trans; btVector3 to_vec = convert_vec(pos + dir * float(1e12)); to_trans.setIdentity(); to_trans.setOrigin(to_vec); btTransform obj_trans; obj_trans.setIdentity(); btCollisionWorld::ClosestRayResultCallback callback(from_vec, to_vec); btCollisionWorld::rayTestSingle(from_trans, to_trans, obj, obj->getCollisionShape(), obj_trans, callback); if (!callback.hasHit()) { vec3 min = voxel->get_min(); vec3 max = voxel->get_max(); btStaticPlaneShape plane(btVector3(0.0f, 0.0f, 1.0f), min.z); obj->setCollisionShape(&plane); btCollisionWorld::rayTestSingle(from_trans, to_trans, obj, obj->getCollisionShape(), obj_trans, callback); if (!callback.hasHit()) return; float x = callback.m_hitPointWorld.x(); float y = callback.m_hitPointWorld.y(); if (x >= max.x || x < min.x || y >= max.y || y < min.y) return; hit_floor = true; } vec3 hit_normal = convert_vec(callback.m_hitNormalWorld); vec3 hit_pos = convert_vec(callback.m_hitPointWorld); hit_next = get_pos_vec(hit_pos + hit_normal * 0.1f); hit_block = get_pos_vec(hit_pos - hit_normal * 0.1f); has_hit = true; }
int main(void){ long t, *a, i; scanf("%ld", &t); a=(long*)malloc(t*sizeof(long)); for(i=0;i<t;i++){ scanf("%ld",&a[i]); } for(i=0;i<t;i++){ printf("%ld\n", win_pos(a[i])); } free(a); return 0; }
LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType, CMP_LIBRARY* aLibrary ) : SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Library Browser" ), wxDefaultPosition, wxDefaultSize, aFrameType==FRAME_SCH_VIEWER ? KICAD_DEFAULT_DRAWFRAME_STYLE : KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT, GetLibViewerFrameName() ) { wxASSERT( aFrameType==FRAME_SCH_VIEWER || aFrameType==FRAME_SCH_VIEWER_MODAL ); if( aFrameType == FRAME_SCH_VIEWER_MODAL ) SetModal( true ); wxAcceleratorTable table( ACCEL_TABLE_CNT, accels ); m_FrameName = GetLibViewerFrameName(); m_configPath = wxT( "LibraryViewer" ); // Give an icon wxIcon icon; icon.CopyFromBitmap( KiBitmap( library_browse_xpm ) ); SetIcon( icon ); m_HotkeysZoomAndGridList = s_Viewlib_Hokeys_Descr; m_cmpList = NULL; m_libList = NULL; SetScreen( new SCH_SCREEN() ); GetScreen()->m_Center = true; // Axis origin centered on screen. LoadSettings( config() ); SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); // Initialize grid id to the default value (50 mils): m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000; GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); ReCreateHToolbar(); ReCreateVToolbar(); wxSize size = GetClientSize(); size.y -= m_MsgFrameHeight + 2; wxPoint win_pos( 0, 0 ); if( !aLibrary ) { // Creates the libraries window display m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxPoint( 0, 0 ), wxSize(m_libListWidth, -1), 0, NULL, wxLB_HSCROLL ); } else { m_libraryName = aLibrary->GetName(); m_entryName.Clear(); m_unit = 1; m_convert = 1; m_libListWidth = 0; } // Creates the component window display win_pos.x = m_libListWidth; m_cmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST, wxPoint( 0, 0 ), wxSize(m_cmpListWidth, -1), 0, NULL, wxLB_HSCROLL ); if( m_libList ) ReCreateListLib(); DisplayLibInfos(); if( m_canvas ) m_canvas->SetAcceleratorTable( table ); m_auimgr.SetManagedWindow( this ); EDA_PANEINFO horiz; horiz.HorizontalToolbarPane(); EDA_PANEINFO vert; vert.VerticalToolbarPane(); EDA_PANEINFO info; info.InfoToolbarPane(); EDA_PANEINFO mesg; mesg.MessageToolbarPane(); // Manage main toolbal m_auimgr.AddPane( m_mainToolBar, wxAuiPaneInfo( horiz ).Name( wxT ("m_mainToolBar" ) ).Top().Row( 0 ) ); // Manage the left window (list of libraries) if( m_libList ) m_auimgr.AddPane( m_libList, wxAuiPaneInfo( info ).Name( wxT( "m_libList" ) ). Left().Row( 0 ) ); // Manage the list of components) m_auimgr.AddPane( m_cmpList, wxAuiPaneInfo( info ).Name( wxT( "m_cmpList" ) ). Left().Row( 1 ) ); // Manage the draw panel m_auimgr.AddPane( m_canvas, wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() ); // Manage the message panel m_auimgr.AddPane( m_messagePanel, wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom().Layer(10) ); /* Now the minimum windows are fixed, set library list * and component list of the previous values from last viewlib use */ if( m_libList ) { m_auimgr.GetPane( m_libList ).MinSize( wxSize( 80, -1) ); m_auimgr.GetPane( m_libList ).BestSize( wxSize(m_libListWidth, -1) ); } m_auimgr.GetPane( m_cmpList ).MinSize( wxSize( 80, -1) ); m_auimgr.GetPane( m_cmpList ).BestSize(wxSize(m_cmpListWidth, -1) ); m_auimgr.Update(); // Now Drawpanel is sized, we can use BestZoom to show the component (if any) #ifdef USE_WX_GRAPHICS_CONTEXT GetScreen()->SetZoom( BestZoom() ); #else Zoom_Automatique( false ); #endif Show( true ); }
void cv::viz::InteractorStyle::OnKeyDown() { CV_Assert("Interactor style not initialized. Please call Initialize() before continuing" && init_); FindPokedRenderer(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1]); // Save the initial windows width/height if (win_size_[0] == -1 || win_size_[1] == -1) win_size_ = Vec2i(Interactor->GetRenderWindow()->GetSize()); bool alt = Interactor->GetAltKey() != 0; std::string key(Interactor->GetKeySym()); if (key.find("XF86ZoomIn") != std::string::npos) zoomIn(); else if (key.find("XF86ZoomOut") != std::string::npos) zoomOut(); switch (Interactor->GetKeyCode()) { case 'h': case 'H': { std::cout << "| Help:\n" "-------\n" " p, P : switch to a point-based representation\n" " w, W : switch to a wireframe-based representation (where available)\n" " s, S : switch to a surface-based representation (where available)\n" "\n" " j, J : take a .PNG snapshot of the current window view\n" " k, K : export scene to Wavefront .obj format\n" " ALT + k, K : export scene to VRML format\n" " c, C : display current camera/window parameters\n" " f, F : fly to point mode, hold the key and move mouse where to fly\n" "\n" " e, E : exit the interactor\n" " q, Q : stop and call VTK's TerminateApp\n" "\n" " +/- : increment/decrement overall point size\n" " +/- [+ ALT] : zoom in/out \n" "\n" " r, R [+ ALT] : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}]\n" "\n" " ALT + s, S : turn stereo mode on/off\n" " ALT + f, F : switch between maximized window mode and original size\n" "\n" << std::endl; break; } // Switch representation to points case 'p': case 'P': { vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors(); vtkCollectionSimpleIterator ait; for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); ) for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); ) { vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp()); apart->GetProperty()->SetRepresentationToPoints(); } break; } // Save a PNG snapshot case 'j': case 'J': saveScreenshot(cv::format("screenshot-%d.png", (unsigned int)time(0))); break; // Export scene as in obj or vrml format case 'k': case 'K': { String format = alt ? "scene-%d.vrml" : "scene-%d"; exportScene(cv::format(format.c_str(), (unsigned int)time(0))); break; } // display current camera settings/parameters case 'c': case 'C': { vtkSmartPointer<vtkCamera> cam = Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetActiveCamera(); Vec2d clip(cam->GetClippingRange()); Vec3d focal(cam->GetFocalPoint()), pos(cam->GetPosition()), view(cam->GetViewUp()); Vec2i win_pos(Interactor->GetRenderWindow()->GetPosition()); Vec2i win_size(Interactor->GetRenderWindow()->GetSize()); double angle = cam->GetViewAngle () / 180.0 * CV_PI; String data = cv::format("clip(%f,%f) focal(%f,%f,%f) pos(%f,%f,%f) view(%f,%f,%f) angle(%f) winsz(%d,%d) winpos(%d,%d)", clip[0], clip[1], focal[0], focal[1], focal[2], pos[0], pos[1], pos[2], view[0], view[1], view[2], angle, win_size[0], win_size[1], win_pos[0], win_pos[1]); std::cout << data.c_str() << std::endl; break; } case '=': { zoomIn(); break; } case 43: // KEY_PLUS { if (alt) zoomIn(); else { vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors(); vtkCollectionSimpleIterator ait; for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); ) for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); ) { vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp()); float psize = apart->GetProperty()->GetPointSize(); if (psize < 63.0f) apart->GetProperty()->SetPointSize(psize + 1.0f); } } break; } case 45: // KEY_MINUS { if (alt) zoomOut(); else { vtkSmartPointer<vtkActorCollection> ac = CurrentRenderer->GetActors(); vtkCollectionSimpleIterator ait; for (ac->InitTraversal(ait); vtkActor* actor = ac->GetNextActor(ait); ) for (actor->InitPathTraversal(); vtkAssemblyPath* path = actor->GetNextPath(); ) { vtkActor* apart = vtkActor::SafeDownCast(path->GetLastNode()->GetViewProp()); float psize = apart->GetProperty()->GetPointSize(); if (psize > 1.0f) apart->GetProperty()->SetPointSize(psize - 1.0f); } } break; } // Switch between maximize and original window size case 'f': case 'F': { if (alt) { Vec2i screen_size(Interactor->GetRenderWindow()->GetScreenSize()); Vec2i win_size(Interactor->GetRenderWindow()->GetSize()); // Is window size = max? if (win_size == max_win_size_) { Interactor->GetRenderWindow()->SetSize(win_size_.val); Interactor->GetRenderWindow()->SetPosition(win_pos_.val); Interactor->GetRenderWindow()->Render(); Interactor->Render(); } // Set to max else { win_pos_ = Vec2i(Interactor->GetRenderWindow()->GetPosition()); win_size_ = win_size; Interactor->GetRenderWindow()->SetSize(screen_size.val); Interactor->GetRenderWindow()->Render(); Interactor->Render(); max_win_size_ = Vec2i(Interactor->GetRenderWindow()->GetSize()); } } else { AnimState = VTKIS_ANIM_ON; Interactor->GetPicker()->Pick(Interactor->GetEventPosition()[0], Interactor->GetEventPosition()[1], 0.0, CurrentRenderer); vtkSmartPointer<vtkAbstractPropPicker> picker = vtkAbstractPropPicker::SafeDownCast(Interactor->GetPicker()); if (picker) if (picker->GetPath()) Interactor->FlyTo(CurrentRenderer, picker->GetPickPosition()); AnimState = VTKIS_ANIM_OFF; } break; } // 's'/'S' w/out ALT case 's': case 'S': { if (alt) { vtkSmartPointer<vtkRenderWindow> window = Interactor->GetRenderWindow(); if (!window->GetStereoRender()) { static Vec2i red_blue(4, 3), magenta_green(2, 5); window->SetAnaglyphColorMask (stereo_anaglyph_mask_default_ ? red_blue.val : magenta_green.val); stereo_anaglyph_mask_default_ = !stereo_anaglyph_mask_default_; } window->SetStereoRender(!window->GetStereoRender()); Interactor->Render(); } else Superclass::OnKeyDown(); break; } case 'o': case 'O': { vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera(); cam->SetParallelProjection(!cam->GetParallelProjection()); CurrentRenderer->Render(); break; } // Overwrite the camera reset case 'r': case 'R': { if (!alt) { Superclass::OnKeyDown(); break; } WidgetActorMap::iterator it = widget_actor_map_->begin(); // it might be that some actors don't have a valid transformation set -> we skip them to avoid a seg fault. for (; it != widget_actor_map_->end(); ++it) { vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second); if (actor && actor->GetUserMatrix()) break; } vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera(); // if a valid transformation was found, use it otherwise fall back to default view point. if (it != widget_actor_map_->end()) { vtkMatrix4x4* m = vtkProp3D::SafeDownCast(it->second)->GetUserMatrix(); cam->SetFocalPoint(m->GetElement(0, 3) - m->GetElement(0, 2), m->GetElement(1, 3) - m->GetElement(1, 2), m->GetElement(2, 3) - m->GetElement(2, 2)); cam->SetViewUp (m->GetElement(0, 1), m->GetElement(1, 1), m->GetElement(2, 1)); cam->SetPosition(m->GetElement(0, 3), m->GetElement(1, 3), m->GetElement(2, 3)); } else { cam->SetPosition(0, 0, 0); cam->SetFocalPoint(0, 0, 1); cam->SetViewUp(0, -1, 0); } // go to the next actor for the next key-press event. if (it != widget_actor_map_->end()) ++it; else it = widget_actor_map_->begin(); CurrentRenderer->SetActiveCamera(cam); CurrentRenderer->ResetCameraClippingRange(); CurrentRenderer->Render(); break; } case 'q': case 'Q': { Interactor->ExitCallback(); return; } default: { Superclass::OnKeyDown(); break; } } KeyboardEvent event(KeyboardEvent::KEY_DOWN, Interactor->GetKeySym(), Interactor->GetKeyCode(), getModifiers()); if (keyboardCallback_) keyboardCallback_(event, keyboard_callback_cookie_); Interactor->Render(); }