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
Rotating problem (Read 425 times)
Rotating problem
Jul 23rd, 2008, 11:16am
 
Hi,i am doing a FPS game with processing,but i have a problem when i rotate the axis,because i dont rotate like an human.If anybody test my code, he understand this.
Code:
Variables:
float heading;
float jugador_x;
float jugador_z;
//float walk;
float piover180 = 0.0174532925f;
float rotacion_y;
The draw:
void draw() {
 background(0);
 float xtrans = -jugador_x;
 float ztrans = -jugador_z;
 float ytrans = -walkbias-0.25;
 float sceneroty = radians(360 - rotacion_y);


 rotateY(sceneroty);
 
 translate(xtrans,ytrans,ztrans);
}
The movements:
 if (keyCode == UP) {
 
   jugador_x -= (float)sin(heading*piover180)* 5;
   jugador_z -= (float)cos(heading*piover180)* 5;
   
 }
 if (keyCode == DOWN) {

   jugador_x += (float)sin(heading*piover180)* 5;
   jugador_z += (float)cos(heading*piover180)* 5;
   
 }
 if (keyCode == RIGHT) {

   heading -= 1.0;
   rotacion_y = heading;


 }
 if (keyCode == LEFT) {
 
   heading += 1.0;
   rotacion_y = heading;


 }
}
(i dont put the another part of the code because its only drawing a room.)
Re: Rotating problem
Reply #1 - Jul 23rd, 2008, 11:37am
 
you need to do your transformations in the following order for it to work as you'd expect:

Code:
translate(...);
rotateY(...);
rotateX(...);


Re: Rotating problem
Reply #2 - Jul 23rd, 2008, 11:49am
 
Quote:
you need to do your transformations in the following order for it to work as you'd expect:

Code:
translate(...);
rotateY(...);
rotateX(...);



Thanks for your answer,but continues doing the same;
this is my code,but simplified:

Code:

import processing.opengl.*;

float heading;
float xpos;
float zpos;
float yrot;
float lookupdown = 0.0f;

void setup() {
 size (800,600, OPENGL);
}

void draw() {
 background(0); ;
 float xtrans = -xpos;
 float ztrans = -zpos;
 float sceneroty = radians(360 - yrot);



 translate(xtrans, 0, ztrans);

 rotateY(sceneroty);
    rotateX(lookupdown);
 pushMatrix();
   translate(width/2-200, height/2-200);
   rect(0,0,400,400);
 popMatrix();
}

void keyPressed() {
 if (keyCode == UP) {
   xpos -= (float)sin(radians(heading));
   zpos -= (float)cos(radians(heading));
 }
 if (keyCode == DOWN) {
   xpos += (float)sin(radians(heading));
   zpos += (float)cos(radians(heading));
 }
 if (keyCode == RIGHT) {
   heading -= 1.0f;
   yrot = heading;
 }
 if (keyCode == LEFT) {
   heading += 1.0f;
   yrot = heading;
 }
}
Re: Rotating problem
Reply #3 - Jul 23rd, 2008, 1:44pm
 
here's a simple example. im using vector/matrix math

www.pixelnerve.com/downloads/processing/simpleMoveRotateCamera.zip

enjoy
Re: Rotating problem
Reply #4 - Jul 23rd, 2008, 6:42pm
 
thanks for your sample. I use it for my FPS game.

Page Index Toggle Pages: 1