Strange behavior with object.setLocalTranslation()

Hi there!

I believe I am misunderstanding the mechanics of setLocalTranslation…

I am currently using mouse picking to get a location in my world, and then trying to teleport a cube to the new location from the old one. My problem is that the first click I do places the cube in the correct location… subsequent clicks seem to go haywire.



For example:



My cube starts at 0,0,0.

I click at 3,0,0

the cube moves to 3,0,0.

I click again at 3,0,0.

the cube moves to 6,0,0(rather than staying in the same spot)

I click again at 3,0,0

the cube moves to 9,0,0

etc…



it seems like setLocalTranslation is adding x,y,z of wherever I click - to the current x,y,z location of the cube, rather than setting the new x,y,z of the cube to the x,y,z of my clicklocation[outright]. any ideas for avoiding this?



each click:

[java]moveLocation = mark.getWorldTranslation();

//This sets a Vector3f[moveLocation] to the current location of my mousepick[mark]

cubes.setLocalTranslation(moveLocation);

//sets the ‘cubes’ node to ‘moveLocation’

[/java]



What am I doing wrong?

The problem is that you’re assuming that the translation sets the object at an absolute position in the world when in fact it is just a displacement from it’s current position…



If you look at the example you gave then you should be able to see the pattern in it.



What you might try to do is take the difference between the object position and the ‘mark’ position and pass that as your ‘moveLocation’.



HTH,



-Feen

1 Like

Thank you, its very obvious when you point it out like that haha. I have the movement working properly now.

I also have a strange behaviour with the setLocalTranslation-function.

As long as x is < 6, the object will be translated, but as soon as it hits 6, it’s completely gone from the screen. Does anyone have an idea?

[java]

setLocalTranslation(6, 0, 0); // object is not visible

setLocalTranslation(5, 0, 0); // object has been moved by 5 pixels to the right

setLocalTranslation(-20, 0, 0); // object has been moved by 20 pixels to the left

[/java]



The object is of type Sprite (my own class) and uses the setPostion-function I copied from the Picture-class.



Objects derived from the Picture class seem to have no problem at all. :frowning:

I guess you move the mesh instead of the object.

Okay, well, I tested it, to be sure, and Picture class objects now have the same problem.

This is the setPosition()-function of the Picture-class

[java]public void setPosition(float x, float y){

float z = getLocalTranslation().getZ();

setLocalTranslation(x, y, z);

}[/java]

which seemed to have worked before and I have no idea why it doesn’t anymore. :frowning:





Edit:



When I use setPosition on the Picture, it will be set to the specified position. If I set the position of the Sprite to anything > 6, nothing is shown on the screen. Not even Picture. So I guess somewhere I’m messing around with the orldViewProjectionMatrix where I shouldn’t?

Could you post a complete test case of your issue please?

Hey,



this is my (eclipse) project:



http://rapidshare.com/files/456733370/jME_Test.zip



I think some of the classpath’s need to be reset in order for the project to work, but the source files are there. I think it’s just easier to post a zip rather than every source file I feel might contribute to solving the problem. ^^’

Well I meant, a simple test case that would fit in one class, not your complete project.

If it’s an issue with the engine, you should be able to reproduce it easily.

I’m sorry, but i have not enough time to spend on this to setup your project on my side, and debug it.

Okay, I just found out that I forgot to set the QueueBucket and the CullHint for the rootNode. With those two set, I can position the sprite anywhere I want, without it deleting everything from the screen. I still wonder about this odd behaviour, though.

off to read some stuff about QueueBuckets and CullHints