1 #include <aros/oldprograms.h>
13 extern struct Library
* MathTransBase
;
15 short RevMesh
= DefRevMeshVal
;
16 short RevImageR
, /* revolution index */
17 RevImageB
; /* bezier index */
19 static int RotRange
= DefRotRange
;
20 static int RotStart
= DefRotStart
;
21 static int SecAngle
= DefTilt
;
22 static float SurfDist
= DefSurfDist
;
23 static float ViewDist
= DefViewDist
;
24 static bool Perspective
= DefPersp
;
26 void SetPerspective( value
)
34 void SetRevAxis( int value
)
37 RevAxis
= (value
)? RevY
: RevX
;
41 void SetRotStart( value
)
47 void SetRotRange( value
)
53 void SetSecAng( value
)
59 void SetRevMesh( value
)
67 void SetSurfDist( value
)
70 SurfDist
= (float )value
;
74 void SetViewDist( value
)
77 ViewDist
= (float )value
;
83 float secsin
, seccos
; /* trig values of secondary angle */
93 int NumEnts
; /* number of angle slices */
102 * allocate space 3d descriptions of a point revolved x degrees
104 if( NumEnts
> sizeptlist
) {
105 if( ptlist1
) free(ptlist1
);
106 if( ptlist2
) free(ptlist2
);
108 ptlist1
=(PtGen
*) malloc( NumEnts
* sizeof(PtGen
) );
109 ptlist2
=(PtGen
*) malloc( NumEnts
* sizeof(PtGen
) );
110 if( !ptlist1
|| !ptlist2
) {
111 OutErr("PrepRev:not enough memory");
117 if( InitFastTrig( RotStart
, RotRange
, NumEnts
)) return(true);
118 secsin
= sin((float)SecAngle
*PI
/180);
119 seccos
= cos((float)SecAngle
*PI
/180);
125 void CalcRing(ptlist
, xpos
, ypos
)
126 register PtGen
*ptlist
;
131 for( angle
= 0; angle
< NumEnts
; angle
++, ptlist
++) {
134 * calculate 3d coordinate of point revolved
136 if( RevAxis
== RevX
) {
137 ptlist
->d3
.y
= ypos
* fcos(angle
);
138 temp
= ypos
* fsin(angle
);
139 ptlist
->d3
.x
= xpos
* seccos
- temp
*secsin
;
140 ptlist
->d3
.z
= xpos
* secsin
+ temp
* seccos
;
143 ptlist
->d3
.x
= xpos
* fcos(angle
);
144 temp
= xpos
* fsin( angle
);
145 ptlist
->d3
.y
= ypos
* seccos
+ temp
* secsin
;
146 ptlist
->d3
.z
= secsin
* ypos
- temp
* seccos
;
148 ptlist
->d3
.z
-= SurfDist
;
150 /* if( Perspective ) {
153 PerspScale = fabs(ViewDist / ptlist->d3.z);
154 ptlist->d3.x *= PerspScale;
155 ptlist->d3.y *= PerspScale;
159 * calculate the 2d screen coordinate equvalent
162 ptlist->d2.x = (short) ptlist->d3.x;
163 ptlist->d2.y = (short) ptlist->d3.y;
165 ptlist
->d2
.x
= (short) (ptlist
->d3
.x
+ 0.5);
166 ptlist
->d2
.y
= (short) (ptlist
->d3
.y
+ 0.5);
176 * return true on failure
178 bool Revolve(acceptfunc
)
179 void (*acceptfunc
)();
188 deltat
= 1.0/BezMesh
;
196 xpos
= StartPtX(GetCurSeg());
197 ypos
= StartPtY(GetCurSeg());
198 CalcRing(ptlist1
, xpos
, ypos
);
199 for( subseg
= 1; subseg
<= BezMesh
; subseg
++ ) {
200 register PtGen
*ptlista
, *ptlistb
;
201 register int numpoly
;
203 tparm
= subseg
* deltat
;
205 ptlista
= ptlist2
; ptlistb
= ptlist1
;
208 ptlista
= ptlist1
; ptlistb
= ptlist2
;
211 CalcBezPt(tparm
, &xpos
, &ypos
);
212 CalcRing( ptlista
, xpos
, ypos
);
214 for( numpoly
= NumEnts
-1; numpoly
--; ) {
215 (* acceptfunc
)(ptlistb
, ptlista
, ptlista
+1, ptlistb
+1);
229 * write a ring of points
231 static void WriteRing(fileout
, ptlist
, numpnts
)
237 fprintf(fileout
, "%f %f %f \n", ptlist
->d3
.x
,
238 ptlist
->d3
.y
, ptlist
->d3
.z
);
244 * write the list of vertices to file pointer
245 * this function performs a similar function to revolve
247 static void WriteRevolve(fileout
)
256 OldSurfDist
= SurfDist
;
258 deltat
= 1.0/BezMesh
;
262 * write out the starting ring
265 xpos
= StartPtX(GetCurSeg());
266 ypos
= StartPtY(GetCurSeg());
267 CalcRing(ptlist1
, xpos
, ypos
);
268 WriteRing(fileout
, ptlist1
, NumEnts
);
270 * loop to write out all the other rings
275 for( subseg
= 1; subseg
<= BezMesh
; subseg
++ ) {
276 tparm
= subseg
* deltat
;
277 CalcBezPt(tparm
, &xpos
, &ypos
);
278 CalcRing( ptlist1
, xpos
, ypos
);
279 WriteRing(fileout
, ptlist1
, NumEnts
);
285 SurfDist
= OldSurfDist
;
291 * this function writes a list of vertices to "filename"
293 void WriteData(filename
)
298 if(( GetNumSegs() < 1) || PrepRev()){
302 fileout
= fopen(filename
,"w");
304 OutErr("could not open data file");
309 fprintf(fileout
, "%d * number of Rings\n", BezRings());
310 fprintf(fileout
, "%d * Rev mesh\n", RevMesh
);
311 fprintf(fileout
, "%d * Rotation range\n", RotRange
);
312 WriteRevolve(fileout
);
313 fprintf(fileout
, "end\n");