Box not attached to node in nightly

Hi,
I put together this small test case. I’m using two cameras, one with parallel projection and one with perspective projection. Don’t ask me about the values as they are taken from a specific scenario and don’t make much sense probably.

This test case works with nightly build from 2012-09-15 but doesn’t work with the latest build (2013-01-02).

[java]package cz.unknown.jme;

import com.jme3.app.SimpleApplication;
import com.jme3.collision.CollisionResult;
import com.jme3.collision.CollisionResults;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Ray;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;

public class CollisionBugTest extends SimpleApplication {

private Camera perspectiveCam = null;
private ViewPort perspectiveViewPort = null;
private Node perspectiveNode = null;

@Override
public void simpleInitApp() {
	perspectiveNode = new Node("Perspective node");
	perspectiveCam = new Camera(settings.getWidth(), settings.getHeight());
	perspectiveViewPort = renderManager.createMainView("Perspective port", perspectiveCam);
	perspectiveViewPort.attachScene(perspectiveNode);
	perspectiveViewPort.setClearFlags(false, false, false);
	
	flyCam.setEnabled(false);
	initCamera();
	initScene();
	registerInputListener();
}

/**
 * @param args
 */
public static void main(String[] args) {
	CollisionBugTest test = new CollisionBugTest();
	test.start();
}

private void initScene() {
	Box b = new Box(Vector3f.ZERO, 10000, 1, 10000);
	Geometry geom = new Geometry("Plane", b);
	Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
	ColorRGBA color = new ColorRGBA(1, 0, 0, 0f);
	mat.setColor("Color", color);
	geom.setMaterial(mat);
	perspectiveNode.attachChild(geom);
	
	DirectionalLight dl = new DirectionalLight();
	dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
	dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
	perspectiveNode.addLight(dl);
}

private void initCamera() {
	// parallel camera
	cam.setParallelProjection(true);
	cam.setFrustum(0.1f, 1000, -640, 640, 360, -360);
	Vector3f loc = new Vector3f(640, 360, 2.0f);
	Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
	Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
	Vector3f dir = new Vector3f(0.0f, 0.0f, -1.0f);
	cam.setLocation(loc);
	cam.setFrame(loc, left, up, dir);
	
	// perspective camera
	perspectiveCam.setFrustum(1000.1f, 2000, -640, 640, 360, -360);
	Vector3f loc2 = new Vector3f(640, 360, 1000f);
	Vector3f up2 = new Vector3f(0, 1, 0);
	Vector3f lookAt = new Vector3f(640, 360, 0f);
	perspectiveCam.setLocation(loc2);
	perspectiveCam.lookAt(lookAt, up2);		
}

@Override
public void simpleUpdate(float tpf) {
	perspectiveNode.updateLogicalState(tpf);
	perspectiveNode.updateGeometricState();
}

private void registerInputListener() {
    inputManager.addMapping("click", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(new ActionListener() {
        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if("click".equals(name) && isPressed) {
                CollisionResults results = new CollisionResults();
                Vector2f click2d = inputManager.getCursorPosition();
                Vector3f click3d = perspectiveCam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0f).clone();
                Vector3f dir = perspectiveCam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 1f).subtractLocal(click3d).normalizeLocal();
                printVector(click3d);
                printVector(dir);
                Ray ray = new Ray(click3d, dir);
                perspectiveNode.collideWith(ray, results);
                 
                for (CollisionResult collisionResult : results) {
                    System.out.println(collisionResult.getGeometry().getName());
                }
                System.out.println("-------");
            }
        }
    }, "click");
}

public static void printVector(Vector3f vect) {
	System.out.println(vect.x + "/" + vect.y + "/" + vect.z);
}

}
[/java]

The problem with not asking about those values is that if one removes them it works. If you could explain what you intend to do with that somebody could help you find a solution. If not then not as you already found out.

I’m sorry normen but you are clearly confused as to what is the difference between “broken functionality or changed behavior between two versions” and “I’m trying to do A and B but it doesn’t work, what am I doing wrong?”.

There was a “minor” change between these two versions.
When you create camera like this:
[java]new Camera(settings.getWidth(), settings.getHeight());[/java]
It is using parallel projection by default in latest nightly.
nightly from 2012-09-15:
[java]private boolean parallelProjection;[/java]

nightly from 2013-01-16:
[java]private boolean parallelProjection = true;[/java]

@raistm said: I'm sorry normen but you are clearly confused as to what is the difference between "broken functionality or changed behavior between two versions" and "I'm trying to do A and B but it doesn't work, what am I doing wrong?".

There was a “minor” change between these two versions.
When you create camera like this:
[java]new Camera(settings.getWidth(), settings.getHeight());[/java]
It is using parallel projection by default in latest nightly.
nightly from 2012-09-15:
[java]private boolean parallelProjection;[/java]

nightly from 2013-01-16:
[java]private boolean parallelProjection = true;[/java]

Yes, because it always was parallel projection it just didn’t indicate that it was before. It was in some kind of weird “I have parallel projection parameters and matrix but still return false for isParallelProjection.”

Proper camera setup prevents this issue.

@pspeed said: Yes, because it always was parallel projection it just didn't indicate that it was before. It was in some kind of weird "I have parallel projection parameters and matrix but still return false for isParallelProjection."

Proper camera setup prevents this issue.

Now I’m confused, you mean that the default was always parallel projection? Because that’s not true :slight_smile:
Or you mean that it was always meant to be parallel projection and that the opposite was actually a bug?

@raistm said: Now I'm confused, you mean that the default was always parallel projection? Because that's not true :-) Or you mean that it was always meant to be parallel projection and that the opposite was actually a bug?

If you set nothing about the camera then it was effectively parallel projection… is just reported that it wasn’t. For example, the camera setup for the gui viewport said it was perspective when it wasn’t.

Since you use setFrustum instead of setPerspectiveFrustum, you are bypassing the automatic settings of the parallel flag and so must specifically mark the camera as perspective.

@pspeed said: If you set nothing about the camera then it was effectively parallel projection... is just reported that it wasn't. For example, the camera setup for the gui viewport said it was perspective when it wasn't.

Since you use setFrustum instead of setPerspectiveFrustum, you are bypassing the automatic settings of the parallel flag and so must specifically mark the camera as perspective.


That’s true now.

But when I created camera like this:
[java]new Camera(settings.getWidth(), settings.getHeight());[/java]
while using setFrustum() in nightly 2012-09-15 and older then not only it reported that it is perspective projection but it really was perspective projection.
And that’s what I’m talking about.

@raistm said: That's true now.

But when I created camera like this:
[java]new Camera(settings.getWidth(), settings.getHeight());[/java]
while using setFrustum() in nightly 2012-09-15 and older then not only it reported that it is perspective projection but it really was perspective projection.
And that’s what I’m talking about.

Yes, but it was doing it in error.