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, 31 October 2012

Improved Joons-Fork (ArcBall added)

Despite there being very little current interest in the Joons library I have continued to meddle with my fork, I have now implemented the rotate(w, x, y, z) function, which was pre-requisite before adding ArcBall functionality. Here is my FTest sketch that demonstrates the ArcBall usage (the rotate function is 'hidden' in the library so don't expect to see it). In this sketch rotation is constrained about the Z axis, and achieved by
'dragging the mouse'.

   1 import joons.JoonsRenderer;
   2 import joons.util.ArcBall;
   3 import joons.util.Constrain;
   4 
   5 JoonsRenderer jr;
   6 ArcBall arcball;
   7 float eyeX = 0;
   8 float eyeY = 115;
   9 float eyeZ = 40;
  10 float centerX = 0;
  11 float centerY = 0;
  12 float centerZ = 40;
  13 float upX = 0;
  14 float upY = 0;
  15 float upZ = -1;
  16 float fov = PI / 4; 
  17 float aspect = 1.0;  
  18 float zNear = 5;
  19 float zFar = 10000;
  20 
  21 void setup() {
  22   size(600, 600, P3D);
  23   jr = new JoonsRenderer(this);
  24   arcball = new ArcBall(this, 0, 0, width*0.8);
  25   arcball.constrain(Constrain.ZAXIS);  
  26   jr.setRenderSpeed(1);  
  27   //renderSpeed is set 1 by default, if this method is not called.
  28   //speed is inversely proportional to the render quality
  29 
  30   /*SC file format:-
  31    Image Settings
  32    Lights
  33    Shaders
  34    Modifiers
  35    Objects
  36    Instances
  37    */
  38 }
  39 
  40 
  41 void draw() {
  42   background(200);
  43   if (jr.displaySketch()){
  44   beginRecord("joons.OBJWriter", "");// just call like this. Leave the second parameter as "".
  45 
  46   perspective(fov, aspect, zNear, zFar);// use perspective() before camera()!!
  47   camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
  48   arcball.update();     // need this here for JoonsRenderer to record rotations
  49   render();
  50   endRecord();
  51   }
  52 }
  53 
  54 void render() {  // encapsulate the processing sketch as a function  
  55   translate(0, 0, 8);
  56   fill(255, 0, 0);
  57   box(15);
  58   translate(0, 0, 15);
  59   box(15);
  60   translate(15, 0, 0);
  61   box(15);
  62   translate(-15, 0, 15);
  63   box(15);
  64   translate(0, 0, 15);  
  65   box(15);
  66   translate(15, 0, 0);
  67   box(15);
  68 }
  69 
  70 
  71 void keyPressed() {
  72   if (key == 'r' || key == 'R' && jr.displaySketch()) {
  73     saveFrame("capture.png");
  74     jr.setShader("object0", "Red");
  75     jr.setSC(dataPath("cornell_box.sc"));
  76     
  77     jr.render("ipr");
  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 
FTest sketch snapshot ('F' rotated via arcball)
Sunflow ray traced sketch

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