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 & HelpSyntax Questions › Translate object using keyboard
Page Index Toggle Pages: 1
Translate object using keyboard (Read 685 times)
Translate object using keyboard
Dec 4th, 2009, 7:43am
 
Using saito obj loader, I made an object called 'shuttle'.

Code:
import processing.opengl.*;
import javax.media.opengl.*;

OBJModel model;

class Shuttle
{
 Shuttle(PApplet app, String name)
 {
   model = new OBJModel(app, name);
 }

 void drawShuttle(GL gl)
 {
   pushMatrix();
   translate(2016, 2016, 1200);
   scale(50);
   model.drawMode(POLYGON);
   model.draw();
   popMatrix();
 }
}


In the main draw function:

Code:
  GL gl = pgl.beginGL();
 cameraControl(gl);
 shuttle.drawShuttle(gl);
 pgl.endGL();


Using the camera() function I move the camera around.

Code:
  if (keyPressed)
 {
   if ( key == 'w' )
     camY -= cameraSpeed;        
   if ( key == 's' )
     camY += cameraSpeed;        
   if ( key == 'a' )
     camX -= cameraSpeed;
   if ( key == 'd' )
     camX += cameraSpeed;
   if ( key == 'q' )
     camZ -= cameraSpeed*2.5;
   if ( key == 'e' )
     camZ += cameraSpeed*2.5;
 }


The problem is that when I move the camera around, the object moves in the opposite direction of the camera. I have also drawn a box() which doesn't move. And if I zoom out far enough the object moves behind the box.

Why?
Re: Translate object using keyboard
Reply #1 - Dec 5th, 2009, 6:04am
 
Just a guess... but isn't it normal that if you move your camera to the left, your object appears to be moving to the right...
Page Index Toggle Pages: 1