Ben,
I send you a code with an animated sphere under 3 different lights (ambient, point, directional).
You can go in the code and switch each light on and off if you want.
You should read j3d tutorials and chapter 6 about lights anyway..
JR

Ben Logan wrote:
Hello, I wonder if someone could take the time to write a simple
lighting example for me, just to help me get my head around how to
program lights.
For example; a simple (ceiling) light on the roof of a 1,1,1 cube,
shining down and lighting the contents of the box (but nothing else) -
so it shouldn't breach the walls in anyway. Of all the books I have on
Java3D this simple example is all I need to help get me started, but I
cant find example code anywhere!
Any help would be much appreciated

Regards
Ben

********************************************
Ben Logan - Graduate Software Engineer
RCID
Stephenson Building
Newcastle Upon Tyne
NE1 7RU
www.rcid.ncl.ac.uk
********************************************

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".


  

--
D'Amore Jean-Robert
IT Systems
Bell Geospace Ltd.
Unit 5A, Crombie Lodge
Aberdeen A.S.T.P
Balgownie Drive
Aberdeen AB228GU

Tel: +44(0)1224227703
Email: [EMAIL PROTECTED]

=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.Sphere;
import javax.media.j3d.*;
import javax.vecmath.*;
import javax.media.j3d.SpotLight;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.PointLight;
import javax.media.j3d.Appearance;
import javax.media.j3d.Material;
import com.sun.j3d.utils.behaviors.mouse.MouseBehavior;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;


//   CubeLight renders a single, rotating sphere, under light.

public class LightSphere extends Applet {

    public LightSphere() {

        setLayout(new BorderLayout());
        GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
        Canvas3D canvas3D = new Canvas3D(config);
        add("Center", canvas3D);
        BranchGroup scene = createSceneGraph();
        SimpleUniverse simpleU = new SimpleUniverse(canvas3D);   // SimpleUniverse is 
a Convenience Utility class
        simpleU.getViewingPlatform().setNominalViewingTransform();      // This will 
move the ViewPlatform back a bit so the
                                                                        // objects in 
the scene can be viewed.
        simpleU.addBranchGraph(scene);
    }

     public BranchGroup createSceneGraph() {

        BranchGroup objRoot = new BranchGroup();        // Create the root of the 
branch graph

        TransformGroup transGroup = new TransformGroup();
        transGroup.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE);
        transGroup.setCapability( TransformGroup.ALLOW_TRANSFORM_READ);

        BoundingSphere bounds = new BoundingSphere();   // I set the bounds for the 
light
        bounds.setRadius(1);

        // Here I create three different types of light
        // The only one missing is spotlight
        AmbientLight ambient = new AmbientLight();
        ambient.setColor( new Color3f(0.4f, 0.4f, 0.4f));
        ambient.setEnable( true);
        ambient.setInfluencingBounds( bounds);

        DirectionalLight directional = new DirectionalLight();
        ((DirectionalLight)directional).setDirection( 0.0f, 0.0f, -1.0f);
        directional.setColor( new Color3f(0.6f, 0.6f, 0.6f));
        directional.setEnable( true);
        directional.setInfluencingBounds( bounds);

        PointLight point = new PointLight();
        ((PointLight)point).setPosition( 0.0f, 0.0f, 1.0f);
        point.setColor( new Color3f(0.6f, 0.6f, 0.6f));
        point.setEnable( true);
        point.setInfluencingBounds( bounds);

        // here are the three lights you can switch on and off to see the influence of 
each
        objRoot.addChild( ambient);
        objRoot.addChild( directional);
        objRoot.addChild( point);

        // Mouse behaviors for animation
        MouseTranslate myMouseTranslate = new 
MouseTranslate(MouseBehavior.INVERT_INPUT);
        myMouseTranslate.setTransformGroup( transGroup);
        myMouseTranslate.setSchedulingBounds(bounds);
        MouseRotate myMouseRotate = new MouseRotate(MouseBehavior.INVERT_INPUT);
        myMouseRotate.setTransformGroup( transGroup);
        myMouseRotate.setSchedulingBounds(bounds);

        objRoot.addChild( myMouseRotate);
        objRoot.addChild( myMouseTranslate);
        objRoot.addChild( transGroup);

        // Here we create a sphere, generate normals and the appearence and material 
properties.
        // the chapter 6 lights of j3d tutorials v1.5
        transGroup.addChild(new Sphere(0.5f, Sphere.GENERATE_NORMALS, 
createAppearance()));

        return objRoot;
    }

    private Appearance createAppearance() {

        Appearance appear = new Appearance();
        Material material = new Material();
        appear.setMaterial( material);
        return appear;
    }

    //  The following allows this to be run as an application
    //  as well as an applet
    public static void main(String[] args) {
        Frame frame = new MainFrame(new LightSphere(), 256, 256);
    }

}

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to