ear members,

I am now learning JAVA 3D graphics and as a first step I like
to make a solar system (earth rotates the sun and the moon rotates both
the earth and sun).

I am struggling with this problem for the past two weeks and I hope you
can help me in this regard.

In my present program, the earth rotates the sun. The moon also rotates
the
sun.  But I want to rotate also the MOON TOWARDS EARTH as its rotate the
sun.

The problem is I don't know how to rotate
the moon towards earth and towards sun (it rotates around the sun
alone).

I am sending the source code that I have written for your kind perusal.
Could you please go through the program, modify it as you wish and
send me the corrected version which solves my problem
(make a solar system in Java 3D graphics) or kindly tell me the
changes that I have to make in my program.

I am looking for your kind reply.

Thanking you and
with best regards,

Michael

==========
Code
====

//<applet code="SolarAppMod1" width=800 height=500>
//</applet>

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Label.*;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;

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


public class SolarAppMod1 extends Applet{

        Appearance createAppearance()
            {
                Appearance app = new Appearance();
                String fn = "earth.jpg";
                TextureLoader loader = new TextureLoader(fn,this);
                ImageComponent2D image = loader.getImage();
                Texture2D texture = new
Texture2D(Texture.BASE_LEVEL,Texture.RGBA,
                image.getWidth(),image.getHeight());

                texture.setImage(0,image);
                texture.setEnable(true);
                texture.setMagFilter(Texture.BASE_LEVEL_LINEAR);
                texture.setMinFilter(Texture.BASE_LEVEL_LINEAR);

                        Material material = new Material();
                material.setShininess(100.0f);
                        app.setMaterial(material);
                        app.setTexture(texture);
                        return app;
            }


     public BranchGroup createSunEarthScene()
            {
                BranchGroup scene = new BranchGroup();

                //scene.addChild(new Axis());


                                Transform3D translate = new
Transform3D();
                Transform3D rotate = new Transform3D();



                //SUN

                translate.set(new Vector3f(0.0f, 0.2f, 0.0f));
                TransformGroup BallTGT1 = new TransformGroup(translate);
                TransformGroup BallTGR1 = new TransformGroup(rotate);
                scene.addChild(BallTGT1);
                rotate.rotX(Math.PI/180.0d);
                BallTGR1.addChild(new Sphere (0.2f,
Sphere.GENERATE_NORMALS, createAppearance()));
                BallTGT1.addChild(BallTGR1);


                // Earth rotating around the sun

                translate.set(new Vector3f(-0.7f, 0.20f, 0.20f));

                TransformGroup BallTGT2 = new TransformGroup(translate);
                TransformGroup BallTGR2 = new TransformGroup(rotate);

BallTGT2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
                scene.addChild(BallTGT2);
                Appearance appear = createAppearance();
                rotate.rotZ(Math.PI/5.0d);
                BallTGR2.addChild(new
Sphere(0.1f,Primitive.GENERATE_TEXTURE_COORDS,appear));
                BallTGT2.addChild(BallTGR2);



                BranchGroup gp = new BranchGroup();

                TransformGroup objSpin = new TransformGroup();


objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);


                gp.addChild(objSpin);



                objSpin.addChild(scene);



                Transform3D yAxis = new Transform3D();
                Alpha rotationAlpha = new Alpha(3, 16000);


                RotationInterpolator rotator =
                        new RotationInterpolator(rotationAlpha,
objSpin,yAxis,0.0f,(float)Math.PI*2.0f);
                BoundingSphere bounds =
                new BoundingSphere(new Point3d(0.0,0.0,0.0), 10.0);




                DirectionalLight light1 = new DirectionalLight();
                light1.setInfluencingBounds(bounds);
                Vector3f light1Direction = new Vector3f(-1.0f, -1.0f,
-1.0f);
                light1Direction.normalize();
                light1.setDirection(light1Direction);
                light1.setColor(new Color3f(1.0f, 1.0f, 1.0f));
                scene.addChild(light1);

                DirectionalLight light2 = new DirectionalLight();
                light2.setInfluencingBounds(bounds);
                Vector3f light2Direction = new Vector3f(1.0f, 1.0f,
1.0f);
                light2Direction.normalize();
                light2.setDirection(light2Direction);
                light2.setColor(new Color3f(0.0f, 1.0f, 0.0f));
                scene.addChild(light2);





                rotator.setSchedulingBounds(bounds);
                objSpin.addChild(rotator);




                Background bg = new Background();
                bg.setColor(0.05f, 0.05f, 0.2f);
                bg.setApplicationBounds(new BoundingSphere());
                scene.addChild(bg);

                //scene.addChild(new Axis());

                 gp.compile();
                 return gp;

               }


         BranchGroup createMoon()
               {
                        BranchGroup moon = new BranchGroup();

                        //scene.addChild(new Axis());


                                        Transform3D translate1 = new
Transform3D();
                                        Transform3D tempRotate1 = new
Transform3D();
                        Transform3D rotate1 = new Transform3D();

                        //Moon rotating around earth
                        translate1.set(new Vector3f(-0.9f, 0.20f,
0.25f));
                                        TransformGroup BallTGT3 = new
TransformGroup(translate1);
                                        moon.addChild(BallTGT3);
                                        Appearance appear =
createAppearance();
                                        rotate1.rotZ(Math.PI/2.0d);
                                        TransformGroup BallTGR3 = new
TransformGroup(rotate1);
                                        //rotate1.set(m1);
                                        BallTGR3.addChild(new
Sphere(0.1f,Sphere.GENERATE_NORMALS,createAppearance()));
                                        BallTGT3.addChild(BallTGR3);


                                        BranchGroup gp1 = new
BranchGroup();

                                        TransformGroup objSpin1 = new
TransformGroup();


objSpin1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);


                                        gp1.addChild(objSpin1);



                                        objSpin1.addChild(moon);



                                        Transform3D yAxis = new
Transform3D();
                                        Alpha rotationAlpha1 = new
Alpha(-1,
Alpha.INCREASING_ENABLE,0,0,

4000,0,0,

0,0,0);


                                    RotationInterpolator rotator1 =
                                        new
RotationInterpolator(rotationAlpha1,
objSpin1,yAxis,0.0f,(float)Math.PI*2.0f);
                                        BoundingSphere bounds1 =
                                        new BoundingSphere(new
Point3d(-0.7,0.20,20.0), 0.1);


rotator1.setSchedulingBounds(bounds1);
                                         objSpin1.addChild(rotator1);
                     gp1.compile();
                     return gp1;

             }








    public SolarAppMod1()
    {
        setLayout(new BorderLayout());
        Canvas3D canvas3D = new
Canvas3D(SimpleUniverse.getPreferredConfiguration());
        add("Center", canvas3D);


        BranchGroup scene = createSunEarthScene();
        BranchGroup moon = createMoon();
        //scene.addChild(new Axis());
        scene.compile();
        moon.compile();

        SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

        simpleU.getViewingPlatform().setNominalViewingTransform();

        simpleU.addBranchGraph(scene);
        simpleU.addBranchGraph(moon);
    }

    public static void main(String[] args)
    {
        Frame frame = new MainFrame(new SolarAppMod1(), 400, 300);
    }
}
--
**********************************************************************
Dr. M. Michael Gromiha, Ph.D         Tel: 0081-298-36-9082 (Office)
Bio Informatics Lab                       0081-298-38-2956 (home)
RIKEN Tsukuba Institute              Fax: 0081-298-36-9080
The Institute of Physical and      E-mail: [EMAIL PROTECTED]
        Chemical Research (RIKEN)          [EMAIL PROTECTED]
3-1-1 Koyadai, Tsukuba, Ibaraki 305-0074
JAPAN                        URL: http://www.rtc.riken.go.jp/~gromiha
**********************************************************************

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