// Processingのウインドウにぴったり収まるポリゴンを配置してみるテスト // BG表示に使いたい /* @pjs preload="tex.png"; */ PImage img; float fov; float scz; void setup() { size(640, 480, P3D); img = loadImage("tex.png"); fov = PI / 3.0; // π = 180度。ソレを3で割ってるから、60度のはず。 scz = (height / 2.0) / tan(fov / 2.0); // 画面までの距離 println("scz = " + str(scz)); // パース変更 // perspective(視野角(ラジアン), 画面比率, 近い面までの距離, 遠い面までの距離); perspective(fov, float(width) / float(height), 1, 6000); noStroke(); } void draw() { background(128); pushMatrix(); translate(width/2, height/2); // カメラの位置と方向を設定 camera(0, 0, 0, // カメラ位置 0, 0, -scz, // 注視点位置 0, 1, 0); // どちらが上か float dist = 5000; // 背景ポリゴンまでの距離 //float hh = (dist + scz) * tan(fov / 2.0); float hh = dist * tan(fov / 2.0); // ポリゴン上半分の縦幅 float y0 = -hh; float y1 = hh; float wm = float(width) / float(height); // 画面比率 float x0 = -hh * wm; float x1 = hh * wm; //float z0 = -dist; float z0 = -dist; // テクスチャUV float t0 = 0; float t1 = 256; // テクスチャを貼ったポリゴンを描画 beginShape(QUADS); texture(img); vertex(x0, y0, z0, t0, t0); vertex(x1, y0, z0, t1, t0); vertex(x1, y1, z0, t1, t1); vertex(x0, y1, z0, t0, t1); endShape(); popMatrix(); }