Deploying 3D Objects on Embedded Devices – source code

Here is the source code to Cube01 referenced in the article:

[sourcecode language="javascript"]

PImage img;

void setup() {
size(640, 480, P3D);
img = loadImage("cube.png");
noStroke();
}

void draw() {
background(0);
noFill();
translate(width / 2, height / 2, 360);
rotateX(map(mouseY, 0, height, -PI, PI));
rotateY(map(mouseX, 0, width, -PI, PI));
textureMode(NORMALIZED);
beginShape(TRIANGLES);
texture(img);
DrawVertices();
endShape();
}

void DrawVertices() {
// f 1/1 2/2 3/3
vertex(-10.000000, 0.000000, 10.000000, 0.9988, 0.3344); // 1/1
vertex(-10.000000, 0.000000, -10.000000, 0.9988, 0.6648); // 2/2
vertex( 10.000000, 0.000000, -10.000000, 0.6681, 0.6648); // 3/3
// f 3/3 4/4 1/1
vertex(10.000000, 0.000000, -10.000000, 0.6681, 0.6648); // 3/3
vertex(10.000000, 0.000000, 10.000000, 0.6681, 0.3344); // 4/4
vertex(-10.000000, 0.000000, 10.000000, 0.9988, 0.3344); // 1/1
// f 5/5 6/6 7/7
vertex(-10.000000, 20.000000, 10.000000, 0.3359, 0.6668); // 5/5
vertex(10.000000, 20.000000, 10.000000, 0.6663, 0.6668); // 6/6
vertex(10.000000, 20.000000, -10.000000, 0.6663, 0.9992); // 7/7
// f 7/7 8/8 5/5
vertex(10.000000, 20.000000, -10.000000, 0.6663, 0.9992); // 7/7
vertex(-10.000000, 20.000000, -10.000000, 0.3359, 0.9992); // 8/8
vertex(-10.000000, 20.000000, 10.000000, 0.3359, 0.6668); // 5/5
// f 1/9 4/10 6/11
vertex(-10.000000, 0.000000, 10.000000, 0.0007, 0.6666); // 1/9
vertex(10.000000, 0.000000, 10.000000, 0.3347, 0.6666); // 4/10
vertex(10.000000, 20.000000, 10.000000, 0.3347, 0.9992); // 6/11
// f 6/11 5/12 1/9
vertex(10.000000, 20.000000, 10.000000, 0.3347, 0.9992); // 6/11
vertex(-10.000000, 20.000000, 10.000000, 0.0007, 0.9992); // 5/12
vertex(-10.000000, 0.000000, 10.000000, 0.0007, 0.6666); // 1/9
// f 4/13 3/14 7/15
vertex(10.000000, 0.000000, 10.000000, -0.0000, 0.3340); // 4/13
vertex(10.000000, 0.000000, -10.000000, 0.3344, 0.3340); // 3/14
vertex(10.000000, 20.000000, -10.000000, 0.3344, 0.6658); // 7/15
// f 7/15 6/16 4/13
vertex(10.000000, 20.000000, -10.000000, 0.3344, 0.6658); // 7/15
vertex(10.000000, 20.000000, 10.000000, -0.0000, 0.6658); // 6/16
vertex(10.000000, 0.000000, 10.000000, -0.0000, 0.3340); // 4/13
// f 3/17 2/18 8/19
vertex(10.000000, 0.000000, -10.000000, 0.3370, 0.3347); // 3/17
vertex(-10.000000, 0.000000, -10.000000, 0.6652, 0.3347); // 2/18
vertex(-10.000000, 20.000000, -10.000000, 0.6652, 0.6662); // 8/19
// f 8/19 7/20 3/17
vertex(-10.000000, 20.000000, -10.000000, 0.6652, 0.6662); // 8/19
vertex(10.000000, 20.000000, -10.000000, 0.3370, 0.6662); // 7/20
vertex(10.000000, 0.000000, -10.000000, 0.3370, 0.3347); // 3/17
// f 2/21 1/22 5/23
vertex(-10.000000, 0.000000, -10.000000, 0.6681, 0.6679); // 2/21
vertex(-10.000000, 0.000000, 10.000000, 0.9996, 0.6679); // 1/22
vertex(-10.000000, 20.000000, 10.000000, 0.9996, 0.9980); // 5/23
// f 5/23 8/24 2/21
vertex(-10.000000, 20.000000, 10.000000, 0.9996, 0.9980); // 5/23
vertex(-10.000000, 20.000000, -10.000000, 0.6681, 0.9980); // 8/24
vertex(-10.000000, 0.000000, -10.000000, 0.6681, 0.6679); // 2/21
}

[/sourcecode]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>