CameraNode is not my friend

I have a particleNode that I have attached to my cameraNode.  The particleNode is visible when the game starts but then I change the location of the cameraNode and tell it to lookAt(0.0f, 0.0f, 0.0f) and the particleNode is no longer visible.  If I move the cameraNode back to the original position the particleNode is visible again.  It would seem that the particleNode is not being moved along with the cameraNode or the rotation is not changing.



It is my understanding that cameraNode being moved and rotated will also move and rotate anything else in that node along with it, is this not necessarily true?



darkfrog

Okay, I have a test case that Mojo was helping me with and I modified it to show one of my problems I’m having:







And here is the test case:


import java.net.*;

import com.jme.app.BaseGame;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingSphere;
import com.jme.image.Texture;
import com.jme.input.*;
import com.jme.input.InputHandler;
import com.jme.input.NodeHandler;
import com.jme.input.action.*;
import com.jme.light.DirectionalLight;
import com.jme.light.SpotLight;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.CameraNode;
import com.jme.scene.Line;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.Text;
import com.jme.scene.TriMesh;
import com.jme.scene.shape.Box;
import com.jme.scene.state.AlphaState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.TextureManager;
import com.jme.util.Timer;
import com.jmex.effects.ParticleManager;

public class TestCameraNodeRain extends SimpleGame {
    private TriMesh t, t2;

    private Node particleNode;
   
    private CameraNode camNode;

    private Node scene;
    private Timer timer;

    public static void main(String[] args) {
        TestCameraNodeRain app = new TestCameraNodeRain();
        app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
        app.start();
    }

    protected void simpleInitSystem() {
        try {
            display = DisplaySystem.getDisplaySystem(properties.getRenderer());
            display.createWindow(properties.getWidth(), properties.getHeight(),
                    properties.getDepth(), properties.getFreq(), properties
                            .getFullscreen());
            cam = display.getRenderer().createCamera(properties.getWidth(),
                    properties.getHeight());

        } catch (JmeException e) {
            e.printStackTrace();
            System.exit(1);
        }
        ColorRGBA blackColor = new ColorRGBA(0, 0, 0, 1);
        display.getRenderer().setBackgroundColor(blackColor);
       
       
        timer = Timer.getTimer("LWJGL");

    }

    protected void simpleInitGame() {
        scene = new Node("Scene");
        cam.setFrustum(1.0f, 1000.0f, -0.55f, 0.55f, 0.4125f, -0.4125f);
        Vector3f loc = new Vector3f(0.0f, 0.0f, 0.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, 0f, -1.0f);
        cam.setFrame(loc, left, up, dir);
        display.getRenderer().setCamera(cam);
        camNode = new CameraNode("Camera Node", cam);
        input = new NodeHandler(camNode, 15f, 1);
       
        ZBufferState buf = display.getRenderer().createZBufferState();
        buf.setEnabled(true);
        buf.setFunction(ZBufferState.CF_LEQUAL);

        SpotLight am = new SpotLight();
        am.setDiffuse(new ColorRGBA(0.0f, 1.0f, 0.0f, 1.0f));
        am.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
        am.setDirection(new Vector3f(0, 0, 0));
        am.setLocation(new Vector3f(25, 10, 0));
        am.setAngle(15);

        SpotLight am2 = new SpotLight();
        am2.setDiffuse(new ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f));
        am2.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
        am2.setDirection(new Vector3f(0, 0, 0));
        am2.setLocation(new Vector3f(-25, 10, 0));
        am2.setAngle(15);

