Hi everyone!
I am expierencing difficulties when I try to let my wonderfull rocket be controlled by altering the pitch and the yaw. But because the rocket experiences gravity, I dont think I can use rotate(). Please correct me if im wrong on that. I have searched a while for the answer, but never found it... so can anyone help? im posting one tab, and a link to the whole package ;)
Link:
htt p://ww w.fileshost.com/download.php?id=CA159A091
klik on the mouse to let it explode, a and d control the roll and z and x change the x direction of the speed
sorry, can't post an proper url because im new (A)
This is the main part of the code:
Code:import processing.opengl.*;
float frames = 120;
PVector rocket, engine, speed;
float friction = 0.99;
float power = 30/frames;
float gravity = 9.81/frames;
float roll = 0;
float pitch = 0;
float yaw = 0;
void setup() {
size(800,900, OPENGL);
noStroke();
rocket = new PVector(0.5*width,height+300,0);
speed = new PVector(-0.01,1,0.000);
camera(0.5*width,0.5*height,2000,0.5*width,0.5*height,0,0,1,0);
}
void keyPressed() {
if(key=='a')
{
roll+=TWO_PI/20;
}
if(key=='d')
{
roll-=TWO_PI/20;
}
if(key=='x')
{
speed.x+=1;
}
if(key=='z')
{
speed.x-=1;
}
}
void draw() {
background(10); // top-left = -630,-702 top-right = width+630,-702 bottom-left = -630,height+702 bottom-right = width+630,height+702
fill(255);
lights();
if(explosion == 1)
{
explode();
}
if(fadeout<=0)
{
explosion = 1;
}
if(explosion == 0)
{
rocket.y = height-rocket.y;
speed.mult(power/speed.mag()+1);
speed.y-=gravity;
speed.mult(friction);
rocket.add(speed);
rocket.x = ((rocket.x+630)%(width+1260))-630;
if(rocket.x<-630)
{
rocket.x = width+630;
}
rocket.y = ((rocket.y+702)%(height+1404))-702;
if(rocket.y<-702)
{
rocket.y = height+702;
}
rocket.y = height-rocket.y;
pushMatrix();
drawrocket();
popMatrix();
}
smoke();
}