Re: Learning how to code free movement and panning in a game like Swamp.

Hi there,
@62: you can imagine it easily from sine's and cosine's diagrams (warning, I mean diagrams, not function graphs).

Imagine a 2d graphing plane, with x axis going from left to right, and y axis from bottom to top. On this plane, imagine a cyrcle with radius 1 and center in coordinates 0;0.
Now, imagine a pointer, vector, which would be fixed in 0;0, and point to 1;0 i.e. to the right. This pointer has length 1, and angle 0 degrees with x axis.
Imagine this pointer would start rotating in the cyrcle, like clock pointer rotates in watches, just in opposite direction i.e. counterclockwise.
At every moment, distance between pointer's ending and x axis is sine of the current angle.

Why?
Because the pointer has length 1 and is hypotenuse, whereas the distance between pointer's ending and x axis is the opposite cathetus to our angle. Marking this distance as d, from definition of sine as oppositeCathetus/hypotenuse we get:
sin=d/1
and thus:
sin=d

The distance between pointer's ending and y axis is on the other hand cosine. Reason is similar like with sine, cosine is defined as:
cos=nearbyCathetus/hypotenuse
i.e. in this case:
cos=nearbyCathetus/1
cos=nearbyCathetus

I'm not sure if I'm using the right english term for nearby cathetus, I mean thatone directly near the angle.

Now, you should be able to tell just naturally, why sine for one and cosine for other dymension.

If your angle system has 0 degrees on the east and increases in counterclockwise movement, like in the case above, sine is logical choice for forward movement i.e. y axis, because the sine goes in this direction, whereas cosine is natural for sides, as it's the distance from y axis and thus modifies your x coordinate.
Infact, any angle you choose on these "clocks", you can see its sine and cosine, like you'd need to add in a game.

If your angle system works like in perhaps most games, i.e. with zero pointing to north and angle increasing when turning right, the same diagram applies, you just need to turn it to right position.
Now zero is infront of you, the pointer rotates in clockwise movement and sine is the distance between its ending and y axis, whereas cosine the distance between its ending and x axis.
Thus it makes sense to increase x by sine and y by cosine, as those are their natural directions.

I hope this explanation made at least some sense.

Best regards

Rastislav

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : chrisnorman7 via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : Nuno via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : Rastislav Kiss via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : Rastislav Kiss via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : Rastislav Kiss via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : Rastislav Kiss via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : Rastislav Kiss via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : Rastislav Kiss via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : Blind angel 444 via Audiogames-reflector

Reply via email to