Picking in 3D
In this recipe, we will calculate the intersection of the mouse cursor with a 3D model.
Getting ready
Include the necessary files to draw using OpenGL, use textures and load images, load 3D models, define OpenGL lights and materials, and use Cinder's Maya camera.
#include "cinder/gl/gl.h" #include "cinder/gl/Texture.h" #include "cinder/gl/Light.h" #include "cinder/gl/Material.h" #include "cinder/TriMesh.h" #include "cinder/ImageIo.h" #include "cinder/MayaCamUI.h"
Also, add the following using
statements:
using namespace ci; using namespace ci::app; using namespace std;
We will use a 3D model, so place a file and its texture in the assets
folder. For this example, we will be using a mesh file named ducky.msh
and a texture named ducky.png
.
How to do it…
We will use the
ci::CameraPersp
andci::Ray
classes to convert the mouse coordinates to our rotated 3D scene and calculate the intersection with a 3D model.Declare the members to define the 3D model and its intersection with the mouse...