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.
Pages: 1 2 
Camera interface (Read 7678 times)
Camera interface
Apr 27th, 2005, 4:46pm
 
OK, here's what I've got so far. Let me know what you'd like to see added. There are also some notes about usage questions that I'd appreciate feedback on. I'm looking forward to hearing from you all.

Oh, I'm also considering adding a MultiCam class for setting up multiple cameras in one viewport. Thoughts? (Just ironing out the details of that at the moment).

Library

Obsessive Camera Direction (OCD)
The OCD library allows intuitive control and creation of Processing viewport Cameras. With OCD,  it is easy set up several cameras and switch between them. It is also easy to manipulate individual cameras using standard camera movement commands.

Camera
The Camera class represents a virtual viewport camera. The camera feed can be made active at any point by issuing the feed command. The camera is manipulated using the remaining commands.

Camera
feed()
zoom()
truck()
boom()
dolly()
aim()
jump()
tilt()
pan()
roll()
arc()
circle()
tumble()
look()
track()
Camera interface
Reply #1 - Apr 27th, 2005, 4:51pm
 
Classes

Name
Camera

Description
Data Type for manipulating the Processing viewport. There are several ways to create a Camera, but all cameras are manipulated the same way. The default camera position sits on the positive z axis. The default target position is at the world origin. The default up direction is in the negative y. The default field-of-view is 60 degrees PI/3 radians. The default aspect ratio is the ratio of the applet width to the applet height. The default near clipping plane is placed a 1/10 x shot length. The default far clipping plane is placed at 10x the shot length. Each constructor provides a way to override these default values.

Methods
Camera Switching
feed()
send what this camera sees to the view port

Perspective changes
zoom(amount)
change the field of view by the specified amount

Straight-line movements
truck(distance)
move the camera and c.o.i. along the side vector by the specified distance

boom(distance)
move the camera and c.o.i. along the up vector by the specified distance

dolly(distance)
move the camera and c.o.i. along the view vector by the specified distance

Arc movements
arc(amount)
arcs the camera over (under) a center of interest at its present azimuth by the specified amount
(which would be preferred here... arc length or change in elevation?)

circle(amount)
arcs the camera around a center of interest at its present elevation by the specified amount
(which would be preferred here... arc length or change in azimuth?)

Instantaneous Changes
jump(locationX, locationY, locationZ)
instantly change the camera's position to the specified location

aim(targetX, targetY, targetZ)
instantly change the camera's center of interest to the specified target

