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

Wednesday, 24 October 2012

Nested Matrix test Joons-Fork render

In my previous post I presented an intermediate step to this a full nested matrix test, the code for Vec3D and MyBox is presented there, here is the nested matrix test:-


   1 import joons.JoonsRenderer;
   2 
   3 JoonsRenderer jr;
   4 
   5 float eyeX = 0;
   6 float eyeY = 115;
   7 float eyeZ = 40;
   8 float centerX = 0;
   9 float centerY = 0;
  10 float centerZ = 40;
  11 float upX = 0;
  12 float upY = 0;
  13 float upZ = -1;
  14 float fov = PI / 4; 
  15 float aspect = 1.0;  
  16 float zNear = 5;
  17 float zFar = 10000;
  18 MyBox[] boxes;
  19 Vec3D incTrans = new Vec3D(-10, 0, 10);
  20 Vec3D incRot = new Vec3D(radians(5), 0, radians(10));
  21 Vec3D sz = new Vec3D(20, 20, 20);
  22 float rotX = 0;
  23 float ROT_INC = 0.01;
  24 void setup() {
  25   size(600, 600, P3D);
  26   jr = new JoonsRenderer(this, width, height);
  27   jr.setRenderSpeed(1);  
  28   //renderSpeed is set 1 by default, if this method is not called.
  29   //speed is inversely proportional to the render quality
  30   boxes = new MyBox[4];
  31   /*SC file format:-
  32    Image Settings
  33    Lights
  34    Shaders
  35    Modifiers
  36    Objects
  37    Instances
  38    */
  39 }
  40 
  41 
  42 void draw() {
  43   if (jr.displaySketch()) {
  44     beginRecord("joons.OBJWriter", "");// just call like this. Leave the second parameter as "".
  45     perspective(fov, aspect, zNear, zFar);// use perspective() before camera()!!
  46     camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
  47     render();
  48     endRecord();
  49   }
  50 }
  51 
  52 void render() {  // encapsulate the processing sketch as a function
  53   background(100);
  54   Vec3D pos = new Vec3D(25, 0, 20);
  55   Vec3D rot = new Vec3D();
  56   rotX += ROT_INC;
  57   translate(7, -20, 30);
  58   fill(255);
  59   sphere(15);
  60   pushMatrix();
  61   rotateX(rotX);
  62   for (MyBox myBox: boxes) {
  63     myBox = new MyBox(sz, pos, rot);
  64     pos = pos.add(incTrans);
  65     rot = rot.add(incRot);
  66   }
  67   popMatrix();
  68 }
  69 
  70 void keyPressed() {
  71   if (key == 'r' || key == 'R' && jr.displaySketch()) {
  72     noLoop();
  73     saveFrame("capture.png");
  74     jr.setShader("object0", "Red");
  75     jr.setShader("sphere0", "Glass");
  76     jr.setSC(dataPath("cornell_box.sc"));
  77     jr.render("bucket");
  78     // render using render("ipr") to render quick and rough,
  79     // and render("bucket") to render slow and smooth
  80     // if successfully rendered, returns true
  81   }
  82 }
  83 
processing sketch
sunflow rendered

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