Hello,
Does anyone know how to fix BitmapText fixed position?
After camera move from (0,0,0) to anywhere, BitmapText position is wrong if create new instance.
I attached BitmapText to GUINode but it behave in not GUIObject.
How do I fix BitmapText same position?
Thanks,
Karakuri
if you attach it to the guiNode, it shouldn’t move. You tried TestBitmapText?
You will need to show us code or we cannot help. Normally BitmapText works just fine.
The label is a 3d object and not 2d on your display. If you want to move the label, you have to use label.setLocalRotation().
EDIT: Oops, I meant label.setLocalTranslation(x,y,z)
Keep in mind that if you attach it to the GUINode, it will be on your display but in 2d screen coordinates. Hope that I remember it correcty.
Thank you for answer my question.
I solve that problem.
The problem was following image.
When I change camera location by Camera::setLocation(loc)
loc instance from Location.ZERO
from
to
But change camera location by loc instance from Camera::getLocation
succeed.
You will have to show us code. Something very strange is going on and it sounds like you are sharing vector instances that you shouldn’t be.
All code is too long to paste this thread, I show moving camera pos code.
Maybe I fail in this Class Constructor.
[java]
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package objects;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import timer.GameTimer;
/**
*
-
@author Karakuri
*/
public class GameCamera extends GameObject {
private static Camera camera;
private Vector3f location;
private Quaternion rotation;
private GameMovement forwardMove;
private GameMovement backwardMove;
private GameMovement turnleftMove;
private GameMovement turnrightMove;
public static void setCamera(Camera camera) {
GameCamera.camera = camera;
}
public GameCamera() {
location = Vector3f.ZERO;
rotation = Quaternion.DIRECTION_Z;
}
public void apply() {
camera.setLocation(location);
camera.setRotation(rotation);
camera.update();
}
public void moveForward(final float speed,final long time) {
if(forwardMove==null && turnleftMove==null && turnrightMove==null) {
final GameTimer timer = new GameTimer();
final Vector3f prevDir = rotation.getRotationColumn(2);
forwardMove = new GameMovement() {
private Vector3f prev;
@Override
public void move() {
if(timer.getTime()>=time) {
location.addLocal(prev.negate());
location.addLocal(prevDir.normalize().mult(speed * time / 1000));
stopForward();
return;
}
if(prev!=null) location.addLocal(prev.negate());
prev = prevDir.normalize().mult(speed * (timer.getCurrentTicks()-timer.getStartTicks()) / 1000);
location.addLocal(prev);
timer.reset();
}
};
addMovement(forwardMove);
}
}
public void moveBackward(final float speed,final long time) {
if(backwardMove==null && turnleftMove==null && turnrightMove==null) {
final GameTimer timer = new GameTimer();
final Vector3f prevDir = rotation.getRotationColumn(2);
backwardMove = new GameMovement() {
private Vector3f prev;
@Override
public void move() {
if(timer.getTime()>=time) {
location.addLocal(prev.negate());
location.addLocal(prevDir.negate().normalize().mult(speed * time / 1000));
stopBackward();
return;
}
if(prev!=null) location.addLocal(prev.negate());
prev = prevDir.negate().normalize().mult(speed * (timer.getCurrentTicks()-timer.getStartTicks()) / 1000);
location.addLocal(prev);
timer.reset();
}
};
addMovement(backwardMove);
}
}
public void turnLeft(final float angle,final long time) {
if(turnleftMove==null) {
final GameTimer timer = new GameTimer();
turnleftMove = new GameMovement() {
private Quaternion prev;
@Override
public void move() {
if(timer.getTime()>=time) {
rotation.multLocal(prev.inverse());
rotation.multLocal(new Quaternion().fromAngles(0f, FastMath.PI * 2 * angle * time / 360 / 1000, 0f));
stopTurnLeft();
return;
}
if(prev!=null) rotation.multLocal(prev.inverse());
prev = new Quaternion().fromAngles(0f, FastMath.PI * 2 * angle * (timer.getCurrentTicks()-timer.getStartTicks()) / 360 / 1000, 0f);
rotation.multLocal(prev);
timer.reset();
}
};
addMovement(turnleftMove);
}
}
public void turnRight(final float angle,final long time) {
if(turnrightMove==null) {
final GameTimer timer = new GameTimer();
turnrightMove = new GameMovement() {
private Quaternion prev;
@Override
public void move() {
if(timer.getTime()>=time) {
rotation.multLocal(prev.inverse());
rotation.multLocal(new Quaternion().fromAngles(0f, -(FastMath.PI * 2 * angle * time / 360 / 1000), 0f));
stopTurnRight();
return;
}
if(prev!=null) rotation.multLocal(prev.inverse());
prev = new Quaternion().fromAngles(0f, -(FastMath.PI * 2 * angle * (timer.getCurrentTicks()-timer.getStartTicks()) / 360 / 1000), 0f);
rotation.multLocal(prev);
timer.reset();
}
};
addMovement(turnrightMove);
}
}
public void stopForward() {
if(forwardMove!=null) {
forwardMove.destroy();
forwardMove = null;
}
}
public void stopBackward() {
if(backwardMove!=null) {
backwardMove.destroy();
backwardMove = null;
}
}
public void stopTurnLeft() {
if(turnleftMove!=null) {
turnleftMove.destroy();
turnleftMove = null;
}
}
public void stopTurnRight() {
if(turnrightMove!=null) {
turnrightMove.destroy();
turnrightMove = null;
}
}
public float getX() {
return location.x;
}
public float getY() {
return location.y;
}
public float getZ() {
return location.z;
}
public String getDirectionString() {
Vector3f vec = rotation.getRotationColumn(2);
if(vec.getZ() > 0.5) {
return "N";
} else if(vec.getX() > 0.5) {
return "W";
} else if(vec.getX() < -0.5) {
return "E";
} else if(vec.getZ() < -0.5) {
return "S";
}
return "";
}
}
[/java]
I fixed to this.
[java]
public GameCamera() {
location = camera.getLocation().clone().set(Vector3f.ZERO);
rotation = camera.getRotation().clone().set(Quaternion.DIRECTION_Z);
}
[/java]
So I solve that problem.
thanks.
ka_rakuri said:
[java]
location = Vector3f.ZERO;
rotation = Quaternion.DIRECTION_Z;
[/java]
Those are also a problem. It looks like you set them directly to the references and then later modify them. So Vector3f.ZERO and Quaternion.DIRECTION_Z will be modified from their original values.
...and that's very very bad.
Kudos to you then because when I see a “It’s fixed” I just barely skim and leave the topic.
madjack said:
Kudos to you then because when I see a "It's fixed" I just barely skim and leave the topic. ;)
Heheh... yeah, well, this: "But change camera location by loc instance from Camera::getLocation succeed." scared me. Since there was at least one way of interpreting that to mean something very bad.