Scene graph

Started by
5 comments, last by Xperience 9 years, 11 months ago

Hi,

I'm trying to create my own 3D engine, but I have some problems with implementing scene graph. I want to achieve this:

Assume that our character is on the ship. He doesn't move relative to the ship, but he moves relative to world(where ship go, he go too). Not only he, but everything what is on the board.

I'm using actor component system and I'm storing WorldMatrix inside transform component(But I have idea to store scene node directly to the actor, as a component, is this a bad idea?)

I have created scene graph based on GCC one(but it doesn't work in deeper hierarchy what is what I want to achieve).

My second question is:

I read : http://www.gamedev.net/topic/619283-are-scene-graphs-worth-it/

that I should separate rendering from scene graph(I'm reading GCC and they used scene graph as rendering system).

But if I do it, is then scene graph unnecessary?

Advertisement
I think it's still necessary, some way or another. Could also be childs pointing to parents etc.
In your use case you could say that:

- player has it's local orientation (it's childs and renderables derive it's world matrix)
- you can give player a parent for world orientation.
This would be an identity matrix if the player's state is on the land or in the sea, and it could be the derived world matrix of for example your ship or a car (depending on the state of the player).

To visualize a bit:

- player parent = ship transform or car transform or identity (on land, walking), based on player state
- player world matrix = own orientation * parent (either identity or ship orientation)
- player head = own orientation * player matrix/ orientation

I don't know how you can fully seperate the scenegraph from the rendering system. In my engine I have a renderqueue holding only ID's etc. These point to renderables/ objects/ materials/ shaders etc. When something is rendered through the order determined by the queue, my rendering system retrieves the world matrix for that renderable (kept as member in all renderable and object objects). All dynamic objects and their renderables are updated within the classes of both of themselves.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

The reason to have a scene graph is so that you can represent hierarchical relationships in your scene. If you have your player walking on a ship, it would make sense to have them as a child of the ship until they leave it where it would become a child of the world or whatever else he was on.

Thank about the situation where the ship has to bob up and down because something heavy was dropped on it. If your player (and everything else on the ship) isn't a child of the ship, how do you know that you also have to make your player bob up and down?

One other comment is this: if you think a scene graph is going to work for you, then try it out and experiment with it. Don't rely on what others are saying, because you need to understand the reasons behind the decision for yourself. Just remember to design your code so that an entity binding system can be swapped in and out without too much pain, and then you can try different schemes without having to totally rewrite your engine.

Thank you for your advices!

This is exactly like I'm doing it:

|- Car -|- Player

|

Root(just identity matrix) -| - Ship -|- AI

-|- Machine gun

|

|- Another AI(walking on the land)

But I had some problems with concatenating matrices, like car stopped, but Player was still moving, or(the funniest one) player in the car was moving with exponential speed.

I solved this by using three matrices(is there a better way? This one brings a lot of matrix concatenations):

1) Parent transformation

2) Local transformation relative to the parent

3) World transformation

Now, I'm using scene graph for computing world transformations and visibility tests and I'm trying to experiment with graphics too.

Ok, I try to rely less on what others are saying, but I want to find and develop things in the best way I can do it.

And what about rendering system? What is meaning to separate it?(This or not(If I understand it correctly)?: Traverse scene graph, compute world matrices, find which scene nodes can be renderered and add them into rendering queue?)

And my final question(or request), can someone review my English, please? Thank you

That's a lot of questions :)

- three matrices shouldn't be a problem, assuming that 2 is for the player, 1 is identity/boat/car and 3 is the multiplication of both (there would be a 4th variant for the childs/ renderables of objects that are related to for example the boat: boat to world, object to boat, child/ renderable of object to object)
- there's no law on this, but you can use a renderqueue for sorting out everything you need to render in a frame, I only keep id's and indices in the queue, pointing to objects, renderables, shaders etc. (in the wanted order to reduce draw calls).
- my d3dscene class has an update function, which does the culling and save visibility per zone/ object/ renderable/ positional light. In this class I also update all objects's matrices, each object kan have childs which update accordingly. This last 'job' could also be separated into a scenegraph (class), but I didn't see the advantage of doing that yet (maybe later on when things get more complex in the scene/ level)

Your english doesn't seem to be too bad (for usage on the forums), looking at your post/ replies. Did you mean these texts or something else you wanted to have reviewed? (of course if you want to write for example a letter, resume or motivation for a job application, then I'm not the right person to judge/ review :))

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

I solved this by using three matrices(is there a better way? This one brings a lot of matrix concatenations):

1) Parent transformation

2) Local transformation relative to the parent

3) World transformation

That's the general idea behind a hierarchy tree of transformations.

In fact what you really need are just ToParent relative (local) transformation matrices. Then you can get all global (world) transformations just by multiplying the ToParent matrix of the actual node with the ToParent matrix of its parent with the ToParent matrix of this parent's parent.... all the way to the top-most node. The top-most node has no parents and you assume it's global transform to be identity.

This is very inefficient, because you'll be repeating the same multiplications a lot, unless each parent has only one descendant. So it's a good idea to store the global (world) transform of each node and when you go from the top to the bottom, you calculate the world matrix of each node by just multiplying its ToParent matrix with the parent's World matrix (which already incorporates all the ToParent*ToParent*ToParent... multiplications).

Yes, I'm using system like a stack for computing world matrices.

No, I don't have a specific post (just if you look at it, if it is readable or you must read a lot to understand what I mean)

Probably my last question is: Where is a good place to attach scene node to the Actor?

This topic is closed to new replies.

Advertisement