1 #include <proto/mathffp.h>
2 #include <proto/mathtrans.h>
3 #include <aros/oldprograms.h>
15 #define FarBottom -0x7fff
19 #include <libraries/mathffp.h>
25 extern struct Library
* MathBase
;
26 extern struct Library
* MathTransBase
;
28 void PaintPoint(short, short, float);
30 typedef struct { float left
, right
; } Hedge
;
32 static float *BezMapping
= null
,
34 static float revmin
, revdiff
,
39 * given the ptlist of a polygon, find its vertical range
41 static void FindVRange(scrnlist
, top
, bottom
)
42 register ScrnPair
*scrnlist
;
46 short localtop
, localbot
;
51 for( i
= 4; i
--; scrnlist
++ ) {
52 if( localtop
< scrnlist
->y
) localtop
= scrnlist
->y
;
53 if( localbot
> scrnlist
->y
) localbot
= scrnlist
->y
;
59 * allocate table to store a quick and dirty representation of the
60 * quadrilateral segments
62 static Hedge
*InitVRange( depth
, tabptr
, olddepth
)
63 short depth
, *olddepth
;
67 if( *olddepth
< depth
|| !tabptr
) {
68 if( tabptr
) free( tabptr
);
69 tab
= (Hedge
*) malloc(sizeof(Hedge
)*depth
);
75 if( !tab
) return( null
);
77 for( edgel
= tab
; depth
--; edgel
++) {
78 edgel
->left
= FarRight
;
79 edgel
->right
= FarLeft
;
86 * add line to quadrilateral descriptions
88 static void AddVLine( tab
, x1
, y1
, x2
, y2
)
95 * want y1 to have smaller value, ie, y1 below y2
99 temp
= y1
; y1
= y2
; y2
= temp
;
100 temp
= x1
; x1
= x2
; x2
= temp
;
108 tempx
= x1
; x1
= x2
; x2
= tempx
;
110 if( x2
< tab
->left
) tab
->left
= x2
;
111 if( x1
> tab
->right
) tab
->right
= x1
;
114 slope
= (float)(x2
- x1
)/dy
;
117 #define ZipIt(xxx) { if( xxx < tab->left) tab->left = xxx; \
118 if( xxx > tab->right ) tab->right = xxx; }
128 static void AdjMapXY( inx
, iny
, outpair
)
133 MapXYRatio( inx
, iny
, &outx
, &outy
);
135 outpair
->y
= MapImageH
* (bezmin
+ bezdiff
* outy
);
136 outpair
->x
= MapImageV
* (revmin
+ revdiff
* outx
);
139 if( RevAxis == RevX ) {
140 outpair->y = MapImageH * (bezmin + bezdiff * outy);
141 outpair->x = MapImageV * (revmin + revdiff * outx);
143 outpair->x = MapImageH * (bezmin + bezdiff * outy);
144 outpair->y = MapImageV * (revmin + revdiff * outx);
149 static void ScanCnvQuad( tab
, pt
)
154 ScrnPair
*listb
, *liste
;
159 AddVLine( tab
, listb
->x
, listb
->y
, liste
->x
, liste
->y
);
164 static float AverageShade(pts
)
168 static Hedge
*tabfree
= null
;
169 static short olddepth
= 0;
174 FindVRange( pts
, &top
, &bot
);
175 tabfree
= tab
= InitVRange( top
- bot
+ 1, tabfree
, &olddepth
);
176 if(!tabfree
) return(0.0);
178 ScanCnvQuad( tab
-bot
, pts
);
181 printf("AverageShade top is %d, bot = %d\n", top
, bot
);
185 while( bot
<= top
) {
190 printf("....row %d \t%d -> %d\n", bot
, left
, right
);
194 left
= (int) ceil(tab
->left
- SingleTinyVal
);
195 right
= (int)floor(tab
->right
+ SingleTinyVal
);
197 for( hori
= left
; hori
<= right
; hori
++ ) {
198 shade
+= GetImgPix( bot
, hori
);
203 if( RevAxis == RevX ) {
204 for( hori= left; hori <= right; hori++ ) {
205 shade += GetImgPix( bot, hori);
210 for( hori= left; hori <= right; hori++ ) {
211 shade += GetImgPix( hori, bot);
219 return( (float)shade
/ (pixcnt
*(15 *16)) );
223 * mess with the number so truncation doesn't
224 * do nasty things to a float containing an int
226 static int NearestInt( afloat
)
229 afloat
+= ( afloat
> 0 )? 1e-2 : -1e-2;
230 return( (int)afloat
);
234 static void ShadeQuad(tab
, top
, bot
, intensity
)
240 float rowminl
, rowminr
,
242 Hedge
*oldtab
= NULL
, *nexttab
;
245 nexttab
= tab
+1, vert
<= top
;
246 vert
++, oldtab
= tab
, tab
++ ) {
248 float colmin
, colmax
;
249 float leftmost
, rightmost
;
250 int ihori
, ileftmost
, irightmost
;
253 #define lefttop MpPnts[0]
254 #define leftbot MpPnts[3]
255 #define righttop MpPnts[1]
256 #define rightbot MpPnts[2]
259 rowminl
= (float)vert
;
260 rowmaxr
= rowmaxl
= rowminr
= rowminl
;
262 if( vert
> bot
&& oldtab
->left
< tab
->left
) {
265 if( vert
> bot
&& oldtab
->right
> tab
->right
) {
268 if( vert
< top
&& nexttab
->left
< tab
->left
) {
271 if( vert
< top
&& nexttab
->right
> tab
->right
) {
275 irightmost
= NearestInt( tab
->right
);
276 rightmost
= irightmost
;
277 ileftmost
= NearestInt( tab
->left
);
278 leftmost
= ileftmost
;
279 if( irightmost
< ileftmost
) {
280 irightmost
= ileftmost
;
282 for( ihori
= leftmost
, hori
= leftmost
;
284 ihori
+= 1, hori
+= 1.0 ) {
287 if( AbortDraw
) { return; }
292 colmin
=(colmin
> leftmost
)?colmin
: tab
->left
;
293 colmax
=(colmax
< rightmost
)?colmax
: tab
->right
;
295 AdjMapXY( colmin
, rowmaxl
, &lefttop
, MP_XMIN
| MP_YMAX
);
296 AdjMapXY( colmax
, rowmaxr
, &righttop
, MP_XMAX
| MP_YMAX
);
297 AdjMapXY( colmin
, rowminl
, &leftbot
, MP_XMIN
| MP_YMIN
);
298 AdjMapXY( colmax
, rowminr
, &rightbot
, MP_XMAX
| MP_YMIN
);
300 PaintPoint(ihori
, vert
, AverageShade(MpPnts
) *intensity
);
310 void DrawRhomMap(mpr
)
314 static Hedge
*tab
= null
;
315 static short olddepth
= 0;
317 CalcMapConsts( mpr
->rhom
.pt
);
318 FindVRange( mpr
->rhom
.pt
, &top
, &bottom
);
319 tab
= InitVRange( top
- bottom
+ 1, tab
, &olddepth
);
321 ScanCnvQuad( tab
-bottom
, mpr
->rhom
.pt
);
323 bezmin
= BezMapping
[mpr
->bezindex
];/* make it global */
324 bezdiff
= BezMapping
[mpr
->bezindex
+1] - bezmin
;
325 revmin
= RevMapping
[mpr
->revindex
];
326 revdiff
= RevMapping
[mpr
->revindex
+1] - revmin
;
329 DBMAP(mpr
->rhom
.pt
, mpr
->bezindex
, mpr
->revindex
);
332 ShadeQuad(tab
, top
, bottom
, mpr
->rhom
.intensity
);
336 DBMAP(ptlist
, bindex
, rindex
)
338 short bindex
, rindex
;
342 printf("...................................\n");
343 for( i
= 0; i
< 4; i
++ ) {
344 printf("%10d", ptlist
[i
].x
);
347 for( i
= 0; i
< 4; i
++ ) {
348 printf("%10d", ptlist
[i
].y
);
351 printf(" bezmin %f bezdiff %f index = %d \n", bezmin
, bezdiff
, bindex
);
352 printf(" revmin %f revdiff %f index = %d \n", revmin
, revdiff
, rindex
);
358 * return true if image mappings could not be performed
359 * false if successful
367 if( BezMapping
) free( BezMapping
);
368 if( RevMapping
) free( RevMapping
);
371 * compute width of each bezier segment
373 numvslices
= BezMesh
*GetNumSegs() +1;
374 vfmptr
= BezMapping
= (float *) malloc(sizeof(float) * numvslices
);
375 if( !BezMapping
) return(true);
377 *vfmptr
++ = totallen
= 0.0;
380 float t
, ffromx
, ftox
, ffromy
, ftoy
;
383 for( i
= 1, ffromx
= StartPtX(ActSeg
), ffromy
= StartPtY(ActSeg
);
384 i
<= BezMesh
; i
++, ffromx
= ftox
, ffromy
= ftoy
) {
387 t
= (float)i
/BezMesh
;
389 CalcBezPt( t
, &ftox
, &ftoy
);
390 diffx
= ftox
- ffromx
;
391 diffy
= ftoy
- ffromy
;
392 totallen
+= sqrt( diffx
* diffx
+ diffy
* diffy
);
393 *vfmptr
++ = totallen
;
398 * convert scale floating point values to integer pixel positions
400 scaling
= 1.0 / totallen
;
401 for( vfmptr
= BezMapping
; numvslices
; numvslices
--, vfmptr
++ ) {
405 * compute height of each revolution segment
407 RevMapping
= (float *) malloc( sizeof(float) * (RevMesh
+ 1));
408 if( !RevMapping
) return( true );
411 for( i
= 0; i
<= RevMesh
; i
++ ) {
412 RevMapping
[i
] = ((float) i
)/RevMesh
;