ofDoc > 3d > of3dPrimitives

of3dPrimitivesfile

of3dPrimitiveclass

A class representing a 3d primitive.

Parent Node

Getters

getX ()
getY ()
getZ ()
getRoll ()

Setters

Modifiers

move ()
truck ()
boom ()
dolly ()
tilt ()
pan ()
roll ()
rotate ()
lookAt ()
orbit ()

OpenGL Transformation

Drawing

Functions

getMesh ()
getMesh ()
draw ()

ofPlanePrimitiveclass

The ofPlanePrimitive allows you to create an UV plane. Can be used for example as simple canvas for projecting simple texture .

Like all primitives it allows you to set the size, in this case height and width, draw it, set positions, etc, as a simple example:

void setup()
{
// resolution 640x480...
plane.set(640, 480);
plane.setPosition(320, 240, 0);
plane.setResolution(2, 2);
}
void draw()
{
plane.drawWireframe();
}

As you can see, plane is constructed from two triangles. To draw a texture over any primitive, simply bind the ofTexture instance and then draw your primitive:

texture.getTextureReference().bind();
// now draw filled...
plane.draw();

The plane primitive also allows you to simply pass an ofTexture to the plane and generate the texture coordinates from that texture so that the ofTexture fills the plane when it's drawn. This saves you the hassle of creating all the texture coordinates for each vertex, which is nice.

Parent Node

Getters

getX ()
getY ()
getZ ()
getRoll ()

Setters

Modifiers

move ()
truck ()
boom ()
dolly ()
tilt ()
pan ()
roll ()
rotate ()
lookAt ()
orbit ()

OpenGL Transformation

Drawing

Functions

set ()
setRows ()
setMode ()
getMesh ()
draw ()

ofSpherePrimitiveclass

The ofSpherePrimitive allows you to create a UV sphere. A UV spherewhich is a sphere based on UV slices rather than faces like the ofIcoSpherePrimitive. Note this:

IMG

On the left is a UV sphere and on the right is an ICO sphere.

Like all primitives it allows you to set the size (radius), draw it, set positions, etc, as a simple example:

void setup()
{
sphere.setRadius( width );
}
void draw()
{
sphere.setPosition(ofGetWidth()*.2, ofGetHeight()*.75, 0);
sphere.rotate(spinX, 1.0, 0.0, 0.0);
sphere.rotate(spinY, 0, 1.0, 0.0);
// get all the faces from the icoSphere, handy when you want to copy
// individual vertices or tweak them a little ;)
vector<ofMeshFace> triangles = sphere.getMesh().getUniqueFaces();
// now draw
sphere.draw();
}

To draw a texture over any primitive, simply bind the ofTexture instance and then draw your primitive:

texture.getTextureReference().bind();
// now draw
sphere.draw();

The sphere can look a little weird if you don't do ofEnabledDepthTesting() and ofDisableAlphaBlending().

Parent Node

Getters

getX ()
getY ()
getZ ()
getRoll ()

Setters

Modifiers

move ()
truck ()
boom ()
dolly ()
tilt ()
pan ()
roll ()
rotate ()
lookAt ()
orbit ()

OpenGL Transformation

Drawing

Functions

set ()
setMode ()
getMesh ()
draw ()

ofIcoSpherePrimitiveclass

The ofIcoSpherePrimitive allows you to create an icosphere. An icosphere is a sphere not based on UV slices like the ofSpherePrimitive, but rather faces. Like this:

Like all primitives it allows you to set the radius, draw it, set positions, etc.

void setup()
{
icoSphere.setRadius( width );
}
void draw()
{
icoSphere.setPosition(ofGetWidth()*.2, ofGetHeight()*.75, 0);
icoSphere.rotate(spinX, 1.0, 0.0, 0.0);
icoSphere.rotate(spinY, 0, 1.0, 0.0);
// get all the faces from the icoSphere, handy when you want to copy
// individual vertices or tweak them a little ;)
vector<ofMeshFace> triangles = icoSphere.getMesh().getUniqueFaces();
// now draw
icoSphere.draw();
}

Parent Node

Getters

getX ()
getY ()
getZ ()
getRoll ()

