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 & HelpSyntax Questions › Camera and objects relative position
Page Index Toggle Pages: 1
Camera and objects relative position (Read 409 times)
Camera and objects relative position
Dec 5th, 2007, 10:50pm
 
Hi all,
I confess that I'm unconfortable with the camera control.
Maybe somemone could explain where I'm wrong ?
I defined an object AerialCamera to handle a camera flying over the 2D plane (on X and Y axis). The idea is to be able to  "fly" over the plane, controlled by the mouse.

I tried severeal solutions. The one I share with you here is to move the object to be drawn, the camera being always at x=y=0. This let me use the rotate() functions
The problem I'm unable to solve is that once rotated on one axis, the other axis does not correspond to the axis I would like to rotate around.
Hmmm, well, maybe better understandable with an example.
See http://o.marce.free.fr/Processing/AerialCamera.pde


I draw a 4 colored square, then I try to control the rotation of the camera.

To play with it: mouse1 to move the object, mouse3 to change the view distance, shift+mouse2 to (try to) rotate the object such that I can fly above it.

Any idea, or better, solutions ?

Re: Camera and objects relative position
Reply #1 - Dec 6th, 2007, 10:17pm
 
Me again
Ok I found myself the answer to my question.

First answer is : use OCD library, dumb !!
(http://www.cise.ufl.edu/~kdamkjer/processing/libraries/ocd/)
Unfortunately it does not work for my Processing v135.
Got :
java.lang.IncompatibleClassChangeError
at damkjer.ocd.Camera.atan2(Camera.java:413)

Second (and correct) answer is to use beginCamera()/endCamera()
It apply the transformation to the camera rather than the objects. It is exactly what I'm looking for. Great !

Then, the draw() method of my AerialCamera object is now :
void draw(){
   beginCamera();
   camera(0,0,0.0001,0,0,0,0,1,0);
   rotateZ(alphaX);
   rotateX(-alphaZ);
   translate(0,0,ratioZ*eyeZ);
   endCamera();
}

The only point is that if I put :
   camera(0,0,0,0,0,0,0,1,0);
instead, it does not work... Why ?

Looks like a bug, no ? (indeed I put 0.0001 to workaround)


Re: Camera and objects relative position
Reply #2 - Dec 7th, 2007, 9:39am
 
That is not a bug. You're telling the renderer to put the camera at position (0, 0, 0) and look at (0, 0, 0) : hence it doesn't know which orientation to choose for the camera.

You shouldn't specify the same vectors for position and lookAt.

If you want the camera to look forward, try :

Code:
camera(
0, 0, 0, // camera position
0, 0, 1, // camera looking direction
0, 1, 0 // camera 'up' vector
}
Page Index Toggle Pages: 1