Here is the source Code!!

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.Color.*;

public class Solarsistema extends Applet {

    private SimpleUniverse u = null;


    public BranchGroup createSceneGraph() {



        //Objetos que definen el grafo de escena

        //Raiz del grafo de escena
        BranchGroup Raiz = new BranchGroup();


        TransformGroup SunGroup = new TransformGroup();
        TransformGroup EarthGroup = new TransformGroup();
        TransformGroup PGroup = new TransformGroup();
        TransformGroup KGroup = new TransformGroup();
        TransformGroup MoonGroup = new TransformGroup();
        TransformGroup TGroup = new TransformGroup();
        //Capabilities

        //Vector desplazamiento que situa al planeta respecto del sol.
        Vector3f t_sol_earth = new Vector3f(0.3f, 0.0f, 0.0f);
        //Vector desplazamiento que situa la luna respecto del palenta.
        Vector3f t_earth_moon = new Vector3f(0.3f, 0.0f, 0.0f);
        //Para escalar el grafo de escena (Todos los objetos)
        double valor_escala = 0.9f;
        Transform3D escala = new Transform3D();
        escala.setScale(valor_escala);

        //Ejes de Rotacion

        //Matriz que define el eje X de Rotacion Levogira
        float mX[]={0.0f, 1.0f, 0.0f,
        -1.0f, 0.0f, 0.0f,
        0.0f, 0.0f, 1.0f};
        //Matriz que define el eje Z de Rotacion Levogira
        float mZ[]={1.0f, 0.0f, 0.0f,
        0.0f,0.0f, 1.0f,
        0.0f, -1.0f, 0.0f};



        Transform3D yAxis = new Transform3D();
        Transform3D xAxis = new Transform3D();
        xAxis.setRotation(new Matrix3f(mX));

        Transform3D zAxis = new Transform3D();
        zAxis.setRotation(new Matrix3f(mZ));
        //Colores.

        final Color3f Amarillo  = new Color3f(java.awt.Color.yellow);
        final Color3f Azul      = new Color3f(java.awt.Color.blue);
        final Color3f Blanco    = new Color3f(java.awt.Color.white);

        Color3f eColor    = new Color3f(0.0f, 0.0f, 0.0f);
        Color3f sColor    = new Color3f(0.0f, 0.0f, 0.0f);
        Color3f objColor  = new Color3f(0.0f, 0.1f, 0.1f);
        Color3f lColor1   = new Color3f(1.0f, 0.0f, 0.0f);
        Color3f lColor2   = new Color3f(0.0f, 1.0f, 0.0f);
        Color3f alColor   = new Color3f(0.2f, 0.2f, 0.2f);
        Color3f bgColor   = new Color3f(0.05f, 0.05f, 0.2f);

        Color3f sunEmision = new Color3f(0.0f,1.0f,1.0f);


        //Cuerpos Celestes



        //Behaviors
        // Create a bounds for the background and lights
        BoundingSphere bounds =
        new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);

        Alpha sun_around_alpha = new Alpha(-1, 2000);
        Alpha earth_around_alpha = new Alpha(-1, 500);
        Alpha axis_around_alpha = new Alpha(-1, 750);

        RotationInterpolator around_sun =
        new RotationInterpolator(sun_around_alpha,
        PGroup, zAxis,
        0.0f, (float) Math.PI*2.0f);

        RotationInterpolator around_earth =
        new RotationInterpolator(earth_around_alpha,
        KGroup, yAxis,
        (float) Math.PI*2.0f,0.0f);

        RotationInterpolator earth_around_earth =
        new RotationInterpolator(axis_around_alpha, TGroup, xAxis,
        (float) Math.PI*2.0f,0.0f);

        around_sun.setSchedulingBounds(bounds);
        around_earth.setSchedulingBounds(bounds);
        earth_around_earth.setSchedulingBounds(bounds);

        ColorCube sunSphere = new ColorCube(0.06f);
        ColorCube earthSphere = new ColorCube(0.025f);
        ColorCube moonSphere  = new ColorCube(0.01f);


        Raiz.addChild(SunGroup);

        SunGroup.addChild(sunSphere);

        //Hay que tener en cuenta que el resto de objetos (luna y planeta),
        //seran descendientes de SunGroup, y por lo tanto la siguiente
        //transformacion tambien les afecta a todos ellos.

        SunGroup.setTransform(escala);
        SunGroup.addChild(PGroup);

        PGroup.addChild(EarthGroup);



        PGroup.addChild(around_sun);


        Transform3D EarthTraslacion = new Transform3D();
        EarthTraslacion.setTranslation(t_sol_earth);
        EarthGroup.setTransform(EarthTraslacion);
        EarthGroup.addChild(TGroup);
        EarthGroup.addChild(KGroup);

        TGroup.addChild(earthSphere);
        TGroup.addChild(earth_around_earth);



        KGroup.addChild(around_earth);
        KGroup.addChild(MoonGroup);



        MoonGroup.addChild(moonSphere);
        Transform3D MoonTraslacion = new Transform3D();
        MoonTraslacion.setTranslation(t_earth_moon);
        MoonGroup.setTransform(MoonTraslacion);



        //Capacidades para poder rotar los cuerpos
        EarthGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        MoonGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        SunGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        EarthGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        MoonGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        SunGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        PGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        PGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        KGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        KGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        TGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        TGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);




        //SunGroup.addChild(around_sun);



        Raiz.compile();

        return Raiz;
    }

    public Solarsistema() {
    }


    public void init() {
        setLayout(new BorderLayout());
        GraphicsConfiguration config =
        SimpleUniverse.getPreferredConfiguration();

        Canvas3D c = new Canvas3D(config);
        add("Center", c);

        // Create a simple scene and attach it to the virtual universe
        BranchGroup scene = createSceneGraph();
        u = new SimpleUniverse(c);

        // This will move the ViewPlatform back a bit so the
        // objects in the scene can be viewed.
        u.getViewingPlatform().setNominalViewingTransform();


        u.addBranchGraph(scene);



    }


    public void destroy() {
        u.removeAllLocales();
    }

    public static void main(String[] args) {
        new MainFrame(new Solarsistema(), 556, 556);
    }
}

===========================================================================
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