In this recipe, we will learn how to draw the following 3D geometric shapes:
Cube
Sphere
Line
Torus
Cylinder
Include the necessary header to draw in OpenGL using Cinder commands and statements. Add the following code to the top of your source file:
#include "cinder/gl/gl.h" #include "cinder/Camera.h" using namespace ci;
We will create several geometric primitives using Cinder's methods for drawing in 3D.
Declare the member variables with information of our primitives:
Vec3f mCubePos, mCubeSize; Vec3f mSphereCenter; float mSphereRadius; Vec3f mLineBegin, mLineEnd; Vec3f mTorusPos; float mTorusOuterRadius, mTorusInnerRadius; Vec3f mCylinderPos; float mCylinderBaseRadius, mCylinderTopRadius, mCylinderHeight;
Initialize the member variables with the position and sizes of the geometry. Add the following code in the
setup
method:mCubePos = Vec3f( 100.0f, 300.0f, 100.0f ); mCubeSize = Vec3f( 100.0f, 100.0f, 100.0f ); mSphereCenter = Vec3f( 500...