実現したいこと
円柱の曲面に文字や図形を表示したいです。
以下サイトを参考に文字入力を行っていますが、文字をz軸方向に90度回転させて表示したいです。
https://teratail.com/questions/114591
JAVA
1import processing.opengl.*; 2 3float rotation = 0; //*** 4PImage texture; //*** 5 6void setup() { 7 size(400, 400, OPENGL); 8 9 texture = createTexture(); //*** 10} 11 12PImage createTexture() { 13 PImage img = createImage(314, 150, RGB); 14 PGraphics g = createGraphics(img.width, img.height); 15 g.beginDraw(); 16 g.noStroke(); 17 g.fill(255); 18 g.rect(0, 0, g.width, g.height); 19 20 g.fill(255, 0, 0); 21 g.textSize(64); 22 g.text("Texture", 5, 60); 23 24 g.fill(0, 0, 255); 25 g.textSize(64); 26 g.text("mapping!", 15, 120); 27 28 g.endDraw(); 29 img.pixels = g.pixels; 30 return img; 31} 32 33void draw() { 34 rotation += 1; //*** 35 noStroke(); 36 directionalLight(255, 255, 255, 1, 1, -1); 37 background(0); 38 translate(width / 2, height / 2); 39 40 pillar(150, 50 , 50); //円柱の作成(長さ,上面の半径,底面の半径) 41} 42 43void pillar(float length, float radius1, float radius2) { 44 float x, y, z; 45 float tx, ty; //*** 46 47 //pushMatrix(); //***不要 48 49 //上面の作成 50 beginShape(TRIANGLE_FAN); 51 y = -length / 2; 52 vertex(0, y, 0); 53 for(int deg = 0; deg <= 360; deg = deg + 10){ 54 x = cos(radians(deg)) * radius1; 55 z = sin(radians(deg)) * radius1; 56 vertex(x, y, z); 57 } 58 endShape(); 59 60 //底面の作成 61 beginShape(TRIANGLE_FAN); 62 y = length / 2; 63 vertex(0, y, 0); 64 for(int deg = 0; deg <= 360; deg = deg + 10){ 65 x = cos(radians(deg)) * radius2; 66 z = sin(radians(deg)) * radius2; 67 vertex(x, y, z); 68 } 69 endShape(); 70 71 //側面の作成 72 beginShape(TRIANGLE_STRIP); 73 texture(texture); //*** 74 for(int deg =0; deg <= 360; deg += 5){ 75 float radian = radians(-deg + rotation); //*** 76 float cos = cos(radian); //*** 77 float sin = sin(radian); //*** 78 x = cos * radius1; //*** 79 y = -length / 2; 80 z = sin * radius1; //*** 81 tx = texture.width * deg / 360; //*** 82 ty = 0; //*** 83 vertex(x, y, z, tx, ty); //*** 84 x = cos * radius2; //*** 85 y = length / 2; 86 z = sin * radius2; //*** 87 ty = texture.height; //*** 88 vertex(x, y, z, tx, ty); //*** 89 } 90 endShape(); 91 92 //popMatrix(); //***不要 93}
宜しくお願い致します。
z軸方向に90度、というのがどうなるのかよくわからないので手書きででも図示していただけませんか。
回答1件
あなたの回答
tips
プレビュー