1 / 15

# Fundamentals of Programming - PowerPoint PPT Presentation

Fundamentals of Programming. SM1204 Semester A 2010/2011. 3D Programming. 3D Programming. First Step: Select rendering engine size(w, h, P3D); OR size (w, h, OPENGL); P3D (Processing 3D) - Fast 3D renderer for the web. Sacrifices rendering quality for quick 3D drawing.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about ' Fundamentals of Programming' - marva

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Fundamentals of Programming

SM1204 Semester A 2010/2011

• First Step: Select rendering engine

• size(w, h, P3D); OR size (w, h, OPENGL);

• P3D (Processing 3D) - Fast 3D renderer for the web. Sacrifices rendering quality for quick 3D drawing.

• OPENGL - High speed 3D graphics renderer that makes use of OpenGL-compatible graphics hardware is available.

• light() - Sets the default ambient light, directional light, falloff, and specular values.

• box() - A box with equal dimension on all sides is a cube.

• sphere() - A sphere is a hollow ball made from tessellated triangles.

• sphereDetial() - Controls the detail used to render a sphere by adjusting the number of vertices of the sphere.

size(640, 360, P3D);

background(0);

lights();

noStroke();

pushMatrix();

translate(130, height/2, 0);

rotateY(1.25);

rotateX(-0.4);

box(100);

popMatrix();

noFill();

stroke(255);

pushMatrix();

translate(500, height*0.35, -200);

sphere(280);

popMatrix();

http://processing.org/learning/3d/primitives3d.html

float spin = 0.0;

void setup() {

size(640, 360, P3D);

noStroke();

}

void draw() {

background(51);

lights();

spin += 0.01;

pushMatrix();

translate(width/2, height/2, 0);

rotateX(PI/9);

rotateY(PI/5 + spin);

box(150);

popMatrix();

}

http://processing.org/learning/3d/lights1.html

• pointLight() - Adds a point light.

• spotLight() - Adds a spot light.

• directionalLight() - Adds a directional light.

• ambientLight() - Adds an ambient light.

• Lights need to be included in the draw() to remain persistent in a looping program.

void setup() {

size(640, 360, P3D);

noStroke();

}

void draw() {

background(0);

translate(width / 2, height / 2);

// Orange point light on the right

pointLight(150, 100, 0, // Color

200, -150, 0); // Position

// Blue directional light from the left

directionalLight(0, 102, 255, // Color

1, 0, 0); // The x-, y-, z-axis direction

// Yellow spotlight from the front

spotLight(255, 255, 109, // Color

0, 40, 200, // Position

0, -0.5, -0.5, // Direction

PI / 2, 2); // Angle, concentration

rotateY(map(mouseX, 0, width, 0, PI));

rotateX(map(mouseY, 0, height, 0, PI));

box(150);

}

http://processing.org/learning/3d/lights2.html

• beginShape(MODE)

• endShape()

• Using the beginShape() and endShape() functions allow creating more complex forms.

• The MODEs available are POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, and QUAD_STRIP

• vertex() - used to specify the vertex coordinates for points.

http://processing.org/learning/3d/rgbcube.html

http://processing.org/learning/3d/cubicgrid.html

• texture() - Sets a texture to be applied to vertex points.

• textureMode() - Sets the coordinate space for texture mapping (either IMAGE or NORMALIZED).

http://processing.org/learning/3d/texture1.html

• ortho() - Sets an orthographic projection and defines a parallel clipping volume.

• perspective() - Sets a perspective projection applying foreshortening, making distant objects appear smaller than closer ones.

• camera() - Sets the position of the camera through setting the eye position, the center of the scene, and which axis is facing upward.

void setup() {

size(640, 360, P3D);

fill(204);

}

void draw() {

lights();

background(0);

// Change height of the camera with mouseY

camera(30.0, mouseY, 220.0, // eyeX, eyeY, eyeZ

0.0, 0.0, 0.0, // centerX, centerY, centerZ

0.0, 1.0, 0.0); // upX, upY, upZ

noStroke();

box(90);

stroke(255);

line(-100, 0, 0, 100, 0, 0);

line(0, -100, 0, 0, 100, 0);

line(0, 0, -100, 0, 0, 100);

}

http://processing.org/learning/3d/moveeye.html

Ortho vsPerspective

void setup()

{

size(640, 360, P3D);

noStroke();

fill(204);

}

void draw()

{

background(0);

lights();

if(mousePressed) {

float fov = PI/3.0;

float cameraZ = (height/2.0) / tan(PI * fov / 360.0);

perspective(fov, float(width)/float(height),

cameraZ/2.0, cameraZ*2.0);

} else {

ortho(-width/2, width/2, -height/2, height/2, -10, 10);

}

translate(width/2, height/2, 0);

rotateX(-PI/6);

rotateY(PI/3);

box(160);

}

http://processing.org/learning/3d/orthovsperspective.html