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 & HelpPrograms › 3D moving camera
Page Index Toggle Pages: 1
3D moving camera (Read 1191 times)
3D moving camera
Apr 14th, 2007, 3:04pm
 
Hello,

I would like to have a 3D environment with lots of different objects (instantiated from a class) moving about (within and outside of camera view) and to have a camera be able to track an object for a while (be locked to it, say just in front of it in z-coordinates) before letting go and smoothly locking into another object.

It seems that cameraBegin and cameraEnd are the way to go as you can translate, rotate etc. But I'm not sure.

Is there a way to get world coordinates of a specific object (modelX, modelY, modelZ ???) ?

Ultimately I would like to have a class that controls the camera.

Has anyone delved into this? I've skowered the forums but didn't come up with too much.

Thanks in advance,
Jeff
Re: 3D moving camera
Reply #1 - Apr 14th, 2007, 4:12pm
 
I'd suggest that as part of your 3DObject class, you have the world co-ordinates, and use them as the base for all omvements etc of the object, rather than trying to reverse engineer them from some other values.

As for camera control, there's:
http://www.cise.ufl.edu/%7Ekdamkjer/processing/libraries/ocd/

or possibly you could make use of http://www.cs.princeton.edu/~traer/animation/ and it's smooth transition properties.

As for doing it manually, I think that http://processing.org/reference/camera_.html is more useful than beginCamera/endCamera since it's very easy to say "I want the camera at 30,20,10 and it pointing at 0,45,20" than it is to move the camera, then try to work out the various rotations to get it looking at a certain point.
Re: 3D moving camera
Reply #2 - Apr 14th, 2007, 4:41pm
 
Quote:
I'd suggest that as part of your 3DObject class, you have the world co-ordinates, and use them as the base for all omvements etc of the object, rather than trying to reverse engineer them from some other values.


I'm not totally sure I understand.

If I have two (or more) objects in a 3DObjects that are moving (and maybe offscreen) how do I know what world coordinates they are in?

Maybe I'm stuck on a Director metaphor where for example, you have the method -

getWorldTransform().position  
to get world coordinates of a transform

and you can then move to it with -
scene.camera[1].transform.interpolateto(vector)  

What I would like is to have a cameraOBJ that can get the coordinates of a 3DObject to go to it.

traer.animation looks interesting, thanks for the link, although the camera still needs to know where to go to.

Am I missing something?

Quote:
As for doing it manually, I think that http://processing.org/reference/camera_.html is more useful than beginCamera/endCamera since it's very easy to say "I want the camera at 30,20,10 and it pointing at 0,45,20" than it is to move the camera, then try to work out the various rotations to get it looking at a certain point.


is eye the "pointing at" part?

In this idea would I put this inside each 3DObject? Or could I call it in the main script?

Hope I'm clear...
     
Re: 3D moving camera
Reply #3 - Apr 14th, 2007, 7:38pm
 
What I'm suggesting is something like:

Code:
class Object3D
{
float x,y,z; //position
float vx,vy,vz; //velocity
Object3D(float _x, float _y, float _z)
{
x=_x;
y=_y;
z=_z;
vx=random(-10,10);
vy=random(-10,10);
vz=random(-10,10);
}

void draw()
{
x+=vx;
y+=vy;
z+=vz;
pushMatrix();
translate(x,y,z);
cube(2); //or you could draw far more complex things
popMatrix();
}
}

Object3D[] myObjects;

void setup()
{
size(640,480,P3D);
myObjects=new Object3D[5]; //just 5 objects to start.
for(int i=0;i<myObjects.length;i++)
{
myObjects[i]=new Object3D(0,0,0); //start them all from the middle;
}
}

void draw()
{
background(0);
camera(0,0,-50,myObjects[0].x,mtObjects[0].y,myObjects[0].z,0,1,0);
//look from (0,0,-50) directly at myObjects[0]
for(int i=0;i<myObjects.length;i++)
{
myObjects[i].draw();
}
}

(n.b. I typed this directly into the board, so there may be bugs, but it shows the principle)

That creates 5 objects, and gives them a position, and speed, and they start to move, the camera sits at a point in the world, and looks directly at one of them.
Re: 3D moving camera
Reply #4 - Apr 14th, 2007, 10:41pm
 
Excellent!
Thanks for trying it out in code!

But I still have a question.
how would it work if you do a series of

translate(x,y,z);
rotateX()
translate(x,y,z);
etc. within Object3D?

What would be the value for the centerX, centerY, centerZ of camera in that case?


Re: 3D moving camera
Reply #5 - Apr 15th, 2007, 12:35am
 
If you're doing it like that, that's the "pain in the ass to reverse engineer" part. I don't know any way of working out where in the world you end up after a series of such translations, other than to do the maths yourself.

And using beginCamera() etc won't make it any easier to track an object, as there's no easy way to get ask "what series of translates and rotates happened to get you where you are" in order to replay them to move the camera to the right place.

I have a feeling it would be possible, but would require some very careful setting up of classes and methods, such that all the right translates and rotates happen in sequence.
Re: 3D moving camera
Reply #6 - Apr 16th, 2007, 11:17am
 
Hmmmm....

I must be hardheaded but I'm trying to set up something where one 3DObject is tracked (trackedobj) by running the camera sequence before the actual movements in all the 3DObjects.

in pseudocode -

3DObject trackedobj = (3DObject)AllObjects.getCurrentcamera();

beginCamera();

translate(trackedobj.OriginX, trackedobj.OriginY, 0);                                      
rotateY(radians(trackedobj.rot));
translate(200, 0, 0);    
                                             
endCamera();

AllObjects.update();  //cycles through all 3DObjects and make them move via an identical sequence.

What I want is for the camera to be set up in a certain location and then the tracked object will be drawn there just after (need to set z so I can see it). The other objects would be in their normal places in relation to the tracked 3DObject.

Something is happening but it's all out of whack.

Am I using beginCamera / endCamera right? Can I use pushMatrix and popMatrix with it? Is this futile?
Does modelX work?

Thanks for any help!
Page Index Toggle Pages: 1