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 & HelpOther Libraries › peasyCam: how to get angles
Page Index Toggle Pages: 1
peasyCam: how to get angles? (Read 1931 times)
peasyCam: how to get angles?
Apr 20th, 2010, 12:51am
 
Hello everyone. Don't know if it's the right place to ask but here's my problem.

I have a skecth in wich I create a graphic buffer to be rendered on demand with P5Sunflow (thanks to antiplastik)
That means that when i am satisfied with my 3d lsystem growth and angle of observation i can render the frame.
Here's the code, it is executed when the 's' key is pressed.
The sketch uses the peasycam for cam controls but despite my efforts i cannot spot how to retrieve the cam angles on the 3 axis.
cam.getRotations() and its value stored in a float array don't work as i expect.
Could you help me?
Thanks in advance.
Here's the code for a on demand render of 1 frame.

Code:

    case 's':
noLoop();
recorder = createGraphics(width, height, "hipstersinc.P5Sunflow");
recorder.beginDraw();
// scale(40.0);
// rotateX(???);
// rotateY(???);
draw();
recorder.endDraw();
recorder.save((int) random(10000)+".png");
recorder = null;
loop();
    break;
Re: peasyCam: how to get angles?
Reply #1 - Apr 20th, 2010, 3:57am
 
Quote:
cam.getRotations() and its value stored in a float array don't work as i expect.
Could you help me


What were you expecting

Note that angles are expressed in radians so if you were expecting degrees then you need to convert the values returned by PeasyCam to degrees see http://processing.org/reference/degrees_.html
Re: peasyCam: how to get angles?
Reply #2 - Apr 20th, 2010, 4:06am
 
Quark wrote on Apr 20th, 2010, 3:57am:
Quote:
cam.getRotations() and its value stored in a float array don't work as i expect.
Could you help me


What were you expecting

Note that angles are expressed in radians so if you were expecting degrees then you need to convert the values returned by PeasyCam to degrees see http://processing.org/reference/degrees_.html



Hi, did a quick test yesterday.
Don't know, but when i rotateX, Y, or Z using these values, rotations are not correct:

float[] rotations = cam.getRotations();
rotateX(rotations[0]);
rotateY(rotations[1]);
rotateZ(rotations[2]);

I was trying this other solution:

float[] camPos = cam.getPosition();

PVector c = new PVector(camPos[0]-0,camPos[1]-0,camPos[2]-0);
float r = sqrt(pow(c.x,2)+pow(c.y,2)+pow(c.z,2));
theta = atan2(c.y,c.x);
phi = acos(c.z/r);


then, on the the buffer:
recorder.beginDraw();
translate(width/2, height/2, 0);
rotateZ(theta);
rotateY(phi);
rotateX(-HALF_PI);
scale(16.0);
draw();
recorder.endDraw();

It's still not working as I expected....   Shocked


GC
Re: peasyCam: how to get angles?
Reply #3 - Apr 20th, 2010, 7:06am
 
I think I'm having a similar problem, which I posted here, in case you want to watch that thread as well for any answers.  Make sure you post if you find the solution. Smiley
I've even made a request to Jonathan to add something into the library.  Perhaps you can vote on it at GitHub.
Re: peasyCam: how to get angles?
Reply #4 - Apr 20th, 2010, 7:19am
 
Rereading your post, you could probably just capture the camera matrix and apply it to the buffer.

PGraphics3D g3 = (PGraphics3D)g;

recorder.setMatrix(g3.camera);
Re: peasyCam: how to get angles?
Reply #5 - Apr 20th, 2010, 8:12am
 
jeffg wrote on Apr 20th, 2010, 7:19am:
Rereading your post, you could probably just capture the camera matrix and apply it to the buffer.

PGraphics3D g3 = (PGraphics3D)g;

recorder.setMatrix(g3.camera);


Thanks but i searched on the API and could not find anything related.
I was wondering, where the hell exactly is (x,y,z) an object if 'watched' with the peasycam
Re: peasyCam: how to get angles?
Reply #6 - Apr 20th, 2010, 8:19am
 
I believe anything that is set as the lookAt is positioned at 0,0,0.  I guess the getRotations and getDistance may tell you how it is looking at it.
Re: peasyCam: how to get angles?
Reply #7 - Apr 21st, 2010, 12:00pm
 
Quote:
I believe anything that is set as the lookAt is positioned at 0,0,0.


PeasyCam is basically an orbital camera i.e. it orbits some position in 3D space and that position is specified with the lookAt method. So lookAt(earth) it orbits the Earth lookAt(venus) its orbits Venus but the planets don't move.

You show this code
Code:
recorder.beginDraw();
translate(width/2, height/2, 0);
rotateZ(theta);
rotateY(phi);
rotateX(-HALF_PI);
scale(16.0);
draw();
recorder.endDraw();


Now I have not used P5SunFlower but if this was a P3D buffer I would need to
Code:

recorder.beginDraw();
recorder.translate(width/2, height/2, 0);
recorder.rotateZ(theta);
recorder.rotateY(phi);
recorder.rotateX(-HALF_PI);
recorder.scale(16.0);
draw(); // not sure of this
recorder.endDraw();
Re: peasyCam: how to get angles?
Reply #8 - Apr 22nd, 2010, 1:08am
 
Quote:
Now I have not used P5SunFlower but if this was a P3D buffer I would need to ....

Hi Quark, and thank you for the reply.
That thing is driving me crazy. You are right, recorder.stuff may be better but is not required to affect the transformation.. at least for this situation.
Anyhow, that not solves the problem.

Filling the variables phi and theta with the value extracted while drawing/rotating does not work. When rendered the angles does not macth.
Here is the result. The shape has been rotated (or better, the cam) to the left on the y axis and to the bottom on the x axis.

...

As you can see, the orientation is completely different.
It is a shame, because i would like to render big images generated with an l-system but i would like to do it by first rotating it to see wich part is more interesting.
Re: peasyCam: how to get angles?
Reply #9 - Apr 22nd, 2010, 7:50am
 
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;

Page Index Toggle Pages: 1