Scene Graph Approach to Game

Hi There, i’m new from Argentina.

I’ve started to develop a Chess Game in 3d with this amazing engine. I’ve made a board with Boxes and used the test models as pieces and that’s all i have achieved.

Thing is i want to be able to highlight both (box and model) when the center of the camera points at either one. With a ray i can detect collisions on models to make them “shiny” by adding/removing an ambient Light to them on the update method. The very same doesn’t apply to my boxes, they collide but they don’t shine. Besides i can’t seem to find a proper way to find out which box has the model i select with the crosshair and viceversa.

Perhaps i should have designed a different node hierarchy? I have three nodes attached to the rootNode, the one with the board and two for the pieces owned by each chess player.

Any help is appreciated!

One way of doing this is to use a filter… in postQueue render a GeometryList containing the chess piece + board cube using a forced material and then blend the output of that frame buffer back into the scene.

There are multiple ways of determining which box has the selected piece… but I would think you would know already simply due to the nature of chess. If the game isn’t this far alone just worry about highlighting the piece for now… and snag the board geometry later.

A second thought would be to use a single geometry for the board and projective texturing to show the piece that is currently active (or a combo of the above idea and this.

just store your boxes in a list and loop over them comparing the localposition with the loclaposition of the chest piece ( rounding to grid size)

<cite>@TRON said:</cite> ...Besides i can't seem to find a proper way to find out which box has the model i select with the crosshair and viceversa.

I did something similar for the Ludum Dare contest, maybe you could steal some code.

https://code.google.com/p/subterraneanfarmmaniac/

But basically, I shoot a ray, when it intersects the board I take the world coordinates X,Z and since I know how large my “tiles” are I just divide to get the correct tile.

So yeah, exactly what Emipre Phoenix said :slight_smile:

@Empire Phoenix @jmaasing Are you guys serious? Would u actually take this approach considering the game is CHESS and it is an ABSOLUTE REQUIREMENT to know what piece reside where on the board. Why would u loop over the entire board when you HAVE to know that pawn3 is on a5 just to write the logic portion of the game.

This isn’t trying to be offensive, I’m actually curious… would you do this?

F it… can’t link his name to save my life

I wouldn’t…

but the chess pieces are game objects and not scene objects and so have their own board data structure that they use. At least if things are done right. So then “picking” a piece is just a matter of division.

But my “spatials are not game objects” recording is getting kind of worn through at the moment.

1 Like
<cite>@pspeed said:</cite> I wouldn't...

but the chess pieces are game objects and not scene objects and so have their own board data structure that they use. At least if things are done right. So then “picking” a piece is just a matter of division.

But my “spatials are not game objects” recording is getting kind of worn through at the moment.

No they are not, but you have to have some sort of linkage between your visual representation and game objects if you want the user to be able to interact via the spatials… and in this case, the rules have been setup for the OP far before we had computers to simulate the game. I was just curious what the reasoning behind a blind sweep of spatials was all about when the game requires knowing this information to write any form of AI for a computer based opponent… actually… screw the AI… board setup requires specifying where to place the pieces. /boggle

1 Like
<cite>pspeedsaid:</cite> but the chess pieces are game objects and not scene objects and so have their own board data structure that they use. At least if things are done right. So then "picking" a piece is just a matter of division.

Which is precisely what the code I shared do for picking a tile, It does not pick a chess piece.

For determining what game object/chess piece lives in a specific tile, that has nothing to do with the scene graph. That is a model of the game that lives outside the scene graph and that can be solved in different ways. Like pspeed already said :slight_smile:

That is why the code I shared is divided into two separate packages, one called “model” that is the game world - nothing to do with the scene graph. It is even runnable as a static void main() that runs the simulation without any graphics. Google Code Archive - Long-term storage for Google Code Project Hosting.

Then there is an “appstates” package that is jME specific. It looks at the game model and draws it on the screen using the scene graph, example:
https://code.google.com/p/subterraneanfarmmaniac/source/browse/source/SFM-jME/src/nu/zoom/ld25/sfm/appstates/TerrainAppState.java

I’m sure this could be done differently but I was pretty happy with that design.

1 Like

Thanks guys!

I’m sorry for being so late. I’ve learned two things here : that the community is cooler than what i would have imagined and that my game needs to be re-engineered.

I’m going to download jmaasing’s code, i was in need of a proper guidance as it’s very hard for me to learn both jME and game development’s good practices. :smiley:

The loop was the simplest approach, it’s not bad but i was aiming for the best approach with my question.

Thanks again!

2 Likes