Processingのサンプルを参考にコードを書いた。(立方体の回転と拡大)
改良点
マウスを右に移動することで、回転速度が増加。"0.02"の値を変えることで、増加の割合を調節できます。
float speed = (mouseX) * 0.02;
マウスを下に移動することで、立方体の辺の長さが増加。"0.002"の値を変えることで、増加の割合を調節できます。
TexturedCube(tex, 1+mouseY * 0.002, 1);
PImage tex; float rotx = PI/4; float roty = PI/4; int value = 0; void setup() { size(809, 500, P3D); tex = loadImage("01.JPG"); textureMode(NORMALIZED); fill(255); stroke(color(44,48,32)); } void draw() { background(#dddddd); noStroke(); translate(width/2.0, height/2.0, -100); rotateX(rotx); rotateY(roty); scale(90); TexturedCube(tex, 1+mouseY * 0.002, 1); autorotate(); } void autorotate() { float rate = 0.01; float speed = (mouseX) * 0.02; rotx += speed * rate; roty += speed * rate;; } void TexturedCube(PImage tex, float i, int type) { beginShape(QUADS); texture(tex); CubeFace c1 = new CubeFace(); if(type == 1){ c1.PZface(i); c1.MZface(i); c1.BYface(i); c1.TYface(i); c1.RXface(i); c1.LXface(i); } else if(type == 2){ c1.PZface(i); c1.BYface(i); c1.RXface(i); } else{ c1.MZface(i); c1.BYface(i); c1.LXface(i); } endShape(); } class CubeFace { void PZface(float i) { vertex(-i, -i, i, 0, 0); vertex( i, -i, i, i, 0); vertex( i, i, i, i, i); vertex(-i, i, i, 0, i); } void MZface(float i) { vertex( i, -i, -i, 0, 0); vertex(-i, -i, -i, i, 0); vertex(-i, i, -i, i, i); vertex( i, i, -i, 0, i); } void BYface(float i) { vertex(-i, i, i, 0, 0); vertex( i, i, i, i, 0); vertex( i, i, -i, i, i); vertex(-i, i, -i, 0, i); } void TYface(float i) { vertex(-i, -i, -i, 0, 0); vertex( i, -i, -i, i, 0); vertex( i, -i, i, i, i); vertex(-i, -i, i, 0, i); } void RXface(float i) { vertex( i, -i, i, 0, 0); vertex( i, -i, -i, i, 0); vertex( i, i, -i, i, i); vertex( i, i, i, 0, i); } void LXface(float i) { vertex(-i, -i, -i, 0, 0); vertex(-i, -i, i, i, 0); vertex(-i, i, i, i, i); vertex(-i, i, -i, 0, i); } }