Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Designing a 3D car

843799Apr 10 2007
My problem is in creating or designing a 3D car by measuring the shapes and size to fix or develop a car which can be see each angle of the car by dragging the mouse up and down, left and right by the user.

Here is the link where u can see the car rotating as I show below

http://www.frontiernet.net/~imaging/games_with_java3d.html

Hope u can help me out. PLEASE.
Remember: It just designing a simple car, it is not a game program

Here I also have send a sample code which I done using a cube is output will rotate.

/*
* Loader.java
*
* Created on March 6 , 2006, 1:38 AM
*
* @author C. Parameswary
*/

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;

import javax.media.j3d.Alpha;
import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.RotationInterpolator;
import javax.media.j3d.Texture;
import javax.media.j3d.Texture2D;
import javax.media.j3d.TextureAttributes;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Point3d;

import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class Loader extends Applet {

private java.net.URL texImage = null;

String play;

private SimpleUniverse u = null;

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

// Create the transform group node and initialize it to the
// identity. Enable the TRANSFORM_WRITE capability so that
// our behavior code can modify it at runtime. Add it to the
// root of the subgraph.
TransformGroup objTrans = new TransformGroup();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objTrans);

// Create appearance object for textured cube
Appearance app = new Appearance();

TextureLoader tex = new TextureLoader(texImage, null);
Texture2D texture = (Texture2D) tex.getTexture();
app.setTexture(texture);
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.MODULATE);
app.setTextureAttributes(texAttr);

// Create textured cube and add it to the scene graph.
Box textureCube = new Box(0.4f, 0.4f, 0.4f,Box.GENERATE_TEXTURE_COORDS, app);
objTrans.addChild(textureCube);

// Create a new Behavior object that will perform the desired
// operation on the specified transform object and add it into
// the scene graph.
Transform3D yAxis = new Transform3D();
Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0,
4000, 0, 0, 0, 0, 0);

RotationInterpolator rotator = new RotationInterpolator(rotationAlpha,
objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f);
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
100.0);
rotator.setSchedulingBounds(bounds);
objTrans.addChild(rotator);

// Have Java 3D perform optimizations on this scene graph.
objRoot.compile();

return objRoot;
}

public Loader()
{

}

public Loader(java.net.URL url)
{
texImage = url;
}

public void init()
{
/*add by Parames*/

if (texImage == null)
{
// the path to the image for an applet
System.out.println("hihi");
try
{
texImage = new java.net.URL(getCodeBase().toString()+ "c:\\.sunset");
} catch (java.net.MalformedURLException ex)
{
System.out.println(ex.getMessage());
System.exit(1);
}
}
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);

/*Add by Parames*/

// 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.cleanup();
}

//
// The following allows TextureImage to be run as an application
// as well as an applet
//
public static void main(String[] args)
{
/*Add by Parames*/

java.net.URL url = null;
if (args.length > 0)
{
try {
url = new java.net.URL("file:" + args[0]);
} catch (java.net.MalformedURLException ex) {
System.out.println(ex.getMessage());
System.exit(1);
}
} else {
// the path to the image for an application
try {
url = new java.net.URL("file:c:\\sunset.jpg");
} catch (java.net.MalformedURLException ex) {
System.out.println(ex.getMessage());
System.exit(1);
}
}
new MainFrame(new Loader(url), 256, 256);
}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 8 2007
Added on Apr 10 2007
0 comments
108 views