2017-06-08 7 views
0

したがって、PVector値を使用して複数の図形を同じ方向に移動しようとしています。私が直面している問題は、オブジェクトを私は(この場合はフライの原型のイラスト)にするために、オブジェクトを回転させる必要があるということです。そうすると、ベクトル演算がオブジェクトの回転方向に追加されます。各形状の角速度を正規化するために使用できる関数か数学はありますか?ここで処理:同じ方向に複数の図形を移動する

class tFly{ 

boolean count=false; 
boolean countTwo=false; 
boolean move=false; 
PVector location; 
PVector velocity; 




    tFly(){ 
    location= new PVector(0,0); 
    velocity = new PVector(1,1); 
    } 
void flap(){//flap wings if moving, else keep them still 

    if(move==false){ 
    pushMatrix(); //wings 
noStroke(); 

translate(235,285); 
rotate(radians(25)); 
ellipse(location.x,location.y,25,50); 

popMatrix(); 


pushMatrix(); //wings 
noStroke(); 

translate(263,285); 
rotate(radians(340)); 
ellipse(location.x,location.y,25,50); 


popMatrix(); 


    }else{ 
pushMatrix(); //wings 
noStroke(); 
translate(235,285); 
if(count==false){ 
rotate(radians(49)); 
ellipse(location.x,location.y,25,50); 
count=true; 
}else{ 
rotate(radians(21)); 
ellipse(location.x,location.y,25,50); 
count=false; 
} 

popMatrix(); 


pushMatrix(); //wings 
noStroke(); 
translate(263,285); 
if(countTwo==false){ 
rotate(radians(320)); 
ellipse(location.x,location.y,25,50); 
countTwo=true; 
}else{ 
rotate(radians(340)); 
ellipse(location.x,location.y,25,50); 
countTwo=false; 
} 

popMatrix(); 
} 
} 
void display(){ 
    fill(0); 
ellipse(location.x+250,location.y+265,20,50); 

ellipse(location.x+250,location.y+280,25,34); 
pushMatrix(); 

translate(240,230); 
rotate(radians(70)); 
rect(location.x,location.y,15,.5); 
popMatrix(); 

pushMatrix(); 
translate(262,232); 
rotate(radians(110)); 
rect(location.x,location.y,15,.5); 
popMatrix(); 


pushMatrix(); 
translate(230,260); 
rotate(radians(40)); 
rect(location.x,location.y,15,.5); 
popMatrix(); 

pushMatrix(); 
translate(270,262); 
rotate(radians(140)); 
rect(location.x,location.y,15,.5); 
popMatrix(); 

pushMatrix(); 
translate(240,285); 
rotate(radians(120)); 
rect(location.x,location.y,15,.5); 
popMatrix(); 

pushMatrix(); 
translate(260,285); 
rotate(radians(50)); 
rect(location.x,location.y,15,.5); 
popMatrix(); 

fill(255,0,0); 

ellipse(location.x+240,location.y+250,20,18); 
ellipse(location.x+260,location.y+250,20,18); 
fill(128,128,128,127); 

flap(); 

} 
void update(){ 
location.add(velocity); 

} 

} 

私はすでに、なぜないの巣の別々の内display()からすべての描画呼び出し... pushMatrix()/popMatrix()のこつを取得している設定で、これを使用して

tFly fly; 


void setup(){ 
size(500,500); 
background(255); 
fly=new tFly(); 
} 

void draw(){ 
background(255); 
    ellipseMode(CENTER); 

fly.display(); 
fly.update(); 

} 
+0

スケッチ全体から切り離されたスニペットの代わりに[mcve]を投稿できますか? 2つのハードコードされた形状からなる単純な例で十分である。 –

+0

質問は実際にプログラミング上の問題ではなく、使用する数学のように思われるので、この質問を議論の対象外とすることにしました。プログラミング上の問題は、(既知の)数学を実装する方法であり、数学ではありません。 – Makyen

答えて

1

を描く方法ですpushMatrix()/popMatrix()を呼び出すと、そのグループ全体を簡単に翻訳できますか?

class tFly { 

    boolean count=false; 
    boolean countTwo=false; 
    boolean move=true; 
    PVector location; 
    PVector velocity; 




    tFly() { 
    location= new PVector(0, 0); 
    velocity = new PVector(1, 1); 
    } 
    void flap() {//flap wings if moving, else keep them still 

    if (move==false) { 
     pushMatrix(); //wings 
     noStroke(); 

     translate(235, 285); 
     rotate(radians(25)); 
     ellipse(0, 0, 25, 50); 

     popMatrix(); 


     pushMatrix(); //wings 
     noStroke(); 

     translate(263, 285); 
     rotate(radians(340)); 
     ellipse(0, 0, 25, 50); 


     popMatrix(); 
    } else { 
     pushMatrix(); //wings 
     noStroke(); 
     translate(235,285); 
     if (count==false) { 
     rotate(radians(49)); 
     ellipse(0, 0, 25, 50); 
     count=true; 
     } else { 
     rotate(radians(21)); 
     ellipse(0, 0, 25, 50); 
     count=false; 
     } 

     popMatrix(); 


     pushMatrix(); //wings 
     noStroke(); 
     translate(263, 285); 
     if (countTwo==false) { 
     rotate(radians(320)); 
     ellipse(0, 0, 25, 50); 
     countTwo=true; 
     } else { 
     rotate(radians(340)); 
     ellipse(0, 0, 25, 50); 
     countTwo=false; 
     } 

     popMatrix(); 
    } 
    } 
    void display() { 
    pushMatrix(); 
    translate(location.x, location.y); 

    fill(0); 
    ellipse(250, 265, 20, 50); 

    ellipse(250, 280, 25, 34); 
    pushMatrix(); 

    translate(240, 230); 
    rotate(radians(70)); 
    rect(0, 0, 15, .5); 
    popMatrix(); 

    pushMatrix(); 
    translate(262, 232); 
    rotate(radians(110)); 
    rect(0, 0, 15, .5); 
    popMatrix(); 


    pushMatrix(); 
    translate(230, 260); 
    rotate(radians(40)); 
    rect(0, 0, 15, .5); 
    popMatrix(); 

    pushMatrix(); 
    translate(270, 262); 
    rotate(radians(140)); 
    rect(0, 0, 15, .5); 
    popMatrix(); 

    pushMatrix(); 
    translate(240, 285); 
    rotate(radians(120)); 
    rect(0, 0, 15, .5); 
    popMatrix(); 

    pushMatrix(); 
    translate(260, 285); 
    rotate(radians(50)); 
    rect(0, 0, 15, .5); 
    popMatrix(); 

    fill(255, 0, 0); 

    ellipse(240, 250, 20, 18); 
    ellipse(260, 250, 20, 18); 
    fill(128, 128, 128, 127); 

    flap(); 

    popMatrix(); 
    } 
    void update() { 
    location.add(velocity); 
    } 
} 


tFly fly; 


void setup() { 
    size(500, 500); 
    background(255); 
    fly=new tFly(); 
} 

void draw() { 
    background(255); 
    ellipseMode(CENTER); 

    fly.display(); 
    fly.update(); 
} 
関連する問題