zomaru Posted March 1, 2021 Share Posted March 1, 2021 Hello! I have such a question as to use the mouse to manipulate objects, as well as bones so that you can control, for example, a manipulator. Link to comment
zomaru Posted March 1, 2021 Author Share Posted March 1, 2021 I understand it using World :: getIntersection. But you need to somehow convert the coordinates of the mouse. Any example? Link to comment
thomalex Posted March 1, 2021 Share Posted March 1, 2021 Hello @zomaru! To retrieve an object under mouse cursor, one needs to cast a ray from the camera and find the first intersected object. You may find these articles helpful on this question: Intersections. WorldIntersection Usage Example. In brief, use Player::getDirectionFromScreen() and World::getIntersection() for that like in the example: Spoiler NodePtr AppWorldLogic::getNodeUnderCursor() { ivec2 mouse = Input::getMouseCoord(); Vec3 p0 = player->getWorldPosition(); Vec3 p1 = p0 + Vec3(player->getDirectionFromScreen(mouse.x, mouse.y)) * 100; WorldIntersectionPtr intersection = WorldIntersection::create(); NodePtr nd = World::getIntersection(p0, p1, ~0, intersection); return nd; } So, you'll need a custom logic for moving objects (e.g. screen-space offset by using mouse delta). For your convenience, there are ready-to-use widgets for node manipulation, they are: WidgetManipulatorTranslator WidgetManipulatorRotator WidgetManipulatorScaler Here's an example on how to use such a widget: Spoiler NodePtr selected_node; PlayerPtr player; GuiPtr gui; WidgetManipulatorPtr wm; int AppWorldLogic::init() { selected_node = World::getNodeByName("my_node"); player = Game::getPlayer(); gui = Gui::get(); wm = WidgetManipulatorTranslator::create(gui); wm->setTransform(selected_node->getWorldTransform()); wm->setProjection(player->getProjection()); wm->addCallback(Gui::CHANGED, MakeCallback(this, &AppWorldLogic::move)); gui->addChild(wm); return 1; } int AppWorldLogic::update() { wm->setModelview(player->getCamera()->getModelview()); return 1; } void AppWorldLogic::move() { selected_node->setWorldTransform(wm->getTransform()); } Please find the attached files for complete sample sources. AppWorldLogic.h AppWorldLogic.cpp 3 Link to comment
zomaru Posted March 1, 2021 Author Share Posted March 1, 2021 Большое спасибо! У вас очень хорошая тех поддержка и продукт. 1 Link to comment
Recommended Posts