Package com.sun.j3d.utils.geometry

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

/*     */ package com.sun.j3d.utils.geometry;
/*     */
/*     */ import javax.media.j3d.Appearance;
/*     */ import javax.media.j3d.Node;
/*     */ import javax.media.j3d.Shape3D;
/*     */ import javax.vecmath.Vector3f;
/*     */
/*     */ public class Box extends Primitive
/*     */ {
/*     */   public static final int FRONT = 0;
/*     */   public static final int BACK = 1;
/*     */   public static final int RIGHT = 2;
/*     */   public static final int LEFT = 3;
/*     */   public static final int TOP = 4;
/*     */   public static final int BOTTOM = 5;
/*     */   float xDim;
/*     */   float yDim;
/*     */   float zDim;
/* 118 */   int numTexUnit = 1;
/*     */
/* 301 */   private static final float[] verts = { 1.0F, -1.0F, 1.0F, 1.0F, 1.0F, 1.0F, -1.0F, 1.0F, 1.0F, -1.0F, -1.0F, 1.0F, -1.0F, -1.0F, -1.0F, -1.0F, 1.0F, -1.0F, 1.0F, 1.0F, -1.0F, 1.0F, -1.0F, -1.0F, 1.0F, -1.0F, -1.0F, 1.0F, 1.0F, -1.0F, 1.0F, 1.0F, 1.0F, 1.0F, -1.0F, 1.0F, -1.0F, -1.0F, 1.0F, -1.0F, 1.0F, 1.0F, -1.0F, 1.0F, -1.0F, -1.0F, -1.0F, -1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, -1.0F, -1.0F, 1.0F, -1.0F, -1.0F, 1.0F, 1.0F, -1.0F, -1.0F, 1.0F, -1.0F, -1.0F, -1.0F, 1.0F, -1.0F, -1.0F, 1.0F, -1.0F, 1.0F };
/*     */
/* 334 */   private static final double[] tcoords = { 1.0D, 0.0D, 1.0D, 1.0D, 0.0D, 1.0D, 0.0D, 0.0D, 1.0D, 0.0D, 1.0D, 1.0D, 0.0D, 1.0D, 0.0D, 0.0D, 1.0D, 0.0D, 1.0D, 1.0D, 0.0D, 1.0D, 0.0D, 0.0D, 1.0D, 0.0D, 1.0D, 1.0D, 0.0D, 1.0D, 0.0D, 0.0D, 1.0D, 0.0D, 1.0D, 1.0D, 0.0D, 1.0D, 0.0D, 0.0D, 0.0D, 1.0D, 0.0D, 0.0D, 1.0D, 0.0D, 1.0D, 1.0D };
/*     */
/* 368 */   private static final Vector3f[] normals = { new Vector3f(0.0F, 0.0F, 1.0F), new Vector3f(0.0F, 0.0F, -1.0F), new Vector3f(1.0F, 0.0F, 0.0F), new Vector3f(-1.0F, 0.0F, 0.0F), new Vector3f(0.0F, 1.0F, 0.0F), new Vector3f(0.0F, -1.0F, 0.0F) };
/*     */
/*     */   public Box()
/*     */   {
/* 127 */     this(1.0F, 1.0F, 1.0F, 1, null);
/*     */   }
/*     */
/*     */   public Box(float xdim, float ydim, float zdim, Appearance ap)
/*     */   {
/* 142 */     this(xdim, ydim, zdim, 1, ap);
/*     */   }
/*     */
/*     */   public Box(float xdim, float ydim, float zdim, int primflags, Appearance ap, int numTexUnit)
/*     */   {
/* 160 */     this.xDim = xdim;
/* 161 */     this.yDim = ydim;
/* 162 */     this.zDim = zdim;
/* 163 */     this.flags = primflags;
/* 164 */     numTexUnit = numTexUnit;
/*     */     double sign;
/*     */     double sign;
/* 167 */     if ((this.flags & 0x4) != 0)
/* 168 */       sign = -1.0D;
/* 169 */     else sign = 1.0D;
/*     */
/* 175 */     Shape3D[] shape = new Shape3D[6];
/*     */
/* 177 */     GeomBuffer cache = null;
/*     */
/* 179 */     for (int i = 0; i <= 5; i++)
/*     */     {
/* 181 */       cache = getCachedGeometry(8, xdim, ydim, zdim, i, i, primflags);
/*     */
/* 183 */       if (cache != null)
/*     */       {
/* 185 */         shape[i] = new Shape3D(cache.getComputedGeometry());
/* 186 */         this.numVerts += cache.getNumVerts();
/* 187 */         this.numTris += cache.getNumTris();
/*     */       }
/*     */       else
/*     */       {
/* 191 */         GeomBuffer gbuf = new GeomBuffer(4, numTexUnit);
/*     */
/* 193 */         gbuf.begin(1);
/* 194 */         for (int j = 0; j < 2; j++) {
/* 195 */           gbuf.normal3d(normals[i].x * sign, normals[i].y * sign, normals[i].z * sign);
/*     */
/* 198 */           gbuf.texCoord2d(tcoords[(i * 8 + j * 2)], tcoords[(i * 8 + j * 2 + 1)]);
/* 199 */           gbuf.vertex3d(verts[(i * 12 + j * 3)] * xdim, verts[(i * 12 + j * 3 + 1)] * ydim, verts[(i * 12 + j * 3 + 2)] * zdim);
/*     */         }
/*     */
/* 203 */         for (int j = 3; j > 1; j--) {
/* 204 */           gbuf.normal3d(normals[i].x * sign, normals[i].y * sign, normals[i].z * sign);
/*     */
/* 207 */           gbuf.texCoord2d(tcoords[(i * 8 + j * 2)], tcoords[(i * 8 + j * 2 + 1)]);
/* 208 */           gbuf.vertex3d(verts[(i * 12 + j * 3)] * xdim, verts[(i * 12 + j * 3 + 1)] * ydim, verts[(i * 12 + j * 3 + 2)] * zdim);
/*     */         }
/*     */
/* 212 */         gbuf.end();
/* 213 */         shape[i] = new Shape3D(gbuf.getGeom(this.flags));
/* 214 */         this.numVerts = gbuf.getNumVerts();
/* 215 */         this.numTris = gbuf.getNumTris();
/*     */
/* 217 */         if ((primflags & 0x10) == 0) {
/* 218 */           cacheGeometry(8, xdim, ydim, zdim, i, i, primflags, gbuf);
/*     */         }
/*     */
/*     */       }
/*     */
/* 223 */       if ((this.flags & 0x40) != 0) {
/* 224 */         shape[i].setCapability(14);
/* 225 */         shape[i].setCapability(15);
/*     */       }
/*     */
/* 228 */       if ((this.flags & 0x20) != 0) {
/* 229 */         shape[i].setCapability(12);
/*     */       }
/*     */
/* 233 */       addChild(shape[i]);
/*     */     }
/*     */
/* 236 */     if (ap == null)
/* 237 */       setAppearance();
/*     */     else
/* 239 */       setAppearance(ap);
/*     */   }
/*     */
/*     */   public Box(float xdim, float ydim, float zdim, int primflags, Appearance ap)
/*     */   {
/* 244 */     this(xdim, ydim, zdim, primflags, ap, 1);
/*     */   }
/*     */
/*     */   public Shape3D getShape(int partId)
/*     */   {
/* 257 */     if ((partId >= 0) && (partId <= 5))
/*     */     {
/* 259 */       return (Shape3D)getChild(partId);
/* 260 */     }return null;
/*     */   }
/*     */
/*     */   public void setAppearance(Appearance ap)
/*     */   {
/* 277 */     ((Shape3D)getChild(4)).setAppearance(ap);
/* 278 */     ((Shape3D)getChild(3)).setAppearance(ap);
/* 279 */     ((Shape3D)getChild(2)).setAppearance(ap);
/* 280 */     ((Shape3D)getChild(0)).setAppearance(ap);
/* 281 */     ((Shape3D)getChild(1)).setAppearance(ap);
/* 282 */     ((Shape3D)getChild(5)).setAppearance(ap);
/*     */   }
/*     */
/*     */   public Appearance getAppearance(int partId)
/*     */   {
/* 296 */     if ((partId > 5) || (partId < 0)) return null;
/* 297 */     return getShape(partId).getAppearance();
/*     */   }
/*     */
/*     */   public Node cloneNode(boolean forceDuplicate)
/*     */   {
/* 402 */     Box b = new Box(this.xDim, this.yDim, this.zDim, this.flags, getAppearance());
/* 403 */     b.duplicateNode(this, forceDuplicate);
/* 404 */     return b;
/*     */   }
/*     */
/*     */   public void duplicateNode(Node originalNode, boolean forceDuplicate)
/*     */   {
/* 434 */     super.duplicateNode(originalNode, forceDuplicate);
/*     */   }
/*     */
/*     */   public float getXdimension()
/*     */   {
/* 443 */     return this.xDim;
/*     */   }
/*     */
/*     */   public float getYdimension()
/*     */   {
/* 452 */     return this.yDim;
/*     */   }
/*     */
/*     */   public float getZdimension()
/*     */   {
/* 461 */     return this.zDim;
/*     */   }
/*     */ }

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

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

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.