Eu consigo fazer uma transformação num objeto normal(rotação, escala, translação) e tal, mas a minha duvida é a seguinte: como resgatar os novos valores do vértice do meu objeto(Shape3D) após aplicada uma transformação? vou colocar o meu codigo abaixo para deixar mais claro oq eu quero.
Classe principal:
public class Teste extends JApplet {
public Teste() {
this.getContentPane().setLayout(new BorderLayout());
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas3D = new Canvas3D(config);
this.getContentPane().add("Center", canvas3D);
TexturedPlane p1 = new TexturedPlane();
TexturedPlane p2 = new TexturedPlane();
BranchGroup bg = new BranchGroup();
bg.addChild(p1);
Transform3D rotate = new Transform3D();
rotate.rotY(Math.toRadians(120));
Transform3D translate = new Transform3D();
translate.setTranslation(new Vector3f(1,0f,0f));
Transform3D translateCima = new Transform3D();
translateCima.setTranslation(new Vector3f(1f,0f,0f));
translate.mul(translateCima);
translate.mul(rotate);
TransformGroup objRotate = new TransformGroup(translate);
objRotate.addChild(p2);
bg.addChild(objRotate);
QuadArray g = (QuadArray)p2.getGeometry();
Point3f pp = new Point3f();
g.getCoordinate(3, pp);
//imprime o vertice 3 do Shape3D (nao alterado)
System.out.println(pp);
bg.compile();
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
simpleU.getViewingPlatform().setNominalViewingTransform();
}
}
Objeto TexturedPlane(peguei no tutorial da sun)
public class TexturedPlane extends Shape3D {
TexturedPlane(String filename) {
if (NewTextureLoader.getImageObserver() == null)
System.out.println(“call NewTextureLoader.setImageObserver()”);
this.setGeometry(createGeometry());
if(filename != “”)
this.setAppearance(createAppearance(filename));
}
Geometry createGeometry(){
QuadArray plane = new QuadArray(4, GeometryArray.COORDINATES
| GeometryArray.TEXTURE_COORDINATE_2
);
Point3f p = new Point3f(-1.0f, 1.0f, 0.0f);
plane.setCoordinate(0, p);
p.set(-1.0f, -1.0f, 0.0f);
plane.setCoordinate(1, p);
p.set(1.0f, -1.0f, 0.0f);
plane.setCoordinate(2, p);
p.set(1.0f, 1.0f, 0.0f);
plane.setCoordinate(3, p);
Point2f q = new Point2f( 0.0f, 1.0f);
plane.setTextureCoordinate(0, q);
q.set(0.0f, 0.0f);
plane.setTextureCoordinate(1, q);
q.set(1.0f, 0.0f);
plane.setTextureCoordinate(2, q);
q.set(1.0f, 1.0f);
plane.setTextureCoordinate(3, q);
return plane;
}
Appearance createAppearance(String filename) {
Appearance appear = new Appearance();
System.out.println("TexturedPlane attempt to load file: "+filename);
TextureLoader loader = new NewTextureLoader(filename);
ImageComponent2D image = loader.getImage();
if(image == null) {
System.out.println("load failed for texture: "+filename);
}
System.out.println("Image width = " + image.getWidth());
System.out.println("Image height = " + image.getHeight());
// can't use parameterless constuctor
Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA,
image.getWidth(), image.getHeight());
texture.setImage(0, image);
texture.setEnable(true);
texture.setMagFilter(Texture.NICEST);
appear.setTexture(texture);
appear.setTransparencyAttributes(
new TransparencyAttributes(TransparencyAttributes.FASTEST, 0.1f));
return appear;
}
}