Can someone please help me with fixed to integer math?
Displaying 1-17 of 17 total.
1
blues_zodiakos
|
I'm having a lot of trouble making my Mode 7 function because of the lack of decimal math. I can't seem to find a way around it. I can't even find a way to fake it.
I've ported most of the code here:
http://www.pixelate.co.za/issues/5/articles/circle/sincos.htm
in the Mode 7 section. However, most of those lines return "0" because of the lack of decimals. I've tried multiplying them by 100 and then dividing by 100 when they are used, but the functions themselves don't seem to be doing decimal math behind the scenes, and simply round down. Can anyone help?
Posted on 2004-05-28 21:01:39
|
Buckermann
|
If you post some of your code I may be able to help. I too had some trouble with my menu functions regarding decimals and eventually was able to solve them.
Posted on 2004-05-29 03:17:25
|
blues_zodiakos
|
I'm not actually at my main computer right now, so I can't post the code, but it's functionally the same as the code listed at that link, with the functions replaced by the equivalent verge functions, and all FIXED converted to INT, and all the sin and cosine * blah divided by 65535 at the end, and the MODE_7_PARAMS struct replaced with simple global integers. If there were floats or fixed in verge, it would work with almost no modification.
Posted on 2004-05-29 07:35:07
|
RageCage
|
I'm kinda busy so I dont want to spend too much time but here's my source for a line. It might help you figure out what you need to do...
void testline(int x1, int y1, int x2, int y2){
int i, x, y;
int a=x2-x1;
int b=y2-y1;
int c=sqrt(pow(a,2)+pow(b,2));
int ang= abs(atan(b*65536/a));
if(a<0) ang=180-ang;
if(a=0) ang=90-ang;
if(b<0) ang=360-ang;
for(i=0;i<=c;i++){
x=i*cos(ang)/65536;
y=i*sin(ang)/65536;
setPixel(x +x1, y +y1, RGB(255,255,255),screen);
}
}
Posted on 2004-05-29 17:05:22 (last edited on 2004-05-29 17:07:11)
|
blues_zodiakos
|
O.o
Posted on 2004-05-29 18:48:04
|
RageCage
|
65536 is some kinda special number that you use to get the right answer out of verge when using sin,cos,tan and arcs. use it the way I did and you should be safe
edit: you already knew that.. whoops... uhh... can you help me out a little more than o.O with fixing your confusion? =p
Posted on 2004-05-29 23:37:34 (last edited on 2004-05-29 23:39:26)
|
Gayo
|
I recommend that you bitshift by 16 instead for the sake of clarity! But, uh, no help re: the actual thing.
Posted on 2004-05-30 00:28:50 (last edited on 2004-05-30 00:28:51)
|
Gayo
|
Ignore this. You saw nothing.
Posted on 2004-05-30 08:08:53 (last edited on 2004-05-30 08:09:31)
|
el_desconocido
|
Quote:Originally posted by Gayo
Ignore this. You saw nothing.
Crap! I missed the pre-edit version, and so really did see nothing. And the fact that I know there was something you don't want me to see will keep me up nights wondering. :(
Sometimes I really hate being so curious...
El Gato
Posted on 2004-05-30 08:20:04
|
blues_zodiakos
|
Sorry it took so long to respond.
It took me about a week to finally understand what Sine and Cosine do. Enter square roots and magnitude into the mix and Zodiakos' head go boom. I'm trying to work it out, but it hurts so good!
I think a good explanation of a workaround for floats would benifit many people greatly.
Posted on 2004-05-30 23:26:36
|
mcgrue
|
I agree. And as soon as someone's willing to explain it all very nicely, it'll go into the docs ;)
Posted on 2004-05-31 01:19:35
|
RageCage
|
if someone doesnt do it before the HOV is over, I'll see how well I can write an article on it
Posted on 2004-05-31 05:03:01
|
Gayo
|
I tried reading a paper about how floats work once, and it was complicated and made me sad.
Posted on 2004-06-01 04:04:21
|
el_desconocido
|
Quote:Originally posted by Gayo
I tried reading a paper about how floats work once, and it was complicated and made me sad.
Dude floats are easy. The water they displace weighs more than the float itself, so the water is pulled beneath them by gravity, pushing them up. ;)
El Ligero
Posted on 2004-06-01 05:50:13
|
aen
|
If anybody is having a little bit of trouble with the concept of fixed-point, I wrote up a little mini intro on the topic:
fixed-point-r3.txt
Posted on 2004-06-02 06:27:40 (last edited on 2004-06-02 06:29:08)
|
RageCage
|
Is there anything you can't do aen? ^_^
Posted on 2004-06-02 13:25:40
|
aen
|
I can't... I can't... man, this is so hard to say. I can't... not rock! OH GOD IT'S TRUE-HOO-HOOOOO ;_;
Posted on 2004-06-02 20:11:10
|