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 › A difficult 3D problem (for me anyway)
Page Index Toggle Pages: 1
A difficult 3D problem (for me anyway) (Read 635 times)
A difficult 3D problem (for me anyway)
Feb 28th, 2006, 7:03pm
 
Hi Ive made a program that allows you to move a cube around the screen + and - control the speed of the cude and the left and right keys control its direction.

i wish to extend this program to work in 3D (IE you will be able to turn the cube along the Z axis and have it move either towards or away from you)

I have absolutley no idea on how to do this.
any able to give me some code examples?

heres the code for the 2D movement

import processing.opengl.*;

float radius;
float angle;
float speed;
float rotation;
float y;
float x;
float xpos;
float ypos;


void setup ()
{
 size(1280,1024,OPENGL);
 radius = 40;
 angle = 180;
 speed = 0.5;
 rotation = radians(0);
 y =0;
 x =0;
 xpos = 0;
 ypos =0;
 speed  = 0;
}  
void draw ()
{
 lights();
 background(255);
 translate(width/2,height/2,0);
 scale(.5);
 
 if(keyPressed)
 {
   if(keyCode == LEFT)
   {
     angle = angle + .2;
     movement();
     
   }
   if(keyCode == RIGHT)
   {
     angle = angle - .2;
     movement();
   
   }
   if(key == '=')
   {
       speed = speed + 0.01;
       movement();
   }
   if(key == '-')
   {
       speed = speed - 0.01;
       movement();
   }
   if(key == 'z')
  {    
       
       firePhaser();
       movement();
   }
  }
  else
  {
     movement();
  }
 
  translate(x,y,0);
  fill(255,0,255);
  rotate(-angle/57.5);  
  box(60);
   
 
}
void movement()
{
   x = x + xpos;
   y = y + ypos;
   xpos = sin(radians(angle))*speed;
   ypos = cos(radians(angle))*speed;
}
Page Index Toggle Pages: 1