理論根據:
假設一個光的方向是(
一個是直線方程
而且平面方程還比較特殊
簡化後就簡單了
x
v
平面方程 y =
帶入就得到了
x = vertex
z = vertex
源程序:
import java
import java
import java
import java
import com
import com
import com
import dia
import javax
public class SimpleShadow extends Applet{
//三角平面類
public class TriPlane extends Shape
TriPlane(Point
this
this
}
//建立三角平面
Geometry createGeometry
TriangleArray plane=new TriangleArray(
//設置平面
plane
plane
plane
//計算平面法向量
Vector
Vector
Vector
n
//法向量單位化
n
//設置平面
plane
plane
plane
return plane;
}
//創建Material不為空的外觀
Appearance createAppearance(){
Appearance appear=new Appearance();
Material material=new Material();
appear
return appear;
}
}
//四邊平面類
public class QuadPlane extends Shape
QuadPlane(Point
this
this
}
//創建四邊性平面
Geometry createGeometry
QuadArray plane=new QuadArray(
//設置平面
plane
plane
plane
plane
//計算平面法向量
Vector
Vector
Vector
n
//法向量單位化
n
//設置平面
plane
plane
plane
plane
return plane;
}
//創建Material不為空的外觀
Appearance createAppearance(){
Appearance appear=new Appearance();
Material material=new Material();
appear
return appear;
}
}
//陰影類
public class Shadow
Shadow
int vCount=geom
TriangleArray poly=new TriangleArray(vCount
int v;
Point
Point
for(v=
//計算可見面頂點在投影面上的投影坐標
geom
System
shadow
poly
poly
}
this
}
}
public SimpleShadow(){
this
//GraphicsConfiguration config =SimpleUniverse
Canvas
this
//創建分支節點
BranchGroup scene=new BranchGroup();
//創建三角形可見平面
Shape
//添加到根分支節點
scene
//創建四邊形投影平面
Shape
//添加到根分支節點
scene
//添加到環境光
AmbientLight lightA=new AmbientLight();
lightA
scene
//添加平行光
DirectionalLight lightD
lightD
Vector
//方向矢量單位化
direction
lightD
scene
//創建陰影物體
Shape
scene
SimpleUniverse u=new SimpleUniverse(c);
u
u
}
public static void main(String argv[]){
new MainFrame(new SimpleShadow()
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26962.html