X, Y, Z fields in Geometry Class?

Hi,

x,y,z fields not exists in the Geometry Class, How to access there ?



Thanks in advance.

You are not supposed to extend Geometry. Its a spatial, so its got a translation you can change.

Humm, I poorly explained, for example:

This is the code of the 1st tutorial “Hello SimpleApplication”:

[java]package jme3test;

import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import com.jme3.math.ColorRGBA;

/** Sample 1 - how to get started with the most simple JME 3 application.

  • Display a blue 3D cube and view from all sides by
  • moving the mouse and pressing the WASD keys. */

    public class HelloJME3 extends SimpleApplication {

    public static void main(String[] args){

    HelloJME3 app = new HelloJME3();

    app.start();

    }

    @Override

    public void simpleInitApp() {

    Box b = new Box(Vector3f.ZERO, 1, 1, 1);

    Geometry geom = new Geometry("Box", b);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    mat.setColor("Color", ColorRGBA.Blue);

    geom.setMaterial(mat);

    rootNode.attachChild(geom);

    }

    }[/java]

    And I want to do something like that:

    [java]if (geom.position.y == 100) { System.out.println("ok"); }[/java]

    How I can do this?

You are not supposed to change the values like this. Use setLocalTranslation()

I don’t change any values, I just check one value.



How I can access Y axis translation from getLocalTranslation(), something like that:[java] if (geom.getLocalTranslation(y) == 100 { System.out.println(“ok”); }[/java]

getLocalTranslation().getX()? :roll:

Thanks a lot :smiley: , and sorry for this issue but I come from AS3, I have not used the Java.

Yeah. In java its bad style to access a field directly, you always use getters and setters. Even if it seems like “more work” don’t worry, the compiler takes care of this. In addition to that the location of a spatial should always be changed by using setLocalTranslation(vector) so that the necessary update of the scene graph gets triggered.