Jump to content

Movimento do sol


Go to solution Solved by ribeiro55,

Recommended Posts

Posted

Boas pessoal, estou a desenvolver um jogo onde quero aplicar o dia e a noite e queria que o sol fizesse o seguinte movimento :

73khgu2.png

Estou a usar Monogame com C#, como posso alcançar isto ?

Cumprimentos.

Learning:

C++
  • Solution
Posted

Trigonometria.

Podes calcular a posição do sol em função de um ângulo.

Se considerares que 0 graus é o teu sol da esquerda, 90 o sol de cima e 180 o sol da direita:

float dist_sol = 500f; //o que fizer sentido no teu mundo
float ang_sol = 45f;
sol.x = centro.x + Math.Cos(ang_sol * (Math.PI/180))*dist_sol
sol.y = centro.y + Math.Sin(ang_sol * (Math.PI/180))*dist_sol

45 graus será uma posição a meio caminho do sol da esquerda e do sol de cima, a descrever um círculo.

Se aumentares o ang_sol, a posição do sol vai andando a descrever um círculo por aí fora.

O "centro" é o centro do teu mundo.

O "sol" é o centro do teu sol.

Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.