本文整理汇总了Java中com.sun.j3d.utils.geometry.Sphere类的典型用法代码示例。如果您正苦于以下问题:Java Sphere类的具体用法?Java Sphere怎么用?Java Sphere使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Sphere类属于com.sun.j3d.utils.geometry包,在下文中一共展示了Sphere类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create3D
import com.sun.j3d.utils.geometry.Sphere; //导入依赖的package包/类
/** Create 3D geometry. */
@Override
protected void create3D() {
Appearance appear = new Appearance();
material.setCapability(Material.ALLOW_COMPONENT_WRITE);
material.setDiffuseColor(color);
material.setSpecularColor(black);
appear.setMaterial(material);
int flags = Primitive.GEOMETRY_NOT_SHARED | Primitive.ENABLE_GEOMETRY_PICKING | Primitive.GENERATE_NORMALS;
body = new Sphere(radius, flags, appear);
// we must be able to change the pick flag of the agent
body.setCapability(Node.ALLOW_PICKABLE_READ);
body.setCapability(Node.ALLOW_PICKABLE_WRITE);
body.setPickable(true);
body.setCollidable(true);
addChild(body);
// Add bounds for interactions
Bounds bounds = new BoundingSphere(new Point3d(0, 0, 0), radius);
setBounds(bounds);
}
示例2: testOBJWriter
import com.sun.j3d.utils.geometry.Sphere; //导入依赖的package包/类
/**
* Simple test of OBJWriter class with Java 3D objects.
*/
public void testOBJWriter() throws IOException {
// 1. Open the OBJ file "Test.obj"
OBJWriter writer = new OBJWriter("[email protected]#.obj", "Test", 3);
assertTrue("[email protected]#.obj not created", new File("[email protected]#.obj").exists());
// 2. Write a box at center
writer.writeNode(new Box());
// Write a sphere centered at (2, 0, 2)
Transform3D translation = new Transform3D();
translation.setTranslation(new Vector3f(2f, 0, 2f));
TransformGroup translationGroup = new TransformGroup(translation);
translationGroup.addChild(new Sphere());
writer.writeNode(translationGroup);
// 3. Close file
writer.close();
assertTrue("[email protected]#.mtl not created", new File("[email protected]#.mtl").exists());
if (!new File("[email protected]#.obj").delete()
|| !new File("[email protected]#.mtl").delete()) {
fail("Couldn't delete test files");
}
}
示例3: J3dTest
import com.sun.j3d.utils.geometry.Sphere; //导入依赖的package包/类
public J3dTest(){
// 创建一个虚拟空间
SimpleUniverse universe = new SimpleUniverse();
// 创建一个用来包含对象的数据结构
BranchGroup group = new BranchGroup();
// 创建一个球并把它加入到group中
Sphere sphere = new Sphere(0.5f); // 小球的半径为0.5米
group.addChild(sphere);
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);
// 将光源加入group组,安放观察点
universe.getViewingPlatform().setNominalViewingTransform();
// 把group加入到虚拟空间中
universe.addBranchGraph(group);
}
示例4: create3D
import com.sun.j3d.utils.geometry.Sphere; //导入依赖的package包/类
/** Create 3D geometry. */
@Override
protected void create3D() {
Appearance appear = new Appearance();
material.setDiffuseColor(color);
material.setSpecularColor(black);
appear.setMaterial(material);
int flags = Primitive.GEOMETRY_NOT_SHARED | Primitive.ENABLE_GEOMETRY_PICKING | Primitive.GENERATE_NORMALS;
body = new Sphere(radius, flags, appear);
// we must be able to change the pick flag of the agent
body.setCapability(Node.ALLOW_PICKABLE_READ);
body.setCapability(Node.ALLOW_PICKABLE_WRITE);
body.setPickable(true);
body.setCollidable(true);
addChild(body);
// Add bounds for interactions
Bounds bounds = new BoundingSphere(new Point3d(0, 0, 0), radius);
setBounds(bounds);
}
示例5: createLight
import com.sun.j3d.utils.geometry.Sphere; //导入依赖的package包/类
/**
* Fuegt ein Licht ein
*
* @param pointLightBounds
* @param pointLightColor
* @param x
* X-Koordinate
* @param y
* Y-Koordinate
* @param appearance
* Die Appearance
*/
private void createLight(BoundingSphere pointLightBounds, Color3f pointLightColor, int x, int y, Appearance appearance) {
// Lichter bestehen aus dem echten Licht
PointLight pointLight = new PointLight();
pointLight.setColor(pointLightColor);
pointLight.setPosition((x + 0.5f) * parcours.getBlockSizeInM(), (y + 0.5f) * parcours.getBlockSizeInM(), LIGHTZ);
pointLight.setInfluencingBounds(pointLightBounds);
pointLight.setAttenuation(1f, 3f, 0f);
pointLight.setEnable(true);
parcours.addLight(pointLight);
// Und einer gelben Kugel, um es zu visualisieren
Sphere lightSphere = new Sphere(0.07f);
lightSphere.setAppearance(appearance);
parcours.addLight(lightSphere, x + 0.5f, y + 0.5f, LIGHTZ);
}
示例6: create3D
import com.sun.j3d.utils.geometry.Sphere; //导入依赖的package包/类
/** Create 3D geometry. */
@Override
protected void create3D() {
Appearance appear = new Appearance();
material.setDiffuseColor(color);
material.setSpecularColor(black);
appear.setMaterial(material);
int flags = Primitive.GEOMETRY_NOT_SHARED | Primitive.ENABLE_GEOMETRY_PICKING | Primitive.GENERATE_NORMALS;
body = new Sphere(radius, flags, appear);
// we must be able to change the pick flag of the agent
body.setCapability(Node.ALLOW_PICKABLE_READ);
body.setCapability(Node.ALLOW_PICKABLE_WRITE);
body.setPickable(true);
body.setCollidable(true);
addChild(body);
// Add bounds for interactions
Bounds bounds = new BoundingSphere(new Point3d(0, 0, 0), radius);
setBounds(bounds);
}
示例7: create3D
import com.sun.j3d.utils.geometry.Sphere; //导入依赖的package包/类
/** Create 3D geometry. */
@Override
protected void create3D() {
Appearance appear = new Appearance();
material.setCapability(Material.ALLOW_COMPONENT_WRITE);
material.setDiffuseColor(color);
material.setSpecularColor(black);
appear.setMaterial(material);
int flags = Primitive.GEOMETRY_NOT_SHARED | Primitive.ENABLE_GEOMETRY_PICKING | Primitive.GENERATE_NORMALS;
body = new Sphere(radius, flags, appear);
// we must be able to change the pick flag of the agent
body.setCapability(Node.ALLOW_PICKABLE_READ);
body.setCapability(Node.ALLOW_PICKABLE_WRITE);
body.setPickable(true);
body.setCollidable(true);
addChild(body);
// Add bounds for interactions
Bounds bounds = new BoundingSphere(new Point3d(0, 0, 0), radius);
setBounds(bounds);
}
示例8: Ball
import com.sun.j3d.utils.geometry.Sphere; //导入依赖的package包/类
public Ball(double x, double y, double z, double vx, double vy, double vz) {
position = new Vector3d(x, y, z);
speed = new Vector3d(vx, vy, vz);
// �ړ��\
this.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
this.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
app = new Appearance();
app.setTexture(loadTexture("carpet.jpg"));
// �{�[����lj�
this.addChild(new Sphere(radius, Sphere.GENERATE_TEXTURE_COORDS, 100, app));
move();
}
示例9: Ball
import com.sun.j3d.utils.geometry.Sphere; //导入依赖的package包/类
public Ball(double x, double y, double z) {
position = new Vector3d(x, y, z);
velocity = new Vector3d(0, 0, 0);
acceleration = new Vector3d(0, -0.01, 0); // �����x�͈��
// �ړ��\
this.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
this.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
app = new Appearance();
Material mat = new Material();
mat.setAmbientColor(new Color3f(0.0f, 0.0f, 1.0f));
mat.setSpecularColor(new Color3f(1.0f, 1.0f, 1.0f));
app.setMaterial(mat);
TransparencyAttributes transAttr = new TransparencyAttributes(
TransparencyAttributes.BLENDED, 0.2f);
app.setTransparencyAttributes(transAttr);
// �{�[����lj�
this.addChild(new Sphere(radius, Sphere.GENERATE_NORMALS, 100, app));
move();
}
示例10: createPlaneteTraces
import com.sun.j3d.utils.geometry.Sphere; //导入依赖的package包/类
/**
* Called to create ghosts of the body
* Ghost are the ancien position of a body
* (slows down the java3D tree creation)
* @param root where to add these ghost
* @param i body to be ghosted
* @param a appearance of the ghosts
*/
private void createPlaneteTraces(BranchGroup root, int i, Appearance a) {
for (int j = 0; j < (this.MAX_HISTO_SIZE - 1); j++) {
// Trace Transformation Group
TransformGroup traceGroup = new TransformGroup();
traceGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
this.tracesGroup[i][j] = traceGroup;
// Trace Transformation (place and direction)
Transform3D traceTransformation = new Transform3D();
this.tracesTransformation[i][j] = traceTransformation;
// Cylinder representing a segment
//Cylinder(float radius, float height, Appearance ap)
Sphere ghost = new Sphere(0.005f, a);
//Assembling group
traceGroup.addChild(ghost);
//traceGroup.setTransform(traceTransformation);
root.addChild(traceGroup);
}
}
示例11: create3D
import com.sun.j3d.utils.geometry.Sphere; //导入依赖的package包/类
void create3D(float radius) {
super.create3D(true);
// body
if (radius > 0) {
Color3f color = new Color3f(0.8f, 0.8f, 0.0f);
Appearance appear = new Appearance();
appear.setMaterial(new Material(color, black, color, white, 100.0f));
Node node = new Sphere(radius, appear);
node.setCollidable(false);
node.setPickable(false);
addChild(node);
}
}
示例12: addLight
import com.sun.j3d.utils.geometry.Sphere; //导入依赖的package包/类
/**
* Add a light to the 3d world. Used only in the creation phase.
*/
Light addLight(Vector3d pos, Color3f color) {
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), worldSize * 2);
TransformGroup tg = new TransformGroup();
Transform3D t3d = new Transform3D();
t3d.set(pos);
tg.setTransform(t3d);
PointLight light = new PointLight();
light.setAttenuation(0.5f, 0, 0);
// light.setAttenuation(0f,.08f,0);
// light.setAttenuation(1.2f,0,0);
// note : light pos not affected by transform (but bound is).
light.setPosition((float) pos.x, (float) pos.y, (float) pos.z);
light.setInfluencingBounds(bounds);
sceneTrans.addChild(light);
// light geometry
ColoringAttributes ca = new ColoringAttributes();
ca.setColor(color);
Appearance appL1 = new Appearance();
appL1.setColoringAttributes(ca);
Primitive s = new Sphere(0.4f, appL1);
s.setCollidable(true);
tg.addChild(s);
sceneTrans.addChild(tg);
return light;
}
示例13: CanvasPickInfoListener
import com.sun.j3d.utils.geometry.Sphere; //导入依赖的package包/类
public CanvasPickInfoListener() {
Appearance app = new Appearance();
Material mat = new Material();
mat.setAmbientColor(Utils3D.green);
mat.setSpecularColor(Utils3D.skyblue);
mat.setDiffuseColor(Utils3D.darkBlue);
//a,e,d,s
app.setMaterial(mat);
//greenlook.setMaterial(new Material(objColor, Utils3D.black, objColor, Utils3D.white, 128.0f));
sphere = new Sphere(0.004f, Primitive.GENERATE_NORMALS, 100, app);
sphere.setPickable(false);
t3d = new Transform3D();
sphTrans = new TransformGroup(t3d);
//sphTrans = new TransformGroup();
sphTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
sphTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
// Add sphere, transform
sphTrans.addChild(sphere);
sceneBG.addChild(sphTrans);
pickCanvas = new PickCanvas(canvas3D, sceneBG);
pickCanvas.setTolerance(3.5f);
pickCanvas.setMode(PickInfo.PICK_GEOMETRY);
pickCanvas.setFlags(PickInfo.LOCAL_TO_VWORLD | PickInfo.CLOSEST_GEOM_INFO | PickInfo.NODE);
}
示例14: addCoordinateSphereAxesToSceneGraph
import com.sun.j3d.utils.geometry.Sphere; //导入依赖的package包/类
/**
* Function to add a white sphere and axes at the origin of the
* coordinate system for better orientation. The z-axis is in black.
*/
public static void addCoordinateSphereAxesToSceneGraph(BranchGroup scene, float radius) {
float rad = (radius <= 0.0f) ? 0.1f : radius;
Appearance ap = new Appearance();
ColoringAttributes ca = new ColoringAttributes();
ca.setColor(white);
ap.setColoringAttributes(ca);
scene.addChild(new Sphere(rad, ap));
LineArray la1 = new LineArray(2, LineArray.COORDINATES | LineArray.COLOR_3);
la1.setCoordinate(0, new Point3f());
la1.setCoordinate(1, new Point3f(5.0f * rad, 0.0f, 0.0f));
for (int i = 0; i < 2; ++i) {
la1.setColor(i, white);
}
scene.addChild(new Shape3D(la1));
LineArray la2 = new LineArray(2, LineArray.COORDINATES | LineArray.COLOR_3);
la2.setCoordinate(0, new Point3f());
la2.setCoordinate(1, new Point3f(0.0f, 5.0f * rad, 0.0f));
for (int i = 0; i < 2; ++i) {
la2.setColor(i, white);
}
scene.addChild(new Shape3D(la2));
LineArray la3 = new LineArray(2, LineArray.COORDINATES | LineArray.COLOR_3);
la3.setCoordinate(0, new Point3f());
la3.setCoordinate(1, new Point3f(0.0f, 0.0f, 5.0f * rad));
for (int i = 0; i < 2; ++i) {
la3.setColor(i, black);
}
scene.addChild(new Shape3D(la3));
}
示例15: showDebugSphere
import com.sun.j3d.utils.geometry.Sphere; //导入依赖的package包/类
/**
* Zeichnet eine Kugel zu Debug-Zwecken, indem sie zu TestBG hinzugefuegt wird
* @param radius Radius der Kugel
* @param transform Transformation, die auf die Box angewendet werden soll
*/
public void showDebugSphere(final double radius, Transform3D transform) {
final Sphere sphare = new Sphere((float) radius);
TransformGroup tg = new TransformGroup();
tg.setTransform(transform);
tg.addChild(sphare);
BranchGroup bg = new BranchGroup();
bg.setCapability(BranchGroup.ALLOW_DETACH);
bg.addChild(tg);
testBG.addChild(bg);
}