マウスを左右に移動させると画面を左右にスライドさせる。
動画ではスペースキー押下とマウスを組み合わせているけどProcessingではキー入力中はマウスが動かなかったのでスペースキーの押下でフラグを切り替えることにした。
あと、pushMatrix()とpopMatrix()を書いてても書いてなくても動作に変化はなかったのでその辺のサンプルとしては意味が無い・・・。
package episode017
import processing.core.PApplet
class DisplayTest extends PApplet {
def translation_x =0
def moveEnabled = false
def void setup() {
size(640, 480, P3D)
frameRate(60)
// 正射影投影法
ortho()
}
def void draw() {
background(0, 0, 0)
pushMatrix()
if (moveEnabled) translation_x += mouseX - pmouseX
translate(translation_x, 0, 0)
stroke(255, 255, 255)
fill(255, 255, 255)
rect(400, 300, 50, 50)
line(100, 100, 200, 200)
popMatrix()
}
def void keyTyped() {
if (key == ' ') {
moveEnabled = !moveEnabled
}
}
def static void main(args) {
PApplet.main('episode017.DisplayTest')
}
}