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>
19 /***********************************************************************************/
21 struct IntuitionBase
*IntuitionBase
;
22 struct GfxBase
*GfxBase
;
23 struct Library
*CyberGfxBase
;
27 ULONG cgfx_coltab
[256];
28 UBYTE remaptable
[256];
31 WORD winx
= -1, winy
= -1;
32 BOOL forcescreen
, forcewindow
;
33 BOOL mustremap
, truecolor
, remapped
, wbscreen
= TRUE
;
35 static void cleanup(char *msg
);
37 /***********************************************************************************/
43 #define M_PI 3.14159265358979323846 /* pi */
49 void do_precalc(float Hp2
, /* altitude du 2eme plan (1er = 0) (positif...) */
50 float Xd
, float Yd
, float Zd
,
51 float cx
, float cy
, float cz
, /* vecteur de visee central */
52 float vx1
, float vy1
, float vz1
, /* vecteur selon X ecran */
53 float vx2
, float vy2
, float vz2
/* vecteur selon Y ecran */
58 extern void refresh_prout(); /* eh eh */
61 float alpha
[H
/8+1][W
/8+1] ;
62 float zede
[H
/8+1][W
/8+1] ;
64 unsigned char *texture1
, *buffer
, *buffer_remapped
;
66 int ikse
[H
/8+1][W
/8+1] ;
67 int igrek
[H
/8+1][W
/8+1] ;
69 /***********************************************************************************/
71 void rotate3d(float *xr
, float *yr
, float *zr
, /* le point a faire tourner */
72 float ax
, float ay
, float az
) /* les 3 angles (ordre ?..) */
77 xr2
= (*xr
*cos(az
) + *yr
*sin(az
));
78 yr2
= (*xr
*sin(az
) - *yr
*cos(az
));
82 xr2
= (*xr
*cos(ay
) + *zr
*sin(ay
));
83 zr2
= (*xr
*sin(ay
) - *zr
*cos(ay
));
87 zr2
= (*zr
*cos(ax
) + *yr
*sin(ax
));
88 yr2
= (*zr
*sin(ax
) - *yr
*cos(ax
));
93 void initinfplane(void)
98 /* Chargement de la texture */
100 c
= (char *) malloc ( 256*257 );
101 buffer
= (char *)malloc (W
*(H
+1));
103 cleanup("Out of memory!");
107 buffer_remapped
= malloc(W
*H
);
108 if (!buffer_remapped
)
109 cleanup("Out of memory!");
112 fichier
= fopen ( "pattern.data" , "rb" );
114 cleanup("Can't open pattern.data file!");
116 if (fread ( c
, 1, 256*256 , fichier
) != 256*256)
117 cleanup("Error reading pattern.data file!");
122 fichier
= fopen ( "pattern.pal" , "rb" );
126 cleanup("Can't open pattern.pal file!");
129 if (fread ( cgfx_coltab
, 1, 256 * 4 , fichier
) != 256 * 4)
132 cleanup("Error reading pattern.pal file!");
137 /* Fix palette endianess */
143 for(i
= 0; i
< 256; i
++)
145 cgfx_coltab
[i
] = AROS_LONG2BE(cgfx_coltab
[i
]);
154 for(i
= 0; i
< 256; i
++)
156 ULONG r
= (cgfx_coltab
[i
] >> 16) & 0xFF;
157 ULONG g
= (cgfx_coltab
[i
] >> 8) & 0xFF;
158 ULONG b
= cgfx_coltab
[i
] & 0xFF;
162 ULONG red
= r
* 0x01010101;
163 ULONG green
= g
* 0x01010101;
164 ULONG blue
= b
* 0x01010101;
166 remaptable
[i
] = ObtainBestPen(scr
->ViewPort
.ColorMap
,
170 OBP_Precision
, PRECISION_IMAGE
,
171 OBP_FailIfBad
, FALSE
,
178 ULONG red
= r
* 0x01010101;
179 ULONG green
= g
* 0x01010101;
180 ULONG blue
= b
* 0x01010101;
182 SetRGB32(&scr
->ViewPort
, i
, red
, green
, blue
);
187 texture1
= (unsigned char *) c
;
191 void do_precalc(float Hp2
,
192 float Xd
, float Yd
, float Zd
,
193 float cx
, float cy
, float cz
, /* vecteur de visee central */
194 float vx1
, float vy1
, float vz1
, /* vecteur selon X ecran */
195 float vx2
, float vy2
, float vz2
/* vecteur selon Y ecran */
203 /* euh hem, tjours le meme probleme qd X ou Y arrivent a 65536... */
215 for (j
=0; j
<=H
/8; j
++)
217 x
= cx
- vx1
*W
/16 + (j
- H
/16)*vx2
;
218 y
= cy
- vy1
*W
/16 + (j
- H
/16)*vy2
;
219 z
= cz
- vz1
*W
/16 + (j
- H
/16)*vz2
;
221 for (i
=0; i
<=W
/8; i
++)
229 if (z
<=0.001) /* look downward ? */
234 ikse
[j
][i
]= (int)256*(Xd
+x
*t
);
235 igrek
[j
][i
]= (int)256*(Yd
+y
*t
);
238 else if (z
>=0.001) /* look at the sky => 2nd plane */
242 ikse
[j
][i
]= (int)256*(Xd
+x
*t
);
243 igrek
[j
][i
]= (int)256*(Yd
+y
*t
);
246 else /* look infinite */
248 ikse
[j
][i
]= -1; /* C'est une valeur completement idiote */
259 int i
,j
; /* macro-bloc */
260 int ii
,jj
; /* dans bloc (interpolation) */
261 int a
,ai
, z
,zi
; /* 8-8 (fixed-point = lsb) (/pixel)*/
267 unsigned char *tmp
,*tmp1
;
270 for (j
=0; j
<H
/8; j
++)
271 for (i
=0; i
<W
/8; i
++)
293 tmp1
= (unsigned char *)buffer
+ i
*8 + (j
*8)*W
-W
;
305 * ( tmp
++ ) = * ( texture1
+
313 /* unrolling loop... just to see if it improves things
317 * ( tmp++ ) = * ( texture1 +
319 | (((z+=zi)) & (255<<8)) )) ;
320 * ( tmp++ ) = * ( texture1 +
322 | (((z+=zi)) & (255<<8)) )) ;
323 * ( tmp++ ) = * ( texture1 +
325 | (((z+=zi)) & (255<<8)) )) ;
326 * ( tmp++ ) = * ( texture1 +
328 | (((z+=zi)) & (255<<8)) )) ;
329 * ( tmp++ ) = * ( texture1 +
331 | (((z+=zi)) & (255<<8)) )) ;
332 * ( tmp++ ) = * ( texture1 +
334 | (((z+=zi)) & (255<<8)) )) ;
335 * ( tmp++ ) = * ( texture1 +
337 | (((z+=zi)) & (255<<8)) )) ;
338 * ( tmp++ ) = * ( texture1 +
340 | (((z+=zi)) & (255<<8)) )) ;
355 /***********************************************************************************/
357 static void cleanup(char *msg
)
362 printf("InfPlane: %s\n",msg
);
365 if (win
) CloseWindow(win
);
371 for(i
= 0; i
< 256; i
++)
373 ReleasePen(scr
->ViewPort
.ColorMap
, remaptable
[i
]);
380 UnlockPubScreen(0, scr
);
385 if (CyberGfxBase
) CloseLibrary(CyberGfxBase
);
386 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
387 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
392 /***********************************************************************************/
394 #define ARG_TEMPLATE "WINPOSX=X/N/K,WINPOSY=Y/N/K,FORCESCREEN=SCR/S,FORCEWINDOW=WIN/S"
401 static IPTR args
[NUM_ARGS
];
403 static void getarguments(void)
405 struct RDArgs
*myargs
;
407 if ((myargs
= ReadArgs(ARG_TEMPLATE
, args
, NULL
)))
411 else if (args
[ARG_WIN
])
414 if (args
[ARG_X
]) winx
= *(IPTR
*)args
[ARG_X
];
415 if (args
[ARG_Y
]) winy
= *(IPTR
*)args
[ARG_Y
];
421 /***********************************************************************************/
423 static void openlibs(void)
425 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 39)))
427 cleanup("Can't open intuition.library V39!");
430 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 39)))
432 cleanup("Can't open graphics.library V39!");
435 if (!(CyberGfxBase
= OpenLibrary("cybergraphics.library",0)))
437 cleanup("Can't open cybergraphics.library!");
442 /***********************************************************************************/
444 static void getvisual(void)
451 scr
= OpenScreenTags(NULL
, SA_Width
, W
,
455 if (!scr
) cleanup("Failed to open specified screen!");
457 else if (!(scr
= LockPubScreen(NULL
)))
459 cleanup("Failed to lock pub screen (workbench)!");
462 truecolor
= (GetBitMapAttr(scr
->RastPort
.BitMap
, BMA_DEPTH
) >= 15) ? TRUE
: FALSE
;
464 if ((!truecolor
) && (wbscreen
))
468 /***********************************************************************************/
470 static void makewin(void)
472 struct TagItem winonwbtags
[] =
474 {WA_DragBar
, TRUE
},
475 {WA_DepthGadget
, TRUE
},
476 {WA_CloseGadget
, TRUE
},
477 {WA_Title
, (IPTR
)"InfPlane" },
481 struct TagItem winonscrtags
[] =
483 {WA_Borderless
, TRUE
},
487 if (winx
== -1) winx
= (scr
->Width
- W
- scr
->WBorLeft
- scr
->WBorRight
) / 2;
488 if (winy
== -1) winy
= (scr
->Height
- H
- scr
->WBorTop
- scr
->WBorTop
- scr
->Font
->ta_YSize
- 1) / 2;
490 win
= OpenWindowTags(NULL
, WA_CustomScreen
, (IPTR
)scr
,
495 WA_AutoAdjust
, TRUE
,
497 WA_IDCMP
, IDCMP_CLOSEWINDOW
|
499 TAG_MORE
, wbscreen
? winonwbtags
: winonscrtags
);
502 if (!win
) cleanup("Can't open window");
507 /***********************************************************************************/
510 #define KC_RIGHT 0x4E
515 /***********************************************************************************/
517 static void getevents(void)
519 struct IntuiMessage
*msg
;
521 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
525 case IDCMP_CLOSEWINDOW
:
531 WORD code
= msg
->Code
& ~IECODE_UP_PREFIX
;
533 Keys
[code
] = (code
== msg
->Code
) ? 1 : 0;
539 ReplyMsg((struct Message
*)msg
);
544 /***********************************************************************************/
546 static void action(void)
556 float cx
,cy
,cz
; /* vecteur visee */
557 float exx
,exy
,exz
; /* vecteur ex normal */
558 float eyx
,eyy
,eyz
; /* ey */
573 while (!Keys
[KC_ESC
])
581 if (aa
>1){ /* this is the "keyframing" code :)) */
597 rotate3d(&cx
, &cy
, &cz
,
599 rotate3d(&exx
, &exy
, &exz
,
601 rotate3d(&eyx
, &eyy
, &eyz
,
606 Zd
=10*sin(dzz
/70)*0.9+30;
607 Yd
=dzz
+sin(aa
*0.1-thet
*0.2)*700;
623 refresh1 (); /* la routine en C */
625 refresh_prout (); /* ma routine asm */
630 WriteLUTPixelArray(buffer
,
646 UBYTE
*dest
= buffer_remapped
;
648 for(i
= 0; i
< W
* H
; i
++)
650 *dest
++ = remaptable
[*src
++];
652 WriteChunkyPixels(rp
,
655 win
->BorderLeft
+ W
- 1,
656 win
->BorderTop
+ H
- 1,
663 WriteChunkyPixels(rp
,
666 win
->BorderLeft
+ W
- 1,
667 win
->BorderTop
+ H
- 1,
685 /***********************************************************************************/
699 /***********************************************************************************/