📄 sphere.java
字号:
} } shape = new Shape3D(gbuf.getGeom(flags)); numVerts = gbuf.getNumVerts(); numTris = gbuf.getNumTris(); if ((primflags & Primitive.GEOMETRY_NOT_SHARED) == 0) { cacheGeometry(Primitive.SPHERE, radius, 0.0f, 0.0f, divisions, 0, primflags, gbuf); } } if ((flags & ENABLE_APPEARANCE_MODIFY) != 0) { shape.setCapability(Shape3D.ALLOW_APPEARANCE_READ); shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE); } if ((flags & ENABLE_GEOMETRY_PICKING) != 0) { shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ); } this.addChild(shape); if (ap == null) { setAppearance(); } else setAppearance(ap); } /** * Used to create a new instance of the node. This routine is called * by <code>cloneTree</code> to duplicate the current node. * <code>cloneNode</code> should be overridden by any user subclassed * objects. All subclasses must have their <code>cloneNode</code> * method consist of the following lines: * <P><blockquote><pre> * public Node cloneNode(boolean forceDuplicate) { * UserSubClass usc = new UserSubClass(); * usc.duplicateNode(this, forceDuplicate); * return usc; * } * </pre></blockquote> * @param forceDuplicate when set to <code>true</code>, causes the * <code>duplicateOnCloneTree</code> flag to be ignored. When * <code>false</code>, the value of each node's * <code>duplicateOnCloneTree</code> variable determines whether * NodeComponent data is duplicated or copied. * * @see Node#cloneTree * @see Node#duplicateNode * @see NodeComponent#setDuplicateOnCloneTree */ public Node cloneNode(boolean forceDuplicate) { Sphere s = new Sphere(radius, flags, divisions, getAppearance()); s.duplicateNode(this, forceDuplicate); return s; } /** * Copies all node information from <code>originalNode</code> into * the current node. This method is called from the * <code>cloneNode</code> method which is, in turn, called by the * <code>cloneTree</code> method. * <P> * For any <i>NodeComponent</i> objects * contained by the object being duplicated, each <i>NodeComponent</i> * object's <code>duplicateOnCloneTree</code> value is used to determine * whether the <i>NodeComponent</i> should be duplicated in the new node * or if just a reference to the current node should be placed in the * new node. This flag can be overridden by setting the * <code>forceDuplicate</code> parameter in the <code>cloneTree</code> * method to <code>true</code>. * * @param originalNode the original node to duplicate. * @param forceDuplicate when set to <code>true</code>, causes the * <code>duplicateOnCloneTree</code> flag to be ignored. When * <code>false</code>, the value of each node's * <code>duplicateOnCloneTree</code> variable determines whether * NodeComponent data is duplicated or copied. * * @see Node#cloneTree * @see Node#cloneNode * @see NodeComponent#setDuplicateOnCloneTree */ public void duplicateNode(Node originalNode, boolean forceDuplicate) { super.duplicateNode(originalNode, forceDuplicate); } /** * Returns the radius of the sphere * * @since Java 3D 1.2.1 */ public float getRadius() { return radius; } /** * Returns the number of divisions * * @since Java 3D 1.2.1 */ public int getDivisions() { return divisions; } void buildQuadrant(GeomBuffer gbuf, double startDelta, double endDelta, int sign, int nstep, int n, boolean upperSphere) { double ds, dt, theta, delta; int i, j, index, i2; double h, r, vx, vz; Point3f pt; Vector3f norm; TexCoord2f texCoord; double starth; double t; boolean leftToRight; if (upperSphere) { dt = Math.PI/(2*nstep); theta = dt; starth = 1; leftToRight = (sign > 0); } else { dt = -Math.PI/(2*nstep); theta = Math.PI + dt; starth = -1; leftToRight = (sign < 0); } for (i = 1; i <= nstep; i++) { h = Math.cos(theta); r = Math.sin(theta); if (sign > 0) { t = 1 - theta/Math.PI; } else { t = theta/Math.PI; } i2 = i << 1; // subdivision decreases towards the pole ds = (endDelta - startDelta) / i; gbuf.begin(GeomBuffer.TRIANGLE_STRIP); if (leftToRight) { // Build triangle strips from left to right delta = startDelta; for (j=0; j < i; j++) { vx = r*Math.cos(delta); vz = r*Math.sin(delta); gbuf.normal3d( vx*sign, h*sign, vz*sign ); gbuf.texCoord2d(0.75 - delta/(2*Math.PI), t); gbuf.vertex3d( vx*radius, h*radius, vz*radius ); if (i > 1) { // get previous vertex from buffer index = gbuf.currVertCnt - i2; pt = gbuf.pts[index]; norm = gbuf.normals[index]; texCoord = gbuf.tcoords[index]; // connect with correspondent vertices from previous row gbuf.normal3d(norm.x, norm.y, norm.z); gbuf.texCoord2d(texCoord.x, texCoord.y); gbuf.vertex3d(pt.x, pt.y, pt.z); } else { gbuf.normal3d(0, sign*starth, 0); if (sign > 0) { gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI), 1.0 - (theta - dt)/Math.PI); } else { gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI), (theta - dt)/Math.PI); } gbuf.vertex3d( 0, starth*radius, 0); } delta += ds; } // Put the last vertex in that row, // for numerical accuracy we don't use delta // compute from above. delta = endDelta; vx = r*Math.cos(delta); vz = r*Math.sin(delta); gbuf.normal3d( vx*sign, h*sign, vz*sign ); gbuf.texCoord2d(0.75 - delta/(2*Math.PI), t); gbuf.vertex3d( vx*radius, h*radius, vz*radius); } else { delta = endDelta; // Build triangle strips from right to left for (j=i; j > 0; j--) { vx = r*Math.cos(delta); vz = r*Math.sin(delta); gbuf.normal3d( vx*sign, h*sign, vz*sign ); // Convert texture coordinate back to one // set in previous version gbuf.texCoord2d(0.75 - delta/(2*Math.PI), t); gbuf.vertex3d( vx*radius, h*radius, vz*radius ); if (i > 1) { // get previous vertex from buffer index = gbuf.currVertCnt - i2; pt = gbuf.pts[index]; norm = gbuf.normals[index]; texCoord = gbuf.tcoords[index]; gbuf.normal3d(norm.x, norm.y, norm.z); gbuf.texCoord2d(texCoord.x, texCoord.y); gbuf.vertex3d(pt.x, pt.y, pt.z); } else { gbuf.normal3d(0, sign*starth, 0); if (sign > 0) { gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI), 1.0 - (theta - dt)/Math.PI); } else { gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI), (theta - dt)/Math.PI); } gbuf.vertex3d( 0, starth*radius, 0); } delta -= ds; } // Put the last vertex in that row, // for numerical accuracy we don't use delta // compute from above. delta = startDelta; vx = r*Math.cos(delta); vz = r*Math.sin(delta); gbuf.normal3d( vx*sign, h*sign, vz*sign ); gbuf.texCoord2d(0.75 - delta/(2*Math.PI), t); gbuf.vertex3d( vx*radius, h*radius, vz*radius ); } gbuf.end(); if (i < nstep) { theta += dt; } else { // take care of numerical imprecision theta = Math.PI/2; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -