1 #include <aros/oldprograms.h>
4 #include "revolve.h" /* need to get scrnpair from here */
13 extern struct Library
* MathBase
;
14 extern struct Library
* MathTransBase
;
18 * this section of code derived from:
19 * "The essential algorithms of ray tracing" by Eric Haines
20 * presented in Sigraph proceedings on Ray Tracing
21 * my major change has been to simplify it for two dimensions
28 static float DotVector(a
,b
)
31 return( a
->x
* b
->x
+ a
->y
* b
->y
);
34 static void DivVector(in
, scale
, out
)
38 if ( fabs(scale
) < SingleTinyVal
) {
39 out
->x
= SingleLargeVal
;
40 out
->y
= SingleLargeVal
;
43 out
->x
= in
->x
/ scale
;
44 out
->y
= in
->y
/ scale
;
50 static Vector Na
, Nb
, Nc
;
51 static float Du0
, Du1
, Du2
,
53 static Vector Qux
, Quy
,
55 static float Dux
, Duy
,
57 static bool IsQuadu
, IsQuadv
;
59 void CalcMapConsts(vp
)
60 register ScrnPair
*vp
;
66 Vector Pa
, Pb
, Pc
, Pd
;
68 Pa
.x
= p00
.x
- p10
.x
+ p11
.x
- p01
.x
;
69 Pa
.y
= p00
.y
- p10
.y
+ p11
.y
- p01
.y
;
80 Na
.x
= Pa
.y
; Na
.y
= -Pa
.x
;
81 Nc
.x
= Pc
.y
; Nc
.y
= -Pc
.x
;
82 Nb
.x
= Pb
.y
; Nb
.y
= -Pb
.x
;
84 Du0
= DotVector(&Nc
, &Pd
);
85 Du1
= DotVector(&Na
, &Pd
) + DotVector(&Nc
, &Pb
);
86 Du2
= DotVector( &Na
, &Pb
);
88 if( fabs( Du2
) > SingleTinyVal
) {
93 DivVector( &Na
, TwoDu2
, &Qux
);
94 DivVector( &Nc
, -Du2
, &Quy
);
102 Dv0
= DotVector( &Nb
, &Pd
);
103 Dv1
= DotVector(&Na
, &Pd
) + DotVector(&Nb
, &Pc
);
104 Dv2
= DotVector( &Na
, &Pc
);
105 if( fabs( Dv2
) > SingleTinyVal
) {
110 DivVector( &Na
, TwoDv2
, &Qvx
);
111 DivVector( &Nb
, -Dv2
, &Qvy
);
112 /* DivVector( &Nc, -Dv2, &Qvy); */
121 printf("du2 %f, du1 %f, du0 %f\n", Du2
, Du1
, Du0
);
122 printf("dv2 %f, dv1 %f, dv0 %f\n", Dv2
, Dv1
, Dv0
);
123 printf("Na = (%f, %f), Nb = (%f,%f), Nc = (%f,%f)\n",
124 Na
.x
, Na
.y
, Nb
.x
, Nb
.y
, Nc
.x
, Nc
.y
);
125 printf("IsQuad =(%c, %c)\n", IsQuadu
?'t':'f', IsQuadv
? 't': 'f' );
133 * given points px,py in the quadrilateral, map them to points inside a
136 void MapXYRatio(px
, py
, outx
, outy
, SweepCode
)
145 Ri
.x
= px
; Ri
.y
= py
;
149 denom
= (Du1
- DotVector(&Na
, &Ri
));
150 if( fabs(denom
) < SingleTinyVal
)
153 resu
= (DotVector(&Nc
, &Ri
) - Du0
)/denom
;
158 Ka
= Dux
+ DotVector( &Qux
, &Ri
);
159 Kb
= Duy
+ DotVector( &Quy
, &Ri
);
160 discrim
= sqrt(fabs(Ka
* Ka
- Kb
));
161 resu
= Ka
+ ((discrim
> Ka
)? discrim
: (-discrim
));
164 printf("dux=%f, duy = %f, ka = %f, kb = %f\n",
173 denom
= (Dv1
- DotVector(&Na
, &Ri
));
174 if( fabs(denom
) < SingleTinyVal
)
177 resv
= (DotVector(&Nb
, &Ri
) - Dv0
)/denom
;
182 Ka
= Dvx
+ DotVector( &Qvx
, &Ri
);
183 Kb
= Dvy
+ DotVector( &Qvy
, &Ri
);
184 discrim
= sqrt(fabs( Ka
* Ka
- Kb
));
185 resv
= Ka
+ ((discrim
> Ka
)? discrim
: (-discrim
));
188 printf("dvx=%f, dvy = %f, ka = %f, kb = %f\n",
196 printf("(%f,%f) -> (%f, %f)\n", px
, py
, resu
, resv
);
200 if( resu
> 1.0 || resu
< 0.0 ) {
201 resu
= ( SweepCode
& MP_XMAX
)? 1.0: 0.0;
203 if( resv
> 1.0 || resv
< 0.0 ) {
204 resv
= ( SweepCode
& MP_YMAX
)? 1.0: 0.0;
207 *outx
= resu
; *outy
= resv
;
213 * here abides testcode
223 printf("enter screen pair %s\n",set
);
224 scanf("%d %d", &tx
, &ty
);
225 a
->x
= tx
; a
->y
= ty
;
231 ReadScrnPair("a", &a
[0]);
232 ReadScrnPair("b", &a
[1]);
233 ReadScrnPair("c", &a
[2]);
234 ReadScrnPair("d", &a
[3]);
244 while(!feof(stdin
)) {
245 printf("enter quadrilateral points\n");
246 scanf("%f %f", &inx
, &iny
);
247 MapXYRatio( inx
, iny
, &outx
, &outy
, 0);
248 printf("p(%f,%f)->p(%f,%f)\n", inx
, iny
, outx
, outy
);