# Positionning problem

Hi there,

I’m having a very hard time with pivot and geometry positionning.

I create a circle and then displace it using its node. Geo/node local/world translations say it’s at the right place (50, 50, 50 and ofc 0, 0, 0 for geo localTranslation) but in fact it’s at 1400, 100, 1400. The problem is that I can place other circles correctly.

I made some tests, and it’s like the position vector is being multiplicated by some sort of a constant, though no multiplications are performed, and I didn’t set any constant to this value.

Do you have any clue?

supply the code you are using please, or better a testcase.

you should post the code.

But just a guess: if you are using the same Vector object for multiple nodes/geoms then the references will be shared and other objects using that vector will move as well.

Well, my goal is to create a solar system, and to put a circle around picked star/planet/asteroid etc.

First I create a star :

[java]

public star(…)

{

pivot = new Node();

pivot.attachChild(geometry);

}

[/java]

Then displace it to the randomed solar system location :

[java]

star.getPivot().move(position);

pivot.attachChild(star.getPivot());

[/java]

(where pivot is the pivot of the solar system, we then just need to attach this pivot to the rootNode to make the solar system appears)

Then I create numerous planets :

[java]

public planet(…)

{

pivot = new Node();

pivot.attachChild(geometry);

}

[/java]

That I displace at randomed locations too :

[java]

p.getGeometry().move(pos);

pivot.attachChild(p.getPivot());

[/java]

(note : I displace geometry here, because pivot will be centered at the star, so that I can make planets rotate around the star)

And then I create the relation :

[java]

public BinaryTuple(…)

{

Vector3f pos = planet.getGeometry().getLocalTranslation();

// To directly manipulate the planet pivot when willing to make the planet rotate around the star.

this.pivot = planet.getPivot();

pivot.move(star.getGeometry().getWorldTranslation());

// The circle representing the orbit is centered at the star world position.

WireframeCircle orbitCircle = new WireframeCircle(…, star.getGeometry().getWorldTranslation(), …);

// We don’t need to recall the circle itself, just the pivot.

this.orbit = orbitCircle.getPivot();

// To have the circle correctly positioned to describe the orbiting path of the planet.

this.orbit.lookAt(pos, rotationUp);

star.getPivot().attachChild(orbit);

}

[/java]

All of this works perfectly; I show it to you in case it works by chance, and that my bug would come from here.

Now, the code that is really bugging :

[java]

// geometry is the geometry of the picked entity.

public static void setMark(Geometry geometry, …)

{

// Mark is the circle used to show picked entity.

if (Picking.mark != null)

Picking.detachMark();

// Used to create a big enough circle - maybe there is a best way? Since I also need to circle asteroids, ships, wreckages, etc.

BoundingSphere boundingSphere = new BoundingSphere();

geometry.getMesh().setBound(boundingSphere);

geometry.getMesh().updateBound();

// We retrieve the pivot of the entity, in this case the pivot of the planet.

Picking.attachedToPivot = AbstractSpaceEntities.getEntityByName(geometry.getName()).getPivot();

Picking.mark = new WireframeCircle(Environment.assetManager, color, new Vector3f(1, 0, 0), radius, GraphicConfiguration.CIRCLE_DEFINITION);

System.out.println(“geometry world translation:” + geometry.getWorldTranslation() + “n”

• "mark pivot world translation:" + Picking.mark.getPivot().getWorldTranslation() + "n"
• "mark geometry world translation:" + Picking.mark.getGeometry().getWorldTranslation());

System.out.println("geometry local translation:" + geometry.getLocalTranslation() + "n"
• "mark pivot local translation:" + Picking.mark.getPivot().getLocalTranslation() + "n"
• "mark geometry local translation:" + Picking.mark.getGeometry().getLocalTranslation());

Picking.attachedToPivot.attachChild(Picking.mark.getPivot());

}

[/java]

And my System.out.println show the following results :

geometry world translation:(64.99171, 28.014713, -3.2784812)

mark pivot world translation:(1.0, 0.0, 0.0)

mark geometry world translation:(1.0, 0.0, 0.0)

geometry local translation:(64.99171, 28.014713, -3.2784812)

mark pivot local translation:(1.0, 0.0, 0.0)

