質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Processing

Processingは、オープンソースプロジェクトによるCGのためのプログラミング言語です。Javaをベースにしており、グラフィック機能に特化しています。イメージの生成やアニメーションなど、視覚的なフィードバックを簡単に得ることが可能です。

Q&A

解決済

1回答

1056閲覧

Processingで円柱曲面の文字向きを変えたい

kakashi55

総合スコア25

Processing

Processingは、オープンソースプロジェクトによるCGのためのプログラミング言語です。Javaをベースにしており、グラフィック機能に特化しています。イメージの生成やアニメーションなど、視覚的なフィードバックを簡単に得ることが可能です。

0グッド

0クリップ

投稿2019/08/15 10:04

編集2019/08/15 12:35

実現したいこと

円柱の曲面に文字や図形を表示したいです。
以下サイトを参考に文字入力を行っていますが、文字を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}

宜しくお願い致します。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

thkana

2019/08/15 12:12

z軸方向に90度、というのがどうなるのかよくわからないので手書きででも図示していただけませんか。
guest

回答1

0

ベストアンサー

createTexture()関数だけ差し替えて

Processing

1PImage createTexture() { 2 PGraphics gout = createGraphics(314, 150); 3 PGraphics g = createGraphics(gout.width, gout.height); 4 g.beginDraw(); 5 g.noStroke(); 6 g.fill(255); 7 g.rect(0, 0, g.width, g.height); 8 9 g.fill(255, 0, 0); 10 g.textSize(64); 11 g.text("Texture", 5, 60); 12 13 g.fill(0, 0, 255); 14 g.textSize(64); 15 g.text("mapping!", 15, 120); 16 17 g.endDraw(); 18 gout.beginDraw(); 19 gout.background(255); 20 gout.imageMode(CENTER); 21 gout.translate(gout.width/2,gout.height/2); 22 gout.rotate(HALF_PI); 23 gout.image(g.get(),0,0,gout.height,gout.width); 24 gout.endDraw(); 25 return gout.get(); 26}

でいかがでしょう。文字の縦横比とかは適宜調節してください。
要は、PGraphicsってのはいわば仮想画面で通常の画面と同じ操作が出来るらしいので、そこに画像を横向きに貼ってやってからget()でPImage分を取得すればいいだろう、ということです。

投稿2019/08/15 12:59

thkana

総合スコア7610

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問