[A83] sinus and cosinus


[Prev][Next][Index][Thread]

[A83] sinus and cosinus



Here's a question for David Phillips (but maybe others can reply to it
also):
You wrote to me ot use a table like this one:

SineTable:
 .db   0,   3,   6,   9,  12,  15,  18,  21,  24,  27
 .db  30,  33,  36,  39,  42,  45,  48,  51,  53,  56
 .db  59,  62,  64,  67,  70,  72,  75,  77,  79,  82
 .db  84,  86,  89,  91,  93,  95,  97,  99, 101, 103
 .db 104, 106, 108, 109, 111, 112, 113, 115, 116, 117
 .db 118, 119, 120, 121, 122, 122, 123, 124, 124, 125
 .db 125, 125, 125, 126

And said this:

To get a cosine value from the table, simply add 64 onto the angle before
looking it up in the table.  Because you are using bytes, the value will
wrap around at 0.  What you must remember is that these are signed values.
128 to 255 will be negative.  255 is -1, and 128 is -127.  This matters when
you are adding these as 16 bit values, because you must sign extend the
value.  In other words, when converting an 8 bit signed number to a 16 bit
signed number, the sign bit, which is always the most significant bit, must
be moved.

But i don't understand the part of the signed values.  I have ball that can
be hit at this positions (the number is kept in a variable so i can recall
it to know where my ball has to go to):

6      5   4   3    2
7                      1
8                      0                          => i know it's a square
but you know what i mean
9                      15
10   11 12 13 14


So if you hit him at 0 the ball has to go in a straight line to the left (so
this means sin = 0 and cos = -1 for the speedvector).  Now your method works
but the 'sinetable' has to contain diffent values for me (maybe only 16
different values for sin but perhaps if i want it (later) to change later
(for more accuracy), i leave it this way).  What i don't understand is how
you get these values in that 'sinetable' so i would you explain it a bit
more, 'cause i don't understand how you load negative values in a register
and 'add' (substract) them later on (you gave me a piece of code with (*) in
it but i didn't understand it).  Maybe you can explain me a bit more about
negative values and wrapping around 0...?
Hope you can help me...'cause i'm really stuck.




Follow-Ups: