News for hackers. Stuff that matters.
Re:Donut math: how donut.c works by munchler on Monday September 18, 2023 @12:40AM (#37552305)
(2011)
Re:Donut math: how donut.c works by Agingcoder on Monday September 18, 2023 @01:53AM (#37552690)
That’s the kind of thing that had me learn coding many years ago ( watching demoscene productions).
Re:Donut math: how donut.c works by supportengineer on Monday September 18, 2023 @02:27AM (#37552914)
What platform does this compile on? Didn't work for me on a recent model M1 MacBook Pro.
Re:Donut math: how donut.c works by physicsguy on Monday September 18, 2023 @02:39AM (#37552991)
What were the errors?
Re:Donut math: how donut.c works by unwind on Monday September 18, 2023 @03:15AM (#37553251)
I got it to compile in Linux on x86-64, with the following tiny changes:

- Add #include <stdio.h> (for printf())

- Add #include <string.h> (for memset())

- Add "int" before the initial bare declaration of "k"

I compiled it with:

    $ gcc -o donut -std=c89 donut.c -lm
Which includes:

- Specifying an old language standard to get rid of the need to say "int" before main()

- Linking the math library ("-lm") for the trig functions.

Update: minor grammar and clarification.

Re:Donut math: how donut.c works by stabbles on Monday September 18, 2023 @04:05AM (#37553542)
With -std=c89 you shouldn't need that `int k`, right?

Further, you can add includes on the command line

    cc -std=c89 donut.c -include stdio.h -include string.h -include math.h -lm
Then the source can be left as is.
Re:Donut math: how donut.c works by ptspts on Monday September 18, 2023 @01:27PM (#37559157)
It should compile without the #includes, possibly didplaying some compiler warnings.
Re:Donut math: how donut.c works by forgotpwd16 on Tuesday September 19, 2023 @03:28PM (#37575112)
Yeap. A

   gcc -lm donut.c
is enough. Also type and return type default to `int` so this doesn't need change either.
Re:Donut math: how donut.c works by jheriko on Monday September 18, 2023 @03:13AM (#37553232)
reminds me of stuff i based in basic when i was a kid

made me laugh to see "no raytracing", then immediate use of the perspective projection which is intersecting points and a plane along a ray lol...

Re:Donut math: how donut.c works by waveBidder on Monday September 18, 2023 @04:26AM (#37553655)
it's boutique hand-derived ray tracing! very different
Re:Donut math: how donut.c works by ggambetta on Monday September 18, 2023 @04:44AM (#37553751)
Deriving the perspective projection equations involves intersecting a ray and the projection plane, but this doesn't magically turn a rasterizer into a raytracer.
Re:Donut math: how donut.c works by enigmarc on Monday September 18, 2023 @05:06AM (#37553893)
Interesting.

Tangentially reminds me of my own animated GIF app that I made a while ago.

https://www.gifcii.fun

Re:Donut math: how donut.c works by mkii on Monday September 18, 2023 @05:30AM (#37554036)
This is seriously cool
Re:Donut math: how donut.c works by ryandv on Monday September 18, 2023 @05:52AM (#37554167)
Reminds me of this classic IOCCC entry, implementing a flight simulator in C, whose source code resembles a plane: https://www.ioccc.org/1998/banks.orig.c

https://www.ioccc.org/years.html#1998_banks

Re:Donut math: how donut.c works by ryandv on Monday September 18, 2023 @07:39AM (#37554873)
Reminds me of this classic IOCCC entry implementing a flight simulator, where portions of the source code are formatted to resemble a plane:

https://www.ioccc.org/1998/banks.orig.c

https://www.ioccc.org/years.html#1998_banks