1 16 17 package com.buchuki.ensmer.object; 18 19 import javax.media.j3d.*; 20 21 27 public class Square extends Shape3D { 28 29 32 public Square() { 33 this(1f, 1f); 34 } 35 36 42 public Square(float width, float height) { 43 QuadArray quad = new QuadArray(4, QuadArray.COORDINATES | QuadArray.NORMALS | QuadArray.TEXTURE_COORDINATE_2); 44 quad.setCapability(quad.ALLOW_COORDINATE_WRITE); 45 setCapability(ALLOW_GEOMETRY_READ); 46 setGeometry(quad); 47 setSize(width, height); 48 quad.setNormals(0, new float[] { 49 0, 0, 1, 50 0, 0, 1, 51 0, 0, 1, 52 0, 0, 1 53 }); 54 quad.setTextureCoordinates(0, 0, new float[] { 55 0, 1, 56 0, 0, 57 1, 0, 58 1, 1 59 }); 60 Appearance app = new Appearance(); 61 PolygonAttributes polyAtt = new PolygonAttributes(); 62 polyAtt.setCullFace(polyAtt.CULL_NONE); 63 polyAtt.setBackFaceNormalFlip(true); 64 app.setPolygonAttributes(polyAtt); 65 setAppearance(app); 66 } 67 68 74 public void setSize(float width, float height) { 75 QuadArray quad = (QuadArray) getGeometry(); 76 float w = width / 2; 77 float h = height / 2; 78 quad.setCoordinates(0, new float[] { 79 -w, h, 0, 80 -w, -h, 0, 81 w, -h, 0, 82 w, h, 0 83 }); 84 } 85 } 86 | Popular Tags |