Ich wollte mir in der Schleife mal per TGI die aktuellen Koordinaten ausgeben lassen. Geht auch nicht. Als ob die Schleifen gar nicht laufen. Vermutlich ist es am Besten, wenn man die Grafik mal komplett abschaltet, und erstmal im Testmodus debugged.
Hier die Version, die nicht tut:
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <modload.h>
- #include <tgi.h>
- #include "float.h"
- #include "math.h"
- int main (void) {
- unsigned char Border;
- int XRes, YRes;
- float xf, xfMin, xfMax, xfDelta, yf, yfMin, yfMax, yfDelta, radiusf, zf, zScale;
- int x,y;
- char debugOutput[80];
-
- tgi_load (TGI_MODE_320_200_2);
- tgi_init ();
-
- XRes = tgi_getxres();
- YRes = tgi_getyres();
-
- Border = bordercolor(COLOR_BLACK);
-
-
-
-
- yfMin = itof( -144);
- yfMax = itof( 144);
- yfDelta = _strtof( "2.25");
- zScale = _itof( 20);
- for( yf = yfMin; _fcmp( yf, yfMax) < 1; yf = _fadd( yf, yfDelta)) {
- xfMax = _ftoi( _fadd( _strtof( "0.5"), ( fsqr( _fsub( _fmul( yfMin, yfMin), _fmul( yf, yf))))));
- xfMin = _fneg( xfMax);
- xfDelta = _itof( 1);
- for( xf = xfMin; _fcmp( xf, xfMax) < 1; xf = _fadd( xf, xfDelta)) {
- _ftostr( debugOutput, xf);
- tgi_outtextxy( 10, 20, debugOutput);
- _ftostr( debugOutput, yf);
- tgi_outtextxy( 30, 20, debugOutput);
- radiusf = _fmul( _strtof( ".0327"), _fsqr( _fadd( _fmul( xf, xf), _fmul( yf, yf))));
- zf = _fmul( zScale, _fadd( _fadd( _fcos( radiusf), _fcos( _fmul( radiusf, _itof( 2)))), _fcos( _fmul( radiusf, _itof(5)))));
-
- x = _ftoi( _fmul( _fadd( _fadd( xf, _fdiv( yf, yfDelta)), _itof( 160)), _strtof( ".85")));
- y = _ftoi( _fmul( _fsub( _itof( 199), _fadd( _fsub( zf, _fdiv( yf, yfDelta)), _itof( 90))), _strtof( ".9")));
- if( y > 0 && y < 200) {
- tgi_setpixel( x ,y);
-
- if( y < 199) {
- tgi_setcolor( COLOR_BLACK);
- tgi_line( x, y + 1, x, 199);
- tgi_setcolor( COLOR_WHITE);
- }
- }
- }
- }
- while (!kbhit());
-
-
- tgi_unload ();
-
- bordercolor (Border);
-
- printf ("Done\n");
- return EXIT_SUCCESS;
- }
Display More
Ciao,
Andreas
PS: jetzt mal ohne Grafik probiert...
_ftoi scheint schonmal nicht richtig zu funktionieren. Der Ausdruck
xfMax = _ftoi( _fadd( _strtof( "0.5"), ( fsqr( _fsub( _fmul( yfMin, yfMin), _fmul( yf, yf))))));
ergibt 0, obwohl der Ausdruck _fadd .... 5 ergibt. Was wiederum auch falsch sein müsste, weil yfMin am Anfang doch gleich yf ist, also der Ausdruck in der Wurzel 0 wäre.
Vielleicht wäre es sinnvoll, mal eine Testsuite für die Funktionen zu schreiben, damit man mal sieht, welche Funktion welche Ergebnisse bringt?