Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## sim.portrayal3d.simple
Class LightPortrayal3D

    java.lang.Object
      sim.portrayal3d.SimplePortrayal3D
          sim.portrayal3d.simple.LightPortrayal3D

All Implemented Interfaces:
  Portrayal, Portrayal3D, java.io.Serializable

public class LightPortrayal3D
extends SimplePortrayal3D

A simple Portrayal3D which provides ambient, directional, or point light to the scene. While this could be used in a FieldPortrayal to represent its objects, it's more likely to be dropped directly into the Display3D itself. Your light can be any color, and it will have infinite bounds -- it irradiates everything regardless of where it is -- meaning there's no such thing as a shadow. LightPortrayals aren't selectable: how can you catch a moonbeam in your hand?

- Ambient Light is light which seems to come from all around and has no direct source.
- Directional Light comes from a point light source located infinitely far away. Thus there is a direction in which the light is shining. The classic example: sunlight.
- Point Light comes from a point light source located at a finite position (like a light bulb). If you place a point light source in a field portrayal, the position you'd specified here will get scaled and translated just like any other object. Point light also has an attenuation -- a degree to which its strength drops off. The attenuation is calculated as an equation on the distance d that the object is from the light source: q^2 * d + l * d + c, where q is the quadratic attenuation, l is the linear attenuation and c is the constant attenuation. A good default is c=1,l=0,q=0.

In fact, the default objects provided in the simulator (such as SpherePortrayal3D) don't respond to light at all -- they just display themselves with their given color as if there were a magical light source. To get them to respond in a different fashion, you'll need to provide them with a different Appearance object, and set that Appearance's ColoringAttributes and Material. Here's an example which makes a green sphere that's harshly lit only on the side where it receives light, else it's jet black. ``

        import javax.media.j3d.*;
        import javax.vecmath.*;

        Color3f color = new Color3f(java.awt.Color.green);
        Appearance appearance = new Appearance();
        appearance.setColoringAttributes(
        new ColoringAttributes(color, ColoringAttributes.SHADE_GOURAUD));
        Material m= new Material();
        m.setAmbientColor(color);
        m.setEmissiveColor(0f,0f,0f);
        m.setDiffuseColor(color);
        m.setSpecularColor(1f,1f,1f);
        m.setShininess(128f);
        appearance.setMaterial(m);

        SpherePortrayal3D sphere = new SpherePortrayal3D(appearance, 1.0f);

See Also:
  Serialized Form

Field Summary
`javax.media.j3d.Light` | `light`

Fields inherited from class sim.portrayal3d.SimplePortrayal3D
`DEFAULT_APPEARANCE, parentPortrayal`

Constructor Summary
`LightPortrayal3D(java.awt.Color color)` Ambient Light
`LightPortrayal3D(java.awt.Color color, Double3D direction)` Directional Light
`LightPortrayal3D(java.awt.Color color, Double3D position, float constantAttenuation, float linearAttenuation, float quadraticAttenuation)` Point Light.
`LightPortrayal3D(javax.media.j3d.Light light)` Provide your own Light!

Method Summary
`javax.media.j3d.TransformGroup` | `getModel(java.lang.Object obj, javax.media.j3d.TransformGroup j3dModel)` Provides a TransformGroup which defines the node(s) to place in the scenegraph.

Methods inherited from class sim.portrayal3d.SimplePortrayal3D
`appearanceForColor, appearanceForImage, clearPickableFlags, getInspector, getName, polygonAttributes, setParentPortrayal, setPickableFlags, setPickableFlags, setSelected`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### light

    public javax.media.j3d.Light light

Constructor Detail

### LightPortrayal3D

    public LightPortrayal3D(java.awt.Color color,
                            Double3D direction)

  Directional Light

### LightPortrayal3D

    public LightPortrayal3D(java.awt.Color color)

  Ambient Light

### LightPortrayal3D

    public LightPortrayal3D(java.awt.Color color,
                            Double3D position,
                            float constantAttenuation,
                            float linearAttenuation,
                            float quadraticAttenuation)

  Point Light. If you don't know what to provide for attenutation, you can't go wrong with 1,0,0.

### LightPortrayal3D

    public LightPortrayal3D(javax.media.j3d.Light light)

  Provide your own Light!

Method Detail

### getModel

    public javax.media.j3d.TransformGroup getModel(java.lang.Object obj,
                                                   javax.media.j3d.TransformGroup j3dModel)

  Description copied from interface: `Portrayal3D`
  Provides a TransformGroup which defines the node(s) to place in the scenegraph. This is the Portrayal3D equivalent of Portrayal2D's draw(object, graphics, drawinfo) method.

  You should hang your model off of the TransformGroup provided. You should not transform that TransformGroup in any way -- it is used elsewhere. Instead if you wish to transform your model (rotate it etc.) you should add your own additional TransformGroup as necessary.

  The provided TransformGroup can be null; in this case you need to create and return the outer TransformGroup for the object. If the provided TransformGroup is non-null, you should modify it and return the same.

  SimplePortrayals should assume the following contract: at the point that getModel(...) is called, the parentPortrayal will have already been set if it exists, else it will be null.

  Specified by:
    `getModel` in interface `Portrayal3D`
  Overrides:
    `getModel` in class `SimplePortrayal3D`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD