前提・実現したいこと
Processingで地球儀を作成しています。
自動で回転する機能を実装中に変な回転になってしまいました。
発生している問題・エラーメッセージ
自動で回転の際におかしな回転をする。
該当のソースコード
java
1 1. import java.awt.*; 2 2. import java.awt.event.*; 3 3. Frame f; 4 4. Button b1; 5 5. int r; 6 6. PShape earth; 7 7. PImage earth_tex; 8 8. float rotx; 9 9. float rotz; 1010. void mouseDragged() { 1111. rotx+=(pmouseY-mouseY)*0.01; 1212. rotz+=(mouseX-pmouseX)*0.01; 1313. } 1414. void setup() { 1515. size(400, 400, P3D); 1616. earth_tex=loadImage("Albedo.jpg"); 1717. noStroke(); 1818. earth=createShape(SPHERE, 100); 1919. earth.setTexture(earth_tex); 2020. f=new Frame(); 2121 f.setSize(200, 100); 2222. f.setLayout(new FlowLayout()); 2323. b1=new Button("rotation"); 2424. f.add(b1); 2525. b1.addActionListener(new ActionListener() { 2626. public void actionPerformed(ActionEvent ae) { 2727. if (b1.getLabel().equals("rotation")) { 2828. b1.setLabel("stop"); 2929. } else { 3030. b1.setLabel("rotation"); 3131. } 3232. } 3333. } 3434. ); 3535. f.setVisible(true); 3636. } 3737. void draw() { 3838. background(0); 3939. translate(width/2, height/2); 4040. if (b1.getLabel().equals("stop")) { 4141. r+=3; 4242. rotateX(radians(r)); 4343. rotateY(radians(r)); 4444. } else { 4545. rotateX(rotx); 4646. rotateZ(rotz); 4747. } 4848. shape(earth); 4949. }
試したこと
42、43行目のroteをうまく回るように数値を変換しました。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。