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 › Using a for loop in a camera
Page Index Toggle Pages: 1
Using a for loop in a camera (Read 1074 times)
Using a for loop in a camera
Dec 4th, 2006, 4:34pm
 
Hi I'm using OCD camera and I'm trying to create a for loop so that the person can only walk a certain distance back and forth.

Could someone please look at this code and give me any suggestions?

Code:

void keyPressed()
{
if(keyCode == UP)
{
cz -= 10;
lz -= 10;
}


else if(keyCode == DOWN)
{
while(cz<410)
{
cz += 10;
lz += 10;
}
}

if (keyCode == LEFT)
{
cx -= 10;
lx -= 10;
}
else if (keyCode == RIGHT)
{
cx += 10;
lx += 10;
}

camera1 = new Camera(this, cx, cy, cz);


}



void mouseMoved() {
camera1.pan(radians(mouseX - pmouseX) / 1.0);
}
Re: Using a for loop in a camera
Reply #1 - Dec 4th, 2006, 4:50pm
 
Your are looking for min max.
Code:


cz = min(cz+10,420);//will return cz+10 as long as it's less than 420 otherwise it returns 420
cz = max(cz-10,0);//will return cz-10 as long as it's greater than 0 otherwise it returns 0


Re: Using a for loop in a camera
Reply #2 - Dec 4th, 2006, 5:02pm
 
Fantastic, that works brillantly. Thank you very much
Re: Using a for loop in a camera
Reply #3 - Dec 4th, 2006, 10:04pm
 
Why are you creating a new camera every time you need to move the camera, as opposed to just using the camera movement functions?
Page Index Toggle Pages: 1