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

Author Topic: View problems  (Read 2161 times)

0 Members and 1 Guest are viewing this topic.

Karleon

  • Newbie
  • *
  • Posts: 18
    • View Profile
View problems
« on: March 26, 2013, 01:13:53 pm »
Heeello,

I'm using a sf::view as a camera that follows the player. The update on the different components are done in the following order:
1) The player's position might be updated in a game cicle.
2) Set the view's center to the player's position
3) Set the window's view to the updated view
4) Calculate the line of sight of the player, calculate shadows (do_FOV)
5) Draw everything

The shadows casted from the player's field of view are not draw globally. With this I mean that the shadow's RenderTexture is not as big as my map, but as my window, so the texture for the shadows has the same side of the window.

This means that in order to draw the shadows on my shadowTexture, I must also set the RenderTexture's view the same as my window:

shadowRepresentationRender.setView( engine->view );
shadowRepresentationSprite.setPosition( engine->view.getCenter().x , engine->view.getCenter().y );
//shadowRepresentationSprite's origin is set to it's center  

This is done in the do_FOV function (which is executed after the view and the player's position has been updated).

The problem comes when I draw the shadows on my screen. While standing still, everything is working fine. The problem comes when the players moves. In the following screenshot I'm walking to the left:



As you can see inside the red area, it looks like the shadow's sprite is falling behind the actual movement of the player. If I walk to the right, that gap appears at the right. Same applies when moving up and down.

I have tried setting the sprite's position (and the sprite's origin) to 0,0 and then change the window's view to the defaut view, so it's back in the origin. The exact same error happens.

I think this problems comes from setting the view for the shadow's RenderTexture the same as the window view.


Anyone has any idea of what could be wrong here?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: View problems
« Reply #1 on: March 26, 2013, 01:52:24 pm »
Let the guessing beginn...

If want precise help you should provide code. ;)
At best you create a minimal and complete example (more infos in the FAQ) that reproduces the problem.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Karleon

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: View problems
« Reply #2 on: March 26, 2013, 04:09:07 pm »
I was building a minimal and complete example and I realized something about my code:

-For each polygon on view, I would draw the shadow it casts on a intermediate texture.
-This texture was then drawn on my shadow texture for the final result (while applying a shader)

This intermediate texture had it's view not updated before drawing the shadows on it, but it was later used (and properly set the view on it) for another task that required an intermediated texture. This resulted on the shadows being displayed from the lastest drawn cicle view, and therefore, it seemed to "fall behind".


Bottom line: I'm retarded.




PD: Is there a way to close/delete threads? I mean, this one is pretty useless after all.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: View problems
« Reply #3 on: March 26, 2013, 07:16:13 pm »
I was building a minimal and complete example and I realized something about my code
Yep that often happens when writing minimal examples. :)

Bottom line: I'm retarded.
Not really. ;)

PD: Is there a way to close/delete threads? I mean, this one is pretty useless after all.
Nope there isn't, just let it sink into the depth of the forum. ;D
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything