0 Replies Latest reply: May 11, 2010 1:19 AM by 843799 RSS

    Move the Sphere in opposite direction

    843799
      hello 3D world i'm new to java 3D i created a sphere gave a texture of our planet earth and it revolve round an object which is basically sun.
      Now, by default it revolves West to East (Left To Right)direction. now i want to make it revolve "East To West" or "Right To Left" as venus Moves "east To West" the source of the program is pasted below:--


      Souce---SolarSys.java


      import com.sun.j3d.utils.geometry.*;

      import com.sun.j3d.utils.image.TextureLoader;
      import com.sun.j3d.utils.universe.*;

      import javax.media.j3d.*;

      import javax.vecmath.*;

      public class SolarSys {

      public SolarSys() {

      // 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
      Appearance app = new Appearance();

      TextureLoader tex = new TextureLoader("c:/planets/earth1.jpg", null);
      app.setTexture(tex.getTexture());
      Sphere earth = new Sphere(0.045f, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS, 32, app);

      //Begin rotation of the white sphere
      TransformGroup whiteRotXformGroup = rotate(earth, new Alpha(-1, 1250));

      //Translate the rotating white sphere
      TransformGroup whiteTransXformGroup = translate(whiteRotXformGroup, new Vector3f(0.0f, 0.0f, 0.7f));

      //Begin rotation of the translated rotating white
      // sphere.
      TransformGroup whiteRotGroupXformGroup = rotate(whiteTransXformGroup, new Alpha(-1, 5000));

      group.addChild(whiteRotGroupXformGroup);

      // Create a red light that shines for 100m from the origin

      Material yellowSphMaterial = new Material();
      yellowSphMaterial.setDiffuseColor(1.0f, 1.0f, 0.0f);
      Appearance yellowSphAppearance = new Appearance();
      yellowSphAppearance.setMaterial(yellowSphMaterial);

      //Now instantiate the large yellow sphere with 9
      // divisions. Set the radius to 0.5. The reason for
      // setting GENERATE_NORMALS is unclear at this time.
      Sphere yellowSph = new Sphere(0.35f,
      Primitive.GENERATE_NORMALS,
      32,
      yellowSphAppearance);
      group.addChild(yellowSph);


      Color3f light1Color = new Color3f(1.8f, 0.1f, 0.1f);

      BoundingSphere bounds =
      new BoundingSphere(new Point3d(0.0, 0.0, 0.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 SolarSys();
      }

      TransformGroup rotate(Node node, Alpha alpha) {

      TransformGroup xformGroup = new TransformGroup();
      xformGroup.setCapability(
      TransformGroup.ALLOW_TRANSFORM_WRITE);

      //Create an interpolator for rotating the node.
      RotationInterpolator interpolator =
      new RotationInterpolator(alpha, xformGroup);

      //Establish the animation region for this
      // interpolator.
      interpolator.setSchedulingBounds(new BoundingSphere(
      new Point3d(0.0, 0.0, 0.0), 1.0));

      //Populate the xform group.
      xformGroup.addChild(interpolator);
      xformGroup.addChild(node);

      return xformGroup;

      }

      TransformGroup translate(Node node, Vector3f vector) {

      Transform3D transform3D = new Transform3D();
      transform3D.setTranslation(vector);
      TransformGroup transformGroup =
      new TransformGroup();
      transformGroup.setTransform(transform3D);

      transformGroup.addChild(node);
      return transformGroup;
      }//end translate
      }