3 #include <intuition/intuition.h>
4 #include <graphics/gfx.h>
5 #include <cybergraphx/cybergraphics.h>
6 #include <proto/exec.h>
8 #include <proto/graphics.h>
9 #include <proto/cybergraphics.h>
10 #include <proto/intuition.h>
11 #include <aros/macros.h>
20 /***********************************************************************************/
22 struct IntuitionBase
*IntuitionBase
;
23 struct GfxBase
*GfxBase
;
24 struct Library
*CyberGfxBase
;
28 ULONG cgfx_coltab
[256];
29 UBYTE remaptable
[256];
32 WORD winx
= -1, winy
= -1;
33 BOOL forcescreen
, forcewindow
;
34 BOOL mustremap
, truecolor
, remapped
, wbscreen
= TRUE
;
36 static void cleanup(char *msg
);
38 /***********************************************************************************/
41 /* comment/undefine this define to use the asm routine */
47 #define M_PI 3.14159265358979323846 /* pi */
54 void do_precalc(float Hp2
, /* altitude du 2eme plan (1er = 0) (positif...) */
55 float Xd
, float Yd
, float Zd
,
56 float cx
, float cy
, float cz
, /* vecteur de visee central */
57 float vx1
, float vy1
, float vz1
, /* vecteur selon X ecran */
58 float vx2
, float vy2
, float vz2
/* vecteur selon Y ecran */
61 extern void refresh_prout(); /* eh eh */
63 float alpha
[H
/8+1][W
/8+1] ;
64 float zede
[H
/8+1][W
/8+1] ;
66 unsigned char *texture1
, *buffer
, *buffer_remapped
;
68 int ikse
[H
/8+1][W
/8+1] ;
69 int igrek
[H
/8+1][W
/8+1] ;
71 /***********************************************************************************/
73 void rotate3d(float *xr
, float *yr
, float *zr
, /* le point a faire tourner */
74 float ax
, float ay
, float az
) /* les 3 angles (ordre ?..) */
79 xr2
= (*xr
*cos(az
) + *yr
*sin(az
));
80 yr2
= (*xr
*sin(az
) - *yr
*cos(az
));
84 xr2
= (*xr
*cos(ay
) + *zr
*sin(ay
));
85 zr2
= (*xr
*sin(ay
) - *zr
*cos(ay
));
89 zr2
= (*zr
*cos(ax
) + *yr
*sin(ax
));
90 yr2
= (*zr
*sin(ax
) - *yr
*cos(ax
));
95 void initinfplane(void)
100 /* Chargement de la texture */
102 c
= (char *) malloc ( 256*257 );
103 buffer
= (char *)malloc (W
*(H
+1));
105 cleanup("Out of memory!");
109 buffer_remapped
= malloc(W
*H
);
110 if (!buffer_remapped
)
111 cleanup("Out of memory!");
114 fichier
= fopen ( "pattern.data" , "rb" );
116 cleanup("Can't open pattern.data file!");
118 if (fread ( c
, 1, 256*256 , fichier
) != 256*256)
119 cleanup("Error reading pattern.data file!");
124 fichier
= fopen ( "pattern.pal" , "rb" );
128 cleanup("Can't open pattern.pal file!");
131 if (fread ( cgfx_coltab
, 1, 256 * 4 , fichier
) != 256 * 4)
134 cleanup("Error reading pattern.pal file!");
139 /* Fix palette endianess */
145 for(i
= 0; i
< 256; i
++)
147 cgfx_coltab
[i
] = AROS_LONG2BE(cgfx_coltab
[i
]);
156 for(i
= 0; i
< 256; i
++)
158 ULONG r
= (cgfx_coltab
[i
] >> 16) & 0xFF;
159 ULONG g
= (cgfx_coltab
[i
] >> 8) & 0xFF;
160 ULONG b
= cgfx_coltab
[i
] & 0xFF;
164 ULONG red
= r
* 0x01010101;
165 ULONG green
= g
* 0x01010101;
166 ULONG blue
= b
* 0x01010101;
168 remaptable
[i
] = ObtainBestPen(scr
->ViewPort
.ColorMap
,
172 OBP_Precision
, PRECISION_IMAGE
,
173 OBP_FailIfBad
, FALSE
,
180 ULONG red
= r
* 0x01010101;
181 ULONG green
= g
* 0x01010101;
182 ULONG blue
= b
* 0x01010101;
184 SetRGB32(&scr
->ViewPort
, i
, red
, green
, blue
);
189 texture1
= (unsigned char *) c
;
193 void do_precalc(float Hp2
,
194 float Xd
, float Yd
, float Zd
,
195 float cx
, float cy
, float cz
, /* vecteur de visee central */
196 float vx1
, float vy1
, float vz1
, /* vecteur selon X ecran */
197 float vx2
, float vy2
, float vz2
/* vecteur selon Y ecran */
205 /* euh hem, tjours le meme probleme qd X ou Y arrivent a 65536... */
217 for (j
=0; j
<=H
/8; j
++)
219 x
= cx
- vx1
*W
/16 + (j
- H
/16)*vx2
;
220 y
= cy
- vy1
*W
/16 + (j
- H
/16)*vy2
;
221 z
= cz
- vz1
*W
/16 + (j
- H
/16)*vz2
;
223 for (i
=0; i
<=W
/8; i
++)
231 if (z
<=0.001) /* look downward ? */
236 ikse
[j
][i
]= (int)256*(Xd
+x
*t
);
237 igrek
[j
][i
]= (int)256*(Yd
+y
*t
);
240 else if (z
>=0.001) /* look at the sky => 2nd plane */
244 ikse
[j
][i
]= (int)256*(Xd
+x
*t
);
245 igrek
[j
][i
]= (int)256*(Yd
+y
*t
);
248 else /* look infinite */
250 ikse
[j
][i
]= -1; /* C'est une valeur completement idiote */
261 int i
,j
; /* macro-bloc */
262 int ii
,jj
; /* dans bloc (interpolation) */
263 int a
,ai
, z
,zi
; /* 8-8 (fixed-point = lsb) (/pixel)*/
269 unsigned char *tmp
,*tmp1
;
272 for (j
=0; j
<H
/8; j
++)
273 for (i
=0; i
<W
/8; i
++)
295 tmp1
= (unsigned char *)buffer
+ i
*8 + (j
*8)*W
-W
;
307 * ( tmp
++ ) = * ( texture1
+
315 /* unrolling loop... just to see if it improves things
319 * ( tmp++ ) = * ( texture1 +
321 | (((z+=zi)) & (255<<8)) )) ;
322 * ( tmp++ ) = * ( texture1 +
324 | (((z+=zi)) & (255<<8)) )) ;
325 * ( tmp++ ) = * ( texture1 +
327 | (((z+=zi)) & (255<<8)) )) ;
328 * ( tmp++ ) = * ( texture1 +
330 | (((z+=zi)) & (255<<8)) )) ;
331 * ( tmp++ ) = * ( texture1 +
333 | (((z+=zi)) & (255<<8)) )) ;
334 * ( tmp++ ) = * ( texture1 +
336 | (((z+=zi)) & (255<<8)) )) ;
337 * ( tmp++ ) = * ( texture1 +
339 | (((z+=zi)) & (255<<8)) )) ;
340 * ( tmp++ ) = * ( texture1 +
342 | (((z+=zi)) & (255<<8)) )) ;
356 /***********************************************************************************/
358 static void cleanup(char *msg
)
363 printf("InfPlane: %s\n",msg
);
366 if (win
) CloseWindow(win
);
372 for(i
= 0; i
< 256; i
++)
374 ReleasePen(scr
->ViewPort
.ColorMap
, remaptable
[i
]);
381 UnlockPubScreen(0, scr
);
386 if (CyberGfxBase
) CloseLibrary(CyberGfxBase
);
387 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
388 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
393 /***********************************************************************************/
395 #define ARG_TEMPLATE "WINPOSX=X/N/K,WINPOSY=Y/N/K,FORCESCREEN=SCR/S,FORCEWINDOW=WIN/S"
402 static IPTR args
[NUM_ARGS
];
404 static void getarguments(void)
406 struct RDArgs
*myargs
;
408 if ((myargs
= ReadArgs(ARG_TEMPLATE
, args
, NULL
)))
412 else if (args
[ARG_WIN
])
415 if (args
[ARG_X
]) winx
= *(IPTR
*)args
[ARG_X
];
416 if (args
[ARG_Y
]) winy
= *(IPTR
*)args
[ARG_Y
];
422 /***********************************************************************************/
424 static void openlibs(void)
426 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 39)))
428 cleanup("Can't open intuition.library V39!");
431 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 39)))
433 cleanup("Can't open graphics.library V39!");
436 if (!(CyberGfxBase
= OpenLibrary("cybergraphics.library",0)))
438 cleanup("Can't open cybergraphics.library!");
443 /***********************************************************************************/
445 static void getvisual(void)
447 if (!(scr
= LockPubScreen(NULL
)))
449 cleanup("Can't lock pub screen!");
452 if (GetBitMapAttr(scr
->RastPort
.BitMap
, BMA_DEPTH
) <= 8)
464 if (forcescreen
) wbscreen
= FALSE
;
468 UnlockPubScreen(NULL
, scr
);
471 scr
= OpenScreenTags(NULL
, SA_Width
, W
,
475 if (!scr
) cleanup("Can't open screen!");
478 truecolor
= (GetBitMapAttr(scr
->RastPort
.BitMap
, BMA_DEPTH
) >= 15) ? TRUE
: FALSE
;
481 /***********************************************************************************/
483 static void makewin(void)
485 struct TagItem winonwbtags
[] =
487 {WA_DragBar
, TRUE
},
488 {WA_DepthGadget
, TRUE
},
489 {WA_CloseGadget
, TRUE
},
490 {WA_Title
, (IPTR
)"InfPlane" },
494 struct TagItem winonscrtags
[] =
496 {WA_Borderless
, TRUE
},
500 if (winx
== -1) winx
= (scr
->Width
- W
- scr
->WBorLeft
- scr
->WBorRight
) / 2;
501 if (winy
== -1) winy
= (scr
->Height
- H
- scr
->WBorTop
- scr
->WBorTop
- scr
->Font
->ta_YSize
- 1) / 2;
503 win
= OpenWindowTags(NULL
, WA_CustomScreen
, (IPTR
)scr
,
508 WA_AutoAdjust
, TRUE
,
510 WA_IDCMP
, IDCMP_CLOSEWINDOW
|
512 TAG_MORE
, wbscreen
? winonwbtags
: winonscrtags
);
515 if (!win
) cleanup("Can't open window");
520 /***********************************************************************************/
523 #define KC_RIGHT 0x4E
528 /***********************************************************************************/
530 static void getevents(void)
532 struct IntuiMessage
*msg
;
534 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
538 case IDCMP_CLOSEWINDOW
:
544 WORD code
= msg
->Code
& ~IECODE_UP_PREFIX
;
546 Keys
[code
] = (code
== msg
->Code
) ? 1 : 0;
552 ReplyMsg((struct Message
*)msg
);
557 /***********************************************************************************/
559 static void action(void)
569 float cx
,cy
,cz
; /* vecteur visee */
570 float exx
,exy
,exz
; /* vecteur ex normal */
571 float eyx
,eyy
,eyz
; /* ey */
586 while (!Keys
[KC_ESC
])
594 if (aa
>1){ /* this is the "keyframing" code :)) */
610 rotate3d(&cx
, &cy
, &cz
,
612 rotate3d(&exx
, &exy
, &exz
,
614 rotate3d(&eyx
, &eyy
, &eyz
,
619 Zd
=10*sin(dzz
/70)*0.9+30;
620 Yd
=dzz
+sin(aa
*0.1-thet
*0.2)*700;
636 refresh1 (); /* la routine en C */
638 refresh_prout (); /* ma routine asm */
643 WriteLUTPixelArray(buffer
,
659 UBYTE
*dest
= buffer_remapped
;
661 for(i
= 0; i
< W
* H
; i
++)
663 *dest
++ = remaptable
[*src
++];
665 WriteChunkyPixels(rp
,
668 win
->BorderLeft
+ W
- 1,
669 win
->BorderTop
+ H
- 1,
676 WriteChunkyPixels(rp
,
679 win
->BorderLeft
+ W
- 1,
680 win
->BorderTop
+ H
- 1,
698 /***********************************************************************************/
712 /***********************************************************************************/