[Solved] If I lookAt() a geometry… the geometry desappear!

Hy,



I have an geometry “charge” that is a sphere



[java]

Sphere sphereCharge = new Sphere(10, 10, 2f);

charge = new Geometry(“tete”, sphereCharge);

charge.setMaterial(mat);

[/java]



and in the method simpleUpdate, when i look at “Charge”, Charge desapear. (but the camera look at Charge)



[java]

cam.lookAt(charge.getWorldTranslation(), Vector3f.UNIT_Y);

[/java]



Should i do something different ? should i create another Node who ll be at the same position than “charge” ?



Just wondering the best way to do it :wink:



thanks

No, it should work. I guess it might have to do with the “local updates” that @Momoko_Fan built in when you use getWorldXXX without calling rootNode.updateGeometricState() before… Try adding rootNode.updateGeometricState() at the beginning of your update method.

Cheers,

Normen

no sorry rootNode.updateGeometricState() at the beginning of simpleupdate don t solve the problem

in fact, i just discover that "charge didn t desappear, but returned to 0,0,0 local coordinates…

If that happens when you do the rootNode.updateGeometricState() still the problem is most likely in your code.

Hy Normen,



I created an exemple to show the problem



[java]package jme3test.helloworld;



import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.FastMath;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import com.jme3.scene.shape.Sphere;

import com.jme3.system.AppSettings;



public class HelloLookAtMe extends SimpleApplication{



private Geometry charge;

int cpt = 0;



public static void main(String[] args){

HelloLookAtMe app = new HelloLookAtMe();

AppSettings settings = new AppSettings(true);

settings.setResolution(1280, 720);

settings.setFrameRate(60);

app.setSettings(settings);

app.setShowSettings(false);

app.start();

}



@Override

public void simpleInitApp() {

Material mat = new Material(assetManager, “Common/MatDefs/Misc/WireColor.j3md”);

mat.setColor(“m_Color”, ColorRGBA.Blue);



Box boxBase = new Box(Vector3f.ZERO, 2, 2, 2);

Geometry base = new Geometry(“Box”, boxBase);

base.setMaterial(mat);



Sphere sphereCharge = new Sphere(10, 10, 2f);

charge = new Geometry(“tete”, sphereCharge);

charge.setMaterial(mat);



rootNode.attachChild(base);

rootNode.attachChild(charge);



cam.setLocation(new Vector3f(0, 0, 30f));

cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));

cam.setFrustumFar(500);

}



public void simpleUpdate(float tpf) {

rootNode.updateGeometricState();// ?

charge.setLocalTranslation(0, 10*FastMath.sin(cpt++/100.0f), 0);

cam.lookAt(charge.getWorldTranslation(), Vector3f.UNIT_Y);

}

}[/java]



if you comment the last line [java]am.lookAt(charge.getWorldTranslation(), Vector3f.UNIT_Y);[/java], you ll see the ball moving (and camera don t)



if you don t comment it, you ll see the camera folowing the movement of the ball, but the ball stay a the origin point.



What do you think ?

Try to switch lines 50&51 so that updateGeometric() is called after you modified the spatial. If that works the problem lies in the “local updates” as I suspected earlier.

So yeah if updateGeometric() is called after having made the move of the geometry it works well :slight_smile: (sorry i only tried before as sou said)



Thanks for this help, That was very helpfull



Zoff

is there a way to say “solved” for a topic ?

Seems like @Momoko_Fan has to fix something in the local updates then… You can add [solved] before the topic title if you want…

Thanks for the feedback!

Normen