[A83] Re: sinus and cosinus


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

[A83] Re: sinus and cosinus




Remember that the sine table has 256 values.  So if you only need 16, then
you must divide by 16, since 256 / 16 = 16 (you divide by 16 because that's
how many parts you want to break a circle into).  Dividing by 16 is easy,
since it's a power of two: shift to the right four times.

When you think about negative numbers, the thing to remember is that there
really isn't any difference between signed and unsigned numbers when they
are the same number of bits, except in how you think about them.  If they're
unsigned, they take up the full 8 bits and have a range of 0-255.  If
they're signed, they take up 7 bits and have a range of 0-127, and -1
to -128.  The sign bit is the highest bit.  So when you have 127, and
increment it, it wraps around to 128.  But, since you are using them as
signed numbers, it is really -128.  When you increment it again, it is 129
or -127.  When it finally reaches 255, it is -1.  Thus, if it is 0, and you
decrement it, it is 255 or -1.  Negative numbers go backwards.  Thus, when
you add a negative and a positive number together, you get the correct
result.  The result is the same whether you are using them as positive or
negative numbers, but the meaning can be different depending on what you
want.

> 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):
>
> 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...?





References: