Illustrates how to display a ball lit by a red light : Sphere Ball « 3D « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » 3D » Sphere BallScreenshots 
Illustrates how to display a ball lit by a red light
Illustrates how to display a ball lit by a red light

/*
The Joy of Java 3D

by Greg Hopkins

Copyright Copyright 2001


*/
/*
Lighting up the World. The way the light falls on an object provides us with the 
shading that helps us see shapes in three dimensions

The next example illustrates how to display a ball lit by a red light:

The sphere we created is white (the default), it appears red because of the colored 
light. Since it is a DirectionalLight, we also have to specify how far the light 
shines and in what direction. In the example, the light shines for 100 meters from 
the origin and the direction is to the right, down and into the screen (this is defined 
by the vector: 4.0 right, -7.0 down, and -12.0 into the screen).

You can also create an AmbientLight which will produce a directionless light, or a 
SpotLight if you want to focus on a particular part of your scene. A combination of a 
strong directional light and a weaker ambient light gives a natural-looking appearance to 
your scene. Java 3D lights do not produce shadows.


*/


import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.DirectionalLight;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;

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

public class Ball {
  public Ball() {
    // Create the universe
    SimpleUniverse universe = new SimpleUniverse();

    // Create a structure to contain objects
    BranchGroup group = new BranchGroup();

    // Create a ball and add it to the group of objects
    Sphere sphere = new Sphere(0.5f);
    group.addChild(sphere);

    // Create a red light that shines for 100m from the origin
    Color3f light1Color = new Color3f(1.8f0.1f0.1f);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.00.00.0),
        100.0);
    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
    DirectionalLight light1 = new DirectionalLight(light1Color,
        light1Direction);
    light1.setInfluencingBounds(bounds);
    group.addChild(light1);

    // look towards the ball
    universe.getViewingPlatform().setNominalViewingTransform();

    // add the group of objects to the Universe
    universe.addBranchGraph(group);
  }

  public static void main(String[] args) {
    new Ball();
  }
}

           
       
Related examples in the same category
1. The scene is of nine spheres and one light sourceThe scene is of nine spheres and one light source
2. Sphere SampleSphere Sample
3. A red sphere using the Sphere utility classA red sphere using the Sphere utility class
4. Appearance Bounds
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.