Getting CameraNode to work

Hello fellas



I’m having a bit trouble getting the CameraNode to work proper for my shooter like test that I’m doing.



The purpose of this is of course to get a Node that contains camera, physics and a model.

The basic code is from the beginner tutorials, and consists of the Town scene as a map, a basic model as placeholder, collisionshape(Player).





The problem is, that I can use this code in the Update loop to “Move” the camera:

camNode.setLocalTranslation(player.getPhysicsLocation());



BUT if I use the same code to move my PlayerNode(Children - Model-CamNode) the app crashes detaching and attaching the children.



Rest of the Update Loop:

@Override

public void simpleUpdate(float tpf) {

Vector3f camDir = cam.getDirection().clone().multLocal(0.6f);

Vector3f camLeft = cam.getLeft().clone().multLocal(0.4f);

walkDirection.set(0, 0, 0);

if (left) { walkDirection.addLocal(camLeft); }

if (right) { walkDirection.addLocal(camLeft.negate()); }

if (up) { walkDirection.addLocal(camDir); }

if (down) { walkDirection.addLocal(camDir.negate()); }

player.setWalkDirection(walkDirection);






And My node creation and attachment:



Node PlayerNode = new Node(“PlayerNode”);

rootNode.attachChild(PlayerNode);

PlayerNode.attachChild(ninja);

PlayerNode.attachChild(camNode);

//PlayerNode.attachChild(Player); - Cant be attached/linked





PlayerNode.setLocalTranslation(new Vector3f(0, 10, 0));





And the CamNode creation:



flyCam.setEnabled(false);

camNode = new CameraNode(“camNode”,cam);

camNode.setControlDir(ControlDirection.SpatialToCamera);

rootNode.attachChild(camNode);



camNode.setLocalTranslation(new Vector3f(0, 10, 0));




:slight_smile:

can you post the crash stack please

Sure. Heres the crash stack:



compile-single:

run-single:

16-01-2012 15:03:17 com.jme3.system.JmeSystem initialize

INFO: Running on jMonkeyEngine 3.0.0 Beta

16-01-2012 15:03:17 com.jme3.system.Natives extractNativeLibs

INFO: Extraction Directory: C:UsersMathiasDocumentsHelloCollision

16-01-2012 15:03:17 com.jme3.system.lwjgl.LwjglAbstractDisplay run

INFO: Using LWJGL 2.8.2

16-01-2012 15:03:17 com.jme3.system.lwjgl.LwjglDisplay createContext

INFO: Selected display mode: 640 x 480 x 0 @0Hz

16-01-2012 15:03:18 com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: Adapter: aticfx64

16-01-2012 15:03:18 com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: Driver Version: null

16-01-2012 15:03:18 com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: Vendor: ATI Technologies Inc.

16-01-2012 15:03:18 com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: OpenGL Version: 3.3.11251 Compatibility Profile Context

16-01-2012 15:03:18 com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: Renderer: ATI Radeon HD 4600 Series

16-01-2012 15:03:18 com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: GLSL Ver: 3.30

16-01-2012 15:03:18 com.jme3.system.lwjgl.LwjglTimer

INFO: Timer resolution: 1.000 ticks per second

16-01-2012 15:03:18 com.jme3.renderer.lwjgl.LwjglRenderer initialize

INFO: Caps: [FrameBuffer, FrameBufferMRT, FrameBufferMultisample, TextureMultisample, OpenGL20, OpenGL21, OpenGL30, OpenGL31, OpenGL32, ARBprogram, GLSL100, GLSL110, GLSL120, GLSL130, GLSL140, GLSL150, VertexTextureFetch, TextureArray, TextureBuffer, FloatTexture, FloatColorBuffer, FloatDepthBuffer, PackedFloatTexture, SharedExponentTexture, PackedFloatColorBuffer, TextureCompressionLATC, NonPowerOfTwoTextures, MeshInstancing, VertexBufferArray]

16-01-2012 15:03:18 com.jme3.asset.DesktopAssetManager

INFO: DesktopAssetManager created.

16-01-2012 15:03:18 com.jme3.renderer.Camera

INFO: Camera created (W: 640, H: 480)

16-01-2012 15:03:18 com.jme3.renderer.Camera

INFO: Camera created (W: 640, H: 480)

16-01-2012 15:03:18 com.jme3.input.lwjgl.LwjglMouseInput initialize

INFO: Mouse created.

16-01-2012 15:03:18 com.jme3.input.lwjgl.LwjglKeyInput initialize

INFO: Keyboard created.

16-01-2012 15:03:23 com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread

INFO: AudioRenderer supports 64 channels

16-01-2012 15:03:23 com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread

INFO: Audio effect extension version: 1.0

16-01-2012 15:03:23 com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread

INFO: Audio max auxilary sends: 4

16-01-2012 15:03:23 com.jme3.material.MaterialDef

INFO: Loaded material definition: Unshaded

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Gui Node)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (Statistics View) attached to this node (Gui Node)

