Tutorials:Ofelia Tutorial/Examples/3dPrimitives

"In construction"

This example shows how to draw 3d primitives (sphere, icosphere, plane, cylinder, cone and box) on screen and also giving a simple example of how to manipulate three point lights and how to set material. It is based on 3dPrimitivesExample tutorial from openFrameworks/examples.

The code has 4 parts, each in separate ofelia functions, driven by  ofSetup,  ofUpdate, ofDraw  and  ofExit

ofSetup
In the setup, the code can be also broken in some parts:
 * 
 * 
 * 
 * 

Basic Settings
ofBackground(20); ofSetSmoothLighting(true); ofSetSphereResolution(24);

Instantiation of Primitives
local width, height = ofGetWidth * 0.12, ofGetHeight * 0.12; sphere = ofSpherePrimitive; sphere:setRadius(width); icoSphere = ofIcoSpherePrimitive; icoSphere:setRadius(width); plane = ofPlanePrimitive; plane:set(width * 1.5, height * 1.5); cylinder = ofCylinderPrimitive; cylinder:set(width * 0.7, height * 2.2); cone = ofConePrimitive; cone:set(width * 0.75, height * 2.2); box = ofBoxPrimitive; box:set(width * 1.25);

local screenWidth, screenHeight = ofGetWidth, ofGetHeight; plane:setPosition(screenWidth * 0.2, screenHeight * 0.25, 0); box:setPosition(screenWidth * 0.5, screenHeight * 0.25, 0); sphere:setPosition(screenWidth * 0.8, screenHeight * 0.25, 0); icoSphere:setPosition(screenWidth * 0.2, screenHeight * 0.75, 0); cylinder:setPosition(screenWidth * 0.5, screenHeight * 0.75, 0); cone:setPosition(screenWidth * 0.8, screenHeight * 0.75, 0);

Instantiation of Point Lights
pointLight = ofLight; pointLight:setPointLight; pointLight:setDiffuseColor(ofFloatColor(0.85, 0.85, 0.55)); pointLight:setSpecularColor(ofFloatColor(1, 1, 1)); pointLight2 = ofLight; pointLight2:setPointLight; pointLight2:setDiffuseColor(ofFloatColor(238 / 255, 57 / 255, 135 / 255)); pointLight2:setSpecularColor(ofFloatColor(0.8, 0.8, 0.9)); pointLight3 = ofLight; pointLight3:setPointLight; pointLight3:setDiffuseColor(ofFloatColor(19 / 255, 94 / 255, 77 / 255)); pointLight3:setSpecularColor(ofFloatColor(18 / 255, 150 / 255, 135 / 255));

Instantiation of Material
material = ofMaterial; material:setShininess(120); material:setSpecularColor(ofFloatColor(1, 1, 1));