Package com.sun.j3d.utils.geometry

Source Code of com.sun.j3d.utils.geometry.Cone

/*     */ package com.sun.j3d.utils.geometry;
/*     */
/*     */ import javax.media.j3d.Appearance;
/*     */ import javax.media.j3d.Node;
/*     */ import javax.media.j3d.Shape3D;
/*     */
/*     */ public class Cone extends Primitive
/*     */ {
/*     */   float radius;
/*     */   float height;
/*     */   int xdivisions;
/*     */   int ydivisions;
/*     */   static final int MID_REZ_DIV_X = 15;
/*     */   static final int MID_REZ_DIV_Y = 1;
/*     */   public static final int BODY = 0;
/*     */   public static final int CAP = 1;
/*     */
/*     */   public Cone()
/*     */   {
/*  95 */     this(1.0F, 2.0F, 1, 15, 1, null);
/*     */   }
/*     */
/*     */   public Cone(float radius, float height)
/*     */   {
/* 107 */     this(radius, height, 1, 15, 1, null);
/*     */   }
/*     */
/*     */   public Cone(float radius, float height, Appearance ap)
/*     */   {
/* 122 */     this(radius, height, 1, 15, 1, ap);
/*     */   }
/*     */
/*     */   public Cone(float radius, float height, int primflags, Appearance ap)
/*     */   {
/* 136 */     this(radius, height, primflags, 15, 1, ap);
/*     */   }
/*     */
/*     */   public Shape3D getShape(int partId)
/*     */   {
/* 148 */     if ((partId > 1) || (partId < 0)) return null;
/* 149 */     return (Shape3D)getChild(partId);
/*     */   }
/*     */
/*     */   public void setAppearance(Appearance ap)
/*     */   {
/* 160 */     ((Shape3D)getChild(0)).setAppearance(ap);
/* 161 */     ((Shape3D)getChild(1)).setAppearance(ap);
/*     */   }
/*     */
/*     */   public Appearance getAppearance(int partId)
/*     */   {
/* 175 */     if ((partId > 1) || (partId < 0)) return null;
/* 176 */     return getShape(partId).getAppearance();
/*     */   }
/*     */
/*     */   public Cone(float radius, float height, int primflags, int xdivision, int ydivision, Appearance ap)
/*     */   {
/* 202 */     Shape3D[] shape = new Shape3D[2];
/* 203 */     this.radius = radius;
/* 204 */     this.height = height;
/* 205 */     this.xdivisions = xdivision;
/* 206 */     this.ydivisions = ydivision;
/* 207 */     this.flags = primflags;
/* 208 */     boolean outside = (this.flags & 0x4) == 0;
/* 209 */     Quadrics q = new Quadrics();
/* 210 */     GeomBuffer gbuf = null;
/*     */
/* 212 */     GeomBuffer cache = getCachedGeometry(4, radius, 0.0F, height, xdivision, ydivision, primflags);
/*     */
/* 215 */     if (cache != null)
/*     */     {
/* 217 */       shape[0] = new Shape3D(cache.getComputedGeometry());
/* 218 */       this.numVerts += cache.getNumVerts();
/* 219 */       this.numTris += cache.getNumTris();
/*     */     }
/*     */     else
/*     */     {
/* 224 */       gbuf = q.coneTop(height / 2.0D - height / this.ydivisions, radius / this.ydivisions, height / this.ydivisions, this.xdivisions, 1.0D - 1.0D / this.ydivisions, outside);
/*     */
/* 228 */       shape[0] = new Shape3D(gbuf.getGeom(this.flags));
/* 229 */       this.numVerts += gbuf.getNumVerts();
/* 230 */       this.numTris += gbuf.getNumTris();
/* 231 */       if ((primflags & 0x10) == 0) {
/* 232 */         cacheGeometry(4, radius, 0.0F, height, xdivision, ydivision, primflags, gbuf);
/*     */       }
/*     */
/*     */     }
/*     */
/* 239 */     if (this.ydivisions > 1) {
/* 240 */       cache = getCachedGeometry(64, radius, 0.0F, height, xdivision, ydivision, primflags);
/*     */
/* 242 */       if (cache != null)
/*     */       {
/* 244 */         shape[0].addGeometry(cache.getComputedGeometry());
/* 245 */         this.numVerts += cache.getNumVerts();
/* 246 */         this.numTris += cache.getNumTris();
/*     */       }
/*     */       else {
/* 249 */         gbuf = q.coneBody(-(height / 2.0D), height / 2.0D - height / this.ydivisions, radius, radius / this.ydivisions, this.xdivisions, this.ydivisions - 1, 1.0D / this.ydivisions, outside);
/*     */
/* 254 */         shape[0].addGeometry(gbuf.getGeom(this.flags));
/* 255 */         this.numVerts += gbuf.getNumVerts();
/* 256 */         this.numTris += gbuf.getNumTris();
/* 257 */         if ((primflags & 0x10) == 0) {
/* 258 */           cacheGeometry(64, radius, 0.0F, height, xdivision, ydivision, primflags, gbuf);
/*     */         }
/*     */       }
/*     */
/*     */     }
/*     */
/* 264 */     if ((this.flags & 0x40) != 0) {
/* 265 */       shape[0].setCapability(14);
/* 266 */       shape[0].setCapability(15);
/*     */     }
/*     */
/* 269 */     if ((this.flags & 0x20) != 0) {
/* 270 */       shape[0].setCapability(12);
/*     */     }
/*     */
/* 273 */     addChild(shape[0]);
/*     */
/* 276 */     cache = getCachedGeometry(32, radius, radius, -height / 2.0F, xdivision, xdivision, primflags);
/*     */
/* 279 */     if (cache != null)
/*     */     {
/* 281 */       shape[1] = new Shape3D(cache.getComputedGeometry());
/* 282 */       this.numVerts += cache.getNumVerts();
/* 283 */       this.numTris += cache.getNumTris();
/*     */     }
/*     */     else {
/* 286 */       gbuf = q.disk(radius, xdivision, -height / 2.0D, !outside);
/*     */
/* 288 */       shape[1] = new Shape3D(gbuf.getGeom(this.flags));
/* 289 */       this.numVerts += gbuf.getNumVerts();
/* 290 */       this.numTris += gbuf.getNumTris();
/* 291 */       if ((primflags & 0x10) == 0) {
/* 292 */         cacheGeometry(32, radius, radius, -height / 2.0F, xdivision, xdivision, primflags, gbuf);
/*     */       }
/*     */
/*     */     }
/*     */
/* 297 */     if ((this.flags & 0x40) != 0) {
/* 298 */       shape[1].setCapability(14);
/* 299 */       shape[1].setCapability(15);
/*     */     }
/*     */
/* 302 */     if ((this.flags & 0x20) != 0) {
/* 303 */       shape[1].setCapability(12);
/*     */     }
/*     */
/* 319 */     addChild(shape[1]);
/*     */
/* 321 */     if (ap == null)
/* 322 */       setAppearance();
/*     */     else
/* 324 */       setAppearance(ap);
/*     */   }
/*     */
/*     */   public Node cloneNode(boolean forceDuplicate)
/*     */   {
/* 351 */     Cone c = new Cone(this.radius, this.height, this.flags, this.xdivisions, this.ydivisions, getAppearance());
/*     */
/* 353 */     c.duplicateNode(this, forceDuplicate);
/* 354 */     return c;
/*     */   }
/*     */
/*     */   public void duplicateNode(Node originalNode, boolean forceDuplicate)
/*     */   {
/* 384 */     super.duplicateNode(originalNode, forceDuplicate);
/*     */   }
/*     */
/*     */   public float getRadius()
/*     */   {
/* 393 */     return this.radius;
/*     */   }
/*     */
/*     */   public float getHeight()
/*     */   {
/* 402 */     return this.height;
/*     */   }
/*     */
/*     */   public int getXdivisions()
/*     */   {
/* 411 */     return this.xdivisions;
/*     */   }
/*     */
/*     */   public int getYdivisions()
/*     */   {
/* 420 */     return this.ydivisions;
/*     */   }
/*     */ }

/* Location:           Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name:     com.sun.j3d.utils.geometry.Cone
* JD-Core Version:    0.6.2
*/
TOP

Related Classes of com.sun.j3d.utils.geometry.Cone

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.