16-01-2012 15:03:23 com.jme3.material.MaterialDef

INFO: Loaded material definition: Phong Lighting

16-01-2012 15:03:23 com.jme3.scene.Node attachChild

INFO: Child (level) attached to this node (main-scene_node)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (level-geom-1) attached to this node (level-ogremesh)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (level-geom-2) attached to this node (level-ogremesh)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (level-geom-3) attached to this node (level-ogremesh)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (level-geom-4) attached to this node (level-ogremesh)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (level-geom-5) attached to this node (level-ogremesh)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (level-geom-6) attached to this node (level-ogremesh)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (level-geom-7) attached to this node (level-ogremesh)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (level-geom-8) attached to this node (level-ogremesh)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (level-geom-9) attached to this node (level-ogremesh)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (level-geom-10) attached to this node (level-ogremesh)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (level-geom-11) attached to this node (level-ogremesh)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (level-geom-12) attached to this node (level-ogremesh)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (level-geom-13) attached to this node (level-ogremesh)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (level-ogremesh) attached to this node (level-entity)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (level-entity) attached to this node (level)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (submesh0) attached to this node (Bulop-ogremesh)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (Bulop-ogremesh) attached to this node (Root Node)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (main-scene_node) attached to this node (Root Node)

16-01-2012 15:03:24 com.jme3.bullet.PhysicsSpace addRigidBody

INFO: Adding RigidBody com.bulletphysics.dynamics.RigidBody@19da4fc to physics space.

16-01-2012 15:03:24 com.jme3.bullet.PhysicsSpace addCharacter

INFO: Adding character com.bulletphysics.collision.dispatch.PairCachingGhostObject@16acdd1 to physics space.

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (camNode) attached to this node (Root Node)

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (pivot) attached to this node (Root Node)

16-01-2012 15:03:24 com.jme3.scene.Node detachChildAt

INFO: Root Node (Node): Child removed.

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (Bulop-ogremesh) attached to this node (PlayerNode)

16-01-2012 15:03:24 com.jme3.scene.Node detachChildAt

INFO: Root Node (Node): Child removed.

16-01-2012 15:03:24 com.jme3.scene.Node attachChild

INFO: Child (camNode) attached to this node (PlayerNode)

16-01-2012 15:03:24 com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at jme3test.helloworld.HelloCollision.simpleUpdate(HelloCollision.java:260)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:258)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)

at java.lang.Thread.run(Thread.java:662)

16-01-2012 15:03:24 com.jme3.renderer.lwjgl.LwjglRenderer cleanup

INFO: Deleting objects and invalidating state

16-01-2012 15:03:24 com.jme3.input.lwjgl.LwjglMouseInput destroy

INFO: Mouse destroyed.

16-01-2012 15:03:24 com.jme3.input.lwjgl.LwjglKeyInput destroy

INFO: Keyboard destroyed.

16-01-2012 15:03:24 com.jme3.system.lwjgl.LwjglAbstractDisplay deinitInThread

INFO: Display destroyed.

BUILD SUCCESSFUL (total time: 12 seconds)



At least the build is successful :slight_smile:



Let me know if you want to take a look at the whole source. It needs a bit optimization then as I got a lot of commented-out test-functions.

In line 260 some variable you use is null. Check which and fix that.

Line 260 is in the Update loop. It’s this line to be precise:

PlayerNode.setLocalTranslation(player.getPhysicsLocation());



Under the import and the App extends… I put this variable:



private Node PlayerNode;



Wich when removed - of course crashed the application even more.

so player is null, you cannot call methods on null.

I’m sorry for the noobish questions.

I’ve only been playing/studying Java for the past 2-3 weeks in my spare time, and I can’t seem to figure out why it is null.

What makes the CamNode so deffirent, as the PlayerNode got attachments too?

http://www.javabeginner.com