mark geometry local translation:(0.0, 0.0, 0.0)

But the mark is not at the indicated location.

This is suspicious:

[java]p.getGeometry().move(pos);

pivot.attachChild(p.getPivot());[/java]

If ‘p’ is a planet, just make planet a node and move the planed (node) itself, not its child geometry node. Or else it is still at 0,0,0 and its attached children will also be at 0,0,0 (not counting their local translation).

Your ‘Picking’ class is scary, it’s all public static methods and variables, your setMark method is also static. Those should be removed to clean up all of these floating references to pivots, marks, and their locations.

When you print the stuff above, mark has never been attached to anything to local and world translation will be the same.

Is that the issue?

@Sploreg : Well, ‘p’ is an instance of a class named Planet. It contains a geometry, a pivot (node) to which the geometry is attached, and various methods to manipulate the planet (getAge(), etc).

I move the planet pivot to the location of the star. Then, the geometry is moved to place the planet mesh on its orbit. To rotate the planet, I just then need to make the pivot rotate.

I know about this static problem, I was talking about it to my brother yesterday. The problem is, I don’t need to instantiate it, but since it’s a particular behaviour, I find it logical to make a class for picking. It doesn’t please me that much, but I don’t think it should be put in the class where I manage input, especially because I have more than one method used for picking. About static, is there a way to access assetManager, cam and all without having to pass it to a method whenever I need them? For this I created the Environment class, so I have static references to them for this party, but it doesn’t please me either.

What should be removed? The references or the class?

@pspeed : mark is a class (WireframeCircle) containing a geometry built around a mesh representing a circle. I then attach the pivot holding the geometry with :

[java]

Picking.attachedToPivot.attachChild(Picking.mark.getPivot());

[/java]

Should attach it before, indeed.

Used this code :

[java]

Picking.attachedToPivot = AbstractSpaceEntities.getEntityByName(geometry.getName()).getPivot();

Picking.mark = new WireframeCircle(Environment.assetManager, color, geometry.getWorldTranslation(), radius, GraphicConfiguration.CIRCLE_DEFINITION);

Picking.attachedToPivot.attachChild(Picking.mark.getPivot());

System.out.println("geometry world translation:" + geometry.getWorldTranslation() + "n"

• "mark pivot world translation:" + Picking.mark.getPivot().getWorldTranslation() + "n"
• "mark geometry world translation:" + Picking.mark.getGeometry().getWorldTranslation());

System.out.println("geometry local translation:" + geometry.getLocalTranslation() + "n"
• "mark pivot local translation:" + Picking.mark.getPivot().getLocalTranslation() + "n"
• "mark geometry local translation:" + Picking.mark.getGeometry().getLocalTranslation());

[/java]

And I obtained this :

geometry world translation:(39.473045, -1.0965476, 16.873283)

mark pivot world translation:(39.473045, -1.0965476, 16.873283)

mark geometry world translation:(78.94609, -2.1930952, 33.746567)

geometry local translation:(39.473045, -1.0965476, 16.873283)

mark pivot local translation:(39.473045, -1.0965476, 16.873283)

mark geometry local translation:(39.473045, -1.0965476, 16.873283)

But by using a camera position indicator, it appears the mark was at 500, -2, 500.

There is no way to statically access the assetManager unless you create a static reference yourself, which you have with your Environment class. It’s generally better practice to pass the reference around, but sometimes you just need access to it and getting it statically is the most convenient.

When you say you are “moving the planet pivot to the location of the star” you should just attach the pivot as a child of the star, no moving it. You then set the localTranslation of the child pivot node to move it away from the center pivot. Then when you rotate the center pivot (the parent) the child will rotate around in an orbit.

Indeed, it would finally be better to attach the planet pivot to the star pivot.

Nethertheless, it wouldn’t still correct my original problem. Do you see something that could explain the fact every positions are correct, but still, the circle appears totaly elsewhere?

P.S. : Finally, I’ll try to get rid of static thingy; but I don’t see how to make my Picking class if it’s not static.

Can you paste the code that prints the camera location? It could just be that that is wrong

[java]

this.positionRealText.setText(Environment.camera.getLocation().toString());

[/java]

Even if it’s not the good location, the circle really isn’t at 50, 50, 50.