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 › Camera moving with a trajectory
Page Index Toggle Pages: 1
Camera moving with a trajectory (Read 988 times)
Camera moving with a trajectory
Nov 2nd, 2009, 2:16am
 
Hi,

I am new to processing and I find it great.

I am trying to write a program that plots a given 2d trajectory (x,y) and I want the camera to move with the curve (I want the camera to focus on the point being actually plotted while still displaying some of the preceding points).

I am trying to do it with the ocd package but I am stuck.

With the code below, I have only one point which is displayed

Thanks,

Mohamed
--------------------------------------------------
This is a simplified version of "draw" code

void draw(){
Trajectory trajectory = new Trajectory("positions.txt",this);
camera1.feed();
stroke(255);
point((trajectory.x)[index-1],(trajectory.y)[index-1]);
camera1.aim((trajectory.x)[index],(trajectory_smoothed.y[index],100);

}
Re: Camera moving with a trajectory
Reply #1 - Nov 2nd, 2009, 7:49pm
 
does your trajectory class include an array/Vector/etc. of each point?  It sounds like you need to make sure you're reading the entire file of points into your trajectory object, then looping through each point...
Re: Camera moving with a trajectory
Reply #2 - Nov 3rd, 2009, 5:51am
 
Thank you for answering Smiley

Ma trajectory object has two attributes :

Trajectory(float[] x, float[] y)
 {
   this.x = x;
   this.y = y;
 }

I am incrementing the index variable so I loop through the arrays (I did not put all the code in the example to make it simple).
I really think that the problem comes from the camera management.

Re: Camera moving with a trajectory
Reply #3 - Nov 3rd, 2009, 5:57am
 
Here is the code


import damkjer.ocd.*;

int index = 1;
Camera camera1;

void setup() {
 size(800,800, P3D);
 background(0, 0, 0);
 stroke(255);
 frameRate(30);  
 camera1 = new Camera(this, 0, 0, 500);


}

void draw(){
 Trajectory trajectory = new Trajectory("positions.txt",this);

 float xMin = min(trajectory.x);
 float yMin = min(trajectory.y);
 float xMax = max(trajectory.x);
 float yMax = max(trajectory.y);

 index = index + 1 ;
 index = index%((trajectory.x).length);
 trajectory = rescale(trajectory, xMin, xMax, yMin, yMax);
 
 camera1.feed();

 stroke(255);
 point((trajectory.x)[index-1],(trajectory.y)[index-1]);


camera1.aim((trajectory.x)[index],(trajectory.y)[index],600);

}
Page Index Toggle Pages: 1