You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to be able to allow touch drag to scroll in my imgui gui. While investigating the problem I made a small example based on magnum example which uses drag to rotate a cube.
I modified this example so it works with emscripten, compiled it with emscripten for wasm and put it online. Drag with mouse works but on mobile it does not work. How to enable touch drag?
Modified example:
/* This file is part of Magnum. Original authors — credit is appreciated but not required: 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 — Vladimír Vondruš <mosra@centrum.cz> This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/
#include<Magnum/GL/Buffer.h>
#include<Magnum/GL/DefaultFramebuffer.h>
#include<Magnum/GL/Mesh.h>
#include<Magnum/GL/Renderer.h>
#include<Magnum/Math/Color.h>
#include<Magnum/Math/Matrix4.h>
#include<Magnum/MeshTools/CompressIndices.h>
#include<Magnum/MeshTools/Interleave.h>
#include<Magnum/Platform/EmscriptenApplication.h>
#include<Magnum/Platform/Sdl2Application.h>
#include<Magnum/Primitives/Cube.h>
#include<Magnum/Shaders/PhongGL.h>
#include<Magnum/Trade/MeshData.h>namespaceMagnum
{
namespaceExamples
{
usingnamespaceMagnum::Math::Literals;classPrimitivesExample : publicPlatform::Application
{
public:explicitPrimitivesExample (const Arguments &arguments);
private:voiddrawEvent () override;
voidmousePressEvent (MouseEvent &event) override;
voidmouseReleaseEvent (MouseEvent &event) override;
voidmouseMoveEvent (MouseMoveEvent &event) override;
GL::Mesh _mesh;
Shaders::PhongGL _shader;
Matrix4 _transformation, _projection;
Color3 _color;
};
PrimitivesExample::PrimitivesExample (const Arguments &arguments) : Platform::Application{ arguments, Configuration{}.setTitle ("Magnum Primitives Example") }
{
GL::Renderer::enable (GL::Renderer::Feature::DepthTest);
GL::Renderer::enable (GL::Renderer::Feature::FaceCulling);
Trade::MeshData cube = Primitives::cubeSolid ();
GL::Buffer vertices{ GL::Buffer::TargetHint::Array };
vertices.setData (MeshTools::interleave (cube.positions3DAsArray (), cube.normalsAsArray ()));
std::pair<Containers::Array<char>, MeshIndexType> compressed = MeshTools::compressIndices (cube.indicesAsArray ());
GL::Buffer indices{ GL::Buffer::TargetHint::ElementArray };
indices.setData (compressed.first);
_mesh.setPrimitive (cube.primitive ()).setCount (cube.indexCount ()).addVertexBuffer (std::move (vertices), 0, Shaders::PhongGL::Position{}, Shaders::PhongGL::Normal{}).setIndexBuffer (std::move (indices), 0, compressed.second);
_transformation = Matrix4::rotationX (30.0_degf) * Matrix4::rotationY (40.0_degf);
_projection = Matrix4::perspectiveProjection (35.0_degf, Vector2{ windowSize () }.aspectRatio (), 0.01f, 100.0f) * Matrix4::translation (Vector3::zAxis (-10.0f));
_color = Color3::fromHsv ({ 35.0_degf, 1.0f, 1.0f });
}
voidPrimitivesExample::drawEvent ()
{
GL::defaultFramebuffer.clear (GL::FramebufferClear::Color | GL::FramebufferClear::Depth);
_shader.setLightPositions ({ { 1.4f, 1.0f, 0.75f, 0.0f } }).setDiffuseColor (_color).setAmbientColor (Color3::fromHsv ({ _color.hue (), 1.0f, 0.3f })).setTransformationMatrix (_transformation).setNormalMatrix (_transformation.normalMatrix ()).setProjectionMatrix (_projection).draw (_mesh);
swapBuffers ();
}
voidPrimitivesExample::mousePressEvent (MouseEvent &event)
{
if (event.button () != MouseEvent::Button::Left) return;
event.setAccepted ();
}
voidPrimitivesExample::mouseReleaseEvent (MouseEvent &event)
{
_color = Color3::fromHsv ({ _color.hue () + 50.0_degf, 1.0f, 1.0f });
event.setAccepted ();
redraw ();
}
voidPrimitivesExample::mouseMoveEvent (MouseMoveEvent &event)
{
if (!(event.buttons () & MouseMoveEvent::Button::Left)) return;
Vector2 delta = 3.0f * Vector2{ event.relativePosition () } / Vector2{ windowSize () };
_transformation = Matrix4::rotationX (Rad{ delta.y () }) * _transformation * Matrix4::rotationY (Rad{ delta.x () });
event.setAccepted ();
redraw ();
}
}
}
MAGNUM_EMSCRIPTENAPPLICATION_MAIN (Magnum::Examples::PrimitivesExample)
Reopening until this is actually implemented. For the record, the workaround is to use Sdl2Application instead of EmscriptenApplication on the web as well.
I want to be able to allow touch drag to scroll in my imgui gui. While investigating the problem I made a small example based on magnum example which uses drag to rotate a cube.
I modified this example so it works with emscripten, compiled it with emscripten for wasm and put it online. Drag with mouse works but on mobile it does not work. How to enable touch drag?
Modified example:
Basically I added
Replaced old main with
MAGNUM_EMSCRIPTENAPPLICATION_MAIN (Magnum::Examples::PrimitivesExample)
and changed GL::Buffer vertices to work with emscripten
The text was updated successfully, but these errors were encountered: