This C++ example uses the simple Launcher01.hpp mainloop framework integration.
This C++ example uses the simple Launcher01.hpp mainloop framework integration. It creates a window, provides keyboard and pointer interaction including picking, rotate & drag. It uses GearsES2 gamp::wt::RenderListener for rendering and uses per-pixel-lighting.
#include <cstdio>
#include <cmath>
#include <memory>
#include "../demos/GearsES2.hpp"
#include "../demos/GLLauncher01.hpp"
private:
private:
public:
if( win ) {
}
}
}
};
private:
bool m_dragInit = true;
const float winZ = viewPos.
z;
}
return false;
}
constexpr float winZ0 = 0.0f;
constexpr float winZ1 = 0.3f;
}
if( !mapWinToObjRay(winPos, objRay, shape.
matPMvi()) ) {
return false;
}
return false;
}
if( !objBox.
getRayIntersection(objPos, objRay, std::numeric_limits<float>::epsilon(),
true) ) {
printf(
"obj getRayIntersection failed\n");
return false;
}
preWinPos = winPos;
return true;
}
if( !mapWinToObj(shape, winPos, objPos) ) {
return false;
}
if( m_dragInit ) {
m_dragInit = false;
startPos = objPos;
} else {
m_parent.
pan() += diffPos;
}
} else {
const float thetaY = 360.0f * ((float)(winPos.
x - preWinPos.
x) / (float)sdim.
x);
const float thetaX = 360.0f * ((float)(preWinPos.
y - winPos.
y) / (float)sdim.
y);
m_dragInit = true;
}
preWinPos = winPos;
return true;
}
public:
MyPointerListener(
GearsES2& p): m_parent(p) {
}
if( !win ) {
return;
}
if( m_picked ) {
}
m_picked = new_pick;
if( m_picked ) {
}
}
}
if( m_picked ) {
if( !win ) {
return;
}
if( m_picked ) {
}
m_picked = nullptr;
}
}
}
m_parent.
pan().
z += incr;
} else {
m_parent.
pan().
x -= rot.
x;
m_parent.
pan().
y += rot.
y;
}
}
if( m_picked ) {
printf(
"XXX shape: released\n");
}
m_picked = nullptr;
m_dragInit = true;
}
};
typedef std::shared_ptr<MyPointerListener> MyPointerListenerRef;
MyPointerListenerRef m_pl;
public:
m_kl(std::make_shared<MyKeyListener>(*this)),
m_pl(std::make_shared<MyPointerListener>(*this))
{ }
return false;
}
win->addKeyListener(m_kl);
win->addPointerListener(m_pl);
return true;
}
win->removeKeyListener(m_kl);
win->removePointerListener(m_pl);
}
};
int main(
int argc,
char *argv[])
{
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
std::shared_ptr< MyKeyListener > MyKeyListenerRef
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
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.