We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Sunflow Renderer on demand!
Page Index Toggle Pages: 1
Sunflow Renderer on demand?! (Read 4199 times)
Sunflow Renderer on demand?!
Mar 27th, 2010, 7:08am
 
Hi there,

is it possible to switch the renderer to the sunflow-renderer for just one frame? Often times I have a cool sketch and just want to save one frame as a sunflow rendered frame. Is that possible? Maybe not actualy switching the renderer but via some kind of graphic-context thing?!
Re: Sunflow Renderer on demand?!
Reply #1 - Mar 27th, 2010, 11:58am
 
Re: Sunflow Renderer on demand?!
Reply #2 - Mar 31st, 2010, 10:24am
 
I've been looking for the proper way to do that too! Below is my latest attempt. Works great, though the angles of view don't match...

Quote:
import hipstersinc.sunflow.shape.*;
import hipstersinc.sunflow.*;
import hipstersinc.sunflow.shader.*;
import hipstersinc.sunflow.util.*;
import hipstersinc.*;
import hipstersinc.sunflow.light.*;

float a;

void setup() {
  size(160, 120, P3D);
}

void draw() {
  a += 0.01;
  lights();
  background(255);
  translate(width >> 1, height >> 1);
  rotateX(a);
  rotateY(a);
  fill(255, 180, 0);
  box(50);
}

void keyPressed() {
  if (key == 's') {
    noLoop();
    recorder = createGraphics(width, height, "hipstersinc.P5Sunflow");
    recorder.beginDraw();
    draw();
    recorder.endDraw();
    recorder.save("test.png");
    recorder = null;
    loop();
  }
}
Re: Sunflow Renderer on demand?!
Reply #3 - Apr 6th, 2010, 12:54pm
 
If you keep track of the angles with the use of a variable and pass that to the offscreen image it will work.

e.g.
recorder.rotateX(variable)
Re: Sunflow Renderer on demand?!
Reply #4 - Apr 8th, 2010, 4:14am
 
I was talking about the camera's angle of view, not rotations. Rotations are fine, as they are always processed in the recorder too.

Sunflow's angle of view is larger than Processing's angle of view.
Re: Sunflow Renderer on demand?!
Reply #5 - Apr 15th, 2010, 12:26pm
 
I manipulate the camera in P3D using  scale then I test it once with sunflow

Once I have the camara tracking locked, then i render.
Re: Sunflow Renderer on demand?!
Reply #6 - Apr 20th, 2010, 3:03am
 
andrewowaun wrote on Apr 6th, 2010, 12:54pm:
If you keep track of the angles with the use of a variable and pass that to the offscreen image it will work.

e.g.
recorder.rotateX(variable)


Hi, how do you store the angles from peasyCam
I tried getRotations() but the results are not that good.
Re: Sunflow Renderer on demand?!
Reply #7 - Apr 20th, 2010, 3:21am
 
Quote:
Hi, how do you store the angles from peasyCam?
I tried getRotations() but the results are not that good.


mmmh i have to test (modify for the case) the following lines of code: they served to orient a tentacle section (from another sketch of mine) toward the next section.
Knowing where the peasyCam IS in space, and knowing where the object (the look at point) is, I should be able to get the 3 angles.
Will post back.


// Let particle b coords be the desired base center, and particle a coords be the desired top center.
Particle a;
Particle b;
//If that's where the center of the base stays, then the center of the top needs to end up at:
PVector c = new PVector(a.position().x()-b.position().x(),a.position().y()-b.position().y(),a.po
sition().z()-b.position().z());
float h = dist(0,0,0,c.x,c.y,c.z);
//then define the radius
float r = sqrt(pow(c.x,2)+pow(c.y,2)+pow(c.z,2));
float theta = atan2(c.y,c.x);
float phi = acos(c.z/r); //thank you Dave!
pushMatrix();
//now translate to b position
translate(b.position().x(),b.position().y(),b.position().z());
//and rotate the new tentacle segment
rotateZ(theta);
rotateY(phi);
rotateX(-HALF_PI);
//Segment to rotate
popMatrix();
Re: Sunflow Renderer on demand?!
Reply #8 - Apr 20th, 2010, 5:02am
 
The PeasyCam library is manipulated by the mousePressed events.

Sunflow is so powerful I seldom take the risk of using my own hand to manipulate the camara.

I write a sketch to animate the movement. When I get that movement I save it to an array which creates a black and white image. Each pixel stores a color e.g. (255,255,233) these colours are then mapped to a specific point on the screen (x,y,z)  This is one of the beauties of Processing's pixel array. Then from there you just scan the image from pixel zero to the end and let that control the camera when sunflow is doing it's magic.

I have not been able to rotate using one image so I create four (4) PGraphic offscreen buffers and each one I can rotate on all four axes. When I come  up with a cooler method I will post it here. There is probably a better way of doing this.

Here is a proof of concept sketch
http://www.openprocessing.org/visuals/?visualID=9017
Downkey '3' for demo mode


Download, Access the sketch and Downkey number  '3'
Re: Sunflow Renderer on demand?!
Reply #9 - Apr 22nd, 2010, 7:49am
 
Solved!
With the latest version of PeasyCam, mr Feinberg added a new method for CameraState:
apply(processing.core.PGraphics g)

So to render 'on demand' with the SAME angles you see in the display window, that's all you need to do:

case 's':
noLoop();  
recorder = createGraphics(width, height, "hipstersinc.P5Sunflow");
recorder.beginDraw();
cam.getState().apply(recorder); // apply the latest CameraState
scale(30.0); // a scale factor is needed
draw();
recorder.endDraw();
recorder.save((int) random(10000)+".png");
recorder = null;
loop();
break;

Re: Sunflow Renderer on demand?!
Reply #10 - Apr 25th, 2010, 1:29pm
 
hey which version of processing are you using. i use 1.1 and get the error-message: hipstersinc.p5sunflower needs to be uodated for the current release of Processing.
Re: Sunflow Renderer on demand?!
Reply #11 - Apr 26th, 2010, 2:52am
 
ramin wrote on Apr 25th, 2010, 1:29pm:
hey which version of processing are you using. i use 1.1 and get the error-message: hipstersinc.p5sunflower needs to be uodated for the current release of Processing.


Hello.
Be sure to get p5sunflow from this link:
http://www.punyblog.com/2009/10/sunflow-output-from-processing.html

Wink
Page Index Toggle Pages: 1