質問
使い方を学んでいます 処理, 、例の 1 つを変更して作成しました このアプレット. 。質問が 2 つあります。
- なぜ球体は扁円形なのでしょうか?私が作成したサンプルの球体は、丸くて素敵でした。
- 点光源が球の間にあるのに、球の外側のエッジにライトが表示されるのはなぜですか?
この小さなプログラムのソースは次のとおりです。
int radius = 40;
int spheredist = 320;
int maxlevel = 7;
float ecc = 0.28;
int x1, x2, y1, y2;
void setup() {
size(640, 360, P3D);
fill(204);
//smooth(); // makes spheres ugly
translate(width/2, height/2, 0);
x1 = -spheredist/2+radius;
x2 = spheredist/2-radius;
y1 =
y2 = 0;
}
void drawLightning(int x1_,int y1_,int x2_,int y2_,int lvl){
if (lvl < maxlevel){
int midx = (x1_ + x2_)/2;
int midy = (y1_ + y2_)/2;
float d = dist(x1_, y1_, x2_, y2_);
d *= ecc;
midx += random(-d, d);
midy += random(-d, d);
drawLightning(x1_, y1_, midx, midy, lvl+1);
drawLightning(midx, midy, x2_, y2_, lvl+1);
} else {
strokeWeight(10);
stroke(60,100,255,100);
line(x1_,y1_,x2_,y2_);
strokeWeight(1);
stroke(255);
line(x1_,y1_,x2_,y2_);
}
}
void draw() {
background(0);
noStroke();
int brt = 200;
pointLight(brt/2, brt/2, brt/2, spheredist/2, -spheredist, spheredist);
ambientLight(brt/8,brt/8,brt/8);
if ((mouseX > width/4 && mouseX < width*3/4) &&
(mouseY > height/2-radius && mouseY < height/2+radius)) {
pushMatrix();
translate(width/2, height/2, 0);
pointLight(100, 100, 255, 0, 0, 0);
popMatrix();
}
pushMatrix();
translate(width/2 - spheredist/2, height/2, 0);
sphere(radius);
translate(spheredist, 0, 0);
sphere(radius);
popMatrix();
if ((mouseX > width/4 && mouseX < width*3/4) &&
(mouseY > height/2-radius && mouseY < height/2+radius)) {
pushMatrix();
translate(width/2, height/2, 0);
drawLightning(x1,y1,x2,y2,0);
popMatrix();
}
}
解決
あなたはポリゴンを突き当ててしまったので、
円滑な機能は、この場合にはうまく機能しません。それは絵なしで従うことを少しトリッキーですが、2つのポリゴン間のエッジにあるピクセルを考えます。例えば、(0,0,0)のバックグラウンドがあるとしましょうとポリゴンが(255,255,255)です。最初のポリゴンが描画し、そのピクセルに当たります。それの半分を覆っているので、0.5 *(0,0,0)+ 0.5 *(255,255,255)を計算し、その画素の新しい値として(126126126)保存します。第二のポリゴンを描画します。それは0.5 *(126126126)+ 0.5 *(255,255,255)を計算し、(190190190)保存して、それはまた、ピクセルの半分を覆っています。 2つのポリゴンがそれぞれ異なる半分をカバーし、(255,255,255)の色が生じていなければならないので、これは正しくありません。あなたが個別に各ポリゴンを描画し、その間の任意のカバレッジ情報を保存しない場合しかし、あなたはそれを把握することはできません。
他のヒント
素敵なラウンドエッジについて、)(あなたの設定でスムーズな方法を()を呼び出してみます:
void setup() {
// ...
smooth();
// ...
}
所属していません StackOverflow