1 final float ADJ = 0.288675; // this constant * width = processing depth adjustment
2 List<String> arrayPOV;
3 String light0 = String.format("light_source { <%.1f, %.1f, %.1f> colour White }", 100.0, 500.0, -300.0);
4 String ground0 = "plane { <0.0, 1.0, 0.0>, 0.0\n\tpigment { NeonBlue }\n\tfinish {reflection 0.15}\n}";
5
6
7 /**
8 * Implements the direct write of a sketch sphere as a PovRAY sphere
9 */
10 void drawSphere(float sz) {
11 PMatrix3D matrix = (PMatrix3D)this.g.getMatrix();
12 float[] pos = matrix.get(new float[16]);
13 sphere(sz);
14 arrayPOV.add(String.format("sphere{<%.1f, %.1f, %.1f>,%.1f", pos[3], sz - pos[7], -pos[11], sz));
15 arrayPOV.add("\ttexture{ pigment{ color White }");
16 arrayPOV.add("\tfinish{ finish0 }\n}\n}");
17 }
18
19 void setup() {
20 size(300, 200, P3D);
21 camera(30.0, 100.0, 220.0, // eyeX, eyeY, eyeZ
22 0.0, 0.0, 0.0, // centerX, centerY, centerZ
23 0.0, 1.0, 0.0);
24 arrayPOV = new ArrayList<String>();
25 arrayPOV.add(String.format("#version %.1f;", 3.7));
26 arrayPOV.add(String.format("global_settings {assumed_gamma %.1f}", 1.0));
27 arrayPOV.add(String.format("#include \"%s\"", "colors.inc"));
28 arrayPOV.add(String.format("#include \"%s\"", "skies.inc"));
29 arrayPOV.add(String.format("#declare finish0 = finish{emission %.1f phong %.1f phong_size %.1f}", 0.1, 0.5, 10.0));
30 arrayPOV.add(String.format("camera{\n\tlocation< %f, %f, -%f >", 30.0, 100.0, 220.0));
31 arrayPOV.add(String.format("\tlook_at<0, 0, %.4f>", width*ADJ)); // Apply processing depth adjustment
32 arrayPOV.add(String.format("\tright<0, 0, %.4f>\n}", width * 1.0/height));
33 arrayPOV.add(String.format("%s", light0));
34 arrayPOV.add(String.format("sky_sphere {%s}", "S_Cloud3"));
35 arrayPOV.add(String.format("%s", ground0));
36 drawSphere(70);
37 translate(125, 0, 0);
38 drawSphere(60);
39 try {
40 PrintWriter pw = new PrintWriter(new FileWriter(dataPath("test.pov")));
41 for (String line: arrayPOV) {
42 pw.println(line);
43 }
44 pw.close();
45 }
46 catch (IOException e) {
47 }
48 }
The output PovRAY file is here:-
1 #version 3.7;
2 global_settings {assumed_gamma 1.0}
3 #include "colors.inc"
4 #include "skies.inc"
5 #declare finish0 = finish{emission 0.1 phong 0.5 phong_size 10.0}
6 camera{
7 location< 30.000000, 100.000000, -220.000000 >
8 look_at<0, 0, 86.6025>
9 right<0, 0, 1.5000>
10 }
11 light_source { <100.0, 500.0, -300.0> colour White }
12 sky_sphere {S_Cloud3}
13 plane { <0.0, 1.0, 0.0>, 0.0
14 pigment { NeonBlue }
15 finish {reflection 0.15}
16 }
17 sphere{<0.0, 70.0, 243.5>,70.0
18 texture{ pigment{ color White }
19 finish{ finish0 }
20 }
21 }
22 sphere{<123.9, 66.9, 228.1>,60.0
23 texture{ pigment{ color White }
24 finish{ finish0 }
25 }
26 }
![]() |
| PovRAY rendered balls on reflective plane (slightly fused) |
In my view quite unnecessarily quirky in the PMatrix3D documentation m[3] is m03, m[7] is m13 and m[11] is m23 (seems to follow java 3*3 Matrix3D format?). Perhaps no more quirky than *.net where m11 is the value of the first row and first column of the Matrix3D structure (this at least is if for benefit of human we dispense with begin count of zero for benefit of computer?). ActionScript 3.0 has another convention, letters a ... l for first 3 rows of 4*4 matrix hence more readable transform formulae:-
x' = ax + by + cz + d
y' = ex + fy + gz + h
z' = ix + jy + kz + l



0 comments:
Post a Comment