@pspeed said:
Step 1: put System.out.println() calls at the top of your update methods.
Step 2: figure out what was wrong in your code after you see a ton of printlns in your console.
Remove all faulty assumptions and then the answer will be clear.
Ok, i did the testCase and found the issue. The bug happens with ChaseCamera.
If I use ChaseCamera and attach a Control to rootNode then i get the bug with update.
And also iget the same bug if i convert the Control to AppState.
Here is my another video demonsteration:
__
[video]http://www.youtube.com/watch?v=x87eUW5LRvw&feature=youtu.be[/video]
__
_
Here is my code:
There are 2 classes
AATest.java:
[java]
package com.swe;
import com.jme3.app.SimpleApplication;
import com.jme3.font.BitmapText;
import com.jme3.input.ChaseCamera;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
public class AATest extends SimpleApplication implements AnalogListener{
public static void main(String[] args) {
AATest app = new AATest();
AppSettings aps = new AppSettings(true);
aps.setVSync(true);
app.setSettings(aps);
app.setShowSettings(false);
app.start();
}
private Node cameraNode;
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(50f);
flyCam.setEnabled(false);
cameraNode = new Node();
rootNode.attachChild(cameraNode);
ChaseCamera cama = new ChaseCamera(cam, cameraNode, inputManager);
cama.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
cama.setEnabled(true);
AAControl aps = new AAControl(this);
Node tempNode = new Node();
rootNode.attachChild(tempNode);
// here is a BUG if I attach the Control to RootNode
// but with tempNode the Control work OK!
rootNode.addControl(aps);
setupKeys();
generateBoxes();
// gui
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
BitmapText ch = new BitmapText(guiFont, false);
ch.setSize(guiFont.getCharSet().getRenderedSize());
ch.setText("Press RightClick"); // crosshairs
ch.setColor(new ColorRGBA(1f,0.8f,0.1f,1f));
ch.setLocalTranslation(settings.getWidth()*0.3f,settings.getHeight()*0.1f,0);
guiNode.attachChild(ch);
}
private void setupKeys() {
//Set up keys and listener to read it
String[] mappings = new String[]{
"MoveCameraHelper",
};
inputManager.addMapping("MoveCameraHelper", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
inputManager.addListener(this, mappings);
}
private void generateBoxes() {
Box b = new Box(Vector3f.ZERO, 0.3f, 0.3f, 0.3f);
Geometry geom = new Geometry("Box", b);
geom.updateModelBound();
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Red);
geom.setMaterial(mat);
geom.setLocalTranslation(0,2,1);
int numClones = 1000;
Node instNodes = new Node();
for (int i=0; i<numClones; i++) {
Geometry gm = geom.clone(false);
gm.setName("instance"+i);
gm.setLocalTranslation((float) Math.random() * 200.0f - 50f,(float) Math.random() * 100.0f,(float)Math.random() * 200.0f - 50f);
gm.rotate(0, (float) Math.random() * (float)Math.PI, 0);
instNodes.attachChild(gm);
}
rootNode.attachChild(instNodes);
}
@Override
public void simpleUpdate(float tpf){
}
@Override
public void onAnalog(String name, float value, float tpf) {
if (name.equals("MoveCameraHelper")) {
cameraNode.move(cam.getLeft().normalize().mult(2f));
}
}
}
[/java]
And here is the AAControl.java:
[java]
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package com.swe;
import com.jme3.app.Application;
import com.jme3.app.FlyCamAppState;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.shape.Sphere;
/**
*
-
@author mifth
*/
public class AAControl extends AbstractControl {
private Node root;
private Geometry geom;
private Application app;
public AAControl(Application app) {
//TODO: initialize your AppState, e.g. attach spatials to rootNode
//this is called on the OpenGL thread after the AppState has been attached
this.app = app;
root = (Node) app.getViewPort().getScenes().get(0);
Sphere b = new Sphere(50, 50, 1);
geom = new Geometry("Sphere", b);
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
geom.setMaterial(mat);
geom.setLocalTranslation(0, 2, 1);
root.attachChild(geom);
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.8f, -0.6f, -0.08f).normalizeLocal());
dl.setColor(new ColorRGBA(1, 1, 1, 1));
root.addLight(dl);
app.getStateManager().getState(FlyCamAppState.class).getCamera().setMoveSpeed(30);
app.getViewPort().setBackgroundColor(ColorRGBA.Gray);
}
@Override
protected void controlUpdate(float tpf) {
Camera cam = app.getCamera();
Vector3f vec = cam.getLocation().add(cam.getDirection().normalize().mult(8f));
geom.setLocalTranslation((vec));
}
@Override
protected void controlRender(RenderManager rm, ViewPort vp) {
// throw new UnsupportedOperationException(āNot supported yet.ā); //To change body of generated methods, choose Tools | Templates.
}
}
[/java]
Just run the test and you will see the bug with the update of a Control(attached to rootNode) or AppState.
Just try to change like this:
[java]
rootNode.addControl(aps); // BUG
// OR
tempNode.addControl(aps); // OK
[/java]
So I guess this is the issue either with engineUpdates of Controls/AppStates or the issue with ChaseCamera.
@nehon i think it will be interesting for you too.
Thanks.