Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Scene graphs, transformable and transform...  (Read 3934 times)

0 Members and 1 Guest are viewing this topic.

Wibbs

  • Newbie
  • *
  • Posts: 40
    • View Profile
Scene graphs, transformable and transform...
« on: June 18, 2012, 06:06:02 pm »
Hey,

I'm attempting to implement a simple scene graph, but am having trouble with the way transformable and transform have been implemented and are used by the various drawables.

When traversing the graph to draw each node, you need to be able to apply a cumulative transform to each node. 

However, I cannot see any way of applying this to the node currently being drawn, as the only way of directly changing the orientation of a Drawable is through its Position, Scale and Rotation.  As acumulative transform would be represented as a Transform object, there is no easy way of getting this individual information to use.

Am I missing something obvious here, as I would have thought this should be relatively easy to implement?

Thanks in advance,

Wibbs
« Last Edit: June 18, 2012, 06:23:43 pm by Wibbs »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Scene graphs, transformable and transform...
« Reply #1 on: June 18, 2012, 06:52:25 pm »
Quote
However, I cannot see any way of applying this to the node currently being drawn, as the only way of directly changing the orientation of a Drawable is through its Position, Scale and Rotation.
Transformables have their own transform, but it can be combined with a transform this way:
window.draw(drawable, transform);
Laurent Gomila - SFML developer

Wibbs

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Scene graphs, transformable and transform...
« Reply #2 on: June 19, 2012, 01:11:19 am »
Ah, thanks - I passed over RenderStates without looking at it in detail because of its name.  Looks like it will do exactly what I need  :)

amireldor

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Scene graphs, transformable and transform...
« Reply #3 on: June 13, 2013, 12:28:22 am »
Hello, is there a way to apply a render state to ALL `draw` calls?

I'm trying to scale the whole scene (sprite position and textures) to the window size. i.e. I have a 320x240 background texture and I draw a sprite at 100x100, and then I want to scale the whole scene to fit a 800x600 window.

Currently I have a RenderState with a scale transformation and I pass it to each draw call. It seems funny to do it this way though.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Scene graphs, transformable and transform...
« Reply #4 on: June 13, 2013, 12:47:05 am »
I'm trying to scale the whole scene (sprite position and textures) to the window size. i.e. I have a 320x240 background texture and I draw a sprite at 100x100, and then I want to scale the whole scene to fit a 800x600 window.
Why don't you just use views?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

amireldor

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Scene graphs, transformable and transform...
« Reply #5 on: June 13, 2013, 12:49:16 am »
I thought about that, but a view only has zoom, and I need scale (I can't zoom differently for X and Y from what I read in the docs).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Scene graphs, transformable and transform...
« Reply #6 on: June 13, 2013, 08:35:58 am »
zoom() is a convenience function, it's just a hidden call to setSize() that does uniform and relative scaling.

So, to apply a scale factor of (sx, sy) you just have to do this:
view.setSize(view.getSize().x * sx, view.getSize().y * sy);
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Scene graphs, transformable and transform...
« Reply #7 on: June 13, 2013, 12:33:12 pm »
As far as I understand your description, you don't want to scale (relatively), rather set the size (absolutely). In your case, to 320x240.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

amireldor

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Scene graphs, transformable and transform...
« Reply #8 on: June 14, 2013, 01:51:29 pm »
Alright, thanks for the help! Views it is.

I ended up using:

sf::View view;
view.reset(sf::FloatRect(0, 0, 320, 240));
view.setSize(320, 240);
window.setView(view);

Or more generally:

sf::View view;
view.reset(sf::FloatRect(0, 0, map_width, map_height));
view.setSize(map_width, map_height);
window.setView(view);
 

As I draw my sprites relative to 0, 0 and the edge of the scene is 320, 240.

If I understand correctly, I first reset the View to 'focus' on the (0, 0, 320, 240) of the whole scene, and then I set its size to 320x240 so it shows the whole (0, 0, 320, 240) rectangle (from the 'focus') on the View's viewport which is (0, 0, 1, 1) i.e. the whole screen. Thus I get the (0, 0, 320, 240) to the whole viewport. And all is scaled as I wanted.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Scene graphs, transformable and transform...
« Reply #9 on: June 14, 2013, 02:31:21 pm »
The call to setSize is redundant, the size is already given by the rectangle passed to reset.
Laurent Gomila - SFML developer

amireldor

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Scene graphs, transformable and transform...
« Reply #10 on: June 14, 2013, 02:44:29 pm »
Hmm, yes Laurent, you're right I missed that. I'm posting the final code for the quick copy-paste coders that might bump into this thread.

sf::View view;
view.reset(sf::FloatRect(0, 0, map_width, map_height));
window.setView(view);


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Scene graphs, transformable and transform...
« Reply #11 on: June 14, 2013, 03:04:39 pm »
Or

window.setView(sf::View(sf::FloatRect(0, 0, map_width, map_height)));

 ;D
Laurent Gomila - SFML developer