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

Author Topic: Setting origin of View  (Read 1673 times)

0 Members and 1 Guest are viewing this topic.

Chaosed0

  • Newbie
  • *
  • Posts: 5
    • View Profile
Setting origin of View
« on: June 20, 2013, 03:19:13 am »
I'd like to have a view follow the player, but the player should be at the bottom of the screen. This works ok when I only set the position of the view - I just need to translate the center of the camera up a bit. However,  when I attempt to set the rotation of the camera, the camera rotates around its center, as one would expect, resulting in the player rotating around the center of the view.

Is there a way to set the origin of the camera to the player's location, instead? Ideally, I'd like to set up a scene graph where the view is just another node, with the player as the parent. However, it's not really possible since the view's transform is not available through its interface. EDIT: I guess you can actually get the view's transform, but (1) you can't set it and (2) it says it's for internal use only.

I suppose I could modify the source to expose the view's transform and just use that, but that's not really an ideal thing to do. Is there something I'm missing, or is this functionality not there?
« Last Edit: June 20, 2013, 03:21:19 am by Chaosed0 »

raycrasher

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Setting origin of View
« Reply #1 on: June 20, 2013, 05:57:21 am »
A good approach is not to use View as the basis for your camera class. Instead, use an sf::Transform wrapped in a Camera class, and pass that transform inside the RenderStates parameter when drawing.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Setting origin of View
« Reply #2 on: June 20, 2013, 07:55:11 am »
raycrasher is right, if all you need is a transform then use a transform, not a view ;)
Laurent Gomila - SFML developer

Chaosed0

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Setting origin of View
« Reply #3 on: June 21, 2013, 01:37:15 am »
Fair enough. I think I'm just too used to always having the View as my camera class; I didn't even know that you could pass a Transform in a RenderStates. Thanks for the input.

Edit: To make the camera follow the player, I had to pass the inverse of the player's transform. It makes some intuitive sense after making a custom camera in SDL (you have to move the scene in the opposite direction that the player's moving, etc), and it works, but is this the best way to do it? Additionally, is taking the inverse computationally expensive?
« Last Edit: June 21, 2013, 02:41:10 am by Chaosed0 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Setting origin of View
« Reply #4 on: June 21, 2013, 07:51:17 am »
Quote
is this the best way to do it?
Is there another way? ;)

Quote
Additionally, is taking the inverse computationally expensive?
I think it's negligible, unless you do it thousands times per frame.
Laurent Gomila - SFML developer

 

anything