Recently I've been looking at Povray, pyprocessing, and cfdg (version 3.0) as tools for creating digital images. I have branched two separate blogs where I mainly explore jruby + processing and processing.py

Friday, 12 October 2012

The Sunflow Coordinate System

The joons renderer seems to be caught in a bit of hybrid convention, well so it seems to me. Here I explore it a bit more using my "F" test which is pretty good at exploring/identifying anomalies in the coordinate system.
As users of processing will know to their cost up is -1 in the Y axis. The Z axis is 1 (into the screen) and X left to right is 1.
Sunflow up is 1 in the Z axis, it seems from the linear translation point of view joons renderer follows the sunflow convention see my sketch below, and with my corrected version the rotation is also about the Z-axis:-

   1 import joons.JoonsRenderer;
   2 
   3 
   4 JoonsRenderer jr;
   5 boolean rendered = false;
   6 
   7 
   8 float eyeX = 0;
   9 float eyeY = 115;
  10 float eyeZ = 40;
  11 float centerX = 0;
  12 float centerY = 0;
  13 float centerZ = 40;
  14 float upX = 0;
  15 float upY = 0;
  16 float upZ = -1;
  17 float fov = PI / 4; 
  18 float aspect = 1.0;  
  19 float zNear = 5;
  20 float zFar = 10000;
  21 
  22 void setup() {
  23   size(600, 600, P3D);
  24   jr = new JoonsRenderer(this, width, height);
  25   jr.setRenderSpeed(1);  
  26   //renderSpeed is set 1 by default, if this method is not called.
  27   //speed is inversely proportional to the render quality
  28 
  29   /*SC file format:-
  30    Image Settings
  31    Lights
  32    Shaders
  33    Modifiers
  34    Objects
  35    Instances
  36    */
  37 }
  38 
  39 
  40 void draw() {
  41   beginRecord("joons.OBJWriter", "");// just call like this. Leave the second parameter as "".
  42   perspective(fov, aspect, zNear, zFar);// use perspective() before camera()!!
  43   camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
  44   rotateZ(PI/10);
  45   render();
  46   endRecord();
  47   if (rendered) {
  48     jr.display();
  49   }
  50 }
  51 
  52 void render() {  // encapsulate the processing sketch as a function  
  53   translate(0, 0, 8);
  54   fill(255, 0, 0);
  55   box(15);
  56   translate(0, 0, 15);
  57   box(15);
  58   translate(15, 0, 0);
  59   box(15);
  60   translate(-15, 0, 15);
  61   box(15);
  62   translate(0, 0, 15);
  63   box(15);
  64   translate(15, 0, 0);
  65   box(15);
  66 }
  67 
  68 
  69 void keyPressed() {
  70   if (key == 'r' || key == 'R' && !rendered) {
  71     saveFrame("capture.png");
  72     jr.setShader("object0", "Red");
  73     //    jr.setShader("object1", "Blue");  // "F"is recognized as one object  
  74     //    jr.setShader("object2","Blue");
  75     //     jr.setShader("object3","Blue");
  76     //     jr.setShader("object4","Blue");
  77     //     jr.setShader("object5","Blue");
  78 
  79     // each sphere is recognized as an object in it self, and are
  80     // given names such as sphere0, sphere1, .. 
  81     // so have set shader separately for each sphere.
  82     jr.setSC(dataPath("cornell_box.sc"));
  83     rendered=jr.render("bucket");
  84     // render using render("ipr") to render quick and rough,
  85     // and render("bucket") to render slow and smooth
  86     // if successfully rendered, returns true
  87   }
  88 }
  89 
The joons renderer conveniently stores a snapshot of the processing sketch:-
snapshot of processing sketch


























This is exactly what should be expected, taking into account the Z is up convention. Here is the sunflow traced version.
sunflow-0.73 raytraced image

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
Pembrokeshire, United Kingdom
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2