42 MyKeyListener(
GearsES2& p): m_parent(p) { }
67 typedef std::shared_ptr<MyKeyListener> MyKeyListenerRef;
75 bool m_dragInit =
true;
81 const float winZ = viewPos.
z;
88 constexpr float winZ0 = 0.0f;
89 constexpr float winZ1 = 0.3f;
100 if( !mapWinToObjRay(winPos, objRay, shape.
matPMvi()) ) {
108 if( !objBox.
getRayIntersection(objPos, objRay, std::numeric_limits<float>::epsilon(),
true) ) {
109 printf(
"obj getRayIntersection failed\n");
121 if( !mapWinToObj(shape, winPos, objPos) ) {
131 m_parent.
pan() += diffPos;
135 const float thetaY = 360.0f * ((float)(winPos.
x - preWinPos.
x) / (float)sdim.
x);
136 const float thetaX = 360.0f * ((float)(preWinPos.
y - winPos.
y) / (float)sdim.
y);
149 MyPointerListener(
GearsES2& p): m_parent(p) {
161 m_picked->
picked() =
false;
165 m_picked->
picked() =
true;
177 m_picked->
picked() =
false;
180 printf(
"XXX shape: lost\n");
189 m_parent.
pan().
z += incr;
192 m_parent.
pan().
x -= rot.
x;
193 m_parent.
pan().
y += rot.
y;
198 m_picked->
picked() =
false;
199 printf(
"XXX shape: released\n");
205 typedef std::shared_ptr<MyPointerListener> MyPointerListenerRef;
207 MyKeyListenerRef m_kl;
208 MyPointerListenerRef m_pl;
213 m_kl(
std::make_shared<MyKeyListener>(*this)),
214 m_pl(
std::make_shared<MyPointerListener>(*this))
232int main(
int argc,
char *argv[])
234 return launch(
"GearsES2.hpp",
236 std::make_shared<Example>(), argc, argv);
int launch(std::string_view sfile, const GLLaunchProps &props, const RenderListenerRef &demo, int argc, char *argv[])
int main(int argc, char *argv[])
jau::function< bool(const PointerEvent &e, const WindowRef &win, GearsObjectES2 &shape)> PointerShapeAction
bool init(const WindowRef &win, const jau::fraction_timespec &when) override
Called by the drawable immediately after the render context is initialized.
void dispose(const WindowRef &win, const jau::fraction_timespec &when) override
Notifies the listener to perform the release of all renderer resources per context,...
constexpr Vec3f & pan() noexcept
bool init(const WindowRef &win, const jau::fraction_timespec &when) override
Called by the drawable immediately after the render context is initialized.
constexpr bool doRotate() const noexcept
constexpr void setDoRotate(bool rotate) noexcept
GearsObjectES2 * findPick(const PointerShapeAction &action, const PointerEvent &e, const WindowRef &win)
Fast loop through all shapes using PointerShapeAction w/o matrix traversal using view-coordinates.
constexpr jau::math::Vec3f & rotEuler() noexcept
constexpr const jau::math::Recti & viewport() const noexcept
bool dispatchForShape(GearsObjectES2 &shape, const PointerShapeAction &action, const PointerEvent &e, const WindowRef &win)
Dispatch PointerShapeAction to given shape w/ matrix traversal.
constexpr PMVMat4f & pmvMatrix() noexcept
void dispose(const WindowRef &win, const jau::fraction_timespec &when) override
Notifies the listener to perform the release of all renderer resources per context,...
std::string toString() const noexcept
const jau::math::geom::AABBox3f & objBounds() const noexcept
const jau::math::Mat4f & matPMvi() const noexcept
Specifies the OpenGL profile.
static constexpr std::string_view GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
constexpr const Vec2i & surfaceSize() const noexcept
Returns the surface size of the client area excluding insets (window decorations) in pixel units.
size_t removeKeyListener(const KeyListenerRef &l)
size_t removePointerListener(const PointerListenerRef &l)
void addPointerListener(const PointerListenerRef &l)
void dispose(const jau::fraction_timespec &when) noexcept override
std::string toString() const noexcept
void addKeyListener(const KeyListenerRef &l)
constexpr VKeyCode keySym() const noexcept
Returns the virtual key symbol reflecting the current keyboard layout.
Listener for multiple KeyEvent.
Pointer event of type PointerType.
constexpr const jau::math::Vec2i & position(size_t index=0) const noexcept
Returns position of given pointer-index in pixel units.
constexpr size_t pointerCount() const noexcept
See details for multiple-pointer events.
constexpr const jau::math::Vec3f & rotation() const noexcept
Returns a 3-component float array filled with the values of the rotational axis in the following orde...
Listener for PointerEvent.
constexpr const WindowWeakPtr & source() const noexcept
constexpr const jau::fraction_timespec & when() const noexcept
static bool mapWinToAnyRay(const value_type winx, const value_type winy, const value_type winz0, const value_type winz1, const Matrix4 &invAny, const Recti &viewport, Ray3 &ray) noexcept
std::string toString() const noexcept
std::string toString() const noexcept
Axis Aligned Bounding Box.
constexpr bool intersectsRay(const Ray3f &r) const noexcept
Check if Ray intersects this bounding box.
bool getRayIntersection(Vec3f &result, const Ray3f &ray, const float epsilon, const bool assumeIntersection) const noexcept
Return intersection of a Ray with this bounding box, or false if none exist.
constexpr const Point3f & center() const noexcept
Returns computed center of this aabbox3f of low() and high().
bool mapWinToObj(const float winx, const float winy, const float winz, const Recti &viewport, Vec3 &objPos) noexcept
Map window coordinates to object coordinates.
bool mapObjToWin(const Vec3 &objPos, const Recti &viewport, Vec3 &winPos) const noexcept
Map object coordinates to window coordinates.
constexpr T adeg_to_rad(const T arc_degree) noexcept
Converts arc-degree to radians.
jau::function< R(A...)> bind_member(C1 *base, R(C0::*mfunc)(A...)) noexcept
Bind given class instance and non-void member function to an anonymous function using func_member_tar...
@ verbose
Verbose operations (debugging).
VKeyCode
Virtual key code following UTF16 specification.
std::shared_ptr< Window > WindowRef
@ VK_ESCAPE
Constant for the ESCAPE function key.
@ VK_RIGHT
Constant for the cursor- or numerical-pad right arrow key.
@ VK_DOWN
Constant for the cursor- or numerical pad down arrow key.
@ VK_UP
Constant for the cursor- or numerical-pad up arrow key.
@ VK_LEFT
Constant for the cursor- or numerical-pad left arrow key.
@ VK_PAUSE
Constant for the PAUSE function key.
constexpr jau::math::Vec3f getEulerAngleOrientation(const jau::math::Vec3f &eulerRotation) noexcept
Returns an orientation vector for given eurler X/Y/Z angles in radians.
int fprintf_td(const uint64_t elapsed_ms, FILE *stream, const char *format,...) noexcept
Convenient fprintf() invocation, prepending the given elapsed_ms timestamp.
Timespec structure using int64_t for its components in analogy to struct timespec_t on 64-bit platfor...
constexpr uint64_t to_ms() const noexcept
Returns time in milliseconds.
int printf(const char *format,...)
Operating Systems predefined macros.