participate


Java 3D - Carlos Hank Rhon - help with java 3D
<<   Back to Forum  |   Give us Feedback
This topic has 1 reply on 1 page.
Carlos-Hank-Rhon
Posts:1
Registered: 7/17/08
Carlos Hank Rhon - help with java 3D   
Jul 17, 2008 6:37 AM

 
hey guys.

Basically I have made a program which creates a sphere with the map of the earth round it but I want to make it spin (ie like the earth spins)

Ive never used java 3d before and im absolute clueless on how to go about it as everything on the net just puzzles me. would appreciate if anyone could show me what to do.

heres my code. needless to say to run it you would need to save your own earth.jpg picture. thanks


import java.awt.Container;

import javax.media.j3d.;
import javax.vecmath.
;
import com.sun.j3d.utils.universe.SimpleUniverse;

import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.image.TextureLoader;


public class PictureBall {

public PictureBall() {

// Create the universe
SimpleUniverse universe = new SimpleUniverse();

// Create a structure to contain objects
BranchGroup group = new BranchGroup();

// Set up colors
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
Color3f red = new Color3f(0.7f, .15f, .15f);

// Set up the texture map
TextureLoader loader = new TextureLoader("earth.jpg",
"RGB", new Container());
Texture texture = loader.getTexture();
texture.setBoundaryModeS(Texture.WRAP);
texture.setBoundaryModeT(Texture.WRAP);
texture.setBoundaryColor(new Color4f(0.0f, 1.0f, 0.0f, 0.0f));

// Set up the texture attributes
//could be REPLACE, BLEND or DECAL instead of MODULATE
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.REPLACE);
Appearance ap = new Appearance();
ap.setTexture(texture);
ap.setTextureAttributes(texAttr);

//set up the material
ap.setMaterial(new Material(red, black, red, black, 1.0f));

// Create a ball to demonstrate textures
int primflags = Primitive.GENERATE_NORMALS
+ Primitive.GENERATE_TEXTURE_COORDS;
Sphere sphere = new Sphere(0.7f, primflags, ap);
group.addChild(sphere);

// Create lights
Color3f light1Color = new Color3f(1f, 1f, 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);

AmbientLight ambientLight = new AmbientLight(new Color3f(.5f, .5f, .5f));
ambientLight.setInfluencingBounds(bounds);
group.addChild(ambientLight);

// 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 PictureBall();
}
}
Reply With Quote
Thx
 
celsoxavier
Posts:2
Registered: 7/18/08
Re: Carlos Hank Rhon - help with java 3D   
Jul 22, 2008 8:59 AM (reply 1 of 1)  (In reply to original post )

 
//try this, it'll make earth spin, i hope it works
//if ypu have any doubts just post it.
//don't forget to import the classes

TransformGroup transformaObjeto = new TransformGroup();
Transform3D transforma = new Transform3D();

Alpha rotacaoAlpha = new Alpha( -1, Alpha.INCREASING_ENABLE, 0, 0, 5000, 0, 0, 5000, 0, 0 );

RotationInterpolator rotator = new RotationInterpolator( rotacaoAlpha, transformaObjeto, transforma, 0.0f, ( float ) Math.toRadians( 360 ) );
rotator.setSchedulingBounds( bounds );

transformaObjeto.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE );

transformaObjeto.addChild( rotator );
group.addChild(transformaObjeto);
 
This topic has 1 reply on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 28
  • Guests : 129

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums