General Questions - Dungeon Crawler

First of all - disable that ‘spatial following’ camera’s feature and move/rotate camera manually. You don’t need any ‘player’ spatial in FPP game.

Here are my own settings for camera, they looks good, as you mentioned in my own topic.


			CAM_FOVY = 60; 
			CAM_NEARF = 0.15f;
			CAM_ASPECT = 1.2f;
			cam.setFrustumPerspective(CAM_FOVY, CAM_ASPECT,	CAM_NEARF, 23.2f);

Those settings are valid for 4/3 window.
Next hint: do not place camera at the center of the tile, move it a bit backward.


		pos.x = pos.x + (CAM_MOV * FastMath.sin(angl));
		pos.z = pos.z + (CAM_MOV * FastMath.cos(angl));

This way you can see items that are on the floor in the same tile as you are standing on.

Thanks FrozenShade: I think the problem I’ll have with moving the camera back as that’s what I started to play with is I actually need to draw the party characters as mine will be two players so the camera will then show the front party members I expect :frowning:

Does anyone know why when I apply filters to my viewports one disappears ?


for (ViewPort v : renderManager.getMainViews()){
         
            PointLightShadowRenderer dlsr = new PointLightShadowRenderer(assetManager, 4);
            //dlsr.setLight(p2.light);
            dlsr.setLight(p1.light);
            v.addProcessor(dlsr);

            PointLightShadowFilter dlsf = new PointLightShadowFilter(assetManager, 4);
            //dlsf.setLight(v.getCamera().getp);
            dlsf.setLight(p1.light);
            dlsf.setEnabled(true);

            FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
            fpp.addFilter(dlsf);
            

            FogFilter fog=new FogFilter();
            fog.setFogColor(new ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f));
            fog.setFogDistance(100);
            fog.setFogDensity(0.8f);
            fpp.addFilter(fog);

            v.addProcessor(fpp);
            
        }

It works fine with the original viewport but the viewport for player 2 which I created works as long as there is no filter applied.


ViewPort P2_viewPort = renderManager.createMainView("player2ViewPort", player[1].cam); 
P2_viewPort.attachScene(rootNode);
player[1].vp = P2_viewPort;
rootNode.attachChild(player[1].party);      
rootNode.addLight(player[1].light);

Now missing player 2s view…

OK I’ve fixed most my issues the viewport issue and not getting the filter was due to needing a Filter Processor per viewport but you also need this magic line (im not sure why but otherwise the viewports do not show)

viewPort.setClearFlags(true,true,true);

So I now have my two Viewports with my filters applied so on to my next questions :slight_smile:

Can you have multiple light sources for a filter? i.e.


        PointLightShadowRenderer dlsr = new PointLightShadowRenderer(assetManager, 1);
        dlsr.setLight(player2.light);
        dlsr.setLight(player1.light);
        this.vp.addProcessor(dlsr);

And last question for the moment, is there any way to make a single node/Spatial not show in a camera/viewport?

This one is a bit of a show stopper for me if its not possible (or at least I need to work out a way to do it)

is there any way to make a nodes/spatial’s not show in a camera/viewport? With the type of game im doing you could have a spell where you can see hidden/fake objects but this of course would only want to be applied in one camera/viewport not both. I guess I could make two scenes and then shares some objects between them but it doesn’t feel like that’s the right way to go.

@madmunky said: This one is a bit of a show stopper for me if its not possible (or at least I need to work out a way to do it)

is there any way to make a nodes/spatial’s not show in a camera/viewport? With the type of game im doing you could have a spell where you can see hidden/fake objects but this of course would only want to be applied in one camera/viewport not both. I guess I could make two scenes and then shares some objects between them but it doesn’t feel like that’s the right way to go.

It’s absolutely the right way to go. Furthermore, I’d argue that the only thing the two viewports should be sharing are game objects and the scene then derives from the game objects (ie: each viewport is the ‘view’ in a Model-View-Controller sense and the game objects are the ‘model’.)

This bypasses your issue completely and avoids a dozen other issues you might encounter later. It’s also precisely the way you’d have to do it if your were doing real networked multiplayer (only in that case each ‘viewport’ is a separate client).

Also, if you ever want to limit what a particular viewport can see by camera position (ie: only loading what’s nearby) then you can do that if you have separate scenes… where as now you are limited to every viewport having the whole world.

Thanks Pspeed it actually makes sense when you say it :slight_smile:

When I did this in 2d I did it the same way so I dont know why I though it would be different for 3D (Well im a newbie so thats my excuse)

Im trying to get my head round this…

What I am now doing is my player object has a Node (which is their scene) I read my map data and populate this scene with all the objects I then assign this scene/node to the player viewport.

My problem is unless I attach the nodes/scene to the rootNode I get errors but I though I would not want everyone to see these nodes or is that what the viewport does, manages it so it only sees a single tree of nodes.

Then my next issue if I try and modify the player scene/nodes I get errors about it being changed

" Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IllegalStateException: Scene graph is not properly updated for rendering.
State was changed after rootNode.updateGeometricState() call.
Make sure you do not modify the scene from another thread!"

@pspeed said: It's absolutely the right way to go. Furthermore, I'd argue that the only thing the two viewports should be sharing are game objects and the scene then derives from the game objects (ie: each viewport is the 'view' in a Model-View-Controller sense and the game objects are the 'model'.)

This bypasses your issue completely and avoids a dozen other issues you might encounter later. It’s also precisely the way you’d have to do it if your were doing real networked multiplayer (only in that case each ‘viewport’ is a separate client).

Also, if you ever want to limit what a particular viewport can see by camera position (ie: only loading what’s nearby) then you can do that if you have separate scenes… where as now you are limited to every viewport having the whole world.


Actually the current system can be used to share scene data between viewports. You can attach the scene data for all players to your main scene and then selectively cull or apply LOD by using Controls with their render() method which is called per camera as opposed to once for a scene.

@Momoko_Fan said: Actually the current system can be used to share scene data between viewports. You can attach the scene data for all players to your main scene and then selectively cull or apply LOD by using Controls with their render() method which is called per camera as opposed to once for a scene.

That doesn’t mean it’s the right way or good way to do it.

Can someone confirm should I be using a new scene for each player or is one scene with multiple nodes

I cant find any code about how to create a new scene hence why I think it should be on the rootNode?

@madmunky said: Im trying to get my head round this..

What I am now doing is my player object has a Node (which is their scene) I read my map data and populate this scene with all the objects I then assign this scene/node to the player viewport.

My problem is unless I attach the nodes/scene to the rootNode I get errors but I though I would not want everyone to see these nodes or is that what the viewport does, manages it so it only sees a single tree of nodes.

Then my next issue if I try and modify the player scene/nodes I get errors about it being changed

" Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IllegalStateException: Scene graph is not properly updated for rendering.
State was changed after rootNode.updateGeometricState() call.
Make sure you do not modify the scene from another thread!"

When you have your own scene then you have to manage the updates yourself.

Just search the forum for ViewPortAppState or ViewPortState or something like that and you’ll find examples of doing this.

Is there any good ebook that explain all this? maybe its the type of gaming I’m doing and the fact I don’t know any 3D so I guess a book at this stage may help.

This stuff is pretty esoteric. Just do the search I suggest and you will find links. Plus it will teach you a little about app states if you don’t use them already (there are tutorials for that, though).

pspeed: thanks for all your help, I’ved tried searching for ViewPortAppState and ViewPortState but not really getting any results, should I actually be looking at ApplicationState? https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:application_states

I searched for ViewPortState in the upper right and the second link in the search results led me here:
http://test.hub.jmonkeyengine.org/forum/topic/can-i-render-an-object-ontop-of-everything-but-under-gui/page/2/#post-139397

Yes, you should also learn about app states. It’s a way of organizing reusable chunks of code and/or just not having one giant main class doing everything.

pspeed: If I try and create a class the same as your example I get the following on the initialized ‘method does not override or implement a method from a supertype’

If I comment that out and then create a new ViewPortState as soon as I call getRoot() to update the node I end up with the same error as before…

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IllegalStateException: Scene graph is not properly updated for rendering.
State was changed after rootNode.updateGeometricState() call.
Make sure you do not modify the scene from another thread!
Problem spatial name: Viewport Root

Yes, it was typed right in the forum so you will have to use some programming skills to make it right. But the general gist of it is there.

As I cant find this explained anywhere and my Java is not the best I don’t understand what I am doing wrong

So my flow is…

Main loop
Create my Player object and my Player object has a ViewPortState object

In my Main loop update I call a Player function which creates a Node holding all the objects the player can see, I then call my Player.GetViewState().getRoot() and assign my new Node to this, every time I do this I get the exception about the scene being updated incorrectly.

@madmunky said: As I cant find this explained anywhere and my Java is not the best I don't understand what I am doing wrong

So my flow is…

Main loop
Create my Player object and my Player object has a ViewPortState object

In my Main loop update I call a Player function which creates a Node holding all the objects the player can see, I then call my Player.GetViewState().getRoot() and assign my new Node to this, every time I do this I get the exception about the scene being updated incorrectly.

I’m squinting so hard to see your code but I just can’t make it out from here. My binoculars must be not working properly.

When you run your own viewport with your own root, you need to updateLogicalState() and updateGeometricState() on it once per frame. The app state is supposed to facilitate this if it’s setup right. If you know how to use app states then it should have been trivial enough to fix the one I posted. I’d paste one of mine but they all extend Lemur’s BaseAppState (now also in JME 3.1) and so would still have to be converted by hand to be useful to you and then I might make a typo again and we’re no better off than when we started.

Read about app states. Setup an app state that managed your viewport and it’s root and makes sure that it is updated once per frame. When you have problems with the code, post the code.