Rotations
Note: the following three methods assume degrees, but I think I remember seeing an angleMode() somewhere that sets the preferred angular units. Is there any way to check this and use radians or degrees based on the preferred mode? (Everything's in radians now.)

tilt(amount)
rotate the camera about the side vector by the specified amount

pan(amount)
rotate the camera about the up vector by the specified amount

roll(amount)
rotate the camera about the view vector by the specified amount

Combinations
tumble(azAmount, elAmount)
tumbles the camera about its center of interest by the specified amounts
(which would be preferred here... arc lengths or change in azimuth and elevation?)

look(azAmount, elAmount)
moves the c.o.i. around the camera at its present position by the specified amounts
(which would be preferred here... arc lengths or change in azimuth and elevation?)

track(xDistance, yDistance)
move the camera and c.o.i. simulataneously in the local x-y plane

Constructors
Camera(parent)
Camera(parent, shotLength)
Camera(parent, cameraX, cameraY, cameraZ)
Camera(parent, cameraX, cameraY, cameraZ, targetX, targetY, targetZ)
Camera(parent, cameraX, cameraY, cameraZ, targetX, targetY, targetZ, upX, upY, upZ)
Camera(parent, fov, aspect, nearClip, farClip)
Camera(parent, cameraX, cameraY, cameraZ, fov, aspect, nearClip, farClip)
Camera(parent, cameraX, cameraY, cameraZ, targetX, targetY, targetZ, fov, aspect, nearClip, farClip)
Camera(parent, cameraX, cameraY, cameraZ, targetX, targetY, targetZ, upX, upY, upZ, fov, aspect, nearClip, farClip)

Parameters
parentPApplet: typically use "this"
shotLength    float: distance from the camera to the center of interest
cameraXfloat: x coordinate for the camera position
cameraYfloat: y coordinate for the camera position
cameraZfloat: z coordinate for the camera position
targetXfloat: x coordinate for the center of interest
targetYfloat: y coordinate for the center of interest
targetZfloat: z coordinate for the center of interest
upXfloat: x component of the "up" direction vector, usually -1.0, 0.0, or 1.0
upYfloat: y component of the "up" direction vector, usually -1.0, 0.0, or 1.0
upZfloat: z component of the "up" direction vector, usually -1.0, 0.0, or 1.0
fovfloat: field-of-view angle in vertical direction
aspectfloat: ratio of width to height
nearClipfloat: relative z-position of the near clipping plane
farClipfloat: relative z-position of the far clipping plane
Re: Camera interface
Reply #2 - Apr 27th, 2005, 5:15pm
 
Based on the FAQ, the angleMode() has been removed:

http://processing.org/faq/changes.html

Quote:
angleMode() has been removed. Just use radians for everything. To convert from degrees to radians, use something like sin(radians(90))


and all paremeters are in radians, except for the method radians() which allows you to convert from degrees in radians:

http://processing.org/reference/radians_.html

I think it's a good idea to use radians everywhere, and I think it would be better to use radians in your whole library aswell.

What a method to position instantanously the camera in a certain position, it would go good with lookat.
Re: Camera interface
Reply #3 - Apr 28th, 2005, 2:11am
 
i second the recommendation on radians.. we found that angleMode() wound up messing with too much of the api, and decided it'd just create too many bugs for such a minor improvement. putting radians() on things doesn't seem like a big deal for ppl who want to use degrees.
Re: Camera interface
Reply #4 - Apr 28th, 2005, 2:44am
 
Rodger on the rads. Should I make that change for the fov  too It seems that P5 has left that as degrees. Should the default change to PI/3 (I just noticed a very minor typo in the perspective documentation)

Quote:
The devault values are: perspective(60.0, width/height, cameraZ/10.0, cameraZ*10.0) where cameraZ is ((height/2.0) / tan(PI*60.0/360.0));
Re: Camera interface
Reply #5 - Apr 28th, 2005, 3:19am
 
whups, i'll change fov to radians for 86. it's just been degrees forever and that's api that we only recently exposed so it went untouched.
Re: Camera interface
Reply #6 - May 3rd, 2005, 11:52pm
 
Here's a test version of my camera library: http://www.cise.ufl.edu/~kdamkjer/ocd/ocd-1_0.zip. Skeletal docs are posted above. I'll make a website this evening.

Here's a little demo piece of code that shows how to quickly get an arc-ball set up.

http://www.cise.ufl.edu/~kdamkjer/ocd/
Code:
import damkjer.ocd.*;

Camera camera1;

void setup() {
size(320, 240, P3D);

camera1 = new Camera(this, 200, -250, 300);
}

void draw() {
background(204);
lights();
camera1.feed();

box(50);
}

void mouseMoved() {
camera1.tumble(radians(mouseX - pmouseX), radians(mouseY - pmouseY));
}
Re: Camera interface
Reply #7 - May 7th, 2005, 9:25pm
 
Hey Damkjer

I have a question on your library;

how can retrieve the current zoom value for a camera?
I'm asking this because the values that feed camera.zoom
are relative (they're the amount of change);
I want to reset the camera to a initial zoom amount, but since the zoom values are placed by the user at run time, and the camera.zoom does not accept an absolute value, I'm not being able to.

Any ideas?
Re: Camera interface
Reply #8 - May 7th, 2005, 11:39pm
 
This is an issue I've been debating. Should the camera work in two modes: absolute and relative?

Right now everything is relative, but adding in an absolute Mode should be pretty easy.

What do you think?
Re: Camera interface
Reply #9 - May 8th, 2005, 12:34am
 
I've added online documentation and refreshed the download information. I also threw the source into the archive and fixed a very minor bug that was allowing the up and view vectors to be parallel.

The new home for OCD is: http://www.cise.ufl.edu/~kdamkjer/processing/libraries/ocd/

Items I'm currently working on:

1) Additional prespective manipulation
2) Ortho mode
3) Absolute manipulations (possibly a camera mode)
4) Simultaneous camera display

Thoughts
Re: Camera interface
Reply #10 - May 8th, 2005, 1:20am
 
Great! You're online.
http://processing.org/reference/libraries/
Re: Camera interface
Reply #11 - May 8th, 2005, 4:52am
 
hey Damkjer,

I think both modes are fine (relative is even easier to implement the user feedback, absolute is easier to script animations), I was just wondering ways to retrieve the values;
I have a situation where I find a good points of view of my geometry and want to save them for later, to a sketch presentation; it would be great to get camera1.zoom value, camera1.eyeX value, so on so forth...

anyway, I'm an adopter and a fan of OCD. Thanks!

Re: Camera interface
Reply #12 - May 13th, 2005, 9:46pm
 
hey Damkjer

Do you have any suggestion for keeping a 2D user interface on the top of the sketch when using the OCD?

I'm using the resetMatrix(); to put the interface components; it works, but if I use the camera zoom from OCD, the interface zooms as well, no matter how many resetMatrix in different places I use.

Any hint or idea is welcome. Thanks!
Re: Camera interface
Reply #13 - May 14th, 2005, 3:29pm
 
Solution 1:

Code:
import damkjer.ocd.*;

Camera persp;
Camera orth;

void setup() {
size(320, 240, P3D);
persp = new Camera(this, 100,-150, 200);
orth = new Camera(this);
rectMode(CENTER);
}

void draw() {
lights();
background(204);
persp.feed();

rotateY(PI/3);
box(50, 50, 50);

orth.feed();
rect(0, (height / 2) - 20, width, 40);
}

void mouseMoved() {
persp.tumble(radians(mouseX-pmouseX), radians(mouseY-pmouseY));
}
Re: Camera interface
Reply #14 - May 14th, 2005, 3:39pm
 
Zoom example:

Code:
import damkjer.ocd.*;

Camera persp;
Camera orth;

void setup() {
size(320, 240, P3D);
persp = new Camera(this, 100,-150, 200);
orth = new Camera(this);
rectMode(CENTER);
}

void draw() {
lights();
background(204);
persp.feed();

rotateY(PI/3);
box(50, 50, 50);

orth.feed();
rect(0, (height / 2) - 20, width, 40);
}

void mouseMoved() {
persp.zoom(radians(mouseX - pmouseX));
}


This will become more useful once I finish adding in the ortho for the camera (should be soon, just had to focus on other items this week).
Pages: 1 2