Drawing in 3D with the mouse
In this recipe, we will draw with the mouse on a 3D space. We will draw lines when dragging the mouse or rotate the scene in 3D when dragging and pressing the Shift key simultaneously.
Getting ready
Include the necessary files to draw using OpenGL, as well as the files needed to use Cinder's perspective, Maya camera, and poly lines.
#include "cinder/gl/gl.h" #include "cinder/Camera.h" #include "cinder/MayaCamUI.h" #include "cinder/PolyLine.h"
Also, add the following using
statements:
using namespace ci; using namespace ci::app; using namespace std;
How to do it…
We will use the ci::CameraPersp
and ci::Ray
classes to convert the mouse coordinates to our rotated 3D scene.
Declare a
ci::MayaCamUI
object and astd::vector
object ofci::PolyLine<ci::Vec3f>
to store the drawn lines:MayaCamUI mCamera; vector<PolyLine<Vec3f> > mLines;
In the
setup
method, we will createci::CameraPersp
and set it up so that the point of interest is the center of the window....