        DirectionalLight dr = new DirectionalLight();
        dr.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
        dr.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
        dr.setSpecular(new ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f));
        dr.setDirection(new Vector3f(150, 0, 150));

        LightState state = display.getRenderer().createLightState();
        state.attach(am);
        state.attach(dr);
        state.attach(am2);
        am.setEnabled(true);
        am2.setEnabled(true);
        dr.setEnabled(true);
        // scene.setRenderState(state);
        scene.setRenderState(buf);

        camNode.setLocalTranslation(new Vector3f(0, 0, -75));
        camNode.attachChild(t2);
        scene.attachChild(camNode);

        // cam.update();

        TextureState ts = display.getRenderer().createTextureState();
        ts.setEnabled(true);
        ts.setTexture(TextureManager.loadTexture(
                TestCameraNodeRain.class.getClassLoader().getResource(
                        "jmetest/data/images/Monkey.jpg"), Texture.MM_LINEAR,
                Texture.FM_LINEAR));

        scene.setRenderState(ts);
        rootNode.attachChild(scene);
       
        this.createRain();

        scene.updateGeometricState(0.0f, true);
        rootNode.updateRenderState();

        KeyBindingManager keyboard = KeyBindingManager.getKeyBindingManager();
        keyboard.set("ScreenShot", KeyInput.KEY_F12);
        input.addAction(new KeyScreenShotAction("screenshot"), "ScreenShot", false);
    }

    protected void reinit() {

    }

    protected void cleanup() {

    }

    public void createRain() {
        Vector3f[] lines = new Vector3f[260];
        int count = 0;
        float pointZ = -30.0f;
        for (int j = 0; j < 6; j++) {
            float pointX = -50.0f;
            for (int i = 0; i < 26; i++) {
                lines[count++] = new Vector3f(pointX, 0.0f, pointZ);
                pointX += 4;
            }
            pointZ += 10.0f;
        }
        Line line = new Line("Line", lines, null, null, null);
       
        ParticleManager manager = new ParticleManager(200);
        manager.setGravityForce(new Vector3f(0.0f, -0.0020f, 0.0f));
        manager.setEmissionDirection(new Vector3f(0.0f, -1.0f, 0.0f));
        manager.setEmissionMaximumAngle(0.1f * FastMath.PI);
        manager.setEmissionMinimumAngle(0.0f);
        manager.setSpeed(0.6f);
        manager.setParticlesMinimumLifeTime(100.0f);
        manager.setStartSize(1.5f);
        manager.setEndSize(1.5f);
        manager.setStartColor(new ColorRGBA(0.3f, 0.3f, 0.7f, 0.8f));
        manager.setEndColor(new ColorRGBA(0.3f, 0.3f, 0.7f, 0.8f));
        manager.setRandomMod(1.0f);
        manager.setControlFlow(false);
        manager.setReleaseRate(400);
        manager.setReleaseVariance(0.5f);
        manager.setInitialVelocity(0.58f);
        manager.setParticleSpinSpeed(0.0f);

        manager.warmUp(1000);
        manager.getParticles().addController(manager);

        AlphaState as1 = display.getRenderer().createAlphaState();
        as1.setBlendEnabled(true);
        as1.setSrcFunction(AlphaState.SB_SRC_ALPHA);
        as1.setDstFunction(AlphaState.DB_ONE);
        as1.setTestEnabled(true);
        as1.setTestFunction(AlphaState.TF_GREATER);
        as1.setEnabled(true);

        TextureState ts = display.getRenderer().createTextureState();
        try {
            ts.setTexture(
                    TextureManager.loadTexture(new URL("http://www.pyramex.com/download/rainline.jpg"),
                            Texture.MM_LINEAR_LINEAR,
                            Texture.FM_LINEAR));
            ts.setEnabled(true);
        } catch(Exception exc) {
            throw new RuntimeException(exc);
        }

        manager.setGeometry(line);
       
        particleNode = new Node("Particle Nodes");
        particleNode.setRenderState(as1);
        particleNode.setRenderState(ts);
        particleNode.attachChild(manager.getParticles());
        particleNode.setLocalTranslation(new Vector3f(0.0f, 0.0f, 0.0f));
        particleNode.updateRenderState();
        rootNode.attachChild(particleNode);
    }

}



See that particle that's stuck at 0.0f, 0.0f, 0.0f....that shouldn't be there and it is not part of the Line that I set it to use.

darkfrog

The problem is here:


Vector3f[] lines = new Vector3f[260];



You are only initializing the first 156 vertices, so the rest are left at (0,0,0)

Btw, You can also use Line and Rectangle (from the math package) to spawn from if you want.  Then you don't have to use quite as much memory (but you'll have to figure out how to sync it to the camera movements.)

If I set myself on fire would it be a sufficient diversion to keep people from noticing my stupidity? :-p



Thanks Renanse…I think. :o



darkfrog

I think this forum would be pretty empty if everyone who ever made a mistake like that would set themselves on fire :smiley:

You can start up the TestFireMilk and watch him burn for a little while instead.  :wink:

mmm…much less painful.



Thanks Renanse! :o



darkfrog