SimpleUniverse와 Built-in Geometry class인 sphere를 이용하여 sphere 그리는 프로그램.
import ...
public class Basic extends Applets{
public Test2{
SimpleUniverse u=new SimpleUniverse(); // SimpleUniverse 인스턴스
BranchGroup Root=new BranchGroup(); // Root branch group
// Sphere를 만들고, 색 선정 후, BranchGroup 에 추가한다.
Appearance ap=new Appearance();
Color3f=new Color3f(1.0f,0.0f,0.0f);
ColoringAttributes at=new ColoringAttributes(color,ColoringAttributes.shape_flat);
ap.setColoringAttributes(at);
Sphere sp=new Sphere(0.1f,ap);
// 만들어진 sphere를 Branchgroup Root에 연결
Root.addChild(sp);
// Root를 simpleuniverse에 연결
u.addBranchGraph(Root);
// Viewer조절
u.getViewingPlatfrom().setNominalViewingTransform();
}
public static void main(String[] args){
//Applet 스타트
Basic b=new Basic();
}
}
색 지정의 우선순위
- Shape3D나 도형 primitive class(Box, Cone, Sphere, etc) 들은 Appearance 와 Material 클래스가 외형을 정의한다.
- 색 지정의 경우, 두 클래스 모두에서 가능하나, Material 클래스가 우선이다. 따라서 Material class에서 이미 색 지정이 되어 있다면, Appearance 클래서의 색 지정은 무시된다.
Java3d API for Material class
Exam
- Appearance ap=new Appearance();
- Color3f red , black, white, green ...
- Material m=new Material(red,black,white,green,80.0f);
- ap.setMaterial(m);
'JAVA' 카테고리의 다른 글
Java3d와 스윙 for layout, 문제와 해결 (0) | 2007.07.16 |
---|---|
Scene 그래프 갱신 (0) | 2007.07.16 |
기본 동영상 재생 소스 (0) | 2007.06.05 |
mp3 player 오픈프로젝트 "jlGui" (1) | 2007.05.18 |
Controller의 6개 상태 (0) | 2007.05.18 |