SimpleUniverse 我不明白这里的 addChild 行代码请解释一下
SimpleUniverse i dont understand here the addChild line code please explain me
大家好,我想知道为什么在代码中有一行我的过程 addChild(trans) 没有附加到 SimpleUniverse 树中的任何地方,如果有人不能解释我为什么这样做以及它是如何工作的对我有帮助。谢谢(第二行内)
package examples;
import javax.media.j3d.Appearance;
import javax.media.j3d.Group;
import javax.media.j3d.Material;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Vector3d;
import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.geometry.Sphere;
public class SphereGroupExperiment extends Group{
Shape3D[] shapes;
int shapesNum=0;
public SphereGroupExperiment( )
{
// radius x,y spacing x,y count appearance
this(0.25f, 0.75f, 0.75f, 5, 5, null, false );
}
public SphereGroupExperiment( Appearance app )
{
// radius x,y spacing x,y count appearance
this( 0.25f, 0.75f, 0.75f, 5, 5, app, false );
}
public SphereGroupExperiment( float radius, float xSpacing, float ySpacing,
int xCount, int yCount, boolean overrideflag )
{
this( radius, xSpacing, ySpacing, xCount, yCount, null, overrideflag );
}
SphereGroupExperiment(float radius, float xSpace, float ySpace, int xCount, int yCount,Appearance app, boolean overrideFlag){
if(app == null){
Material material = new Material();
material.setDiffuseColor(new Color3f(0.0f, 1.0f, 0.0f));
material.setSpecularColor(new Color3f(0.0f, 0.0f, 0.0f));
material.setShininess(0.0f);
app.setMaterial(material);
}
double xStart = -xSpace * (double)(xCount-1)/2.0;
double yStart = -ySpace * (double)(yCount-1)/2.0;
Sphere sphare= null;
TransformGroup trans = null;
Transform3D t = new Transform3D();
Vector3d vec = new Vector3d();
double x, y = yStart, z = 0.0;
shapes = new Shape3D[xCount*yCount];
for (int i = 0 ; i<yCount ; i++){
x = xStart;
for(int j = 0; j<xCount; j++){
vec.set(x,y,z);
t.setTranslation(vec);
trans = new TransformGroup(t);
addChild(trans);
sphare = new Sphere(
radius, // sphere radius
Primitive.GENERATE_NORMALS, // generate normals
25, // 16 divisions radially
app ); // it's appearance
trans.addChild( sphare );
x += xSpace;
shapes[shapesNum] = sphare.getShape();
if (overrideFlag)
shapes[shapesNum].setCapability(Shape3D.ALLOW_APPEARANCE_OVERRIDE_WRITE);
shapesNum++;
}
y += ySpace;
}
}
public Shape3D[] getSphares(){
return shapes;
}
}
您的 class SphereGroupExperiment
扩展 javax.media.j3d.Group
。你会在 class.
中找到 addChild()
大家好,我想知道为什么在代码中有一行我的过程 addChild(trans) 没有附加到 SimpleUniverse 树中的任何地方,如果有人不能解释我为什么这样做以及它是如何工作的对我有帮助。谢谢(第二行内)
package examples;
import javax.media.j3d.Appearance;
import javax.media.j3d.Group;
import javax.media.j3d.Material;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Vector3d;
import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.geometry.Sphere;
public class SphereGroupExperiment extends Group{
Shape3D[] shapes;
int shapesNum=0;
public SphereGroupExperiment( )
{
// radius x,y spacing x,y count appearance
this(0.25f, 0.75f, 0.75f, 5, 5, null, false );
}
public SphereGroupExperiment( Appearance app )
{
// radius x,y spacing x,y count appearance
this( 0.25f, 0.75f, 0.75f, 5, 5, app, false );
}
public SphereGroupExperiment( float radius, float xSpacing, float ySpacing,
int xCount, int yCount, boolean overrideflag )
{
this( radius, xSpacing, ySpacing, xCount, yCount, null, overrideflag );
}
SphereGroupExperiment(float radius, float xSpace, float ySpace, int xCount, int yCount,Appearance app, boolean overrideFlag){
if(app == null){
Material material = new Material();
material.setDiffuseColor(new Color3f(0.0f, 1.0f, 0.0f));
material.setSpecularColor(new Color3f(0.0f, 0.0f, 0.0f));
material.setShininess(0.0f);
app.setMaterial(material);
}
double xStart = -xSpace * (double)(xCount-1)/2.0;
double yStart = -ySpace * (double)(yCount-1)/2.0;
Sphere sphare= null;
TransformGroup trans = null;
Transform3D t = new Transform3D();
Vector3d vec = new Vector3d();
double x, y = yStart, z = 0.0;
shapes = new Shape3D[xCount*yCount];
for (int i = 0 ; i<yCount ; i++){
x = xStart;
for(int j = 0; j<xCount; j++){
vec.set(x,y,z);
t.setTranslation(vec);
trans = new TransformGroup(t);
addChild(trans);
sphare = new Sphere(
radius, // sphere radius
Primitive.GENERATE_NORMALS, // generate normals
25, // 16 divisions radially
app ); // it's appearance
trans.addChild( sphare );
x += xSpace;
shapes[shapesNum] = sphare.getShape();
if (overrideFlag)
shapes[shapesNum].setCapability(Shape3D.ALLOW_APPEARANCE_OVERRIDE_WRITE);
shapesNum++;
}
y += ySpace;
}
}
public Shape3D[] getSphares(){
return shapes;
}
}
您的 class SphereGroupExperiment
扩展 javax.media.j3d.Group
。你会在 class.
addChild()