Hello,
i want to print the coordinates of my moving box on the screen, but i couldnt find a method which returns the current position as a Vector3f-coordinate. There is only a getCenter(), returning the Point where the box was created, but not with the manipulated value.
Do you know how to print the coordinates of a moving box on the screen?
EDIT:
Here is my code:
[java]
import com.jme3.app.DebugKeysAppState;
import com.jme3.app.FlyCamAppState;
import com.jme3.app.SimpleApplication;
import com.jme3.app.StatsAppState;
import com.jme3.font.BitmapText;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.util.TangentBinormalGenerator;
public class Main extends SimpleApplication {
Box b;
Geometry g;
Material m;
DirectionalLight light;
DirectionalLight light2;
DirectionalLight light3;
DirectionalLight light4;
DirectionalLight light5;
DirectionalLight light6;
BitmapText text;
BitmapText text2;
@Override
public void simpleInitApp() {
//mache Hintergrund Weiss
viewPort.setBackgroundColor(new ColorRGBA(0.2f, 0.1f, 0.1f, 1f));
//mache alle Configs weg
stateManager.detach(stateManager.getState(StatsAppState.class));//Statistiken weg
stateManager.detach(stateManager.getState(FlyCamAppState.class));//Kamera weg
stateManager.detach(stateManager.getState(DebugKeysAppState.class));//Keys weg
//Oberste Textzeile
guiNode.detachAllChildren();
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
text = new BitmapText(guiFont, false);
text.setSize(guiFont.getCharSet().getRenderedSize());
text.setText("hieraus wird tpf");
text.setLocalTranslation(10, 60, 0);
guiNode.attachChild(text);
//unterste Textzeile
text2 = new BitmapText(guiFont, false);
text2.setSize(guiFont.getCharSet().getRenderedSize());
text2.setText("hieraus wird was anderes");
text2.setLocalTranslation(10, 30, 0);
guiNode.attachChild(text2);
//mache box, texturiere
b = new Box(new Vector3f(4,0,0), 0.5f, 0.5f, 0.5f);
TangentBinormalGenerator.generate(b);
m = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
m.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
m.setTexture("NormalMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
m.setColor("Specular",ColorRGBA.Gray);
m.setColor("Diffuse",ColorRGBA.White);
m.setFloat("Shininess", 5f);
g = new Geometry("box",b);
g.setMaterial(m);
//mache Kamera auf box gucken
//cam.lookAt(g.getLocalTranslation(), Vector3f.UNIT_Y);
//mache Lichter von jeder Richtung
light = new DirectionalLight();
light.setDirection(new Vector3f(1, 0, 0));
light2 = new DirectionalLight();
light2.setDirection(new Vector3f(-1, 0, 0));
light3 = new DirectionalLight();
light3.setDirection(new Vector3f(0, 1, 0));
light4 = new DirectionalLight();
light4.setDirection(new Vector3f(0, -1, 0));
light5 = new DirectionalLight();
light5.setDirection(new Vector3f(0, 0, 1));
light6 = new DirectionalLight();
light6.setDirection(new Vector3f(0, 0, -1));
//adde alles zum sceneGraph
rootNode.addLight(light);
rootNode.addLight(light2);
rootNode.addLight(light3);
rootNode.addLight(light4);
rootNode.addLight(light5);
rootNode.addLight(light6);
rootNode.attachChild(g);
}
@Override
public void simpleUpdate(float tpf) {
String str_tpf = String.valueOf(tpf);
text.setText("tpf=" + str_tpf);
g.rotate(0, 0.1f*tpf, 0);
text2.setText("center_at=");
}
public static void main(String[] args) {
Main m = new Main();
m.start();
}
}
[/java]
Here in simpleUpdate() the text2-variable should display the center-coordinate.
g.getLocalTranslation ?
hey,
that is because the Box is only extended from the mesh and the position of a mesh is dependent on the geometries position. Take a look at Geometry.localTranslation and Geometry.worldTranslation. Or you can calculate from the boundingvolume or the vertice list. Or as most likely at some point you extend the box anyways or have you own objects you can as well just save the center on creation and keep it consistent when movin or write your own getCenter().
also, doing this:
[java]new Box(new Vector3f(4,0,0), 0.5f, 0.5f, 0.5f); [/java]
will make it look 4 units right, but have a local translation of (0, 0, 0);
Use Vector3f.ZERO and move/setLocalTranslation (4, 0, 0) instead
@zarch said:
g.getLocalTranslation ?
Tried this before, does print (0,0,0), so i can say that it doesnt work for me.
@zarch said:
Try reading @wezrule's post, and then printing the translation again keeping that in mind ;)
Cool it worked, but i guess i have to check out how quarternions work to get the same rotation as with initializing the box at location (4,0,0).
A useful tutorial about scene graph and transforms:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies