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.
Page Index Toggle Pages: 1
Rotation (Read 438 times)
Rotation
Mar 10th, 2006, 11:57pm
 
Hi all, I got this problem with walking in 3D:

import processing.opengl.*;
float a=0;
int f=-1600;
float Y=0;
float s=512;
float mx=512;
float my=300;
float mxa=512;
int ground = 1024;

void setup()
{
size(1024,600,OPENGL);
background(0);
framerate(80);
stroke(255,255,255);
}

void draw()
{
background(0);  

pushMatrix();
translate(0,height);

rotateX(PI/2);
fill(0,055,0);
rect(0,0,ground,-ground);

pushMatrix();
rotateX(PI/2);
translate(768,0,256);
fill(0,210,0);
box(100,300,100);
popMatrix();

pushMatrix();
rotateX(PI/2);
translate(256,0,256);
fill(0,110,0);
box(100,300,100);
popMatrix();

pushMatrix();
rotateX(PI/2);
translate(768,0,768);
fill(0,0,100);
box(100,300,100);
popMatrix();

pushMatrix();
rotateX(PI/2);
translate(256,0,768);
fill(100,0,0);
box(100,300,100);
popMatrix();

popMatrix();


if(keyPressed && keyCode==UP)f+=3;
if(keyPressed && keyCode==DOWN)f-=3;
if(keyPressed && keyCode==LEFT)mx+=3;
if(keyPressed && keyCode==RIGHT)mx-=3;
if(mousePressed)
{
beginCamera();
camera(mx, my, f, mx, my,2000, 0, 1, 0);
if(mouseButton == RIGHT)a=a+0.02;
if(mouseButton == LEFT)a=a-0.02;
rotateY(a);
endCamera();
}
else
{
beginCamera();
camera(mx, my, f, mx, my,2000, 0, 1, 0);
rotateY(a);
endCamera();
}
}


Now the problem is about walking in direction I am looking at. It always walks in the same direction, no matter where camera is looking. I was thinking to rotate coordinate system so Z axis rotates with a camera, if you know what I mean. Well, have a look, its easy to understand once you look at it running. Thanks for your help in advance.
Page Index Toggle Pages: 1