Page 1 of 1

Sine and Cosine

Posted: Mon Jun 04, 2018 8:19 pm
by WhiteSnoop
I have been struggling for hours trying to get this to work. Now I just don't know what to do anymore so maybe you guys can help me.

Math isn't my strongpoint, so little warning upfront.



[URL]https://prnt.sc/jqu042[/URL]

In the picture, I did sin(90). Even with low precision, I feel that a precision of 0.89 is pretty darn off. It should be 1 right?

For some reason, whenever I run the fsin or fcos instruction, it never seems to give me the right results.

Is there something I am missing in order to have the right values being displayed?



EDIT:

Apparently I had to do some division before I could get the right sine and cosine, not sure if it'll help anyone, but for me the value divided by '56' did the trick.

So this can be closed for all I know

Sine and Cosine

Posted: Tue Jun 05, 2018 8:06 pm
by seikur0
The exact value to divide by is 180/pi ;) In many cases sine/cosine functions take their argument in the unit rad(ians) and not in deg(ree). So you need to convert deg to rad to put it into the function and that's done by multiplying the deg value by pi and dividing it by 180°. Google "radian" for more background.

Sine and Cosine

Posted: Tue Jun 05, 2018 11:48 pm
by WhiteSnoop
Thanks seikur0, I figured this out later aswell. But still thank you for the help. I learned some maths the other day and indeed I thought I could just convert from deg haha.

What I sort of end up doing and to maybe help out others.





[CODE=nasm]

push #18 // mult

push #180 // divider



fld dword ptr [ecx+10] // rotation

fild dword ptr [esp] // divider (int to float)

fldpi // load PI

fdivp // 180 / PI

fdivp // rot / divider

fsin // sine

fimul [esp+4] // sine * mult

fadd [ecx] // add original X axis

fstp [ecx]



add esp,8

[/CODE]



Note: even worse was that the game already stored the values. So eventually I didn't need all this. But hey I learnt something!

Sine and Cosine

Posted: Wed Jun 06, 2018 8:24 am
by SunBeam
^ Was about to ask "can't you find the already calculated values?" :D