Setters

Modifiers

move ()
truck ()
boom ()
dolly ()
tilt ()
pan ()
roll ()
rotate ()
lookAt ()
orbit ()

OpenGL Transformation

Drawing

Functions

set ()
setMode ()
getMesh ()
draw ()

ofCylinderPrimitiveclass

The ofCylinderPrimitive allows you to create an cylinder mesh.

Like all primitives it allows you to set the size, for the cylinder a radius and height, draw it, set positions, etc, as a simple example:

void setup()
{
cylinder.set( cylinderRadius, cylinderHeight );
}
void draw()
{
cylinder.setPosition(ofGetWidth()*.2, ofGetHeight()*.75, 0);
cylinder.rotate(spinX, 1.0, 0.0, 0.0);
cylinder.rotate(spinY, 0, 1.0, 0.0);
// get all the faces from the icoSphere, handy when you want to copy
// individual vertices or tweak them a little ;)
vector<ofMeshFace> triangles = cylinder.getMesh().getUniqueFaces();
// now draw
cylinder.draw();
}

To draw a texture over any primitive, simply bind the ofTexture instance and then draw your primitive:

texture.getTextureReference().bind();
// now draw
cylinder.draw();

Parent Node

Getters

getX ()
getY ()
getZ ()
getRoll ()

Setters

Modifiers

move ()
truck ()
boom ()
dolly ()
tilt ()
pan ()
roll ()
rotate ()
lookAt ()
orbit ()

OpenGL Transformation

Drawing

Functions

set ()
setMode ()
getMesh ()
draw ()

ofConePrimitiveclass

The ofConePrimitive allows you to create a 3D cone. Like all primitives it allows you to set the size, draw it, set positions, etc, as a simple example:

void setup()
{
cone.set( coneRadius, coneHeight, coneRadiusSegments, coneHeightSegments );
}
void draw()
{
cone.setPosition(ofGetWidth()*.2, ofGetHeight()*.75, 0);
cone.rotate(spinX, 1.0, 0.0, 0.0);
cone.rotate(spinY, 0, 1.0, 0.0);
// get all the faces from the cpme, handy when you want to copy
// individual vertices or tweak them a little ;)
vector<ofMeshFace> triangles = cone.getMesh().getUniqueFaces();
// now draw
cone.draw();
}

To draw a texture over any primitive, simply bind the ofTexture instance and then draw your primitive:

texture.getTextureReference().bind();
// now draw
cone.draw();

Beware of the cone texture coordinates, they're a little strange.

Parent Node

Getters

getX ()
getY ()
getZ ()
getRoll ()

Setters

Modifiers

move ()
truck ()
boom ()
dolly ()
tilt ()
pan ()
roll ()
rotate ()
lookAt ()
orbit ()

OpenGL Transformation

Drawing

Functions

set ()
setMode ()
getMesh ()
draw ()

ofBoxPrimitiveclass

The ofBoxPrimitive allows you to create cubes and cuboids.

Like other primitives, it allows you to set its dimensions and position, draw it, etc. As a simple example:

void setup()
{
box.set( boxSize );
// or
// box.set( boxHeight, boxWidth, boxDepth );
}
void draw()
{
box.setPosition(ofGetWidth()*.2, ofGetHeight()*.75, 0);
box.rotate(spinX, 1.0, 0.0, 0.0);
box.rotate(spinY, 0, 1.0, 0.0);
// get all the faces from the icoSphere, handy when you want to copy
// individual vertices or tweak them a little ;)
vector<ofMeshFace> triangles = box.getMesh().getUniqueFaces();
// now draw
box.draw();
}

To draw a texture over any primitive, simply bind the ofTexture instance and then draw your primitive:

texture.getTextureReference().bind();
// now draw
box.draw();

Parent Node

Getters

getX ()
getY ()
getZ ()
getRoll ()

Setters

Modifiers

move ()
truck ()
boom ()
dolly ()
tilt ()
pan ()
roll ()
rotate ()
lookAt ()
orbit ()

OpenGL Transformation

Drawing

Types

BoxSides enum

Functions

set ()
setMode ()
getSize ()
getMesh ()
draw ()