关于Java3D问题..高手帮忙..
我现在用Java3D画出了一个球体
如何让这个球体身上披上一张图片?
而且这个球体 不停的自转??
类似与地球。。谢谢
球体的详细代码如下:
import java.awt.Color;
import com.sun.j3d.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;
public class demo implements Runnable{
Color3f light1Color;
BoundingSphere bounds;
Vector3f light1Direction;
BranchGroup group;
DirectionalLight light1;
SimpleUniverse universe;
Sphere sphere;
float R = 1.8f;
float G = 0.1f;
float B = 0.1f;
public demo(){
// 创建宇宙 JFrame
universe = new SimpleUniverse();
// 创建容纳物体的结构 JPanel
group = new BranchGroup();
// 创建一个球体并加入到物体组 //Sphere球体 0.3为球的半径folat
sphere = new Sphere(0.3f,1,30);
System.out.println(sphere.getDivisions());
group.addChild(sphere);
light1Color = new Color3f(R,G,B);
// 创建一个从原点延伸100米的红色光源
bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
/***定向光源
* (由向量定义: -4.0向右,7.0向下,-12.0向内)。
* 反之 4.0向左,-7.0向上,12.0向外*/
light1Direction = new Vector3f(-4.0f, -7.0f, -30.0f);
light1 = new DirectionalLight(light1Color, light1Direction);
light1.setInfluencingBounds(bounds);
group.addChild(light1);
// 注视球体
universe.getViewingPlatform().setNominalViewingTransform();
// 添加物体组到宇宙中
universe.addBranchGraph(group);
Thread tt = new Thread(this);
tt.start();
}
public void run() {
while(true){
try
{
Thread.sleep(500);
}
catch(Exception e)
{
e.printStackTrace();
}
System.out.println("已经更换");
}
}
public static void main(String[]args)
{
new demo();
}
}