光演示 : 光 « 三维图形动画 « Java

En
Java
1. 图形用户界面
2. 三维图形动画
3. 高级图形
4. 蚂蚁编译
5. Apache类库
6. 统计图
7. 
8. 集合数据结构
9. 数据类型
10. 数据库JDBC
11. 设计模式
12. 开发相关类
13. EJB3
14. 电子邮件
15. 事件
16. 文件输入输出
17. 游戏
18. 泛型
19. GWT
20. Hibernate
21. 本地化
22. J2EE平台
23. 基于J2ME
24. JDK-6
25. JNDI的LDAP
26. JPA
27. JSP技术
28. JSTL
29. 语言基础知识
30. 网络协议
31. PDF格式RTF格式
32. 映射
33. 常规表达式
34. 脚本
35. 安全
36. Servlets
37. Spring
38. Swing组件
39. 图形用户界面
40. SWT-JFace-Eclipse
41. 线程
42. 应用程序
43. Velocity
44. Web服务SOA
45. 可扩展标记语言
Java 教程
Java » 三维图形动画 » 屏幕截图 
光演示
光演示

// From: http://www.micg.et.fh-stralsund.de/Java3D/java3D.htm#Bild1


import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;

import javax.media.j3d.AmbientLight;
import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Material;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;

import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class Licht extends Applet {

  /**
   * init Methoden fur die Darstellung als Applet
   */
  public void init() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse
        .getPreferredConfiguration();
    canvas3D = new Canvas3D(config);
    add("Center", canvas3D);
    BranchGroup szene = macheSzene();
    szene.compile();
    universe = new SimpleUniverse(canvas3D);
    universe.getViewingPlatform().setNominalViewingTransform();
    universe.addBranchGraph(szene);
  }

  /**
   * Erstellt den Szenegraphen
   
   @return BranchGroup
   */
  public BranchGroup macheSzene() {
    BranchGroup objWurzel = new BranchGroup();
    // Transformation, 2 Rotationen:
    Transform3D drehung = new Transform3D();
    Transform3D drehung2 = new Transform3D();
    drehung.rotX(Math.PI / 4.0d);
    drehung2.rotY(Math.PI / 5.0d);
    drehung.mul(drehung2);
    TransformGroup objDreh = new TransformGroup(drehung);

    Sphere kugel = new Sphere(0.5f, Sphere.GENERATE_NORMALS, 50,
        makeAppearance());
    objWurzel.addChild(kugel);
    objWurzel.addChild(objDreh);

    //directes Licht
    DirectionalLight d_Licht = new DirectionalLight();
    d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d0.0d,
        0.0d), Double.MAX_VALUE));
    d_Licht.setColor(new Color3f(1.0f0.0f0.0f));
    Vector3f dir = new Vector3f(1.0f2.0f, -1.0f);
    dir.normalize();
    d_Licht.setDirection(dir);
    objWurzel.addChild(d_Licht);

    // ambient Licht
    AmbientLight a_licht = new AmbientLight();
    a_licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0f0.0f,
        0.0f), Double.MAX_VALUE));
    a_licht.setColor(new Color3f(1.0f0.0f0.0f));
    objWurzel.addChild(a_licht);

    return objWurzel;
  }

  /**
   * Wurfeldarstellung
   
   @return Appearance
   */
  private Appearance makeAppearance() {
    Appearance a = new Appearance();
    Material mat = new Material();
    mat.setShininess(50.0f);
    mat.setDiffuseColor(new Color3f(1.0f0.0f0.0f));
    mat.setSpecularColor(new Color3f(0.0f0.0f0.0f));
    a.setMaterial(mat);
    return a;
  }

  /**
   * gibt speicher frei
   */
  public void destroy() {
    universe.removeAllLocales();
  }

  public static void main(String[] args) {
    frame = new MainFrame(new Licht()500500);
    frame.setTitle("Licht");
  }

  //---- Attribute -----------------------
  private SimpleUniverse universe;

  private Canvas3D canvas3D;

  private static Frame frame;
}

           
       
Related examples in the same category
1. 创建一个环境光线和一个定向光创建一个环境光线和一个定向光
2. This builds a red sphere using the Sphere utility class and adds lightsThis builds a red sphere using the Sphere utility class and adds lights
3. ExDirectionalLight -说明使用方向灯ExDirectionalLight -说明使用方向灯
4. ExAmbientLight -说明使用环境灯ExAmbientLight -说明使用环境灯
5. ExPointLight -说明使用指向灯ExPointLight -说明使用指向灯
6. ExLightScope -说明使用光范围ExLightScope -说明使用光范围
7. Illustrate use of light influencing bounds, and bounding leaves Illustrate use of light influencing bounds, and bounding leaves
8. ExSpotLight -说明使用射灯ExSpotLight -说明使用射灯
9. AmbientLight, DirectionalLight, PointLight and SpotLightAmbientLight, DirectionalLight, PointLight and SpotLight
10. 照明平面照明平面
11. 聚光灯聚光灯
12. LightScopeApp creates a scene that is paritally lightLightScopeApp creates a scene that is paritally light
13. 光查看光查看
14. 轻缺陷轻缺陷
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.