├── SRC ├── COMPILE.BAT ├── CLEAN.BAT ├── WONTRUN.TXT ├── RTMZ3D │ ├── POLYENG.CPP │ ├── TDST_HP.HPP │ ├── O3DFILE.HPP │ ├── READ3DS.HPP │ ├── QUA.HPP │ ├── M44.HPP │ ├── RTMZ3D.HPP │ ├── CLP.HPP │ ├── TRIG.HPP │ ├── FRPLASMA.HPP │ ├── TRIG.CPP │ ├── BMP_POTX.HPP │ ├── QUA.CPP │ ├── MATELIB.HPP │ ├── TDSTUFF.HPP │ ├── GL_MATR.HPP │ ├── COLORS.HPP │ ├── FRPLASMA.CPP │ ├── POLYENG.HPP │ ├── M44.CPP │ ├── OBJ3D.HPP │ ├── BMP_POLY.HPP │ ├── CLP.CPP │ ├── CVEC3.HPP │ ├── TDST_HP.CPP │ ├── COLORS.CPP │ ├── O3DFILE.CPP │ ├── MATELIB.CPP │ └── READ3DS.CPP ├── RTMZ.MK ├── RTMZ.WPJ ├── RTMZBAN.HPP ├── RTMZOS │ ├── RTMZOS.HPP │ ├── PCX.HPP │ ├── DOSUTIL.HPP │ ├── TMR.HPP │ ├── VESA.HPP │ ├── PASCALIB.HPP │ ├── MOU.HPP │ ├── EVT.HPP │ ├── MNU.HPP │ ├── EXTTYPES.HPP │ ├── KBD.HPP │ ├── DOSUTIL.CPP │ ├── BMP.HPP │ ├── VGAPACK.HPP │ ├── TMR.CPP │ ├── PASCALIB.CPP │ ├── PCX.CPP │ ├── KBD.CPP │ ├── MOU.CPP │ └── VESA.CPP ├── RTMZ_SUP.HPP ├── RTMZ.MK1 ├── RTMZBAN.CPP ├── RTMZ.TGT ├── RTMZOS.TGT ├── RTMZ3D.TGT ├── RTMZ_SUP.CPP ├── RTMZOS.MK1 ├── README.TXT ├── RTMZ3D.MK1 └── RTMZMENU.CPP ├── docs ├── sshot_rtmz_cow_menu.png ├── sshot_rtmz_f15_shininess.png └── sshot_rtmz_mask_menu_res.png └── README.md /SRC/COMPILE.BAT: -------------------------------------------------------------------------------- 1 | wmake -f rtmz.mk 2 | 3 | -------------------------------------------------------------------------------- /docs/sshot_rtmz_cow_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpasca/rtmz/HEAD/docs/sshot_rtmz_cow_menu.png -------------------------------------------------------------------------------- /docs/sshot_rtmz_f15_shininess.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpasca/rtmz/HEAD/docs/sshot_rtmz_f15_shininess.png -------------------------------------------------------------------------------- /docs/sshot_rtmz_mask_menu_res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpasca/rtmz/HEAD/docs/sshot_rtmz_mask_menu_res.png -------------------------------------------------------------------------------- /SRC/CLEAN.BAT: -------------------------------------------------------------------------------- 1 | del *.obj 2 | del *.lk1 3 | del *.err 4 | del *.map 5 | del *.sym 6 | del *.lb1 7 | del *.lib 8 | del rtmz.exe 9 | -------------------------------------------------------------------------------- /SRC/WONTRUN.TXT: -------------------------------------------------------------------------------- 1 | won't run ?? 2 | Did you uncompress with pkunzip -d ?? 3 | The archive needs to be decompressed with its full directory tree. 4 | 5 | crashes ?? 6 | 2 bad 7 | 8 | ciaox 9 | 10 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/POLYENG.CPP: -------------------------------------------------------------------------------- 1 | #include "POLYENG.HPP" 2 | 3 | POE_Poly_t __POE_standardPoly; 4 | POE_Poly_t *__POE_curPolyP=&__POE_standardPoly; 5 | POE_Vert_t *__POE_curVertP, *__POE_curVertP_c, *__POE_curVertP_n, *__POE_curVertP_t; 6 | -------------------------------------------------------------------------------- /SRC/RTMZ.MK: -------------------------------------------------------------------------------- 1 | project : c:\prog\src\rtmz\rel30\src\rtmz.exe c:\prog\src\rtmz\rel30\src\rtm& 2 | zos.lib c:\prog\src\rtmz\rel30\src\rtmz3d.lib .SYMBOLIC 3 | 4 | !include c:\prog\src\rtmz\rel30\src\rtmz.mk1 5 | !include c:\prog\src\rtmz\rel30\src\rtmzos.mk1 6 | !include c:\prog\src\rtmz\rel30\src\rtmz3d.mk1 7 | -------------------------------------------------------------------------------- /SRC/RTMZ.WPJ: -------------------------------------------------------------------------------- 1 | 37projectIdent0VpeMain1WRect180280754068002MProject3MCommand04MCommand035WFileName8rtmz.tgt6WFileName10rtmzos.tgt7WFileName10rtmz3d.tgt8WVList39VComponent10WRect0024703160011WFileName8rtmz.tgt0612VComponent13WRect2480022004600014WFileName10rtmzos.tgt0615VComponent16WRect4690027405320017WFileName10rtmz3d.tgt039 -------------------------------------------------------------------------------- /SRC/RTMZ3D/TDST_HP.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // TDST_HP.HPP - 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __TDST_HP_HPP__ 7 | #define __TDST_HP_HPP__ 8 | 9 | #include "OBJ3D.HPP" 10 | #include "TDSTUFF.HPP" 11 | #include "POLYENG.HPP" 12 | 13 | #define VERT_T float 14 | 15 | void W3D_HandlePoly( const POE_PolyI_t *polyP ); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /SRC/RTMZBAN.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // RTMZBAN.CPP 3 | // Copyright (C) Davide Pasca 1995-97 4 | // 5 | // TABS=4 6 | //============================================== 7 | #ifndef __RTMZBAN_H__ 8 | #define __RTMZBAN_H__ 9 | 10 | #include "EXTTYPES.HPP" 11 | 12 | void banpost( long seconds, long pos, const char *fmtP, ... ); 13 | void banidle( void ); 14 | void banprint( UB col, long y ); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/O3DFILE.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // O3DFILE.HPP - 3D file objects 3 | // Copyright (C) Davide Pasca 1994-1995 4 | //============================================== 5 | 6 | #ifndef __O3DFILE_HPP__ 7 | #define __O3DFILE_HPP__ 8 | 9 | #include "OBJ3D.HPP" 10 | 11 | long O3D_LoadGEO( const char *fileName, long *badPolysP ); 12 | long O3D_LoadGEOM( const char *fileName, long *badPolysP ); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /SRC/RTMZOS/RTMZOS.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // RTMZOS.HPP 3 | // Copyright (C) Davide Pasca 1995-97 4 | // 5 | // TABS=4 6 | //============================================== 7 | #ifndef __RTMZOS_HPP__ 8 | #define __RTMZOS_HPP__ 9 | 10 | #include "EXTTYPES.HPP" 11 | 12 | #include "EVT.HPP" 13 | #include "KBD.HPP" 14 | #include "MOU.HPP" 15 | #include "MNU.HPP" 16 | #include "TMR.HPP" 17 | #include "VGAPACK.HPP" 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/READ3DS.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // READ3DS.HPP - 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __READ3DS_HPP__ 7 | #define __READ3DS_HPP__ 8 | 9 | #include "OBJ3D.HPP" 10 | 11 | #define LIST_FIELDS \ 12 | char name[80]; \ 13 | void *next; 14 | 15 | typedef struct { 16 | LIST_FIELDS 17 | } List; 18 | 19 | long O3D_Load3DS(const char *fnameP); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/QUA.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // QUA.HPP - quaternions stuff 3 | // Copyright (C) by Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __QUA_HPP__ 7 | #define __QUA_HPP__ 8 | 9 | #include "EXTTYPES.HPP" 10 | 11 | void QUA_QuatFromAxis(float q[4], float phi, const float a[3]); 12 | void QUA_Normalize(float q[4]); 13 | void QUA_Mul(float dest[4], const float q1[4], const float q2[4]); 14 | void QUA_QuatToMat(const float q[4], float m[4][4]); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /SRC/RTMZOS/PCX.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // PCX.HPP - 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | #ifndef __PCX_HPP__ 6 | #define __PCX_HPP__ 7 | 8 | #include "exttypes.hpp" 9 | 10 | long PCX_Read( const char *fnameP, UB **memPP, US *wdP, US *heP, UB *dpP, UB *palP ); 11 | long PCX_ReadPalette( const char *fnameP, UB *palP ); 12 | long PCX_ReadBitMap( const char *nameP, BitMap *bmP, UB *palP ); 13 | long PCX_ReadBitMaps( const char *fnamep, BitMap *bmlistp, long bobwd, long bobhe, long nframes, UB *palP ); 14 | #endif 15 | -------------------------------------------------------------------------------- /SRC/RTMZOS/DOSUTIL.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // DOSUTIL.HPP - 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __DOSUTIL_HPP__ 7 | #define __DOSUTIL_HPP__ 8 | 9 | char DOS_DrivesGetList( char *listP, short *totalP ); 10 | 11 | typedef struct 12 | { 13 | char name[14]; 14 | long size; 15 | }DirElem; 16 | 17 | long filesize(const char *fnameP); 18 | void SortDirElemsByName(DirElem *deP, UL n); 19 | long ScanDir(const char *dirPath, const char *pattern, DirElem **dePP, UL *entriesP ); 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /SRC/RTMZOS/TMR.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // TMR.HPP - timer handler 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __TMR_HPP__ 7 | #define __TMR_HPP__ 8 | 9 | #include "EXTTYPES.HPP" 10 | 11 | extern volatile UL _TMR_Ticks; 12 | extern UL _TMR_TksPerSec; 13 | extern short _soundEnabled; 14 | 15 | long TMR_Open( UL freq ); 16 | void TMR_Close(void); 17 | long TMR_FuncAdd( void (__interrupt *handlerp)() ); 18 | UL TMR_TicksGet(void); 19 | UL TMR_TicksPerSecGet(void); 20 | void TMR_TicksWait( UL howmany ); 21 | 22 | #endif 23 | 24 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/M44.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // M34.HPP - matrix handler 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __M44_HPP__ 7 | #define __M44_HPP__ 8 | 9 | #include "EXTTYPES.HPP" 10 | 11 | void m44_identity( float m[4][4] ); 12 | void m44_multiply( float d[4][4], const float s1[4][4], const float s2[4][4] ); 13 | void m44_invert( float m[4][4] ); 14 | 15 | void m44_scale( float m[4][4], float x, float y, float z ); 16 | inline void m44_equ( float d[4][4], const float s[4][4] ) 17 | { memcpytiny( d, s, 16*sizeof(float) ); 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/RTMZ3D.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // RTMZ3D.HPP 3 | // Copyright (C) Davide Pasca 1995-97 4 | // 5 | // TABS=4 6 | //============================================== 7 | #ifndef __RTMZ3D_HPP__ 8 | #define __RTMZ3D_HPP__ 9 | 10 | #include "EXTTYPES.HPP" 11 | 12 | #include "BMP.HPP" 13 | #include "BMP_POLY.HPP" 14 | #include "BMP_POTX.HPP" 15 | #include "COLORS.HPP" 16 | #include "CLP.HPP" 17 | #include "GL_MATR.HPP" 18 | #include "M44.HPP" 19 | #include "MATELIB.HPP" 20 | #include "POLYENG.HPP" 21 | #include "PASCALIB.HPP" 22 | #include "PCX.HPP" 23 | #include "TDSTUFF.HPP" 24 | #include "TRIG.HPP" 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/CLP.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // CLP.HPP - clipping routines 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __CLP_HPP__ 7 | #define __CLP_HPP__ 8 | 9 | #include "POLYENG.HPP" 10 | 11 | #define CLP_BIT_Z2 5 12 | #define CLP_BIT_Z1 4 13 | #define CLP_BIT_Y2 3 14 | #define CLP_BIT_Y1 2 15 | #define CLP_BIT_X2 1 16 | #define CLP_BIT_X1 0 17 | 18 | #define CLP_CODE_Z1 (1< 10 | #include "EXTTYPES.HPP" 11 | /* 12 | #include "CVEC3.HPP" 13 | 14 | #define P3DA_MAKEPTSTRANS_FLG 1 15 | typedef struct 16 | { 17 | long npix; 18 | long *vecP; 19 | UB *colP; 20 | long *transVecP; 21 | }Pix3DArray; 22 | 23 | void FreePix3DArray( Pix3DArray *pixP ); 24 | long MakePix3DArray( const char *fnameP, Pix3DArray *pixP, long sx, long sy, UL flags ); 25 | */ 26 | 27 | //extern "C" void setmemMsk(void *addr, void *mask, UL len, char val); 28 | 29 | char *strcpymaxsize(char *dst, const char *src, UL max); 30 | void RandomizeShort( short rd ); 31 | short RandShort(void); 32 | 33 | long timer( void ); 34 | void QSortLX( long *aP, long *idxP, long right ); 35 | void QSortLX( float *aP, long right ); 36 | void QSortLX( long *aP, long right ); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /SRC/RTMZOS/MOU.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // MOUSE.HPP - 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __MOUSE_HPP__ 7 | #define __MOUSE_HPP__ 8 | 9 | #include "exttypes.hpp" 10 | 11 | #define MOU_BUT_LFT 1 12 | #define MOU_BUT_RGT 2 13 | #define MOU_BUT_MID 4 14 | #define MOU_BUT_UP 1 15 | #define MOU_BUT_DOWN 2 16 | 17 | #define MOU_EVT_MAX 100 18 | typedef struct 19 | { 20 | UB b; 21 | short x,y; 22 | }MOU_Event_t; 23 | 24 | short MOU_Init(void); 25 | void MOU_FuncSetClick( UB (*clickFuncP)(UB,UB,short,short) ); 26 | void MOU_FuncSetMove( UB (*moveFuncP)(short,short) ); 27 | void MOU_BoundsSet(short x1, short y1, short x2, short y2); 28 | void MOU_PointerShow(void); 29 | void MOU_PointerHide(void); 30 | void MOU_EventsFlush(long n, const MOU_Event_t *evtsP ); 31 | UL MOU_EventsListGet( MOU_Event_t *listP ); 32 | 33 | US MOU_Buttons(void); 34 | short MOU_GetX(void); 35 | short MOU_GetY(void); 36 | void MOU_GetEvents(UB *bP, short *xP, short *yP); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RTMZ 2 | 3 | | | | 4 | |---|---| 5 | | Author: | Davide Pasca | 6 | | Platform: | PC MS-DOS, 80386 and above | 7 | | Build environment: | Watcom C++ (with DOS4GW) | 8 | 9 | ## Overview 10 | 11 | This repository is an historical archive of a real-time 3D engine that I developed in the mid 90s. 12 | 13 | It's written mostly in 'C'. It runs on MS-DOS with VGA and SVGA resolutions on a 256 colors palette. 14 | 15 | Major features are: 16 | - Gouraud shading 17 | - Texture mapping 18 | - Basic lighting and material properties 19 | - Z-Buffer (optional) 20 | - Cool menu interface 21 | 22 | ## Copyright 23 | 24 | Code and executables are my own. It's free to use. Redistribution should include credits. 25 | 26 | 3D models are not built by me. They were found from multiple sources about 30 years ago. I'm assuming that they are as good as public domain by now. If you are the author and wish to be credited, please let me know. 27 | 28 | ![Screen-shot cow](docs/sshot_rtmz_cow_menu.png) 29 | ![Screen-shot f-15](docs/sshot_rtmz_f15_shininess.png) 30 | ![Screen-shot mask](docs/sshot_rtmz_mask_menu_res.png) 31 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/TRIG.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // TRIG.HPP - 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __TRIG_HPP__ 7 | #define __TRIG_HPP__ 8 | 9 | #ifndef PI 10 | #define PI 3.14159265359 11 | #endif 12 | 13 | #define TR_GIR 4096 14 | #define TR_ISHIFT 15 15 | #define TR_MAXISIN (1L< 7 | #include 8 | #include "EXTTYPES.HPP" 9 | 10 | //======================================= 11 | class FractPlasma 12 | { 13 | public: 14 | UB *_mapYP; 15 | US _wd; 16 | short _frastaWd; 17 | long _max; 18 | double _ratio; 19 | 20 | public: 21 | ~FractPlasma(){ Free(); } 22 | 23 | void Free( void ){ if (_mapYP){ free(_mapYP); _mapYP=0; } } 24 | long Alloc( US dim ) 25 | { 26 | _wd=dim; 27 | if NOT(_mapYP = (UB *)calloc((UL)_wd*_wd*sizeof(UB),1)) 28 | return -1; 29 | return 0; 30 | } 31 | UB GetY( US x, US z ) { return( _mapYP[((long)z*_wd)+x] ); }; 32 | void SetY( US x, US z, short col ) 33 | { 34 | _mapYP[((long)z*_wd)+x] = col; 35 | }; 36 | void Make(short x1,short y1,short x2,short y2,short frasta,long seed, long max=256); 37 | void Make(short x1,short y1,short x2,short y2,long seed) 38 | { 39 | Make(x1, y1, x2, y2, 6, seed); 40 | } 41 | 42 | private: 43 | short RandPixel(short x,short y,short x1,short y1,short x2,short y2); 44 | void DoPlasma(short x1,short y1,short x2,short y2); 45 | }; 46 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/TRIG.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // TRIG.CPP - Am I still using this ?? 3 | // Copyright (C) Davide Pasca 1995-97 4 | // 5 | // TABS=4 6 | //============================================== 7 | #include 8 | #include "TRIG.HPP" 9 | 10 | long _tr_isin11[TR_GIR], _tr_icos11[TR_GIR]; 11 | float _tr_fsin11[TR_GIR], _tr_fcos11[TR_GIR]; 12 | long _tr_sqr[1<<0/*8*/], *_tr_sqrP; 13 | //, _tr_bsr[1<<17]; 14 | unsigned char _tr_sqrt[1<<8]; 15 | 16 | extern long bsright(long a); 17 | #pragma aux bsright = \ 18 | "bsr eax,ebx"\ 19 | parm caller [ebx] \ 20 | value [eax] \ 21 | modify [eax ebx]; 22 | 23 | //============================= 24 | void tr_init( void ) 25 | { 26 | long i; 27 | float ang, angStep, fact; 28 | 29 | angStep = PI*2.0 / (float)TR_GIR; 30 | fact = (float)(1L << TR_ISHIFT); 31 | for (i=0; i < TR_GIR; ++i) 32 | { 33 | ang = angStep * i; 34 | _tr_isin11[i] = (_tr_fsin11[i] = sin(ang)) * fact; 35 | _tr_icos11[i] = (_tr_fcos11[i] = cos(ang)) * fact; 36 | } 37 | 38 | /*_tr_sqrP = _tr_sqr+(1<<17); 39 | for (i=-(1<<17); i < (1<<17); ++i) 40 | _tr_sqrP[i] = i*i; 41 | _tr_sqrP[0] = 1;*/ 42 | 43 | // for(i=0; i < (1<<17); ++i) 44 | // _tr_bsr[i] = bsright(i); 45 | 46 | for(i=0; i < (1<<8); ++i) 47 | _tr_sqrt[i] = sqrt( i ); 48 | } 49 | 50 | -------------------------------------------------------------------------------- /SRC/RTMZOS/EVT.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // EVT.HPP - event stuff 3 | // Copyright (C) by Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __EVT_HPP__ 7 | #define __EVT_HPP__ 8 | 9 | #include "EXTTYPES.HPP" 10 | 11 | void EVT_Install(); 12 | 13 | void EVT_FuncMouseClick( UB (*clickFuncP)(UB,UB,short,short) ); 14 | void EVT_FuncMouseMove( UB (*moveFuncP)(short,short) ); 15 | void EVT_FuncKeyb( UB (*keybFuncP)(US,UB) ); 16 | void EVT_FuncSuperKeyb( UB (*keybFuncP)(US,UB) ); 17 | void EVT_FuncReshape( BitMap* (*rshapeFuncP)(long,long,long) ); 18 | void EVT_FuncRedraw( void (*redrFuncP)(void) ); 19 | void EVT_FuncIdle( void (*idleFuncP)(void) ); 20 | void EVT_FuncsPush(void); 21 | void EVT_FuncsPop(void); 22 | void EVT_FuncsReset(void); 23 | 24 | void EVT_PostRedraw(void); 25 | void EVT_PostReshape(long wd, long he, long res); 26 | void EVT_EventsFlush(void); 27 | long EVT_MainLoop(void); 28 | void EVT_MainLoopReturn(long retval); 29 | void EVT_PointerSet( UB *dataP, US wd, US he ); 30 | 31 | void EVT_RecordingStop(void); 32 | void EVT_RecordingStart(void); 33 | long EVT_RecordingSave( const char *fnameP ); 34 | 35 | long EVT_PlaybackLoad( const char *fnameP ); 36 | void EVT_PlaybackStart(void); 37 | void EVT_PlaybackStop(void); 38 | BO EVT_PlaybackIsActive(void); 39 | 40 | void EVT_DisplayUpdateFlag( UB updateDisplay ); 41 | void EVT_DisplayRestoreOld(void); 42 | 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /SRC/RTMZ_SUP.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // RTMZ_SUP.CPP 3 | // Copyright (C) Davide Pasca 1995-97 4 | // 5 | // TABS=4 6 | //============================================== 7 | #ifndef __RTMZ_SUP_H__ 8 | #define __RTMZ_SUP_H__ 9 | 10 | #include "EXTTYPES.HPP" 11 | #include "TMR.HPP" 12 | 13 | //=========================== 14 | class ZoomTask 15 | { 16 | long Z1,Z2,Z,StpZ; 17 | long Pau; 18 | long StaTick; 19 | UB Status; 20 | long Flags, Steps; 21 | const BitMap *SBmP, *DBmP; 22 | 23 | public: 24 | void Start(const BitMap *dbmP, const BitMap *sbmP, long z1, long z2, short n, UB zoomRot, long cent); 25 | void Idle(void); 26 | ZoomTask(){ Status = 0; } 27 | }; 28 | 29 | //====================== 30 | /*class TickSampler 31 | { 32 | US MaxCnt; 33 | US Cnt; 34 | long TickSum,TickSumRun; 35 | 36 | public: 37 | void Reset( US max ) 38 | { 39 | TickSum = 0; 40 | MaxCnt = max; 41 | Cnt = 0; 42 | } 43 | void Start(void) 44 | { 45 | if ( Cnt == 0 ) 46 | TickSumRun = -TMR_TicksGet(); 47 | else 48 | TickSumRun -= TMR_TicksGet(); 49 | 50 | if ( ++Cnt == MaxCnt ) 51 | Cnt = 0; 52 | } 53 | void Stop(void) 54 | { 55 | TickSumRun += TMR_TicksGet(); 56 | if ( Cnt == 0 ) 57 | TickSum = TickSumRun; 58 | } 59 | UB ReadyToGet(void) 60 | { 61 | return Cnt==0; 62 | } 63 | UL TMR_TicksGetum(void) 64 | { 65 | return TickSum; 66 | } 67 | long GetTickMed( long n ) 68 | { 69 | n = n * TMR_TicksPerSecond() * MaxCnt; 70 | 71 | if ( TickSum ) 72 | return n / TickSum; 73 | else 74 | return n; 75 | } 76 | }; 77 | */ 78 | #endif 79 | -------------------------------------------------------------------------------- /SRC/RTMZOS/MNU.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // MNU.HPP - menu stuff 3 | // Copyright (C) by Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __MNU_HPP__ 7 | #define __MNU_HPP__ 8 | 9 | #include "EXTTYPES.HPP" 10 | 11 | #define MNU_ITM_MAXLEN 40 12 | 13 | #define MNU_FLG_IACTIVE 1 14 | #define MNU_FLG_ICHECKED 2 15 | 16 | typedef void (*MNU_CallBack_t)(long,long); 17 | 18 | long MNU_New(long fontID, UB txCol, UB bkCol, UB ltCol, UB dkCol ); 19 | void MNU_ColorsSet( long menuID, BO subs, UB txCol, UB bkCol, UB ltCol, UB dkCol ); 20 | void MNU_FontSet( long menuID, BO subs, long fontID ); 21 | void MNU_Dispose( long menuID, BO disposeSubs ); 22 | void MNU_ItemsReset( long menuID ); 23 | void MNU_ItemCheckAll( long menuID, UB check ); 24 | void MNU_ItemCheckRange( long menuID, long staitm, long enditm, UB check ); 25 | UL MNU_ItemFlagsGet( long menuID, long itm ); 26 | void MNU_ItemFlagsSet( long menuID, long itm, UL flags ); 27 | void MNU_ItemCheck( long menuID, long itm, UB check ); 28 | void MNU_ItemAddCB( long menuID, const char *textP, MNU_CallBack_t callBack, UL flags=0 ); 29 | void MNU_ItemAddID( long menuID, const char *textP, long subMenu, UL flags=0 ); 30 | void MNU_ItemNameGet( long menuID, long itm, char *nameP ); 31 | long MNU_Set(long menuID); 32 | long MNU_Get(void); 33 | long MNU_UserLongGet( long menuID ); 34 | void MNU_UserLongSet( long menuID, long val ); 35 | void MNU_PointerSet( long menuID, UB *dataP, US wd, US he ); 36 | void MNU_ScaleSet( long menuID, BO doSubs, float scaleWd, float scaleHe ); 37 | 38 | UB MNU_EventMouseMove( short x, short y); 39 | UB MNU_EventMouseClick( UB but, UB state, short x, short y); 40 | UB MNU_Render(BitMap *bmP); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /SRC/RTMZ.MK1: -------------------------------------------------------------------------------- 1 | !define BLANK "" 2 | c:\prog\src\rtmz\rel30\src\rtmz.obj : c:\prog\src\rtmz\rel30\src\rtmz.cpp .A& 3 | UTODEPEND 4 | @c: 5 | cd c:\prog\src\rtmz\rel30\src 6 | *wpp386 rtmz.cpp -i=C:\prog\WATCOM\h -i=rtmzos -i=rtmz3d -w2 -e25 -s -zp4 -& 7 | zq -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 8 | 9 | c:\prog\src\rtmz\rel30\src\rtmz_sup.obj : c:\prog\src\rtmz\rel30\src\rtmz_su& 10 | p.cpp .AUTODEPEND 11 | @c: 12 | cd c:\prog\src\rtmz\rel30\src 13 | *wpp386 rtmz_sup.cpp -i=C:\prog\WATCOM\h -i=rtmzos -i=rtmz3d -w2 -e25 -s -z& 14 | p4 -zq -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 15 | 16 | c:\prog\src\rtmz\rel30\src\rtmzban.obj : c:\prog\src\rtmz\rel30\src\rtmzban.& 17 | cpp .AUTODEPEND 18 | @c: 19 | cd c:\prog\src\rtmz\rel30\src 20 | *wpp386 rtmzban.cpp -i=C:\prog\WATCOM\h -i=rtmzos -i=rtmz3d -w2 -e25 -s -zp& 21 | 4 -zq -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 22 | 23 | c:\prog\src\rtmz\rel30\src\rtmzmenu.obj : c:\prog\src\rtmz\rel30\src\rtmzmen& 24 | u.cpp .AUTODEPEND 25 | @c: 26 | cd c:\prog\src\rtmz\rel30\src 27 | *wpp386 rtmzmenu.cpp -i=C:\prog\WATCOM\h -i=rtmzos -i=rtmz3d -w2 -e25 -s -z& 28 | p4 -zq -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 29 | 30 | c:\prog\src\rtmz\rel30\src\rtmz.exe : c:\prog\src\rtmz\rel30\src\rtmz.obj c:& 31 | \prog\src\rtmz\rel30\src\rtmz_sup.obj c:\prog\src\rtmz\rel30\src\rtmzban.obj& 32 | c:\prog\src\rtmz\rel30\src\rtmzmenu.obj c:\prog\src\rtmz\rel30\src\rtmz3d.l& 33 | ib c:\prog\src\rtmz\rel30\src\rtmzos.lib .AUTODEPEND 34 | @c: 35 | cd c:\prog\src\rtmz\rel30\src 36 | @%write rtmz.lk1 NAME rtmz 37 | @%append rtmz.lk1 FIL rtmz.obj,rtmz_sup.obj,rtmzban.obj,rtmzmenu.obj 38 | @%append rtmz.lk1 LIBR rtmz3d.lib,rtmzos.lib 39 | *wlink SYS dos4g op m d all op st=128000 op maxe=25 op q op symf @rtmz.lk1 40 | 41 | -------------------------------------------------------------------------------- /SRC/RTMZOS/EXTTYPES.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // EXTTYPES.HPP - 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __EXTTYPES_HPP__ 7 | #define __EXTTYPES_HPP__ 8 | 9 | #include 10 | 11 | typedef unsigned long UL; 12 | typedef unsigned short US; 13 | typedef unsigned char UB; 14 | typedef unsigned char BO; 15 | typedef struct 16 | { 17 | US wd,he; 18 | UB dp; 19 | UB Flags; 20 | UB *memP; 21 | UB **offsPP; 22 | }BitMap; 23 | typedef struct { long x,y; }VEC2_t; 24 | typedef struct { short x,y; }Point2D; 25 | 26 | #define MAKE_ID(A,B,C,D) (((UL)A) | ((UL)(B)<<8) | ((UL)(C)<<16) | ((UL)(D)<<24)) 27 | #define NOT(X) ((X)==0) 28 | #define ABS(X) ((X) < 0 ? -(X) : X) 29 | #define MIN(A,B) ((A) < (B) ? (A) : (B)) 30 | #define MAX(A,B) ((A) > (B) ? (A) : (B)) 31 | #define CLAMP(X,MI,MA) {if(XMA)X=MA;} 32 | 33 | inline void *ext_new(UL *ptr,UL siz){ return (void *)(*ptr = (UL)malloc(siz)); } 34 | #define NEW(PTR,N) (ext_new((UL *)&PTR,sizeof(*PTR)*(N))) 35 | 36 | #define FREEIF(X) {if (X) free(X);} 37 | #define SAFE_FREE(X) {if (X){free(X); X=0;}} 38 | 39 | #define FREAD(B,S,F) (fread(B,1,S,F)!=(S)) 40 | #define FWRITE(B,S,F) (fwrite(B,1,S,F)!=(S)) 41 | #define SWAP(A,B,T) {T=A;A=B;B=T;} 42 | inline void swap(long &a, long &b){long t=a; a=b; b=t;} 43 | inline void swap(UL &a, UL &b){UL t=a; a=b; b=t;} 44 | inline void swap(short &a, short &b){short t=a; a=b; b=t;} 45 | inline void swap(US &a, US &b){US t=a; a=b; b=t;} 46 | inline long MulAndDiv(long a, long b, long c){return (float)a*(float)b/(float)c;} 47 | //================================== 48 | extern void memcpytiny(void *dP, const void *sP, long size ); 49 | #pragma aux memcpytiny = \ 50 | " cld"\ 51 | " rep movsb"\ 52 | parm caller [edi][esi][ecx]\ 53 | modify [edi esi ecx]; 54 | 55 | #define TAG_END -1 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/BMP_POTX.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // BMP_POTX.HPP - texture-mapped polygons 3 | // Copyright (C) by Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __BMP_POTX_HPP__ 7 | #define __BMP_POTX_HPP__ 8 | 9 | #include "BMP_POLY.HPP" 10 | 11 | void BMP_PolyTextureLUT3D16( const POE_PolyI_t *polyP, const BitMap *tmP, const UB *lut ); 12 | 13 | //================ TEXTURE 2D ===================== 14 | inline void BMP_PolyTexture2D16( const POE_PolyI_t *polyP, const BitMap *tmP ) 15 | { 16 | extern void _bmp_pt2d16setupI(const POE_PolyI_t *, const BitMap *); 17 | extern void _bmp_pt2d16slope(POE_Vert_t *, POE_Vert_t *, long, long ); 18 | extern void _bmp_pt2d16loop(UB *, long); 19 | 20 | _bmp_pt2d16setupI( polyP, tmP ); 21 | BMP_PolyRoutineI( polyP, 0, _bmp_pt2d16slope, _bmp_pt2d16loop ); 22 | } 23 | //============== TEXTURE 2D LUT ===================== 24 | inline void BMP_PolyTextureLUT2D16( const POE_PolyI_t *polyP, const BitMap *tmP, const UB *lutP ) 25 | { 26 | extern void _bmp_pt2dlut16setupI(const POE_PolyI_t *, const BitMap *, const UB *); 27 | extern void _bmp_pt2d16slope(POE_Vert_t *, POE_Vert_t *, long, long ); 28 | extern void _bmp_pt2dlut16loop(UB *, long); 29 | 30 | _bmp_pt2dlut16setupI( polyP, tmP, lutP ); 31 | BMP_PolyRoutineI( polyP, 0, _bmp_pt2d16slope, _bmp_pt2dlut16loop ); 32 | } 33 | //================ TEXTURE CHROME ===================== 34 | inline void BMP_PolyTextureChrome16( const POE_PolyI_t *polyP, const BitMap *tmP ) 35 | { 36 | extern void _bmp_ptchrome16setupI(const POE_PolyI_t *, const BitMap *); 37 | extern void _bmp_ptchrome16slope(POE_Vert_t *, POE_Vert_t *, long, long ); 38 | extern void _bmp_pt2d16loop(UB *, long); 39 | 40 | _bmp_ptchrome16setupI( polyP, tmP ); 41 | BMP_PolyRoutineI( polyP, 0, _bmp_ptchrome16slope, _bmp_pt2d16loop ); 42 | } 43 | //============== TEXTURE 3D LUT ===================== 44 | void BMP_PolyTextureLUT3D16( const POE_PolyI_t *polyP, const BitMap *tmP, const UB *lut ); 45 | 46 | #endif -------------------------------------------------------------------------------- /SRC/RTMZBAN.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // RTMZBAN.CPP 3 | // Copyright (C) Davide Pasca 1995-97 4 | // 5 | // TABS=4 6 | //============================================== 7 | 8 | #include 9 | #include 10 | #include 11 | #include "BMP.HPP" 12 | #include "EVT.HPP" 13 | #include "RTMZBAN.HPP" 14 | 15 | //=========================== 16 | #define BAN_MAX 5 17 | typedef struct 18 | { 19 | char text[128]; 20 | long staClock, clockCnt; 21 | UB busy; 22 | } banner_t; 23 | static banner_t _banners[ BAN_MAX ]; 24 | 25 | //================================== 26 | void banpost( long seconds, long pos, const char *fmtP, ... ) 27 | { 28 | banner_t *b; 29 | va_list arg; 30 | 31 | if ( pos < 0 ) 32 | { 33 | b = _banners + BAN_MAX - 1; 34 | for(long i=BAN_MAX; i; --i, --b) 35 | { 36 | if NOT( b->busy ) 37 | { 38 | va_start( arg, fmtP ); 39 | vsprintf( b->text, fmtP, arg ); 40 | va_end( arg ); 41 | b->clockCnt = seconds*CLK_TCK; 42 | b->staClock = clock(); 43 | b->busy = 1; 44 | EVT_PostRedraw(); 45 | return; 46 | } 47 | } 48 | } 49 | else 50 | { 51 | CLAMP( pos, 0, BAN_MAX-1 ); 52 | b = _banners + pos; 53 | } 54 | 55 | va_start( arg, fmtP ); 56 | vsprintf( b->text, fmtP, arg ); 57 | va_end( arg ); 58 | b->clockCnt = seconds*CLK_TCK; 59 | b->staClock = clock(); 60 | b->busy = 1; 61 | EVT_PostRedraw(); 62 | } 63 | 64 | //================================== 65 | void banidle(void) 66 | { 67 | long clk = clock(); 68 | 69 | banner_t *b=_banners; 70 | for(long i=BAN_MAX; i; --i, ++b) 71 | if ( b->busy ) 72 | if ( clk - b->staClock > b->clockCnt ) 73 | { 74 | b->busy = 0; 75 | EVT_PostRedraw(); 76 | } 77 | } 78 | 79 | //================================== 80 | void banprint( UB col, long y ) 81 | { 82 | long he = BMP_TFHeight()+1; 83 | 84 | banner_t *b=_banners; 85 | for(long i=BAN_MAX; i; --i, ++b) 86 | if ( b->busy ) 87 | { 88 | BMP_TextWriteCP( b->text, 2, y, col ); 89 | y += he; 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /SRC/RTMZ.TGT: -------------------------------------------------------------------------------- 1 | 37targetIdent0MProject1MComponent02WString3EXE3WString5dr2ew4MCommand05MCommand06MItem8rtmz.exe7WString3EXE8WVList19MVState10WString5WLINK11WString11?????Stack:12WString612800013WVList0-1114WPickList815MItem5*.cpp16WString6CPPOBJ17WVList1918MVState19WString3WPP20WString25d????Include directories:21WString26$(%watcom)\h rtmzos rtmz3d22MRState23WString3WPP24WString20?????Warning level 225MRState26WString3WPP27WString20?????Warning level 428MCState29WString3WPP30WString33?????Disable stack depth checking31MRState32WString3WPP33WString20?????Pack structures34MRState35WString3WPP36WString21?????4 byte alignment37MCState38WString3WPP39WString23?????Loop optimizations40MCState41WString3WPP42WString23?????Math optimizations43MCState44WString3WPP45WString30?????Call/return optimizations46MCState47WString3WPP48WString32?????In-line intrinsic functions49MCState50WString3WPP51WString25?????Relax alias checking52MCState53WString3WPP54WString27?????Instruction scheduling55MVState56WString3WPP57WString29?????Expand function in-line:58WString22059MRState60WString3WPP61WString29?????No debugging information62MRState63WString3WPP64WString24?????Full debugging info65MRState66WString3WPP67WString21?????Compiler default68MRState69WString3WPP70WString33?????In-line Pentium instructions71MRState72WString3WPP73WString21?????Compiler default74MRState75WString3WPP76WString29?????In-line with coprocessor77WVList0-1178MItem8rtmz.cpp79WString6CPPOBJ80WVList081WVList015182MItem12rtmz_sup.cpp83WString6CPPOBJ84WVList085WVList015186MItem11rtmzban.cpp87WString6CPPOBJ88WVList089WVList015190MItem12rtmzmenu.cpp91WString6CPPOBJ92WVList093WVList015194MItem5*.lib95WString3NIL96WVList097WVList0-1198MItem10rtmz3d.lib99WString3NIL100WVList0101WVList0941102MItem10rtmzos.lib103WString3NIL104WVList0105WVList0941 -------------------------------------------------------------------------------- /SRC/RTMZ3D/QUA.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // QUA.CPP - quaternions stuff 3 | // Copyright (C) by Davide Pasca 1995 4 | //============================================== 5 | 6 | #include "CVEC3.HPP" 7 | 8 | //======================================= 9 | void QUA_QuatFromAxis(float q[4], float phi, const float a[3]) 10 | { 11 | vec3_equ( q, a ); 12 | vec3_normalize( q ); 13 | phi /= 2.0; 14 | vec3_mul(q, q, sin(phi)); 15 | q[3] = cos(phi); 16 | } 17 | 18 | //======================================= 19 | void QUA_Normalize(float q[4]) 20 | { 21 | float mag; 22 | 23 | mag = 100000000.; 24 | if ( mag = q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3] ) 25 | mag = 1./sqrt(mag); 26 | q[0] *= mag; q[1] *= mag; q[2] *= mag; q[3] *= mag; 27 | } 28 | 29 | //======================================= 30 | #define RENORMCOUNT 0 31 | void QUA_Mul(float dest[4], const float q1[4], const float q2[4]) 32 | { 33 | //static long count; 34 | float t1[3], t2[3]; 35 | 36 | vec3_mul(t1,q1,q2[3]); 37 | vec3_mul(t2,q2,q1[3]); 38 | vec3_xprd(dest,q2,q1); 39 | vec3_add(dest,dest,t1); 40 | vec3_add(dest,dest,t2); 41 | dest[3] = q1[3] * q2[3] - vec3_dot(q1,q2); 42 | 43 | QUA_Normalize(dest); 44 | /*if (++count > RENORMCOUNT) 45 | { 46 | count = 0; 47 | QUA_Normalize(dest); 48 | }*/ 49 | } 50 | 51 | //======================================= 52 | void QUA_QuatToMat(const float q[4], float m[4][4]) 53 | { 54 | float q0s=q[0]*q[0], q1s=q[1]*q[1], q2s=q[2]*q[2]; 55 | float q01=q[0]*q[1], q23=q[2]*q[3], q03=q[0]*q[3]; 56 | float q12=q[1]*q[2], q02=q[0]*q[2], q13=q[1]*q[3]; 57 | 58 | m[0][0] = 1.0 - 2.0 * (q1s + q2s); 59 | m[1][0] = 2.0 * (q01 - q23); 60 | m[2][0] = 2.0 * (q02 + q13); 61 | m[3][0] = 0.0; 62 | 63 | m[0][1] = 2.0 * (q01 + q23); 64 | m[1][1] = 1.0 - 2.0 * (q2s + q0s); 65 | m[2][1] = 2.0 * (q12 - q03); 66 | m[3][1] = 0.0; 67 | 68 | m[0][2] = 2.0 * (q02 - q13); 69 | m[1][2] = 2.0 * (q12 + q03); 70 | m[2][2] = 1.0 - 2.0 * (q1s + q0s); 71 | m[3][2] = 0.0; 72 | 73 | m[0][3] = 0.0; m[1][3] = 0.0; 74 | m[2][3] = 0.0; m[3][3] = 1.0; 75 | } 76 | 77 | 78 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/MATELIB.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // MATELIB.HPP - 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __MATELIB_HPP__ 7 | #define __MATELIB_HPP__ 8 | 9 | #include "EXTTYPES.HPP" 10 | #include "COLORS.HPP" 11 | 12 | #include 13 | 14 | #define ACT __MLB_actLibP 15 | 16 | #define MLB_MAXMATERIALS 256 17 | 18 | #define MLB_NAME_PTR 6L 19 | #define MLB_LIGHT_PTR 1L 20 | #define MLB_AMBIENT_PTR 2L 21 | #define MLB_DIFFUSE_PTR 3L 22 | #define MLB_SPECULAR_PTR 4L 23 | #define MLB_SHININESS_PTR 5L 24 | #define MLB_TXMAP_N_PALETTE_PTR 7L 25 | 26 | typedef struct 27 | { 28 | UB origPal[768], currPal[768]; 29 | US origNCols, currNCols; 30 | BitMap origMap, currMap; 31 | }MLB_Texture_t; 32 | 33 | typedef struct 34 | { 35 | char name[32]; 36 | UB active; 37 | UB shadePalCol; 38 | float light[4], ambient[4], diffuse[4], specular[4], shininess; 39 | MLB_Texture_t *textureP; 40 | }MLB_Material_t; 41 | 42 | typedef struct 43 | { 44 | US nMaterials, nTextures; 45 | MLB_Material_t materials[ MLB_MAXMATERIALS ]; 46 | COL_ShadePalette_t shadePal; 47 | COL_LevelPalette_t *levPalP; 48 | float deflight[4], defambient[4], defdiffuse[4], defspecular[4], defshininess; 49 | MLB_Texture_t deftexture; 50 | }MLB_Library_t; 51 | 52 | extern MLB_Library_t *__MLB_actLibP; 53 | 54 | inline MLB_Material_t *MLB_MaterialGetPtr( long matID ) 55 | { 56 | return &__MLB_actLibP->materials[matID]; 57 | } 58 | 59 | void MLB_LibraryReset(void); 60 | inline MLB_Library_t *MLB_LibraryGetPtr(void) 61 | { 62 | return ACT; 63 | } 64 | inline MLB_Material_t *MLB_LibraryGetMaterial( US i ){ return &__MLB_actLibP->materials[i]; } 65 | 66 | long MLB_MaterialFind( const char *nameP ); 67 | long MLB_MaterialSetAll( long tag, ... ); 68 | void MLB_MaterialGetDefault( long tag, ... ); 69 | void MLB_MaterialSetDefault( long tag, ... ); 70 | long MLB_MaterialAdd( long tag, ... ); 71 | long MLB_MaterialSetOrAdd( long tag, ... ); 72 | void MLB_MaterialDisposeAll( void ); 73 | 74 | void MLB_PaletteCompute( US userColors ); 75 | UB *MLB_PaletteGet(long *stacolp, long *ncolsp); 76 | 77 | #undef ACT 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/TDSTUFF.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // TDSTUFF.HPP - world 3d engine 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | #ifndef __TDSTUFF_HPP__ 6 | #define __TDSTUFF_HPP__ 7 | 8 | #include 9 | #include 10 | #include "EXTTYPES.HPP" 11 | #include "COLORS.HPP" 12 | #include "OBJ3D.HPP" 13 | 14 | #define W3D_MAXOBJECTS 100 15 | 16 | #define W3D_REND_CHUNKY (1<<0) 17 | #define W3D_REND_GORAUD (1<<1) 18 | 19 | //================================ 20 | typedef struct 21 | { 22 | short NObjs; 23 | Obj3D *objList[ W3D_MAXOBJECTS ]; 24 | BO objMatPresent[ W3D_MAXOBJECTS ]; 25 | float objMatList[ W3D_MAXOBJECTS ][16]; 26 | long NPoints; 27 | long NPolys; 28 | long nActPoints; 29 | long nActPolys; 30 | long *ZMediumP; 31 | US *zBufferP; 32 | long zBufferFlg; 33 | BitMap bitMap; 34 | long outWD, outHE; 35 | 36 | #ifdef __USEFLOAT 37 | float DeeX, DeeY; 38 | #else 39 | short DeeX, DeeY; 40 | #endif 41 | 42 | COL_ShadePalette_t GeoSPal, GemSPal, *ActSPaletteP; 43 | UB UseShadePal; 44 | COL_LevelPalette_t *LevelPalP; 45 | 46 | float lightPos[3]; 47 | }W3D_World_t; 48 | 49 | extern void project(long *des2P, const float *src3P, float deex, float deey, long hwd, long hhe, float minz, long cnt ); 50 | 51 | extern W3D_World_t *_W3D_actWorldP; 52 | #define ACT _W3D_actWorldP 53 | 54 | void W3D_Initialize(void); 55 | void W3D_LightSetPos( float x, float y, float z ); 56 | long W3D_ViewPortSet( US wd, US he ); 57 | void W3D_PerspectiveSet( float fovy, float aspect, float n, float f ); 58 | 59 | 60 | #define W3D_BITMAP_PTR 0 61 | #define W3D_ZBUFFER_FLG 1 62 | void W3D_ValueGet( UB cmd, long *destP ); 63 | void W3D_ValueSet( UB cmd, long *destP ); 64 | 65 | void W3D_FrameClear(void); 66 | void W3D_FrameCalculate(void); 67 | void W3D_FrameRend(void); 68 | 69 | void W3D_ObjectDraw( long objID, const float *matp ); 70 | void W3D_ObjectCenter( long objID ); 71 | 72 | void W3D_ShadePaletteSet(COL_ShadePalette_t *sPalP); 73 | 74 | #undef ACT 75 | 76 | //==================================== 77 | inline UB IsCCW( const long *v1, const long *v2, const long *v3 ) 78 | { 79 | if ( (v2[0]-v1[0]) * (v3[1]-v2[1]) >= 80 | (v2[1]-v1[1]) * (v3[0]-v2[0]) ) 81 | return 0; 82 | 83 | return 1; 84 | } 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/GL_MATR.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // GL_MATR.HPP - matrix handler 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __GL_MATR_HPP__ 7 | #define __GL_MATR_HPP__ 8 | 9 | #include "POLYENG.HPP" 10 | 11 | #define GL_MAX_MATR_DEEP 32 12 | #define GL_PROJECTION 1 13 | #define GL_MODELVIEW 2 14 | 15 | typedef struct GLMatrix_t 16 | { 17 | float mf[4][4]; 18 | char iIsUpdated; 19 | }GLMatrix_t; 20 | 21 | extern GLMatrix_t *_glCurMatP; 22 | 23 | extern GLMatrix_t *_glGetTransMatrix(void); 24 | inline const GLMatrix_t *glGetCurMatrix(void){ return _glCurMatP; } 25 | 26 | void glMatrixModel(UL mode); 27 | void glLoadIdentity (void); 28 | void glLoadMatrix(const float *m); 29 | void glSaveMatrix(float *m); 30 | 31 | void glPushMatrix(void); 32 | void glPopMatrix(void); 33 | 34 | void glTranslate(float x, float y, float z); 35 | void glScale( float x, float y, float z ); 36 | void glRotate(float angle, char axis); 37 | void glMultMatrix(const float *m); 38 | void glMultMatrixInv(const float *m); 39 | void glInvertMatrix(void); 40 | 41 | void glViewPort( long x, long y, UL wd, UL he ); 42 | void glOrtho( float l, float r, float b, float t, float n, float f ); 43 | void glFrustum( float l, float r, float b, float t, float n, float f ); 44 | void gluPerspective(float fovy, float aspect, float n, float f); 45 | void glTransformv3f( const float *srcp, float *desp, long cnt ); 46 | 47 | //=========================================================== 48 | inline void glTransform( float *vP, const float *sgP, long cnt ) 49 | { 50 | void _M34_TransformF( float *vP, const float *sgP, long cnt ); 51 | _M34_TransformF( vP, sgP, cnt ); 52 | } 53 | 54 | //=========================================================== 55 | inline void glTransform3X3( float *vP, const float *sgP, long cnt ) 56 | { 57 | void _glTransform3X3F( float *vP, const float *sgP, long cnt ); 58 | _glTransform3X3F( vP, sgP, cnt ); 59 | } 60 | 61 | void _glPOEVertsToScreen( POE_Vert_t *vertP, long cnt ); 62 | 63 | #include "OBJ3D.HPP" 64 | void _glTransformO3DtoPOE( O3D_VertBase_t *bvertP, POE_Vert_t *pvertP, long cnt ); 65 | void _glTransformO3DtoPOENormals( O3D_VertBase_t *bvertP, POE_Vert_t *pvertP, long cnt ); 66 | 67 | void _glMatrixPrint(void); 68 | #endif 69 | -------------------------------------------------------------------------------- /SRC/RTMZOS.TGT: -------------------------------------------------------------------------------- 1 | 37targetIdent0MProject1MComponent02WString3LIB3WString5d_2sw4MCommand05MCommand06MItem10rtmzos.lib7WString3LIB8WVList09WVList0-1110WPickList1211MItem5*.cpp12WString6CPPOBJ13WVList1814MRState15WString3WPP16WString20?????Warning level 217MRState18WString3WPP19WString20?????Warning level 420MCState21WString3WPP22WString33?????Disable stack depth checking23MRState24WString3WPP25WString20?????Pack structures26MRState27WString3WPP28WString21?????4 byte alignment29MCState30WString3WPP31WString23?????Loop optimizations32MCState33WString3WPP34WString23?????Math optimizations35MCState36WString3WPP37WString30?????Call/return optimizations38MCState39WString3WPP40WString32?????In-line intrinsic functions41MCState42WString3WPP43WString25?????Relax alias checking44MCState45WString3WPP46WString27?????Instruction scheduling47MVState48WString3WPP49WString29?????Expand function in-line:50WString22051MRState52WString3WPP53WString29?????No debugging information54MRState55WString3WPP56WString24?????Full debugging info57MRState58WString3WPP59WString21?????Compiler default60MRState61WString3WPP62WString33?????In-line Pentium instructions63MRState64WString3WPP65WString21?????Compiler default66MRState67WString3WPP68WString29?????In-line with coprocessor69WVList0-1170MItem14rtmzos\bmp.cpp71WString6CPPOBJ72WVList073WVList011174MItem18rtmzos\dosutil.cpp75WString6CPPOBJ76WVList077WVList011178MItem14rtmzos\evt.cpp79WString6CPPOBJ80WVList081WVList011182MItem14rtmzos\kbd.cpp83WString6CPPOBJ84WVList085WVList011186MItem14rtmzos\mnu.cpp87WString6CPPOBJ88WVList089WVList011190MItem14rtmzos\mou.cpp91WString6CPPOBJ92WVList093WVList011194MItem19rtmzos\pascalib.cpp95WString6CPPOBJ96WVList097WVList011198MItem14rtmzos\pcx.cpp99WString6CPPOBJ100WVList0101WVList0111102MItem14rtmzos\tmr.cpp103WString6CPPOBJ104WVList0105WVList0111106MItem15rtmzos\vesa.cpp107WString6CPPOBJ108WVList0109WVList0111110MItem18rtmzos\vgapack.cpp111WString6CPPOBJ112WVList0113WVList0111 -------------------------------------------------------------------------------- /SRC/RTMZOS/KBD.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // KBD.HPP - keyboard handler 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __KBD_HPP__ 7 | #define __KBD_HPP__ 8 | 9 | #include "exttypes.hpp" 10 | 11 | #define KBD_EXT (128) 12 | #define KBD_FLG_KPAD (1024) 13 | #define KBD_NOASC (512) 14 | #define KBD_BACKSPACE (14) 15 | //#define KBD_KP_ENTER (KBD_EXT+28) // ext 156 16 | #define KBD_LCTRL (KBD_NOASC+1) 17 | #define KBD_RCTRL (KBD_EXT+29) // ext 18 | #define KBD_PRTSCR (KBD_EXT+42) // ext 19 | 20 | #define KBD_LSHIFT (KBD_NOASC+2) 21 | //#define KBD_KP_SLASH (KBD_EXT+53) // ext 22 | #define KBD_RSHIFT (KBD_NOASC+3) 23 | 24 | #define KBD_RALT (KBD_EXT+56) // ext 25 | #define KBD_LALT (KBD_NOASC+4) 26 | #define KBD_CAPSLOCK (KBD_NOASC+5) 27 | #define KBD_F1 (KBD_NOASC+6) 28 | #define KBD_F2 (KBD_NOASC+7) 29 | #define KBD_F3 (KBD_NOASC+8) 30 | #define KBD_F4 (KBD_NOASC+9) 31 | #define KBD_F5 (KBD_NOASC+10) 32 | #define KBD_F6 (KBD_NOASC+11) 33 | #define KBD_F7 (KBD_NOASC+12) 34 | #define KBD_F8 (KBD_NOASC+13) 35 | #define KBD_F9 (KBD_NOASC+14) 36 | #define KBD_F10 (KBD_NOASC+15) 37 | #define KBD_F11 (KBD_EXT+87) // ext 38 | #define KBD_F12 (KBD_EXT+88) // ext 39 | #define KBD_NUMLOCK (KBD_NOASC+16) 40 | #define KBD_SCRLLOCK (KBD_NOASC+17) 41 | 42 | #define KBD_HOME (KBD_EXT+71) // ext 43 | 44 | #define KBD_UP (KBD_EXT+72) // ext 45 | #define KBD_PGUP (KBD_EXT+73) // ext 46 | #define KBD_LEFT (KBD_EXT+75) // ext 47 | #define KBD_RIGHT (KBD_EXT+77) // ext 48 | #define KBD_END (KBD_EXT+79) // ext 49 | #define KBD_DOWN (KBD_EXT+80) // ext 50 | #define KBD_PGDOWN (KBD_EXT+81) // ext 51 | #define KBD_INSERT (KBD_EXT+82) // ext 52 | #define KBD_DELETE (KBD_EXT+83) // ext 53 | #define KBD_MACRO (KBD_EXT+111) // ext 54 | 55 | #define KBD_PRESS 1 56 | #define KBD_RELEASE 2 57 | 58 | #define KBD_EVT_MAX 64 59 | 60 | long KBD_Open(void); 61 | void KBD_Close(void); 62 | void KBD_FuncSet( UB (*keyFuncP)(US,UB) ); 63 | void KBD_EventsDisable(void); 64 | void KBD_EventsEnable(void); 65 | UL KBD_EventsListGet( US *listP ); 66 | void KBD_EventsFlush(long n, const US *evtsP); 67 | UB KBD_IsPressed( US c ); 68 | void KBD_ResetPressTable(void); 69 | 70 | void KBD_RepeatIgnore(BO yesNo); 71 | void KBD_HandlerKeepOld(BO yesNo); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/COLORS.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // COLORS.HPP - 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __COLORS_HPP__ 7 | #define __COLORS_HPP__ 8 | 9 | #include "EXTTYPES.HPP" 10 | //#include "winstub.h" 11 | 12 | #ifndef _WINDOWS_ 13 | #ifndef __WINSTUB_H__ 14 | typedef struct tagRGBQUAD { 15 | UB rgbBlue; 16 | UB rgbGreen; 17 | UB rgbRed; 18 | UB rgbReserved; 19 | } RGBQUAD; 20 | #endif 21 | #endif 22 | 23 | #define COL_GET_R(n) (((n)&0x00ff0000)>>16) 24 | #define COL_GET_G(n) (((n)&0x0000ff00)>>8) 25 | #define COL_GET_B(n) ((n)&0x000000ff) 26 | 27 | typedef struct 28 | { 29 | US userColors; 30 | US nColors; 31 | US nShades; 32 | UB palette[256][3]; 33 | }COL_ShadePalette_t; 34 | 35 | typedef struct 36 | { 37 | US nLevels; 38 | UB index[1]; 39 | }COL_LevelPalette_t; 40 | 41 | void COL_LevelPalette( COL_LevelPalette_t *fogP ); 42 | COL_LevelPalette_t *COL_NewFog(const UB *palP, US nLevels, UB fr, UB fg, UB fb ); 43 | COL_LevelPalette_t *COL_NewDark(const UB *palP, US nLevels, float coe, US nColors ); 44 | short COL_LPA_GetColor( const COL_LevelPalette_t *lpP, short col, short lev ); 45 | 46 | UB COL_MatchColorHash15( UB *hashp, UB r, UB g, UB b, const UB *palP, US palWd ); 47 | short COL_FindBestRGBInPalette( UB r, UB g, UB b, const UB *palP, US palWd ); 48 | short COL_FindExactRGB( UB r, UB g, UB b, const UB *palP, US palWd ); 49 | 50 | short COL_FindBestRGBQUAD( long rl, long gl, long bl, const RGBQUAD *palP, US palWd ); 51 | void COL_CreateTransparencyLUT( long rl, long gl, long bl, const UB *palp, UB *lutp, US nColors ); 52 | 53 | void COL_CreateShadePalette( COL_ShadePalette_t *spalP, UB *srcPalP, US nColors, US userColors, float minLight, float maxLight); 54 | void COL_256to64( UB *p, US cnt ); 55 | void COL_CreateRangeRGB64( UB *palP, US i, US n, UB r1, UB g1, UB b1, UB r2, UB g2, UB b2 ); 56 | inline void COL_CreateRangeRgb64( UB *palP, UB i, UB n, UL rgb1, UL rgb2 ) 57 | { 58 | COL_CreateRangeRGB64( palP, i, n, COL_GET_R(rgb1),COL_GET_G(rgb1),COL_GET_B(rgb1), 59 | COL_GET_R(rgb2),COL_GET_G(rgb2),COL_GET_B(rgb2) ); 60 | } 61 | 62 | inline short COL_LPA_GetColor( const COL_LevelPalette_t *lpP, short col, short lev ) 63 | { return lpP->index[col + lev * 256]; } 64 | 65 | UB *COL_InverseTableNew(const RGBQUAD *palP, US palWd); 66 | void COL_InverseTableDispose( UB *itp ); 67 | void COL_TransLUTCreateFast( long rl, long gl, long bl, const RGBQUAD *palp, UB *invTabP, UB *lutp ); 68 | 69 | void COL_CreateRemapLUT(UB *lut, const UB *origpal, const UB *newpal); 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/FRPLASMA.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // FRPLASMA.CPP 3 | // Copyright (C) Davide Pasca 1995-97 4 | // 5 | // TABS=4 6 | //============================================== 7 | #include "FRPLASMA.HPP" 8 | #include "PASCALIB.HPP" 9 | 10 | #define RANDOM(x) (RandShort()%x) 11 | 12 | //---------------------------------- 13 | short FractPlasma::RandPixel(short x,short y,short x1,short y1,short x2,short y2) 14 | { 15 | short col; 16 | 17 | short dx,dy; 18 | dx = x-x1; 19 | dy = y-y1; 20 | col = (RANDOM(_max) - _max/2) * ((long)ABS(dx)+ABS(dy)) / _frastaWd; 21 | col += (long)GetY(x1,y1)+GetY(x2,y2) >> 1; 22 | 23 | if (col < 1) col = 1; 24 | else 25 | if (col >= _max) col = _max-1; 26 | 27 | SetY(x,y,col); 28 | 29 | return col; 30 | } 31 | //---------------------------------- 32 | void FractPlasma::DoPlasma(short x1,short y1,short x2,short y2) 33 | { 34 | long x,y,s,p; 35 | 36 | if (x2-x1 <= 1 && y2-y1 <= 1) 37 | return; 38 | 39 | x = x1 + x2 >> 1; 40 | y = y1 + y2 >> 1; 41 | 42 | if NOT(p = GetY(x, y1)) 43 | p = RandPixel(x,y1,x1,y1,x2,y1); 44 | s = p; 45 | 46 | if NOT(p = GetY(x2,y)) 47 | p = RandPixel(x2,y,x2,y1,x2,y2); 48 | s += p; 49 | 50 | if NOT(p = GetY(x,y2)) 51 | p = RandPixel(x,y2,x1,y2,x2,y2); 52 | s += p; 53 | 54 | if NOT(p = GetY(x1,y)) 55 | p = RandPixel(x1,y,x1,y1,x1,y2); 56 | s += p; 57 | 58 | if NOT(GetY(x,y)) 59 | SetY(x,y,s >> 2); 60 | 61 | DoPlasma(x1,y1,x,y); 62 | DoPlasma(x,y1,x2,y); 63 | DoPlasma(x1,y,x,y2); 64 | DoPlasma(x,y,x2,y2); 65 | } 66 | 67 | //--------------------------------- 68 | #define FP_DOPIX(x,y) \ 69 | if ((val = GetY(x1,y1)) > 0) \ 70 | { \ 71 | av += val; \ 72 | num++; \ 73 | } 74 | 75 | void FractPlasma::Make(short x1,short y1,short x2,short y2, short frasta, long seed, long max) 76 | { 77 | long av = 0; 78 | long val; 79 | short num = 0; 80 | 81 | RandomizeShort(seed); 82 | if NOT( frasta ) 83 | _frastaWd = _wd; 84 | else 85 | _frastaWd = _wd / frasta; 86 | 87 | FP_DOPIX(x1,y1); 88 | FP_DOPIX(x2,y1); 89 | FP_DOPIX(x2,y2); 90 | FP_DOPIX(x1,y2); 91 | 92 | _max = max; 93 | if (!av || RANDOM(max/8) == 0) 94 | av = RANDOM(max); 95 | else 96 | if (num) 97 | av /= num; 98 | 99 | long m1=max/3, m2=max/6; 100 | 101 | if NOT( GetY(x1,y1) ) SetY(x1,y1, av + RANDOM(m1)-m2); 102 | if NOT( GetY(x2,y1) ) SetY(x2,y1, av + RANDOM(m1)-m2); 103 | if NOT( GetY(x2,y2) ) SetY(x2,y2, av + RANDOM(m1)-m2); 104 | if NOT( GetY(x1,y2) ) SetY(x1,y2, av + RANDOM(m1)-m2); 105 | 106 | DoPlasma(x1,y1,x2,y2); 107 | } 108 | 109 | -------------------------------------------------------------------------------- /SRC/RTMZOS/DOSUTIL.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // DOSUTIL.CPP 3 | // Copyright (C) Davide Pasca 1995-97 4 | // 5 | // TABS=4 6 | //============================================== 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "EXTTYPES.HPP" 13 | #include "DOSUTIL.HPP" 14 | 15 | //================================ 16 | char DOS_DrivesGetList( char *listP, short *totalP ) 17 | { 18 | unsigned old, total, i, j, n; 19 | char *runlistP; 20 | 21 | _dos_getdrive( &old ); 22 | _dos_setdrive( old, &total ); 23 | n = total; 24 | if ( n > 32 ) n=32; 25 | runlistP = listP; 26 | for(i=1; i <= n; ++i) 27 | { 28 | _dos_setdrive( i, &total ); 29 | _dos_getdrive( &j ); 30 | if ( i == j ) 31 | *runlistP++ = 'A' + i - 1; 32 | } 33 | 34 | *totalP = runlistP - listP; 35 | _dos_setdrive( old, &total ); 36 | 37 | return 'A' + old - 1; 38 | } 39 | 40 | //================================ 41 | /*long filesize(const char *fnameP) 42 | { 43 | FILE *stream; 44 | long curpos, length; 45 | 46 | if NOT( stream = fopen( fnameP, "rb" ) ) 47 | return -1; 48 | 49 | curpos = ftell(stream); 50 | fseek(stream, 0L, SEEK_END); 51 | length = ftell(stream); 52 | fseek(stream, curpos, SEEK_SET); 53 | 54 | fclose( stream ); 55 | 56 | return length; 57 | }*/ 58 | 59 | //================================ 60 | static short SDE_sort_function( const DirElem *a, const DirElem *b ) 61 | { 62 | return( strcmp(a->name,b->name) ); 63 | } 64 | 65 | //-------------------------------- 66 | void SortDirElemsByName(DirElem *deP, UL n) 67 | { 68 | qsort( deP, n, sizeof(DirElem), (int (*)(const void*,const void*))SDE_sort_function ); 69 | } 70 | 71 | //================================ 72 | long ScanDir(const char *dirPath, const char *pattern, DirElem **dePP, UL *entriesP ) 73 | { 74 | DirElem *deP; 75 | char patDPat[1024]; 76 | find_t fileInfo; 77 | long cnt, err; 78 | 79 | strcpy( patDPat, dirPath ); 80 | strcat( patDPat, pattern ); 81 | 82 | cnt = *entriesP; 83 | deP = *dePP; 84 | 85 | err = _dos_findfirst(patDPat, _A_NORMAL | _A_SUBDIR, &fileInfo); 86 | while NOT(err) 87 | { 88 | if NOT( deP = (DirElem *)realloc(deP, (cnt+1)*sizeof(DirElem)) ) 89 | { 90 | *entriesP = cnt; 91 | return -1; 92 | } 93 | strcpy( deP[cnt].name, fileInfo.name ); 94 | 95 | if ( fileInfo.attrib & _A_SUBDIR ) 96 | deP[cnt].size = -1; 97 | else 98 | deP[cnt].size = fileInfo.size; 99 | 100 | ++cnt; 101 | err = _dos_findnext( &fileInfo ); 102 | } 103 | 104 | *entriesP = cnt; 105 | *dePP = deP; 106 | 107 | return 0; 108 | } 109 | 110 | -------------------------------------------------------------------------------- /SRC/RTMZ3D.TGT: -------------------------------------------------------------------------------- 1 | 37targetIdent0MProject1MComponent02WString3LIB3WString5d_2sw4MCommand05MCommand06MItem10rtmz3d.lib7WString3LIB8WVList09WVList0-1110WPickList1711MItem5*.cpp12WString6CPPOBJ13WVList1914MVState15WString3WPP16WString25d????Include directories:17WString19$(%watcom)\h rtmzos18MRState19WString3WPP20WString20?????Warning level 221MRState22WString3WPP23WString20?????Warning level 424MCState25WString3WPP26WString33?????Disable stack depth checking27MRState28WString3WPP29WString20?????Pack structures30MRState31WString3WPP32WString21?????4 byte alignment33MCState34WString3WPP35WString23?????Loop optimizations36MCState37WString3WPP38WString23?????Math optimizations39MCState40WString3WPP41WString30?????Call/return optimizations42MCState43WString3WPP44WString32?????In-line intrinsic functions45MCState46WString3WPP47WString25?????Relax alias checking48MCState49WString3WPP50WString27?????Instruction scheduling51MVState52WString3WPP53WString29?????Expand function in-line:54WString22055MRState56WString3WPP57WString29?????No debugging information58MRState59WString3WPP60WString24?????Full debugging info61MRState62WString3WPP63WString21?????Compiler default64MRState65WString3WPP66WString33?????In-line Pentium instructions67MRState68WString3WPP69WString21?????Compiler default70MRState71WString3WPP72WString29?????In-line with coprocessor73WVList0-1174MItem19rtmz3d\bmp_poly.cpp75WString6CPPOBJ76WVList077WVList011178MItem19rtmz3d\bmp_potx.cpp79WString6CPPOBJ80WVList081WVList011182MItem14rtmz3d\clp.cpp83WString6CPPOBJ84WVList085WVList011186MItem17rtmz3d\colors.cpp87WString6CPPOBJ88WVList089WVList011190MItem19rtmz3d\frplasma.cpp91WString6CPPOBJ92WVList093WVList011194MItem18rtmz3d\gl_matr.cpp95WString6CPPOBJ96WVList097WVList011198MItem14rtmz3d\m44.cpp99WString6CPPOBJ100WVList0101WVList0111102MItem18rtmz3d\matelib.cpp103WString6CPPOBJ104WVList0105WVList0111106MItem18rtmz3d\o3dfile.cpp107WString6CPPOBJ108WVList0109WVList0111110MItem16rtmz3d\obj3d.cpp111WString6CPPOBJ112WVList0113WVList0111114MItem18rtmz3d\polyeng.cpp115WString6CPPOBJ116WVList0117WVList0111118MItem14rtmz3d\qua.cpp119WString6CPPOBJ120WVList0121WVList0111122MItem18rtmz3d\read3ds.cpp123WString6CPPOBJ124WVList0125WVList0111126MItem18rtmz3d\tdst_hp.cpp127WString6CPPOBJ128WVList0129WVList0111130MItem18rtmz3d\tdstuff.cpp131WString6CPPOBJ132WVList0133WVList0111134MItem15rtmz3d\trig.cpp135WString6CPPOBJ136WVList0137WVList0111 -------------------------------------------------------------------------------- /SRC/RTMZOS/BMP.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // BMP.HPP - raster graphics stuff 3 | // Copyright (C) by Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __BMP_HPP__ 7 | #define __BMP_HPP__ 8 | 9 | #include 10 | #include "EXTTYPES.HPP" 11 | 12 | extern BitMap *_BMP_curBitMapP; 13 | #define ACT _BMP_curBitMapP 14 | #define BMP_MAXPUSH 32 15 | 16 | #define BMP_TF_SUBCH 128 17 | #define BMP_TF_CHKCH 129 18 | 19 | long BMP_TFSet(long fontID); 20 | long BMP_TFGet(void); 21 | void BMP_TFPushSet(long fontID); 22 | void BMP_TFPush(void); 23 | void BMP_TFPop(void); 24 | void BMP_TFDispose(long fontID); 25 | long BMP_TFLoad(const char *fnameP); 26 | long BMP_TFHeight(void); 27 | long BMP_TextWidth(const char *txtP); 28 | void BMP_CharWriteCP( char ch, short x, short y, UB col ); 29 | void BMP_TextWriteCP( const char *strP, short x, short y, UB col ); 30 | void BMP_TextPrintFCP(short x, short y, UB col, const char *fmtP, ... ); 31 | 32 | #define BMP_PIXELPUT(X,Y,C) *(ACT->offsPP[Y]+X)=C 33 | #define BMP_PIXELGET(X,Y) *(ACT->offsPP[Y]+X) 34 | 35 | inline UB BMP_PointIsInMap( short x, short y ){ return (US)x < (US)ACT->wd && (US)y < (US)ACT->he; } 36 | inline void BMP_PixelPut( US x, US y, UB col ){ BMP_PIXELPUT( x, y, col ); } 37 | inline void BMP_PixelPutCP( short x, short y, UB col ){ if (BMP_PointIsInMap( x, y)) BMP_PIXELPUT( x, y, col ); } 38 | inline UB BMP_PixelGet( US x, US y ){ return BMP_PIXELGET( x, y ); } 39 | 40 | inline void BMP_Set(BitMap *bmP){_BMP_curBitMapP=bmP;} 41 | inline BitMap *BMP_Get(void){return _BMP_curBitMapP;} 42 | 43 | void BMP_Clear(void); 44 | 45 | void BMP_PushSet(BitMap *bmP); 46 | void BMP_Push(void); 47 | void BMP_Pop(void); 48 | void BMP_OffsPPCreate( BitMap *bmP ); 49 | void BMP_Free( BitMap *bmP ); 50 | long BMP_Alloc( BitMap *bmP, US wd, US he, UB dp, UB *memP ); 51 | void BMP_LineH( US x1, US x2, US y, UB col ); 52 | void BMP_LineV( US x, US y1, US y2, UB col ); 53 | void BMP_RectFill( US p1x, US p1y, US p2x, US p2y, UB col ); 54 | void BMP_RectFillCP( short p1x, short p1y, short p2x, short p2y, UB col ); 55 | void BMP_BitBltMskColCP(short xd, short yd, short sdx, short sdy, 56 | const BitMap *sbmP, short xs, short ys, UB col ); 57 | void BMP_BitBltCP(long xd, long yd, long sdx, long sdy, 58 | const BitMap *sbmP, long xs, long ys ); 59 | void BMP_BitBlt0CP(long xd, long yd, long sdx, long sdy, 60 | const BitMap *sbmP, long xs, long ys ); 61 | void BMP_BitMapPutCP( const BitMap *sbmP, short dx, short dy ); 62 | void BMP_BitMapPut0CP( const BitMap *sbmP, short dx, short dy ); 63 | void BMP_BitMapStretchCP( const BitMap *sbmP, short dx, short dy, short wd, short he ); 64 | void BMP_BitMapStretch0CP( const BitMap *sbmP, short dx, short dy, short wd, short he ); 65 | void BMP_BitMapStretchDestLUT0CP( const BitMap *sbmP, short dx, short dy, short wd, short he, const UB *lutp ); 66 | 67 | void BMP_ApplyLUT( BitMap *bmP, const UB *lut ); 68 | 69 | #define bpush BMP_PushSet 70 | #define bpop BMP_Pop 71 | 72 | #undef ACT 73 | #endif 74 | -------------------------------------------------------------------------------- /SRC/RTMZOS/VGAPACK.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // VGAPACK.HPP - 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __VGAPACK_HPP__ 7 | #define __VGAPACK_HPP__ 8 | 9 | #include "exttypes.hpp" 10 | #include 11 | #include 12 | //#include "timer.h" 13 | 14 | #define VGA_INTERLINE 2 15 | #define VGA_MODEX 1 16 | #define VGA_SCRTYP_320X200 0 17 | #define VGA_SCRTYP_320X240_X (16|VGA_MODEX) 18 | #define VGA_SCRTYP_320X400_X (32|VGA_MODEX) 19 | #define VGA_SCRTYP_320X480_X (64|VGA_MODEX) 20 | #define VGA_SCRTYP_400X300_X (128|VGA_MODEX) 21 | #define VGA_SCRTYP_400X600_X (256|VGA_MODEX) 22 | #define VGA_SCRTYP_640X400 512 23 | #define VGA_SCRTYP_640X480 1024 24 | #define VGA_SCRTYP_800X600 2048 25 | #define VGA_SCRTYP_80X24_TXT 4096 26 | 27 | #define VLO_WD 320L 28 | #define VLO_HE 200L 29 | #define VLO_SIZ (VLO_WD*VLO_HE) 30 | 31 | 32 | US VGA_ModeGet(void); 33 | void VGA_ModeSet( US smode ); 34 | UB VGA_SetScreenType( UL stype, UB keepPalette ); 35 | 36 | extern BitMap _VLOMap; 37 | extern UB* _VLOOffs[600]; 38 | extern UL _vga_lastFrame; 39 | 40 | void RefreshLoVGAScr( const BitMap *bmP ); 41 | void RefreshClearLoVGAScr( const BitMap *bmP ); 42 | void WaitTof( void ); 43 | //==================================== 44 | short VGA_GetActScanLine(void); 45 | void VGAX_WaitDrawPermission(void); 46 | 47 | extern short _vgax_wd; 48 | extern short _vgax_he; 49 | extern US _vgax_bpr; 50 | extern UL _vgax_actStart, _vgax_visStart; 51 | extern UB *_vgaBaseP; 52 | 53 | void VGAX_SetActiveStart(UL offset); 54 | void VGAX_SetVisibleStart(UL offset); 55 | void VGAX_PagCpy(short to, short from); 56 | 57 | //------------------------------ 58 | void VGAX_SetActivePage(short page); 59 | //------------------------------ 60 | void VGAX_SetVisiblePage(short page); 61 | //------------------------------ 62 | void VGAX_PutPixel(US x, US y, UB color); 63 | //------------------------------ 64 | UB VGAX_GetPixel(US x, US y); 65 | 66 | void VGAX_ClearScreen(void); 67 | void VGAX_horizLine(short x1, short x2, short y, UB col); 68 | void VGAX_RectFill( short p1x, short p1y, short p2x, short p2y, UB col ); 69 | void VGAX_RectFillColCP( short p1x, short p1y, short p2x, short p2y, UB col, UB pCol ); 70 | //void VGAX_DrawPoly( const short *polyP, char nVerts, UB col ); 71 | void VGAX_PutMapStrech( short dx, short dy, const BitMap *sbmP, short wd, short he ); 72 | void VGAX_PutMap3D( const BitMap *mMapP, short x, short y, long z); 73 | void VGAX_PutMap( const BitMap *sbmP, short dx, short dy ); 74 | void VGAX_PutMap0( const BitMap *sbmP, short dx, short dy ); 75 | void VGAX_BitBltMskCol(const BitMap *sbmP, short xs, short ys, 76 | short xd, short yd, short ddx, short ddy, UB col ); 77 | void VGA_DisplayClear(void); 78 | void VGAX_UpdateDisplay( const BitMap *sbmP, UB onepage ); 79 | 80 | void VGA_PaletteGet( UB *p, UB staCol, US cnt ); 81 | void VGA_PaletteSet( const UB *p, UB staCol, US cnt ); 82 | void VGA_Palette8Set( const UB *p, UB staCol, US cnt ); 83 | void VGA_PaletteSetOne( UB col, UB r, UB g, UB b ); 84 | #endif 85 | 86 | -------------------------------------------------------------------------------- /SRC/RTMZOS/TMR.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // TMR.C - timer handler 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "TMR.HPP" 13 | 14 | #define INTR 0x08 15 | #define PIC_CMD 0x20 16 | #define PIC_NONSPEC_EOI 0x20 17 | 18 | 19 | static void (__interrupt __far *_oldHandler)(); 20 | static void (__interrupt __far *_userHandler)(); 21 | 22 | volatile UL _TMR_Ticks; 23 | UL _TMR_TksPerSec=0; 24 | static volatile UL _counter, _counterStp; 25 | 26 | extern void disint(void); 27 | #pragma aux disint = \ 28 | " cli"; 29 | 30 | extern void enint(void); 31 | #pragma aux enint = \ 32 | " sti"; 33 | 34 | //------------------------------- 35 | static void /*_loadds*/ __interrupt __far handler() 36 | { 37 | //static long rgb; 38 | 39 | //disint(); 40 | _disable(); 41 | //VGA_PaletteSetOne( 0, rgb >> 8, rgb >>6, rgb ); 42 | //rgb += 8; 43 | ++_TMR_Ticks; 44 | _counter += _counterStp; 45 | if ( _counter >= 0x10000 ) 46 | { 47 | _counter -= 0x10000; 48 | _chain_intr( _oldHandler ); 49 | } 50 | else 51 | outp(PIC_CMD, PIC_NONSPEC_EOI); 52 | 53 | //if ( _userHandler ) 54 | // _userHandler(); 55 | 56 | //enint(); 57 | _enable(); 58 | } 59 | 60 | //======================================================== 61 | void TMR_Close(void) 62 | { 63 | if ( _oldHandler ) 64 | { 65 | _disable(); 66 | _dos_setvect(INTR, _oldHandler); 67 | outp( 0x43, 0x34 ); 68 | outp( 0x40, 0 ); 69 | outp( 0x40, 0 ); 70 | 71 | signal(SIGABRT, SIG_DFL); 72 | //signal(SIGFPE, SIG_DFL); 73 | signal(SIGINT, SIG_DFL); 74 | 75 | _oldHandler = 0; 76 | _userHandler = 0; 77 | _enable(); 78 | } 79 | } 80 | 81 | //======================================================== 82 | long TMR_Open( UL freq ) 83 | { 84 | UL counter; 85 | 86 | if ( _oldHandler ) return -1; 87 | 88 | atexit( TMR_Close ); /* set traps for error, ctrl c, */ 89 | signal( SIGABRT, (void (*)(int))TMR_Close ); 90 | //signal( SIGFPE, (void (*)(int))TMR_Close ); 91 | signal( SIGINT, (void (*)(int))TMR_Close ); 92 | 93 | _disable(); 94 | 95 | _TMR_Ticks = 0; 96 | _TMR_TksPerSec = freq; 97 | _oldHandler = _dos_getvect( INTR ); 98 | _dos_setvect( INTR, handler ); 99 | 100 | counter = 0x1234DD; 101 | if ( freq ) 102 | counter /= freq; 103 | 104 | outp( 0x43, 0x34 ); 105 | outp( 0x40, counter & 255 ); 106 | outp( 0x40, counter >> 8 ); 107 | 108 | _counter = 0; 109 | _counterStp = counter; 110 | 111 | _enable(); 112 | 113 | return 0; 114 | } 115 | 116 | //======================================================== 117 | long TMR_FuncAdd( void (__interrupt __far *handlerp)() ) 118 | { 119 | _userHandler = handlerp; 120 | 121 | return 0; 122 | } 123 | 124 | //======================================================== 125 | UL TMR_TicksGet(void) 126 | { 127 | return _TMR_Ticks; 128 | } 129 | 130 | //======================================================== 131 | UL TMR_TicksPerSecGet(void) 132 | { 133 | return _TMR_TksPerSec; 134 | } 135 | 136 | //======================================================== 137 | void TMR_TicksWait( UL howmany ) 138 | { 139 | UL sta = _TMR_Ticks; 140 | 141 | while (_TMR_Ticks-sta < howmany); 142 | } 143 | 144 | 145 | -------------------------------------------------------------------------------- /SRC/RTMZ_SUP.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // RTMZ_SUP.CPP 3 | // Copyright (C) Davide Pasca 1995-97 4 | // 5 | // TABS=4 6 | //============================================== 7 | #include "RTMZ_SUP.HPP" 8 | #include "EXTTYPES.HPP" 9 | #include "CLP.HPP" 10 | #include "TRIG.HPP" 11 | 12 | //================================================= 13 | static inline rotate_vec2( long *v, long co, long si ) 14 | { 15 | long t; 16 | 17 | t = v[0] * co - v[1] * si >> TR_ISHIFT; 18 | v[1]= v[0] * si + v[1] * co >> TR_ISHIFT; 19 | v[0] = t; 20 | } 21 | 22 | //================================================= 23 | static void Cnk_PutMapRot3D( const BitMap *dbmP, const BitMap *sbmP, long cx, long cy, long z, float ang ) 24 | { 25 | long wd,he, co, si; 26 | 27 | wd = (128L*sbmP->wd/2 / z)*16; 28 | he = (129L*sbmP->he/2 / z)*16; 29 | long vec[4][2]={-wd,-he, wd,-he, wd,he, -wd,he}; 30 | 31 | wd = sbmP->wd*16-1; 32 | he = sbmP->he*16-1; 33 | long tex[4][2]={0,0, wd,0, wd,he, 0,he}; 34 | 35 | POE_BeginPolygon(); 36 | co = tr_icosf( ang ); 37 | si = tr_isinf( ang ); 38 | cx *= 16; 39 | cy *= 16; 40 | for (long i=0; i < 4; ++i) 41 | { 42 | rotate_vec2( vec[i], co, si ); 43 | POE_Vertex2( vec[i][0] + cx, 44 | vec[i][1] + cy ); 45 | POE_Texture2v( tex[i] ); 46 | } 47 | POE_Color1( 3 ); 48 | POE_EndPolygon(); 49 | //CLP_SetLimits2D( 0,0, dbmP->wd*16-1,dbmP->he*16-1 ); 50 | //CLP_DoPoly( CLP_CODE_XY | CLP_MOD_TEXTURE ); 51 | //Cnk_DrawPolyTextured2D16( dbmP, sbmP ); 52 | //Cnk_DrawPoly16( dbmP ); 53 | } 54 | 55 | //--------------------------- 56 | void ZoomTask::Start(const BitMap *dbmP, const BitMap *sbmP, long z1, long z2, short n, UB zoomRot, long cent ) 57 | { 58 | if ( !n || z1 > z2 ) return; 59 | SBmP = sbmP; 60 | DBmP = dbmP; 61 | Z1 = z1; 62 | Z2 = z2; 63 | Z = Z1 << 16; 64 | StpZ = (Z2-Z1 << 16) / n; 65 | Steps = n; 66 | Status = 1; 67 | Pau = cent; 68 | Flags = zoomRot; 69 | } 70 | 71 | //--------------------------- 72 | void ZoomTask::Idle(void) 73 | { 74 | long z; 75 | static float ang, stpAng; 76 | static long lastTicks; 77 | 78 | if NOT( Status ) return; 79 | 80 | if (Status == 1) 81 | { 82 | //Cnk_PutMap3D( DBmP, SBmP, DBmP->wd-SBmP->wd>>1, DBmP->he-SBmP->he>>1, Z >> 16 ); 83 | 84 | 85 | Z += StpZ; 86 | z = Z >> 16; 87 | if ( z >= Z2 ) 88 | { 89 | Status = 2; 90 | StaTick = TMR_TicksGet(); 91 | Z = Z2 << 16; 92 | } 93 | } 94 | else 95 | if (Status == 2) 96 | { 97 | //Cnk_PutMap( DBmP, SBmP, DBmP->wd-SBmP->wd>>1, DBmP->he-SBmP->he>>1 ); 98 | 99 | if (TMR_TicksGet()-StaTick >= Pau) 100 | { 101 | if ( Flags ) 102 | { 103 | Status = 3; 104 | //StpZ *= .5; 105 | //Steps *= 1./.5; 106 | ang = 0.; 107 | stpAng = .5; 108 | lastTicks = TMR_TicksGet(); 109 | } 110 | else 111 | Status = 0; 112 | return; 113 | } 114 | } 115 | else 116 | if (Status == 3) 117 | { 118 | Cnk_PutMapRot3D( DBmP, SBmP, DBmP->wd>>1, DBmP->he>>1, Z2, ang ); 119 | ang += stpAng; 120 | stpAng += .1; 121 | lastTicks = TMR_TicksGet() - lastTicks; 122 | if ( lastTicks > TMR_TicksPerSecGet()/10 ) 123 | { 124 | if ( lastTicks > TMR_TicksPerSecGet()/5 ) 125 | Status = 0; 126 | else 127 | { 128 | ang += stpAng; 129 | stpAng += .14; 130 | } 131 | } 132 | lastTicks = TMR_TicksGet(); 133 | if ( ang >= 359. ) Status = 4; 134 | } 135 | else 136 | if (Status == 4) 137 | { 138 | Z -= StpZ; 139 | z = Z >> 16; 140 | if ( z > 0 ) 141 | Cnk_PutMapRot3D( DBmP, SBmP, DBmP->wd>>1, DBmP->he>>1, z, ang ); 142 | 143 | if ( --Steps <= 0 ) 144 | Status = 0; 145 | 146 | ang += stpAng; 147 | stpAng += .14; 148 | lastTicks = TMR_TicksGet() - lastTicks; 149 | if ( lastTicks > TMR_TicksPerSecGet()/10 ) 150 | { 151 | if ( lastTicks > TMR_TicksPerSecGet()/5 ) 152 | Status = 0; 153 | else 154 | { 155 | ang += stpAng; 156 | stpAng += .14; 157 | --Steps; 158 | } 159 | } 160 | lastTicks = TMR_TicksGet(); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /SRC/RTMZOS.MK1: -------------------------------------------------------------------------------- 1 | !define BLANK "" 2 | c:\prog\src\rtmz\rel30\src\bmp.obj : c:\prog\src\rtmz\rel30\src\rtmzos\bmp.c& 3 | pp .AUTODEPEND 4 | @c: 5 | cd c:\prog\src\rtmz\rel30\src 6 | *wpp386 rtmzos\bmp.cpp -i=C:\prog\WATCOM\h -w2 -e25 -s -zp4 -zq -otexan -ol& 7 | -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 8 | 9 | c:\prog\src\rtmz\rel30\src\dosutil.obj : c:\prog\src\rtmz\rel30\src\rtmzos\d& 10 | osutil.cpp .AUTODEPEND 11 | @c: 12 | cd c:\prog\src\rtmz\rel30\src 13 | *wpp386 rtmzos\dosutil.cpp -i=C:\prog\WATCOM\h -w2 -e25 -s -zp4 -zq -otexan& 14 | -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 15 | 16 | c:\prog\src\rtmz\rel30\src\evt.obj : c:\prog\src\rtmz\rel30\src\rtmzos\evt.c& 17 | pp .AUTODEPEND 18 | @c: 19 | cd c:\prog\src\rtmz\rel30\src 20 | *wpp386 rtmzos\evt.cpp -i=C:\prog\WATCOM\h -w2 -e25 -s -zp4 -zq -otexan -ol& 21 | -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 22 | 23 | c:\prog\src\rtmz\rel30\src\kbd.obj : c:\prog\src\rtmz\rel30\src\rtmzos\kbd.c& 24 | pp .AUTODEPEND 25 | @c: 26 | cd c:\prog\src\rtmz\rel30\src 27 | *wpp386 rtmzos\kbd.cpp -i=C:\prog\WATCOM\h -w2 -e25 -s -zp4 -zq -otexan -ol& 28 | -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 29 | 30 | c:\prog\src\rtmz\rel30\src\mnu.obj : c:\prog\src\rtmz\rel30\src\rtmzos\mnu.c& 31 | pp .AUTODEPEND 32 | @c: 33 | cd c:\prog\src\rtmz\rel30\src 34 | *wpp386 rtmzos\mnu.cpp -i=C:\prog\WATCOM\h -w2 -e25 -s -zp4 -zq -otexan -ol& 35 | -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 36 | 37 | c:\prog\src\rtmz\rel30\src\mou.obj : c:\prog\src\rtmz\rel30\src\rtmzos\mou.c& 38 | pp .AUTODEPEND 39 | @c: 40 | cd c:\prog\src\rtmz\rel30\src 41 | *wpp386 rtmzos\mou.cpp -i=C:\prog\WATCOM\h -w2 -e25 -s -zp4 -zq -otexan -ol& 42 | -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 43 | 44 | c:\prog\src\rtmz\rel30\src\pascalib.obj : c:\prog\src\rtmz\rel30\src\rtmzos\& 45 | pascalib.cpp .AUTODEPEND 46 | @c: 47 | cd c:\prog\src\rtmz\rel30\src 48 | *wpp386 rtmzos\pascalib.cpp -i=C:\prog\WATCOM\h -w2 -e25 -s -zp4 -zq -otexa& 49 | n -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 50 | 51 | c:\prog\src\rtmz\rel30\src\pcx.obj : c:\prog\src\rtmz\rel30\src\rtmzos\pcx.c& 52 | pp .AUTODEPEND 53 | @c: 54 | cd c:\prog\src\rtmz\rel30\src 55 | *wpp386 rtmzos\pcx.cpp -i=C:\prog\WATCOM\h -w2 -e25 -s -zp4 -zq -otexan -ol& 56 | -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 57 | 58 | c:\prog\src\rtmz\rel30\src\tmr.obj : c:\prog\src\rtmz\rel30\src\rtmzos\tmr.c& 59 | pp .AUTODEPEND 60 | @c: 61 | cd c:\prog\src\rtmz\rel30\src 62 | *wpp386 rtmzos\tmr.cpp -i=C:\prog\WATCOM\h -w2 -e25 -s -zp4 -zq -otexan -ol& 63 | -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 64 | 65 | c:\prog\src\rtmz\rel30\src\vesa.obj : c:\prog\src\rtmz\rel30\src\rtmzos\vesa& 66 | .cpp .AUTODEPEND 67 | @c: 68 | cd c:\prog\src\rtmz\rel30\src 69 | *wpp386 rtmzos\vesa.cpp -i=C:\prog\WATCOM\h -w2 -e25 -s -zp4 -zq -otexan -o& 70 | l -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 71 | 72 | c:\prog\src\rtmz\rel30\src\vgapack.obj : c:\prog\src\rtmz\rel30\src\rtmzos\v& 73 | gapack.cpp .AUTODEPEND 74 | @c: 75 | cd c:\prog\src\rtmz\rel30\src 76 | *wpp386 rtmzos\vgapack.cpp -i=C:\prog\WATCOM\h -w2 -e25 -s -zp4 -zq -otexan& 77 | -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 78 | 79 | c:\prog\src\rtmz\rel30\src\rtmzos.lib : c:\prog\src\rtmz\rel30\src\bmp.obj c& 80 | :\prog\src\rtmz\rel30\src\dosutil.obj c:\prog\src\rtmz\rel30\src\evt.obj c:\& 81 | prog\src\rtmz\rel30\src\kbd.obj c:\prog\src\rtmz\rel30\src\mnu.obj c:\prog\s& 82 | rc\rtmz\rel30\src\mou.obj c:\prog\src\rtmz\rel30\src\pascalib.obj c:\prog\sr& 83 | c\rtmz\rel30\src\pcx.obj c:\prog\src\rtmz\rel30\src\tmr.obj c:\prog\src\rtmz& 84 | \rel30\src\vesa.obj c:\prog\src\rtmz\rel30\src\vgapack.obj .AUTODEPEND 85 | @c: 86 | cd c:\prog\src\rtmz\rel30\src 87 | %create rtmzos.lb1 88 | !ifneq BLANK "bmp.obj dosutil.obj evt.obj kbd.obj mnu.obj mou.obj pascalib.o& 89 | bj pcx.obj tmr.obj vesa.obj vgapack.obj" 90 | @for %i in (bmp.obj dosutil.obj evt.obj kbd.obj mnu.obj mou.obj pascalib.ob& 91 | j pcx.obj tmr.obj vesa.obj vgapack.obj) do @%append rtmzos.lb1 +'%i' 92 | !endif 93 | !ifneq BLANK "" 94 | @for %i in () do @%append rtmzos.lb1 +'%i' 95 | !endif 96 | *wlib -b -c -n -q -p=512 rtmzos.lib @rtmzos.lb1 97 | 98 | -------------------------------------------------------------------------------- /SRC/README.TXT: -------------------------------------------------------------------------------- 1 | Apr/3/1997 2 | Here it is ! 3 | The release 3.0. This is basically the 2.9 with the menu bug fixed, 4 | major hires speedups, Z-Buffer speedups, chrome mapping, more compact 5 | ".rec" files and other small things. 6 | The purpose of the 3.0 is to stabilize a version (the original 2.9 7 | is in my computer in Rome) and make it the last version. 8 | I don't consider this engine to be at the state of the art. Hires 9 | is much faster now but the inner loops aren't blazing fast. 10 | The perspective corrected texture mapping (PCTM) is now done using 11 | a division every 16 pixels. This is definitely the best solution 12 | that I know, although the inner loop isn't using FPU/CPU parallelism 13 | as every Pentium oriented optimal PCTM should do. 14 | I'm releasing the source code, even though I'm not 100% proud of 15 | it, because people always asked me. 16 | Objects can have linked objects (lists) only because it's the way 17 | they are organized in the 3DS format. In RTMZ objects aren't 18 | hierarchically structured nor the engine provides for an optimal 19 | culling (tuned for the viewer when you have one object at the time). 20 | For those that want to use the menu system, the API isn't that 21 | simple and I must warn that it's all integrated with the RTMZ-OS 22 | library. This library is on top of DOS and handles the events and 23 | the interface to the devices. 24 | 25 | I'm very proud of the advanced (advanced as for a real-time 26 | application) lighting effects because after 2 years only now I 27 | can see games starting to use them. The lighting is quite tricky 28 | about the specularity: the specular vector isn't specular at all ! 29 | If I had to introduce a real specular component that would have 30 | thrown away all the concept of fast table-based colored lighting. 31 | Another thing I'm very proud of is the subpixel accuracy.. which 32 | is also the "secret" of the cool smoothness of the animation. 33 | Chrome mapping was added very quickly.. so the code might look 34 | unhappy. 35 | The code is all C+ (better C, extended C or whatever you call it) 36 | but a class to make fractal noise that I use to build the standard 37 | texture map. I made that class long time ago when I was into C++ 38 | and I kept that. The engine actually went from C to C++ to C+. 39 | If I had to write a new engine today (almost everyday 8) then I'd 40 | use plain old C. 41 | The closest companion I had in the development of the actual 3D 42 | code is "Advanced Animation and Rendering Techiniques" by 43 | Alan Watt and Mark Watt. This book introduced me to subpixel 44 | rasterization and helped me out about homogeneous coordinates 45 | and lighting effects. 46 | Other material that came handy (the wheel was invented long time 47 | ago..): 48 | - Polygon rasterization and homogeneous coordinate clipping from 49 | the Graphics Gems source code by Paul Heckbert. 50 | - 3DS parser from 3DS2POV by Steve Anger and Jeff Bowermaster. 51 | - Matrices from MESA library, Graphics Gems, VOGLE, etc etc. 52 | - VESA support, Phil Jones. 53 | - Trackball ..cannot find the original source, I think it was an 54 | SGI demo. 55 | 56 | You are free to contact me as long as you don't have to say 57 | things like "I noticed you use alot of ''short'' did you know 58 | they are slow on the Pentium ?". The code is mostly 2 years old 59 | and so on.. 60 | If you want to make a game or something, then consider that I 61 | already work for a software house: I'm not the man.. 62 | I'm pretty much sick of software rendering and I'm trying to get 63 | some fun with 3Dfx and PSX. 64 | 65 | DISCLAMIER: 66 | This software is provided "as is". You use it at your own risk, I'm 67 | not responsible for misuse or any kind of direct/indirect damage 68 | attributable to the software in question. 69 | 70 | NOTES: 71 | The archive containing this file is Public Domain material. You can use 72 | it as you want as long as you don't sell it. 73 | You are free to use the source code as long as you don't modify and 74 | redistriubuite it to grant credits for yourself. (But then you wouldn't 75 | care about this note 8). 76 | 77 | Have fun 78 | 79 | ciaox 80 | 81 | Davide Pasca - dpasca@ix.netcom.com 82 | dpasca@val.net 83 | http://www.netcom.com/~dpasca 84 | http://val.net/~dpasca 85 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/POLYENG.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // POLYENG.HPP 3 | // Copyright (C) Davide Pasca 1995-97 4 | // 5 | // TABS=4 6 | //============================================== 7 | #ifndef __POLYENG_HPP__ 8 | #define __POLYENG_HPP__ 9 | 10 | #include "EXTTYPES.HPP" 11 | #include "CVEC3.HPP" 12 | 13 | #define POE_MAXVERTS 5 14 | #define POE_VERTBUFSIZ (POE_MAXVERTS+5) 15 | 16 | #define POE_FLG_GSHADE 1 17 | #define POE_FLG_PSHADE 2 18 | #define POE_FLG_ZBUFFER 4 19 | #define POE_FLG_WIRE 16 20 | #define POE_FLG_MAXLITE 32 21 | #define POE_FLG_WIREFILL 64 22 | #define POE_FLG_ISCHILD 128 23 | #define POE_FLG_HALFLITE 256 24 | #define POE_FLG_PALCOL 512 25 | #define POE_FLG_NOBCULL 1024 26 | #define POE_FLG_TEXTURE 2048 27 | #define POE_FLG_TEXIS3D 4096 28 | #define POE_FLG_TEXCHROME 8192 29 | 30 | typedef struct 31 | { 32 | float eye[4]; 33 | long screen[2]; 34 | long sz; 35 | float nor[3]; 36 | long c; 37 | long u,v; 38 | UB clipCode; 39 | UB pad[64 -(4+3+3+1+2)*4 -1]; 40 | }POE_Vert_t; 41 | 42 | typedef struct 43 | { 44 | US nVerts; 45 | POE_Vert_t verts[POE_VERTBUFSIZ]; 46 | 47 | UL flags; 48 | long userLong; 49 | UB clipCode; 50 | }POE_Poly_t; 51 | 52 | typedef struct 53 | { 54 | POE_Vert_t **vertH; 55 | float nor[3], d; 56 | long vertIdx[POE_VERTBUFSIZ]; 57 | UB c[POE_VERTBUFSIZ]; 58 | short txPos[POE_VERTBUFSIZ][2]; 59 | long materialID; 60 | US nVerts; 61 | 62 | UL flags; 63 | long userLong; 64 | UB clipCode; 65 | //UB pad[128 -12-2- 4*POE_VERTBUFSIZ - 4-4 -1*POE_VERTBUFSIZ -4-4-1]; 66 | }POE_PolyI_t; 67 | 68 | //===================================== 69 | extern POE_Poly_t __POE_standardPoly, *__POE_curPolyP; 70 | extern POE_Vert_t *__POE_curVertP, *__POE_curVertP_c, *__POE_curVertP_n, *__POE_curVertP_t; 71 | 72 | //===================================== 73 | inline POE_Poly_t *POE_GetCurPoly(void){return __POE_curPolyP;} 74 | 75 | //===================================== 76 | inline void POE_BeginPolygon(POE_Poly_t *polyP=&__POE_standardPoly) 77 | { 78 | polyP->nVerts = 0; 79 | __POE_curPolyP = polyP; 80 | __POE_curVertP = __POE_curVertP_c = __POE_curVertP_n = __POE_curVertP_t = polyP->verts; 81 | //memset(poly,0,sizeof(POE_Poly_t)); 82 | } 83 | 84 | //===================================== 85 | inline void POE_Vertex2v(const long *v) 86 | { 87 | __POE_curVertP->eye[0] = v[0]; 88 | __POE_curVertP->eye[1] = v[1]; 89 | ++__POE_curVertP; 90 | } 91 | //===================================== 92 | inline void POE_Vertex2(long x, long y) 93 | { 94 | __POE_curVertP->eye[0] = x; 95 | __POE_curVertP->eye[1] = y; 96 | ++__POE_curVertP; 97 | } 98 | //===================================== 99 | inline void POE_Vertex3(long x, long y, long z) 100 | { 101 | vec3_set( __POE_curVertP->eye, x,y,z ); 102 | ++__POE_curVertP; 103 | } 104 | //===================================== 105 | inline void POE_Vertex3v(const long *v) 106 | { 107 | vec3_equ( __POE_curVertP->eye, v ); 108 | ++__POE_curVertP; 109 | } 110 | 111 | //===================================== 112 | inline void POE_Color1(UB col) 113 | { 114 | __POE_curVertP_c->c = col; 115 | ++__POE_curVertP_c; 116 | } 117 | 118 | //===================================== 119 | inline void POE_Normal3(long x, long y, long z) 120 | { 121 | __POE_curVertP_n->nor[0] = x << 10; 122 | __POE_curVertP_n->nor[1] = y << 10; 123 | __POE_curVertP_n->nor[2] = z << 10; 124 | ++__POE_curVertP_n; 125 | } 126 | //===================================== 127 | inline void POE_Normal3v(const short *n) 128 | { 129 | __POE_curVertP_n->nor[0] = (long)n[0] << 10; 130 | __POE_curVertP_n->nor[1] = (long)n[1] << 10; 131 | __POE_curVertP_n->nor[2] = (long)n[2] << 10; 132 | ++__POE_curVertP_n; 133 | } 134 | 135 | //===================================== 136 | inline void POE_Texture2v(const long *v){ __POE_curVertP_t->u = v[0]; __POE_curVertP_t->v = v[1]; ++__POE_curVertP_t; } 137 | inline void POE_Texture2v(const US *v){ __POE_curVertP_t->u = v[0]; __POE_curVertP_t->v = v[1]; ++__POE_curVertP_t; } 138 | 139 | //===================================== 140 | inline void POE_EndPolygon(void) 141 | { 142 | __POE_curPolyP->nVerts = __POE_curVertP-__POE_curPolyP->verts; 143 | } 144 | 145 | #endif 146 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/M44.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // M44.HPP - matrix handler 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #include "EXTTYPES.HPP" 7 | #include "M44.HPP" 8 | 9 | static float identity[4][4]={ 10 | 1.,0.,0.,0., 11 | 0.,1.,0.,0., 12 | 0.,0.,1.,0., 13 | 0.,0.,0.,1. 14 | }; 15 | 16 | //================================== 17 | void m44_identity( float m[4][4] ) 18 | { 19 | memcpytiny( m, identity, 16*sizeof(float) ); 20 | } 21 | 22 | //================================== 23 | void m44_scale( float m[4][4], float x, float y, float z ) 24 | { 25 | m[0][0] *= x; m[1][0] *= x; m[2][0] *= x; m[3][0] *= x; 26 | m[0][1] *= y; m[1][1] *= y; m[2][1] *= y; m[3][1] *= y; 27 | m[0][2] *= z; m[1][2] *= z; m[2][2] *= z; m[3][2] *= z; 28 | } 29 | 30 | //================================== 31 | void m44_multiply( float d[4][4], const float s1[4][4], const float s2[4][4] ) 32 | { 33 | short i; 34 | float tmp[16], *tmpP; 35 | 36 | tmpP = tmp; 37 | for(i=0; i < 4; ++i) 38 | { 39 | float xi0 = s1[i][0], xi1 = s1[i][1], xi2 = s1[i][2], xi3 = s1[i][3]; 40 | 41 | tmpP[0] = xi0 * s2[0][0] + xi1 * s2[1][0] + xi2 * s2[2][0] + xi3 * s2[3][0]; 42 | tmpP[1] = xi0 * s2[0][1] + xi1 * s2[1][1] + xi2 * s2[2][1] + xi3 * s2[3][1]; 43 | tmpP[2] = xi0 * s2[0][2] + xi1 * s2[1][2] + xi2 * s2[2][2] + xi3 * s2[3][2]; 44 | tmpP[3] = xi0 * s2[0][3] + xi1 * s2[1][3] + xi2 * s2[2][3] + xi3 * s2[3][3]; 45 | tmpP += 4; 46 | } 47 | memcpytiny( d, tmp, 16*sizeof(float) ); 48 | } 49 | 50 | //------------------------------------- 51 | static inline float det2x2(float a, float b, float c, float d){ return a * d - b * c; } 52 | //------------------------------------- 53 | static float det3x3(float a1, float a2, float a3, float b1, float b2, float b3, float c1, float c2, float c3) 54 | { 55 | return a1 * det2x2 (b2, b3, c2, c3) - b1 * det2x2 (a2, a3, c2, c3) + c1 * det2x2 (a2, a3, b2, b3); 56 | } 57 | //------------------------------------- 58 | static float det4x4(float mat[4][4]) 59 | { 60 | float a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4; 61 | 62 | a1 = mat[0][0]; b1 = mat[0][1]; 63 | c1 = mat[0][2]; d1 = mat[0][3]; 64 | 65 | a2 = mat[1][0]; b2 = mat[1][1]; 66 | c2 = mat[1][2]; d2 = mat[1][3]; 67 | 68 | a3 = mat[2][0]; b3 = mat[2][1]; 69 | c3 = mat[2][2]; d3 = mat[2][3]; 70 | 71 | a4 = mat[3][0]; b4 = mat[3][1]; 72 | c4 = mat[3][2]; d4 = mat[3][3]; 73 | 74 | return a1 * det3x3 (b2, b3, b4, c2, c3, c4, d2, d3, d4) - 75 | b1 * det3x3 (a2, a3, a4, c2, c3, c4, d2, d3, d4) + 76 | c1 * det3x3 (a2, a3, a4, b2, b3, b4, d2, d3, d4) - 77 | d1 * det3x3 (a2, a3, a4, b2, b3, b4, c2, c3, c4); 78 | } 79 | //------------------------------------- 80 | static void adjoint(float mat[4][4]) 81 | { 82 | float a1, a2, a3, a4, b1, b2, b3, b4; 83 | float c1, c2, c3, c4, d1, d2, d3, d4; 84 | 85 | a1 = mat[0][0]; b1 = mat[0][1]; 86 | c1 = mat[0][2]; d1 = mat[0][3]; 87 | 88 | a2 = mat[1][0]; b2 = mat[1][1]; 89 | c2 = mat[1][2]; d2 = mat[1][3]; 90 | 91 | a3 = mat[2][0]; b3 = mat[2][1]; 92 | c3 = mat[2][2]; d3 = mat[2][3]; 93 | 94 | a4 = mat[3][0]; b4 = mat[3][1]; 95 | c4 = mat[3][2]; d4 = mat[3][3]; 96 | 97 | /* row column labeling reversed since we transpose rows & columns */ 98 | mat[0][0] = det3x3 (b2, b3, b4, c2, c3, c4, d2, d3, d4); 99 | mat[1][0] = -det3x3 (a2, a3, a4, c2, c3, c4, d2, d3, d4); 100 | mat[2][0] = det3x3 (a2, a3, a4, b2, b3, b4, d2, d3, d4); 101 | mat[3][0] = -det3x3 (a2, a3, a4, b2, b3, b4, c2, c3, c4); 102 | 103 | mat[0][1] = -det3x3 (b1, b3, b4, c1, c3, c4, d1, d3, d4); 104 | mat[1][1] = det3x3 (a1, a3, a4, c1, c3, c4, d1, d3, d4); 105 | mat[2][1] = -det3x3 (a1, a3, a4, b1, b3, b4, d1, d3, d4); 106 | mat[3][1] = det3x3 (a1, a3, a4, b1, b3, b4, c1, c3, c4); 107 | 108 | mat[0][2] = det3x3 (b1, b2, b4, c1, c2, c4, d1, d2, d4); 109 | mat[1][2] = -det3x3 (a1, a2, a4, c1, c2, c4, d1, d2, d4); 110 | mat[2][2] = det3x3 (a1, a2, a4, b1, b2, b4, d1, d2, d4); 111 | mat[3][2] = -det3x3 (a1, a2, a4, b1, b2, b4, c1, c2, c4); 112 | 113 | mat[0][3] = -det3x3 (b1, b2, b3, c1, c2, c3, d1, d2, d3); 114 | mat[1][3] = det3x3 (a1, a2, a3, c1, c2, c3, d1, d2, d3); 115 | mat[2][3] = -det3x3 (a1, a2, a3, b1, b2, b3, d1, d2, d3); 116 | mat[3][3] = det3x3 (a1, a2, a3, b1, b2, b3, c1, c2, c3); 117 | } 118 | //------------------------------------- 119 | void m44_invert( float m[4][4] ) 120 | { 121 | float det; 122 | 123 | det = det4x4(m); 124 | if ( ABS(det) < .00001 ) return; 125 | det = 1. / det; 126 | 127 | adjoint(m); 128 | 129 | float *mP = (float *)m; 130 | for (long i=16; i; --i) 131 | *mP++ *= det; 132 | } 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/OBJ3D.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // OBJ3D.HPP - 3D objects 3 | // Copyright (C) Davide Pasca 1994-1995 4 | //============================================== 5 | 6 | #ifndef __OBJ3D_HPP__ 7 | #define __OBJ3D_HPP__ 8 | 9 | typedef float VEC_T; 10 | typedef float NOR_T; 11 | 12 | #include "EXTTYPES.HPP" 13 | #include "CVEC3.HPP" 14 | #include "COLORS.HPP" 15 | #include "POLYENG.HPP" 16 | 17 | //======================================= 18 | typedef struct 19 | { 20 | UB rgb[3]; 21 | 22 | BitMap texMap; 23 | US palSize; 24 | UB mapPalette[256*3]; 25 | }O3D_Material_t; 26 | 27 | //======================================= 28 | #define O3D_INTPREC 1000.0 29 | #define x3DG1_ID MAKE_ID('3','D','G','1') 30 | #define LGO3D_CANNOTOPENFILE -1L 31 | #define LGO3D_UNKNOWFILE -2L 32 | #define LGO3D_NOMEM -3L 33 | #define LGO3D_TOOMUCHVERTS -4L 34 | 35 | #define LIST_FIELDS \ 36 | char name[80]; \ 37 | void *next; 38 | 39 | typedef struct 40 | { 41 | float vert[3]; 42 | float nor[3]; 43 | UB doTrans; 44 | UB shade; 45 | UB pad[32 -3*4 -3*4 -1 -1]; 46 | }O3D_VertBase_t; 47 | 48 | typedef struct 49 | { 50 | LIST_FIELDS 51 | float mat[4][4], matinv[4][4]; 52 | void *worldP; 53 | NOR_T traLight[3]; 54 | 55 | long curVertNum, NVerts; // vertices 56 | O3D_VertBase_t *baseVertsP; 57 | POE_Vert_t *vertsP; 58 | 59 | long curPolyNum, NPolys; // polygons 60 | POE_PolyI_t *curPolyP, *PolysP; 61 | 62 | US nMaterials; 63 | O3D_Material_t *materialsP; 64 | 65 | float sphererad, totsphererad; 66 | VEC_T Min[3], Max[3], Dim[3], totMin[3], totMax[3], totDim[3]; 67 | long totVertNum, totPolyNum; 68 | 69 | UL oflags; 70 | US flags; 71 | UB doNotTransVerts; 72 | } Obj3D, O3D_Object_t; 73 | 74 | #include "GL_MATR.HPP" 75 | 76 | #define ACT __O3D_actObjP 77 | extern O3D_Object_t *__O3D_actObjP; 78 | 79 | inline long O3D_Set(long objID) 80 | { 81 | O3D_Object_t *t=ACT; 82 | ACT = (O3D_Object_t *)objID; 83 | return (long)t; 84 | } 85 | inline long O3D_Get(void){return (long)ACT;} 86 | 87 | inline void O3D_ResetPolys(void){ ACT->curPolyNum = 0; ACT->curPolyP = ACT->PolysP; } 88 | inline void O3D_ResetVerts(void){ ACT->curVertNum = 0; } 89 | long O3D_AllocVerts(UL nverts); 90 | long O3D_AllocPolys(UL npolys); 91 | 92 | //--------------------------------- 93 | inline long _O3D_VertNew(float x, float y, float z) 94 | { 95 | vec3_set( ACT->baseVertsP[ ACT->curVertNum ].vert, x, y, z ); 96 | return ACT->curVertNum++; 97 | } 98 | //--------------------------------- 99 | long O3D_VertNew(float x, float y, float z); 100 | long O3D_VertNew(const float *v); 101 | 102 | //================================= 103 | long O3D_PolyBegin(long mat, US flags); 104 | inline void _O3D_PolyBegin(long mat, US flags) 105 | { 106 | POE_PolyI_t *polyP; 107 | 108 | polyP = ACT->curPolyP; 109 | polyP->nVerts = 0; 110 | polyP->vertH = &ACT->vertsP; 111 | polyP->materialID = mat; 112 | 113 | polyP->flags = flags; 114 | polyP->userLong = (long)ACT; 115 | polyP->clipCode = 0; 116 | } 117 | //--------------------------------- 118 | long O3D_PolyVertNew(long vertIdx,long u=0, long v=0); 119 | inline void _O3D_PolyVertNew(long vertIdx,long u=0, long v=0) 120 | { 121 | POE_PolyI_t *polyP; 122 | 123 | polyP = ACT->curPolyP; 124 | polyP->vertIdx[polyP->nVerts] = vertIdx; 125 | polyP->txPos[polyP->nVerts][0] = u; 126 | polyP->txPos[polyP->nVerts++][1] = v; 127 | } 128 | //--------------------------------- 129 | inline void O3D_PolyEnd(void) 130 | { 131 | ++ACT->curPolyNum; 132 | ++ACT->curPolyP; 133 | } 134 | 135 | #define O3D_TOTAL_POLYS 0 136 | #define O3D_TOTAL_VERTS 1 137 | void O3D_ValueGet(UB cmd, long *valP ); 138 | 139 | #define O3D_SPHERE_RAD 2 140 | #define O3D_TOTAL_SPHERE_RAD 3 141 | void O3D_ValueGet(UB cmd, float *valP ); 142 | 143 | long O3D_New(void); 144 | long O3D_New(const char *nameP); 145 | void O3D_Dispose( long objID ); 146 | 147 | inline void O3D_MatrixSet_NoList(long objID=(long)ACT, const float mat[4][4]=(const float (*)[4])_glCurMatP->mf ) 148 | { 149 | memcpytiny( ((O3D_Object_t *)objID)->mat, mat, 16*sizeof(float)); 150 | ((O3D_Object_t *)objID)->doNotTransVerts = 0; 151 | } 152 | void O3D_MatrixSet(long objID=(long)ACT, const float mat[4][4]=(const float (*)[4])_glCurMatP->mf ); 153 | long O3D_GetByName( const char *nameP ); 154 | 155 | #define O3D_PF_SET 0 156 | #define O3D_PF_AND 1 157 | #define O3D_PF_OR 2 158 | #define O3D_PF_TOGGLE 3 159 | void O3D_PolysFlags( UB cmd, US flags ); 160 | void O3D_PolysFlags_NoList( UB cmd, US flags ); 161 | 162 | long O3D_LoadGEO( const char *fileName, long *badPolysP ); 163 | long O3D_LoadGEOM( const char *fileName, long *badPolysP ); 164 | 165 | void O3D_Update(void); 166 | 167 | void O3D_Init(void); 168 | void O3D_Free( long objID ); 169 | 170 | #define O3D_TD_SPHERE 1 171 | #define O3D_TD_CYLINDER 2 172 | long O3D_TextureDisplace( long txwd, long txhe, UL td_kind ); 173 | long O3D_TextureDisplace_NoList( long txwd, long txhe, UL td_kind ); 174 | 175 | void O3D_CalcNormals(void); 176 | void O3D_CalcNormals_NoList(void); 177 | void O3D_CalcNormals_NoList( double *vecsP ); 178 | void O3D_OptimizeTriObject(void); 179 | void O3D_CalcMinMaxDim(void); 180 | void O3D_CalcMinMaxDim_NoList(void); 181 | void O3D_GetMinMaxDim(float *min, float *max, float *dim ); 182 | #undef ACT 183 | 184 | #include "READ3DS.HPP" 185 | 186 | #endif 187 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/BMP_POLY.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // BMP_POLY.HPP - raster graphics stuff 3 | // Copyright (C) by Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __BMP_POLY_HPP__ 7 | #define __BMP_POLY_HPP__ 8 | 9 | #include "EXTTYPES.HPP" 10 | #include "POLYENG.HPP" 11 | 12 | extern BitMap *_BMP_curBitMapP; 13 | #define ACT _BMP_curBitMapP 14 | 15 | typedef void (*BMP_PolySetupFuncI_t)(const POE_PolyI_t *); 16 | typedef void (*BMP_PolySetupFunc_t)(const POE_Poly_t *); 17 | typedef void (*BMP_PolySlopeFunc_t)(POE_Vert_t *, POE_Vert_t *, long, long ); 18 | typedef void (*BMP_PolyLoopFunc_t)(UB *, long); 19 | 20 | //================================================= 21 | void BMP_PolyRoutine( const POE_Poly_t *polyP, BMP_PolySetupFunc_t setupFunc, 22 | BMP_PolySlopeFunc_t slopeFunc, 23 | BMP_PolyLoopFunc_t loopFunc ); 24 | //------------------------------------------------- 25 | void BMP_PolyRoutineI( const POE_PolyI_t *polyP, BMP_PolySetupFuncI_t setupFunc, 26 | BMP_PolySlopeFunc_t slopeFunc, 27 | BMP_PolyLoopFunc_t loopFunc ); 28 | 29 | //=================== FLAT ======================== 30 | /*inline void BMP_PolyFlat16( const POE_PolyI_t *polyP ) 31 | { 32 | BMP_PolySetupFunc_t _bmp_pf16setup; 33 | BMP_PolyLoopFunc_t _bmp_pf16loop; 34 | BMP_PolySlopeFunc_t _bmp_pf16slope; 35 | 36 | BMP_PolyRoutine( polyP, _bmp_pf16setup, _bmp_pf16slope, _bmp_pf16loop ); 37 | }*/ 38 | //------------------------------------------------- 39 | inline void BMP_PolyFlat16( const POE_PolyI_t *polyP ) 40 | { 41 | extern void _bmp_pf16setupI(const POE_PolyI_t *); 42 | extern void _bmp_pf16slope(POE_Vert_t *, POE_Vert_t *, long, long ); 43 | extern void _bmp_pf16loop(UB *, long); 44 | 45 | BMP_PolyRoutineI( polyP, _bmp_pf16setupI, _bmp_pf16slope, _bmp_pf16loop ); 46 | } 47 | //------------------------------------------------- 48 | inline void BMP_PolyFlatZ16( const POE_PolyI_t *polyP ) 49 | { 50 | extern void _bmp_pf16setupI(const POE_PolyI_t *); 51 | extern void _bmp_pfz16slope(POE_Vert_t *, POE_Vert_t *, long, long ); 52 | extern void _bmp_pfz16loop(UB *, long); 53 | 54 | BMP_PolyRoutineI( polyP, _bmp_pf16setupI, _bmp_pfz16slope, _bmp_pfz16loop ); 55 | } 56 | 57 | //================ GOURAUD ===================== 58 | inline void BMP_PolyGouraud16( const POE_PolyI_t *polyP ) 59 | { 60 | extern void _bmp_pg16setupI(const POE_PolyI_t *); 61 | extern void _bmp_pg16slope(POE_Vert_t *, POE_Vert_t *, long, long ); 62 | extern void _bmp_pg16loop(UB *, long); 63 | 64 | BMP_PolyRoutineI( polyP, _bmp_pg16setupI, _bmp_pg16slope, _bmp_pg16loop ); 65 | } 66 | //------------------------------------------------- 67 | inline void BMP_PolyGouraudZ16( const POE_PolyI_t *polyP ) 68 | { 69 | extern void _bmp_pg16setupI(const POE_PolyI_t *); 70 | extern void _bmp_pgz16slope(POE_Vert_t *, POE_Vert_t *, long, long ); 71 | extern void _bmp_pgz16loop(UB *, long); 72 | 73 | BMP_PolyRoutineI( polyP, _bmp_pg16setupI, _bmp_pgz16slope, _bmp_pgz16loop ); 74 | } 75 | 76 | //================================================= 77 | void BMP_ZBufferSet( UL *zbufP ); 78 | void BMP_PolyPhong16( const POE_PolyI_t *polyP, const float *lightSrcP, US nShad, US nUsrCols ); 79 | 80 | //================================== 81 | static inline long floor4(long a){ return a & 0xfffffff0; } 82 | static inline long ceil4(long a){ return (a+15) & 0xfffffff0; } 83 | 84 | #define LINC(X) lrun.X += ldelta.X 85 | #define RINC(X) rrun.X += rdelta.X 86 | 87 | #define POLYROUTINE( NAME, PREMINCHECK, PREWHILE, DELTANAME, DRAWSPAN ) \ 88 | void NAME \ 89 | {\ 90 | short nVerts;\ 91 | long ymin;\ 92 | long y, top, i;\ 93 | const POE_Vert_t *vertsP, *fvertsP[POE_VERTBUFSIZ];\ 94 | const long *vertIdxP;\ 95 | \ 96 | if ( (nVerts=polyP->nVerts) < 3 ) return;\ 97 | \ 98 | vertsP = *polyP->vertH;\ 99 | vertIdxP = polyP->vertIdx;\ 100 | PREMINCHECK;\ 101 | ymin = LONG_MAX;\ 102 | for (i=nVerts-1; i >= 0; --i)\ 103 | {\ 104 | fvertsP[i] = &vertsP[ vertIdxP[i] ];\ 105 | if ( fvertsP[i]->screen[1] < ymin )\ 106 | {\ 107 | ymin = fvertsP[i]->screen[1];\ 108 | top = i;\ 109 | }\ 110 | }\ 111 | \ 112 | long ly,ry,li,ri,rem;\ 113 | \ 114 | li = ri = top;\ 115 | rem = nVerts;\ 116 | y = ceil4(ymin-8);\ 117 | ly = ry = y-16;\ 118 | \ 119 | POE_Vert_t lrun,ldelta,rrun,rdelta;\ 120 | long bmWd = ACT->wd;\ 121 | PREWHILE;\ 122 | \ 123 | while (rem>0)\ 124 | {\ 125 | while (ly<=y && rem>0)\ 126 | {\ 127 | --rem;\ 128 | if ( (i = li-1) < 0) i = nVerts-1;\ 129 | DELTANAME(y, &lrun, &ldelta, fvertsP[li], fvertsP[i], li,i);\ 130 | ly = floor4(fvertsP[i]->screen[1]+8);\ 131 | li = i;\ 132 | }\ 133 | while (ry<=y && rem>0)\ 134 | {\ 135 | --rem;\ 136 | if ( (i = ri+1) >= nVerts ) i = 0;\ 137 | DELTANAME(y, &rrun, &rdelta, fvertsP[ri], fvertsP[i], ri,i);\ 138 | ry = floor4(fvertsP[i]->screen[1]+8);\ 139 | ri = i;\ 140 | }\ 141 | \ 142 | UB *mapP = ACT->offsPP[y>>4];\ 143 | ymin = MIN(ly,ry);\ 144 | while ( y < ymin )\ 145 | {\ 146 | long xl,xr;\ 147 | POE_Vert_t *l,*r;\ 148 | \ 149 | if ( rrun.screen[0] < lrun.screen[0] )\ 150 | { l=&rrun; r=&lrun; }\ 151 | else\ 152 | { l=&lrun; r=&rrun; }\ 153 | xl = l->screen[0] + 8*16 >>16;\ 154 | xr = r->screen[0] >> 16;\ 155 | DRAWSPAN;\ 156 | LINC(screen[0]); RINC(screen[0]);\ 157 | mapP += bmWd;\ 158 | y += 16;\ 159 | }\ 160 | }\ 161 | } 162 | 163 | #undef ACT 164 | 165 | #include "BMP_POTX.HPP" 166 | 167 | #endif 168 | 169 | 170 | -------------------------------------------------------------------------------- /SRC/RTMZOS/PASCALIB.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // PASCALIB.CPP 3 | // Copyright (C) Davide Pasca 1995-97 4 | // 5 | // TABS=4 6 | //============================================== 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "PASCALIB.HPP" 16 | #include "BMP.HPP" 17 | #include "PCX.HPP" 18 | 19 | //======================================= 20 | char *strcpymaxsize(char *dst, const char *src, UL max) 21 | { 22 | char *oldDst=dst; 23 | 24 | if (max) 25 | while(1) 26 | { 27 | if NOT(--max) 28 | { 29 | *dst = 0; 30 | break; 31 | } 32 | 33 | if NOT( *dst++ = *src++ ) 34 | break; 35 | } 36 | 37 | return oldDst; 38 | } 39 | 40 | //======================================= 41 | static short _RS_seed; 42 | void RandomizeShort( short rd ) 43 | { 44 | _RS_seed = rd; 45 | } 46 | 47 | //--------------------------------------- 48 | short RandShort(void) 49 | { 50 | _RS_seed = (_RS_seed+56791) * 13579; 51 | return _RS_seed & 0x7fff; 52 | } 53 | 54 | //====================================== 55 | long timer( void ) 56 | { 57 | //return( (long)(clock() * 1000.0 / CLK_TCK) ); 58 | return 0; 59 | } 60 | 61 | //====================================== 62 | static void QSortLX_rec( long *left, long *right ) 63 | { 64 | long *j; 65 | static long *i, piv ,x; 66 | 67 | piv = *(left + (((UL)right - (UL)left >> 3 ) & 0xfffffffe) ); 68 | 69 | i = left; 70 | j = right; 71 | for(;;) 72 | { 73 | while ( i[0] < piv ) i += 2; 74 | while ( j[0] > piv ) j -= 2; 75 | 76 | if ( i >= j ) 77 | { 78 | if ( left < j ) QSortLX_rec( left, j ); 79 | j += 2; 80 | if ( j < right ) QSortLX_rec( j, right ); 81 | return; 82 | } 83 | 84 | SWAP( j[0], i[0], x ); 85 | SWAP( j[1], i[1], x ); 86 | i += 2; 87 | j -= 2; 88 | } 89 | } 90 | //---------------------------------------- 91 | void QSortLX( long *aP, long right ) 92 | { 93 | long *endP; 94 | 95 | endP = aP+(right-1)*2; 96 | if ( aP < endP ) 97 | QSortLX_rec( aP, endP ); 98 | } 99 | 100 | //====================================== 101 | static void QSortLX_rec( float *left, float *right ) 102 | { 103 | float *j; 104 | static float *i, piv ,x; 105 | 106 | piv = *(left + (((UL)right - (UL)left >> 3 ) & 0xfffffffe) ); 107 | 108 | i = left; 109 | j = right; 110 | for(;;) 111 | { 112 | while ( i[0] < piv ) i += 2; 113 | while ( j[0] > piv ) j -= 2; 114 | 115 | if ( i >= j ) 116 | { 117 | if ( left < j ) QSortLX_rec( left, j ); 118 | j += 2; 119 | if ( j < right ) QSortLX_rec( j, right ); 120 | return; 121 | } 122 | 123 | SWAP( j[0], i[0], x ); 124 | SWAP( j[1], i[1], x ); 125 | i += 2; 126 | j -= 2; 127 | } 128 | } 129 | 130 | //---------------------------------------- 131 | void QSortLX( float *aP, long right ) 132 | { 133 | float *endP; 134 | 135 | endP = aP+(right-1)*2; 136 | if ( aP < endP ) 137 | QSortLX_rec( aP, endP ); 138 | } 139 | 140 | //============================================= 141 | static long *_qx_aP; 142 | static long *_qx_idxP; 143 | 144 | //#define QLX_GET_L(a,i) (*(long *)(a + i)) 145 | 146 | static void QSortLX_rec( long left, long right ) 147 | { 148 | long j; 149 | static long i; 150 | static long piv,x; 151 | 152 | if ( left >= right ) return; 153 | 154 | piv = _qx_aP[left]; 155 | 156 | i = left + 1; 157 | j = right; 158 | for(;;) 159 | { 160 | while ( _qx_aP[i] < piv ) ++i; 161 | while ( _qx_aP[j] > piv ) --j; 162 | if ( i < j ) 163 | { 164 | SWAP( _qx_aP[j], _qx_aP[i], x ); 165 | SWAP( _qx_idxP[j], _qx_idxP[i], x ); 166 | ++i; 167 | --j; 168 | } 169 | else 170 | break; 171 | } 172 | 173 | SWAP( _qx_aP[j], _qx_aP[left], x ); 174 | SWAP( _qx_idxP[j], _qx_idxP[left], x ); 175 | 176 | QSortLX_rec( left, j-1 ); 177 | QSortLX_rec( j+1, right ); 178 | } 179 | 180 | /*--------------------------------------*/ 181 | void QSortLX( long *aP, long *idxP, long right ) 182 | { 183 | _qx_aP = aP; 184 | _qx_idxP = idxP; 185 | QSortLX_rec( 0, right-1 ); 186 | } 187 | 188 | //============================= 189 | /* 190 | void FreePix3DArray( Pix3DArray *pixP ) 191 | { 192 | SAFE_FREE( pixP->vecP ); 193 | SAFE_FREE( pixP->colP ); 194 | SAFE_FREE( pixP->transVecP ); 195 | } 196 | 197 | //---------------------------------------- 198 | long MakePix3DArray( const char *fnameP, Pix3DArray *pixP, long sx, long sy, UL flags ) 199 | { 200 | BitMap bm; 201 | long npix; 202 | long *vecP, *transVecP=0, vec[3]; 203 | UB *colP, *scolP, col; 204 | short x,y,hwd,hhe; 205 | 206 | 207 | memset( pixP, 0, sizeof(Pix3DArray) ); 208 | 209 | if ( PCX_Read(fnameP, &bm.memP, &bm.wd, &bm.he, 0, 0) ) 210 | return -1; 211 | 212 | scolP = bm.memP; 213 | npix = (long)bm.wd * bm.he; 214 | long i=npix; 215 | while( i-- ) 216 | if NOT( *scolP++ ) 217 | --npix; 218 | 219 | if NOT(vecP=(long *)malloc(npix*3*sizeof(*vecP))) goto err1; 220 | if NOT(colP=(UB*)malloc(npix*sizeof(*colP))) goto err2; 221 | 222 | if ( P3DA_MAKEPTSTRANS_FLG & flags ) 223 | if NOT(transVecP=(long *)malloc(npix*3*sizeof(*transVecP))) goto err3; 224 | 225 | vec[1] = -bm.he >> 1; 226 | vec[2] = 0; 227 | 228 | hwd = bm.wd >> 1; 229 | hhe = bm.he >> 1; 230 | 231 | pixP->vecP = vecP; 232 | pixP->transVecP = transVecP; 233 | pixP->colP = colP; 234 | pixP->npix = npix; 235 | 236 | scolP = bm.memP; 237 | for(y=0; y < bm.he; ++y) 238 | { 239 | vec[1] = -(hhe-y)*sy; 240 | for(x=0; x < bm.wd; ++x) 241 | { 242 | if ( col = *scolP++ ) 243 | { 244 | vec[0] = -(hwd-x)*sx; 245 | vec3_equ( vecP += 3, vec ); 246 | *colP++ = col; 247 | } 248 | } 249 | } 250 | 251 | BMP_Free( &bm ); 252 | return 0; 253 | 254 | err3: 255 | free( colP ); 256 | 257 | err2: 258 | free( vecP ); 259 | err1: 260 | BMP_Free( &bm ); 261 | return -1; 262 | } 263 | */ 264 | -------------------------------------------------------------------------------- /SRC/RTMZOS/PCX.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // PCX.CPP 3 | // Copyright (C) Davide Pasca 1995-97 4 | // 5 | // TABS=4 6 | //============================================== 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | //#include "LINKFILE.HPP" 13 | #include "PCX.HPP" 14 | #include "VGAPACK.HPP" 15 | #include "BMP.HPP" 16 | 17 | typedef struct 18 | { 19 | char manufacturer; 20 | char version; 21 | char encoding; 22 | char bits_per_pixel; 23 | short xmin,ymin; 24 | short xmax,ymax; 25 | short hres; 26 | short vres; 27 | char palette[48]; 28 | char reserved; 29 | char colour_planes; 30 | short bytes_per_line; 31 | short palette_type; 32 | char filler[58]; 33 | }PCXHEAD; 34 | 35 | //==================================== 36 | static US readLine(FILE *fp, UB *p, US wd, US max) 37 | { 38 | US n=0,c,i; 39 | 40 | do{ 41 | c=fgetc(fp) & 0xff; // get a key byte 42 | if((c & 0xc0) == 0xc0) // if it's a run of bytes field 43 | { 44 | i=c & 0x3f; // and off the high bits 45 | c=fgetc(fp); // get the run byte 46 | while(i--) 47 | { 48 | if ( n < wd ) 49 | p[n]=c; // run the byte 50 | ++n; 51 | } 52 | } 53 | else 54 | { 55 | if ( n < wd ) 56 | p[n]=c; // else just store it 57 | ++n; 58 | } 59 | }while(n < max); 60 | 61 | return n; 62 | } 63 | 64 | //------------------------------------ 65 | #define EXITERR(E) {err=E; goto exitErr##E;} 66 | 67 | long PCX_Read( const char *fnameP, UB **memPP, US *wdP, US *heP, UB *dpP, UB *palP ) 68 | { 69 | PCXHEAD head; 70 | US bits; 71 | short wd,he; 72 | UB *memP; 73 | FILE *fp; 74 | short err,i; 75 | UB *p; 76 | 77 | if NOT( fp = fopen( fnameP, "rb" ) ) 78 | return( 1 ); 79 | 80 | if ( FREAD( &head,sizeof(PCXHEAD),fp) ) 81 | EXITERR( 2 ); 82 | 83 | if (head.bits_per_pixel == 1) 84 | bits = head.colour_planes; 85 | else 86 | bits = head.bits_per_pixel; 87 | 88 | if (bits !=8) 89 | EXITERR( 3 ); 90 | 91 | /* check to make sure it's a picture */ 92 | if (head.manufacturer != 0x0a || head.version != 5 ) 93 | EXITERR( 4 ); 94 | 95 | /* Find the palette */ 96 | if NOT( fseek(fp,-769L,SEEK_END) ) 97 | { 98 | if ( fgetc(fp) != 0x0c ) 99 | EXITERR( 5 ); 100 | 101 | if ( palP ) 102 | { 103 | if ( FREAD( palP, 768, fp ) ) 104 | EXITERR( 5 ); 105 | } 106 | else 107 | if ( fseek(fp,768L,SEEK_SET) ) 108 | EXITERR( 5 ); 109 | } 110 | else 111 | EXITERR( 5 ); 112 | 113 | fseek(fp,128L,SEEK_SET); 114 | 115 | he = (head.ymax-head.ymin)+1; 116 | wd = (head.xmax-head.xmin)+1; //head.bytes_per_line; 117 | 118 | if ( memPP ) 119 | { 120 | if ( !wd || !he ) EXITERR( 6 ); 121 | if NOT( NEW( memP, wd*he ) ) EXITERR( 6 ); 122 | p = memP; 123 | for(i=he; i; --i, p += wd) 124 | readLine(fp,p,wd,head.bytes_per_line); 125 | } 126 | fclose(fp); 127 | 128 | if ( wdP ) *wdP = wd; 129 | if ( heP ) *heP = he; 130 | if ( dpP ) *dpP = bits; 131 | if ( memPP ) *memPP = memP; 132 | return(0); 133 | 134 | exitErr7: 135 | free( memP ); 136 | exitErr6: 137 | exitErr5: 138 | exitErr4: 139 | exitErr3: 140 | exitErr2: 141 | fclose(fp); 142 | 143 | if ( wdP ) *wdP = wd; 144 | if ( heP ) *heP = he; 145 | if ( dpP ) *dpP = bits; 146 | if ( memPP ) *memPP = memP; 147 | return( -err ); 148 | } 149 | 150 | //=========================== 151 | long PCX_ReadBitMap( const char *nameP, BitMap *bmP, UB *palP ) 152 | { 153 | if ( PCX_Read( nameP, &bmP->memP, &bmP->wd, &bmP->he, &bmP->dp, palP ) ) 154 | return -1; 155 | 156 | if ( BMP_Alloc( bmP, bmP->wd, bmP->he, bmP->dp, bmP->memP ) ) 157 | { 158 | SAFE_FREE( bmP->memP ); 159 | return -2; 160 | } 161 | 162 | return 0; 163 | } 164 | 165 | //======================================= 166 | long PCX_ReadBitMaps( const char *fnamep, BitMap *bmlistp, long bobwd, long bobhe, long nframes, UB *palP ) 167 | { 168 | BitMap tmap; 169 | long x, y, i; 170 | BitMap *bmp; 171 | 172 | if ( bobwd<=0 || bobhe<=0 || nframes<=0 || PCX_ReadBitMap( fnamep, &tmap, palP ) ) 173 | return -1; 174 | 175 | bmp = bmlistp; 176 | for(i=0; i < nframes; ++i, ++bmp) 177 | { 178 | if ( BMP_Alloc( bmp, bobwd, bobhe, 8, 0 ) ) 179 | { 180 | for(--i, --bmp; i>=0; --bmp) 181 | BMP_Free( bmp ); 182 | BMP_Free( &tmap ); 183 | 184 | return -2; 185 | } 186 | } 187 | 188 | x = y = 0; 189 | bmp = bmlistp; 190 | BMP_Push(); 191 | for(y=0; y < tmap.he; y += bobhe) 192 | for(x=0; x < tmap.wd; x += bobwd) 193 | { 194 | if ( --nframes < 0 ) goto pazzo; 195 | BMP_Set( bmp++ ); 196 | BMP_BitBltCP( 0,0, bobwd, bobhe, &tmap, x, y ); 197 | } 198 | pazzo: 199 | BMP_Pop(); 200 | BMP_Free( &tmap ); 201 | 202 | return 0; 203 | } 204 | 205 | //======================================== 206 | long PCX_ReadPalette( const char *fnameP, UB *palP ) 207 | { 208 | PCXHEAD head; 209 | US bits; 210 | FILE *fp; 211 | 212 | if NOT( fp = fopen( fnameP, "rb" ) ) 213 | return -1; 214 | 215 | if ( FREAD( &head,sizeof(PCXHEAD),fp) ) 216 | goto errExit; 217 | 218 | if (head.bits_per_pixel == 1) 219 | bits = head.colour_planes; 220 | else 221 | bits = head.bits_per_pixel; 222 | 223 | if (bits !=8 || head.manufacturer != 0x0a || head.version != 5) 224 | goto errExit; 225 | 226 | if NOT( fseek(fp,-769L,SEEK_END) ) // Find the palette 227 | { 228 | if ( fgetc(fp) != 0x0c ) 229 | goto errExit; 230 | 231 | if ( FREAD( palP, 768, fp ) ) 232 | goto errExit; 233 | } 234 | else 235 | goto errExit; 236 | 237 | fclose( fp ); 238 | return 0; 239 | 240 | errExit: 241 | fclose( fp ); 242 | return -1; 243 | } 244 | 245 | /******* 246 | static BitMap *bima; 247 | 248 | //------------------------------------ 249 | static BitMap *_read_pp_mapP; 250 | 251 | inline static void read_putpixel(short x, short y, UB col) 252 | { 253 | if NOT( _read_pp_mapP->Flags & BM_MODE_X_FLG ) 254 | Cnk_PutPixel( _read_pp_mapP, x, y, col ); 255 | else 256 | VGAX_PutPixel( x, y, col ); 257 | } 258 | ***********/ 259 | -------------------------------------------------------------------------------- /SRC/RTMZOS/KBD.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // KBD.CPP - keyboard handler 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "KBD.HPP" 14 | 15 | static UB (*_keyFuncP)(US,UB); 16 | static BO _kbd_ingnoreRepeat, _handKeepOld; 17 | 18 | static UB _evt_enabled=1, _atexit_filled; 19 | static long _evt_i=0; 20 | static US _evt_k[KBD_EVT_MAX]; 21 | static US _keyLUT[256]={ 22 | 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', KBD_BACKSPACE, '\t', 23 | 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', KBD_LCTRL, 'a', 's', 24 | 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', KBD_LSHIFT, '!','z', 'x', 'c', 'v', 25 | 'b', 'n', 'm', ',', '.', '/', KBD_RSHIFT, '*'|KBD_FLG_KPAD, KBD_LALT, ' ', KBD_CAPSLOCK, KBD_F1,KBD_F2,KBD_F3,KBD_F4,KBD_F5, 26 | KBD_F6,KBD_F7,KBD_F8,KBD_F9,KBD_F10, 27 | KBD_NUMLOCK|KBD_FLG_KPAD, KBD_SCRLLOCK, 28 | '7'|KBD_FLG_KPAD, '8'|KBD_FLG_KPAD, '9'|KBD_FLG_KPAD, '-'|KBD_FLG_KPAD, '4'|KBD_FLG_KPAD, '5'|KBD_FLG_KPAD, 29 | '6'|KBD_FLG_KPAD, '+'|KBD_FLG_KPAD, '1'|KBD_FLG_KPAD, '2'|KBD_FLG_KPAD, '3'|KBD_FLG_KPAD, '0'|KBD_FLG_KPAD, 30 | '.'|KBD_FLG_KPAD, 84,85,86, 31 | KBD_F11, KBD_F12, 32 | 89, 33 | 90,91,92,93,94,95,96,97,98,99, 34 | 100,101,102,103,104,105,106,107,108,109, 35 | 110,111,112,113,114,115,116,117,118,119, 36 | 120,121,122,123,124,125,126,127,128, 129, 37 | 130,131,132,133,134,135,136,137,138,139, 38 | 140,141,142,143,144,145,146,147,148,149, 39 | 150,151,152,153,154,155, 40 | '\n'|KBD_FLG_KPAD, KBD_RCTRL,128+30, 41 | 128+31,128+32,128+33,128+34,128+35,128+36,128+37,128+38,128+39,128+40,128+41, 42 | KBD_PRTSCR, 43 | 128+43,128+44,128+45,128+46,128+47,128+48,128+49,128+50,128+51,128+52, 44 | '/'|KBD_FLG_KPAD,128+54,128+55, 45 | KBD_RALT,128+57,128+58,128+59, 46 | 128+60,128+61,128+62,128+63,128+64,128+65,128+66,128+67,128+68,128+69, 47 | 128+70, 48 | KBD_HOME,KBD_UP,KBD_PGUP,128+74,KBD_LEFT,128+76,KBD_RIGHT,128+78,KBD_END, 49 | KBD_DOWN,KBD_PGDOWN,KBD_INSERT,KBD_DELETE, 50 | 128+84,128+85,128+86,128+87,128+88,128+89, 51 | 128+90,128+91,128+92,128+93,128+94,128+95,128+96,128+97,128+98,128+99, 52 | 128+100,128+101,128+102,128+103,128+104,128+105,128+106,128+107,128+108,128+109, 53 | 128+110,KBD_MACRO 54 | }; 55 | static UB _kbd_pressTable[2048]; 56 | 57 | //============================== 58 | UB KBD_IsPressed( US c ) 59 | { 60 | return _kbd_pressTable[c]; 61 | } 62 | 63 | //============================== 64 | void KBD_ResetPressTable(void) 65 | { 66 | memset( _kbd_pressTable, 0, sizeof(_kbd_pressTable) ); 67 | } 68 | 69 | //============================== 70 | static void (interrupt far *_oldHandler)(void); 71 | static UB _alreadyInstalled, _expectingExtendedKey; 72 | 73 | #pragma off (check_stack) 74 | static void interrupt far __theHandler(void) 75 | { 76 | UB k; 77 | 78 | _disable(); 79 | k = inp( 0x60 ); 80 | if ( _evt_enabled ) 81 | { 82 | if ( _evt_i < KBD_EVT_MAX ) 83 | { 84 | if ( _expectingExtendedKey ) 85 | { 86 | _evt_k[ _evt_i++ ] = 2048 | (US)k; 87 | --_expectingExtendedKey; 88 | } 89 | else 90 | { 91 | if ( k == 0xE0 ) 92 | { 93 | _expectingExtendedKey = 1; 94 | } 95 | else 96 | _evt_k[ _evt_i++ ] = k; 97 | } 98 | } 99 | } 100 | //else 101 | // _expectingExtendedKey = 0; 102 | 103 | if ( _handKeepOld ) 104 | _oldHandler(); 105 | else 106 | outp( 0x20, 0x20 ); 107 | 108 | _enable(); 109 | } 110 | 111 | //============================== 112 | void KBD_RepeatIgnore(BO yesNo){ _kbd_ingnoreRepeat = yesNo; } 113 | //============================== 114 | void KBD_HandlerKeepOld(BO yesNo){ _handKeepOld = yesNo; } 115 | 116 | //============================== 117 | void KBD_EventsDisable(void){ _evt_enabled = 0; } 118 | void KBD_EventsEnable(void){ _evt_enabled = 1; } 119 | 120 | //============================== 121 | UL KBD_EventsListGet( US *listP ) 122 | { 123 | UL n; 124 | 125 | KBD_EventsDisable(); 126 | memcpytiny( listP, _evt_k, sizeof(US)*_evt_i ); 127 | n = _evt_i; // occhio deve essere nel blocco disable-enable 128 | KBD_EventsEnable(); 129 | 130 | return n; 131 | } 132 | 133 | //============================== 134 | void KBD_EventsFlush(long n, const US *evtsP) 135 | { 136 | US e[KBD_EVT_MAX]; 137 | const US *kp; 138 | 139 | if ( evtsP ) 140 | { 141 | _evt_i = n; 142 | kp = evtsP; 143 | } 144 | else 145 | { 146 | KBD_EventsDisable(); 147 | n = _evt_i; 148 | _evt_i = 0; 149 | memcpy( e, _evt_k, n*sizeof(US) ); 150 | kp = e; 151 | KBD_EventsEnable(); 152 | } 153 | 154 | if ( _keyFuncP ) 155 | { 156 | long i; 157 | 158 | for(i=n; i > 0; --i, ++kp) 159 | { 160 | US key = (US)*kp & 0xff7f; 161 | UB ispress = !(*kp & 0x0080); 162 | 163 | if ( key & 2048 ) // extended ? 164 | key = (key & 0x007f) + 128; 165 | 166 | if ( (_kbd_ingnoreRepeat && !(_kbd_pressTable[ _keyLUT[key] ] && ispress)) || 167 | !_kbd_ingnoreRepeat ) 168 | { 169 | _kbd_pressTable[ _keyLUT[key] ] = ispress; 170 | _keyFuncP( _keyLUT[key], ispress ? KBD_PRESS : KBD_RELEASE ); 171 | } 172 | } 173 | } 174 | } 175 | 176 | //============================== 177 | void KBD_Close(void) 178 | { 179 | if ( _alreadyInstalled ) 180 | { 181 | _disable(); 182 | _dos_setvect( 0x09, _oldHandler ); 183 | _enable(); 184 | _alreadyInstalled = 0; 185 | } 186 | } 187 | //============================== 188 | long KBD_Open(void) 189 | { 190 | if NOT( _alreadyInstalled ) 191 | { 192 | KBD_ResetPressTable(); 193 | _disable(); 194 | _oldHandler = _dos_getvect( 0x09 ); 195 | _dos_setvect( 0x09, __theHandler ); 196 | _enable(); 197 | _alreadyInstalled = 1; 198 | 199 | if NOT( _atexit_filled ) 200 | { 201 | atexit( KBD_Close ); 202 | _atexit_filled = 1; 203 | } 204 | } 205 | 206 | return 0; 207 | } 208 | 209 | //============================== 210 | void KBD_FuncSet( UB (*keyFuncP)(US,UB) ) 211 | { 212 | _keyFuncP = keyFuncP; 213 | } 214 | 215 | -------------------------------------------------------------------------------- /SRC/RTMZOS/MOU.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // MOUSE.CPP - mouse handler 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "mou.hpp" 13 | #include "vgapack.hpp" 14 | 15 | static UB (*_clickFuncP)(UB,UB,short,short), (*_moveFuncP)(short,short); 16 | 17 | //============================== 18 | #define MOVED ((UB)1<<0) 19 | #define LEFT_D ((UB)1<<1) 20 | #define LEFT_U ((UB)1<<2) 21 | #define RITE_D ((UB)1<<3) 22 | #define RITE_U ((UB)1<<4) 23 | #define MID_D ((UB)1<<5) 24 | #define MID_U ((UB)1<<6) 25 | #define ALLFLG (MOVED|LEFT_D|LEFT_U|RITE_D|RITE_U|MID_D|MID_U) 26 | static MOU_Event_t _mou_evt[MOU_EVT_MAX]; 27 | static long _mou_evt_i; 28 | static UB _mou_evt_enabled=1; 29 | 30 | #pragma off (check_stack) 31 | static void _loadds far __MOU_TheHandler(long max, long mcx, long mdx) 32 | { 33 | #pragma aux __MOU_TheHandler parm [EAX] [ECX] [EDX] 34 | 35 | if ( _mou_evt_i < MOU_EVT_MAX && _mou_evt_enabled ) 36 | { 37 | MOU_Event_t *e = &_mou_evt[ _mou_evt_i++ ]; 38 | 39 | e->b = max; 40 | e->x = mcx>>1; 41 | e->y = mdx; 42 | } 43 | } 44 | 45 | //============================== 46 | void MOU_EventsDisable(void){ _mou_evt_enabled = 0; } 47 | void MOU_EventsEnable(void){ _mou_evt_enabled = 1; } 48 | 49 | //============================== 50 | UL MOU_EventsListGet( MOU_Event_t *listP ) 51 | { 52 | UL n; 53 | 54 | MOU_EventsDisable(); 55 | memcpytiny( listP, _mou_evt, sizeof(MOU_Event_t)*_mou_evt_i ); 56 | n = _mou_evt_i; // occhio deve essere nel blocco disable-enable 57 | MOU_EventsEnable(); 58 | 59 | return n; 60 | } 61 | 62 | //============================== 63 | void MOU_EventsFlush(long n, const MOU_Event_t *evtsP) 64 | { 65 | MOU_Event_t e[MOU_EVT_MAX]; 66 | const MOU_Event_t *ep; 67 | 68 | if ( evtsP ) 69 | { 70 | _mou_evt_i = n; 71 | ep = evtsP; 72 | } 73 | else 74 | { 75 | MOU_EventsDisable(); 76 | n = _mou_evt_i; 77 | _mou_evt_i = 0; 78 | memcpy( e, _mou_evt, n*sizeof(MOU_Event_t) ); 79 | ep = e; 80 | MOU_EventsEnable(); 81 | } 82 | 83 | for(; n; --n, ++ep) 84 | { 85 | UB t; 86 | short x,y; 87 | 88 | t = ep->b; 89 | x = ep->x; 90 | y = ep->y; 91 | if ( _clickFuncP ) 92 | { 93 | if (t & LEFT_D) _clickFuncP( MOU_BUT_LFT, MOU_BUT_DOWN, x, y ); else 94 | if (t & LEFT_U) _clickFuncP( MOU_BUT_LFT, MOU_BUT_UP, x, y ); else 95 | if (t & RITE_D) _clickFuncP( MOU_BUT_RGT, MOU_BUT_DOWN, x, y ); else 96 | if (t & RITE_U) _clickFuncP( MOU_BUT_RGT, MOU_BUT_UP, x, y ); else 97 | if (t & MID_D) _clickFuncP( MOU_BUT_MID, MOU_BUT_DOWN, x, y ); else 98 | if (t & MID_U) _clickFuncP( MOU_BUT_MID, MOU_BUT_UP, x, y ); 99 | } 100 | if ( _moveFuncP ) 101 | if (t & MOVED) _moveFuncP( x, y ); 102 | } 103 | } 104 | 105 | //============================== 106 | void MOU_FuncSetClick( UB (*clickFuncP)(UB,UB,short,short) ){ _clickFuncP = clickFuncP; } 107 | void MOU_FuncSetMove( UB (*moveFuncP)(short,short) ){ _moveFuncP = moveFuncP; } 108 | 109 | //============================== 110 | static void mouDispose(void) 111 | { 112 | union REGS inregs, outregs; 113 | struct SREGS sregs; 114 | 115 | segread(&sregs); 116 | inregs.w.ax = 0xC; // install click watcher 117 | inregs.w.cx = 0; // no interrupts 118 | inregs.x.edx = FP_OFF( __MOU_TheHandler ); 119 | sregs.es = FP_SEG( __MOU_TheHandler ); 120 | int386x( 0x33, &inregs, &outregs, &sregs ); 121 | } 122 | //============================== 123 | short MOU_Init(void) 124 | { 125 | union REGS inregs, outregs; 126 | 127 | inregs.w.ax = 0; 128 | int386(0x33, &inregs, &outregs); 129 | 130 | if (outregs.w.ax == 0xffff) 131 | { 132 | struct SREGS sregs; 133 | segread(&sregs); 134 | 135 | inregs.w.ax = 0xC; // install click watcher 136 | inregs.w.cx = ALLFLG; 137 | inregs.x.edx = FP_OFF( __MOU_TheHandler ); 138 | sregs.es = FP_SEG( __MOU_TheHandler ); 139 | int386x( 0x33, &inregs, &outregs, &sregs ); 140 | atexit(mouDispose); 141 | _mou_evt_i = 0; 142 | return 0; 143 | } 144 | else 145 | return -1; 146 | } 147 | 148 | //------------------------------ 149 | void MOU_BoundsSet(short x1, short y1, short x2, short y2) 150 | { 151 | union REGS inregs, outregs; 152 | 153 | inregs.w.ax=7; 154 | inregs.w.cx=(x1+1)*2-1; 155 | inregs.w.dx=(x2+1)*2-1; 156 | int386(0x33, &inregs, &outregs); 157 | 158 | inregs.w.ax=8; 159 | inregs.w.cx=y1; 160 | inregs.w.dx=y2; 161 | int386(0x33, &inregs, &outregs); 162 | } 163 | 164 | //------------------------------ 165 | void MOU_PointerShow(void) 166 | { 167 | union REGS inregs, outregs; 168 | 169 | inregs.w.ax=1; 170 | int386(0x33, &inregs, &outregs); 171 | } 172 | //------------------------------ 173 | void MOU_PointerHide(void) 174 | { 175 | union REGS inregs, outregs; 176 | 177 | inregs.w.ax=2; 178 | int386(0x33, &inregs, &outregs); 179 | } 180 | 181 | //------------------------------ 182 | US MOU_Buttons(void) 183 | { 184 | union REGS inregs, outregs; 185 | 186 | inregs.w.ax=3; 187 | int386(0x33, &inregs, &outregs); 188 | 189 | return outregs.w.bx; 190 | } 191 | 192 | //------------------------------ 193 | short MOU_GetX(void) 194 | { 195 | union REGS inregs, outregs; 196 | 197 | inregs.w.ax=3; 198 | int386(0x33, &inregs, &outregs); 199 | 200 | return outregs.w.cx >> 1; 201 | } 202 | 203 | //------------------------------ 204 | short MOU_GetY(void) 205 | { 206 | union REGS inregs, outregs; 207 | 208 | inregs.w.ax=3; 209 | int386(0x33, &inregs, &outregs); 210 | 211 | return outregs.w.dx; 212 | } 213 | 214 | //------------------------------ 215 | void MOU_GetEvents(UB *bP, short *xP, short *yP) 216 | { 217 | union REGS inregs, outregs; 218 | 219 | inregs.w.ax=3; 220 | int386(0x33, &inregs, &outregs); 221 | *bP = outregs.w.bx; 222 | *xP = outregs.w.cx >> 1; 223 | *yP = outregs.w.dx; 224 | } 225 | 226 | -------------------------------------------------------------------------------- /SRC/RTMZ3D.MK1: -------------------------------------------------------------------------------- 1 | !define BLANK "" 2 | c:\prog\src\rtmz\rel30\src\bmp_poly.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\& 3 | bmp_poly.cpp .AUTODEPEND 4 | @c: 5 | cd c:\prog\src\rtmz\rel30\src 6 | *wpp386 rtmz3d\bmp_poly.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 & 7 | -zq -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 8 | 9 | c:\prog\src\rtmz\rel30\src\bmp_potx.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\& 10 | bmp_potx.cpp .AUTODEPEND 11 | @c: 12 | cd c:\prog\src\rtmz\rel30\src 13 | *wpp386 rtmz3d\bmp_potx.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 & 14 | -zq -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 15 | 16 | c:\prog\src\rtmz\rel30\src\clp.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\clp.c& 17 | pp .AUTODEPEND 18 | @c: 19 | cd c:\prog\src\rtmz\rel30\src 20 | *wpp386 rtmz3d\clp.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 -zq -& 21 | otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 22 | 23 | c:\prog\src\rtmz\rel30\src\colors.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\co& 24 | lors.cpp .AUTODEPEND 25 | @c: 26 | cd c:\prog\src\rtmz\rel30\src 27 | *wpp386 rtmz3d\colors.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 -z& 28 | q -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 29 | 30 | c:\prog\src\rtmz\rel30\src\frplasma.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\& 31 | frplasma.cpp .AUTODEPEND 32 | @c: 33 | cd c:\prog\src\rtmz\rel30\src 34 | *wpp386 rtmz3d\frplasma.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 & 35 | -zq -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 36 | 37 | c:\prog\src\rtmz\rel30\src\gl_matr.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\g& 38 | l_matr.cpp .AUTODEPEND 39 | @c: 40 | cd c:\prog\src\rtmz\rel30\src 41 | *wpp386 rtmz3d\gl_matr.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 -& 42 | zq -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 43 | 44 | c:\prog\src\rtmz\rel30\src\m44.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\m44.c& 45 | pp .AUTODEPEND 46 | @c: 47 | cd c:\prog\src\rtmz\rel30\src 48 | *wpp386 rtmz3d\m44.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 -zq -& 49 | otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 50 | 51 | c:\prog\src\rtmz\rel30\src\matelib.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\m& 52 | atelib.cpp .AUTODEPEND 53 | @c: 54 | cd c:\prog\src\rtmz\rel30\src 55 | *wpp386 rtmz3d\matelib.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 -& 56 | zq -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 57 | 58 | c:\prog\src\rtmz\rel30\src\o3dfile.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\o& 59 | 3dfile.cpp .AUTODEPEND 60 | @c: 61 | cd c:\prog\src\rtmz\rel30\src 62 | *wpp386 rtmz3d\o3dfile.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 -& 63 | zq -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 64 | 65 | c:\prog\src\rtmz\rel30\src\obj3d.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\obj& 66 | 3d.cpp .AUTODEPEND 67 | @c: 68 | cd c:\prog\src\rtmz\rel30\src 69 | *wpp386 rtmz3d\obj3d.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 -zq& 70 | -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 71 | 72 | c:\prog\src\rtmz\rel30\src\polyeng.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\p& 73 | olyeng.cpp .AUTODEPEND 74 | @c: 75 | cd c:\prog\src\rtmz\rel30\src 76 | *wpp386 rtmz3d\polyeng.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 -& 77 | zq -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 78 | 79 | c:\prog\src\rtmz\rel30\src\qua.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\qua.c& 80 | pp .AUTODEPEND 81 | @c: 82 | cd c:\prog\src\rtmz\rel30\src 83 | *wpp386 rtmz3d\qua.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 -zq -& 84 | otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 85 | 86 | c:\prog\src\rtmz\rel30\src\read3ds.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\r& 87 | ead3ds.cpp .AUTODEPEND 88 | @c: 89 | cd c:\prog\src\rtmz\rel30\src 90 | *wpp386 rtmz3d\read3ds.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 -& 91 | zq -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 92 | 93 | c:\prog\src\rtmz\rel30\src\tdst_hp.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\t& 94 | dst_hp.cpp .AUTODEPEND 95 | @c: 96 | cd c:\prog\src\rtmz\rel30\src 97 | *wpp386 rtmz3d\tdst_hp.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 -& 98 | zq -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 99 | 100 | c:\prog\src\rtmz\rel30\src\tdstuff.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\t& 101 | dstuff.cpp .AUTODEPEND 102 | @c: 103 | cd c:\prog\src\rtmz\rel30\src 104 | *wpp386 rtmz3d\tdstuff.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 -& 105 | zq -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 106 | 107 | c:\prog\src\rtmz\rel30\src\trig.obj : c:\prog\src\rtmz\rel30\src\rtmz3d\trig& 108 | .cpp .AUTODEPEND 109 | @c: 110 | cd c:\prog\src\rtmz\rel30\src 111 | *wpp386 rtmz3d\trig.cpp -i=C:\prog\WATCOM\h -i=rtmzos -w2 -e25 -s -zp4 -zq & 112 | -otexan -ol -om -oc -oi -oa -or -oe20 -fp5 -fpi87 -mf -5r -bt=dos 113 | 114 | c:\prog\src\rtmz\rel30\src\rtmz3d.lib : c:\prog\src\rtmz\rel30\src\bmp_poly.& 115 | obj c:\prog\src\rtmz\rel30\src\bmp_potx.obj c:\prog\src\rtmz\rel30\src\clp.o& 116 | bj c:\prog\src\rtmz\rel30\src\colors.obj c:\prog\src\rtmz\rel30\src\frplasma& 117 | .obj c:\prog\src\rtmz\rel30\src\gl_matr.obj c:\prog\src\rtmz\rel30\src\m44.o& 118 | bj c:\prog\src\rtmz\rel30\src\matelib.obj c:\prog\src\rtmz\rel30\src\o3dfile& 119 | .obj c:\prog\src\rtmz\rel30\src\obj3d.obj c:\prog\src\rtmz\rel30\src\polyeng& 120 | .obj c:\prog\src\rtmz\rel30\src\qua.obj c:\prog\src\rtmz\rel30\src\read3ds.o& 121 | bj c:\prog\src\rtmz\rel30\src\tdst_hp.obj c:\prog\src\rtmz\rel30\src\tdstuff& 122 | .obj c:\prog\src\rtmz\rel30\src\trig.obj .AUTODEPEND 123 | @c: 124 | cd c:\prog\src\rtmz\rel30\src 125 | %create rtmz3d.lb1 126 | !ifneq BLANK "bmp_poly.obj bmp_potx.obj clp.obj colors.obj frplasma.obj gl_m& 127 | atr.obj m44.obj matelib.obj o3dfile.obj obj3d.obj polyeng.obj qua.obj read3d& 128 | s.obj tdst_hp.obj tdstuff.obj trig.obj" 129 | @for %i in (bmp_poly.obj bmp_potx.obj clp.obj colors.obj frplasma.obj gl_ma& 130 | tr.obj m44.obj matelib.obj o3dfile.obj obj3d.obj polyeng.obj qua.obj read3ds& 131 | .obj tdst_hp.obj tdstuff.obj trig.obj) do @%append rtmz3d.lb1 +'%i' 132 | !endif 133 | !ifneq BLANK "" 134 | @for %i in () do @%append rtmz3d.lb1 +'%i' 135 | !endif 136 | *wlib -b -c -n -q -p=512 rtmz3d.lib @rtmz3d.lb1 137 | 138 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/CLP.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // CLP.CPP - clipping routines 3 | // Copyright (C) Davide Pasca 1995-97 4 | // 5 | // See "readme.txt" for other credits 6 | // 7 | // TABS=4 8 | //============================================== 9 | #include "EXTTYPES.HPP" 10 | #include "GL_MATR.HPP" 11 | #include "CLP.HPP" 12 | 13 | static UL _flags; 14 | 15 | //================================================= 16 | static void polyi2poly( const POE_PolyI_t *pi, POE_Poly_t *p ) 17 | { 18 | const POE_Vert_t *srcVertsP; 19 | const long *sidxP; 20 | const UB *srcColsP; 21 | const short *srcTxPosP; 22 | POE_Vert_t *dstVertP; 23 | long i; 24 | 25 | srcColsP = pi->c; 26 | srcTxPosP = (const short *)pi->txPos; 27 | sidxP = pi->vertIdx; 28 | srcVertsP = *pi->vertH; 29 | dstVertP = p->verts; 30 | 31 | p->userLong = pi->userLong; 32 | p->flags = pi->flags; 33 | p->clipCode = pi->clipCode; 34 | p->nVerts = pi->nVerts; 35 | 36 | if ( p->flags & POE_FLG_GSHADE ) 37 | { 38 | for(i=p->nVerts; i > 0; --i, ++dstVertP) 39 | { 40 | *dstVertP = srcVertsP[*sidxP++]; 41 | dstVertP->c = *srcColsP++; 42 | } 43 | } 44 | else 45 | if ( p->flags & POE_FLG_TEXTURE ) 46 | { 47 | for(i=p->nVerts; i > 0; --i, ++dstVertP, srcTxPosP += 2) 48 | { 49 | *dstVertP = srcVertsP[*sidxP++]; 50 | dstVertP->c = *srcColsP; 51 | dstVertP->u = srcTxPosP[0]; 52 | dstVertP->v = srcTxPosP[1]; 53 | } 54 | } 55 | else 56 | /*if ( p->flags & (POE_FLG_PSHADE | POE_FLG_TEXCHROME) ) 57 | { 58 | O3D_VertBase_t *bvertP = objP->baseVertsP; 59 | 60 | for(i=p->nVerts; i > 0; --i, ++dstVertP, ++sidxP) 61 | { 62 | *dstVertP = srcVertsP[*sidxP]; 63 | vec3_equ( dstVertP->nor, bvertP[*sidxP].nor ); 64 | dstVertP->c = *srcColsP; 65 | } 66 | } 67 | else*/ 68 | for(i=p->nVerts; i > 0; --i, ++dstVertP) 69 | { 70 | *dstVertP = srcVertsP[*sidxP++]; 71 | dstVertP->c = *srcColsP; 72 | } 73 | } 74 | 75 | //---------------------------------------------- 76 | static void poly2polyi( const POE_Poly_t *p, POE_PolyI_t *pi ) 77 | { 78 | POE_Vert_t *desVertsP, *tvp; 79 | long *didxP, i; 80 | const POE_Vert_t *srcVertP; 81 | UB *colP; 82 | 83 | pi->userLong = p->userLong; 84 | pi->flags = p->flags; 85 | pi->clipCode = p->clipCode; 86 | pi->nVerts = p->nVerts; 87 | 88 | didxP = pi->vertIdx; 89 | desVertsP = *pi->vertH; 90 | srcVertP = p->verts; 91 | colP = pi->c; 92 | 93 | if ( p->flags & POE_FLG_GSHADE ) 94 | { 95 | for(i=p->nVerts; i > 0; --i) 96 | { 97 | tvp = &desVertsP[*didxP++]; 98 | *tvp = *srcVertP++; 99 | *colP++ = tvp->c; 100 | } 101 | } 102 | else 103 | if ( p->flags & POE_FLG_TEXTURE ) 104 | { 105 | short *txP = (short *)pi->txPos; 106 | 107 | *colP = srcVertP->c; 108 | for(i=p->nVerts; i > 0; --i, txP += 2) 109 | { 110 | tvp = &desVertsP[*didxP++]; 111 | *tvp = *srcVertP++; 112 | txP[0] = tvp->u; 113 | txP[1] = tvp->v; 114 | } 115 | } 116 | /*else 117 | if ( p->flags & (POE_FLG_PSHADE | POE_FLG_TEXCHROME) ) 118 | { 119 | O3D_VertBase_t *bvertP = objP->baseVertsP; 120 | 121 | for(i=p->nVerts; i > 0; --i, ++dstVertP, ++sidxP) 122 | { 123 | tvp = &desVertsP[*didxP++]; 124 | *tvp = *srcVertP++; 125 | txP[0] = tvp->u; 126 | txP[1] = tvp->v; 127 | 128 | *dstVertP = srcVertsP[*sidxP]; 129 | vec3_equ( dstVertP->nor, bvertP[*sidxP].nor ); 130 | dstVertP->c = *srcColsP; 131 | } 132 | }*/ 133 | else 134 | { *colP = srcVertP->c; 135 | for(i=p->nVerts; i > 0; --i) 136 | desVertsP[*didxP++] = *srcVertP++; 137 | } 138 | } 139 | 140 | //============================================== 141 | #define CLERP(ELEM) (newP->ELEM = v1P->ELEM + coe * (v2P->ELEM - v1P->ELEM)) 142 | static void clipRecalcVert( POE_Vert_t *newP, POE_Vert_t *v1P, POE_Vert_t *v2P, float coe ) 143 | { 144 | CLERP( eye[0] ); 145 | CLERP( eye[1] ); 146 | CLERP( eye[2] ); 147 | CLERP( eye[3] ); 148 | 149 | //if ( _flags & POE_FLG_GSHADE ) 150 | CLERP( c ); 151 | 152 | if ( _flags & POE_FLG_TEXTURE ) 153 | { 154 | CLERP( u ); 155 | CLERP( v ); 156 | } 157 | 158 | if ( _flags & (POE_FLG_PSHADE | POE_FLG_TEXCHROME) ) 159 | { 160 | CLERP( nor[0] ); 161 | CLERP( nor[1] ); 162 | CLERP( nor[2] ); 163 | } 164 | } 165 | 166 | //---------------------------------------------- 167 | static void clipSide(POE_Poly_t *p, POE_Poly_t *q, long index, float sign) 168 | { 169 | float tu, tv; 170 | POE_Vert_t *v, *u; 171 | long i; 172 | UB cur_is_inside, old_is_inside; 173 | 174 | q->nVerts = 0; // start with u=vert[n-1], v=vert[0] 175 | u = &p->verts[ p->nVerts - 1 ]; 176 | 177 | tu = sign * u->eye[index] - u->eye[3]; 178 | old_is_inside = (tu<=0.); 179 | 180 | for (i=p->nVerts, v=p->verts; i > 0; --i, ++v) 181 | { 182 | tv = sign * v->eye[index] - v->eye[3]; 183 | cur_is_inside = (tv<=0.); 184 | 185 | if (old_is_inside ^ cur_is_inside) 186 | clipRecalcVert( &q->verts[q->nVerts++], u, v, tu / (tu - tv) ); 187 | 188 | if (cur_is_inside) 189 | q->verts[q->nVerts++] = *v; 190 | 191 | old_is_inside = cur_is_inside; 192 | tu = tv; 193 | u = v; 194 | } 195 | } 196 | //---------------------------------------------- 197 | #define CLIP_AND_SWAP(O,N,I,S) { clipSide(O,N,I,S); SWAP(O,N,t); } 198 | 199 | //============================================== 200 | static POE_Vert_t _clp_verts[POE_VERTBUFSIZ]; 201 | static POE_Vert_t *_clp_vertsP=_clp_verts; 202 | static POE_PolyI_t _clp_poly= 203 | { 204 | &_clp_vertsP, 205 | 0,1,2,3,4,5,6,7,8,9,10,11,12,POE_VERTBUFSIZ-1 206 | }; 207 | 208 | const POE_PolyI_t *CLP_PolyI4D( const POE_PolyI_t *srcpolyP ) 209 | { 210 | POE_Poly_t poly1, poly2; 211 | POE_Poly_t *o=&poly1, *n=&poly2, *t; 212 | UB code; 213 | 214 | if NOT( code = srcpolyP->clipCode ) 215 | return srcpolyP; 216 | 217 | polyi2poly( srcpolyP, o ); 218 | _flags = n->flags = o->flags; 219 | 220 | if (code & CLP_CODE_X1) CLIP_AND_SWAP( o, n, 0, -1. ); 221 | if (code & CLP_CODE_X2) CLIP_AND_SWAP( o, n, 0, 1. ); 222 | if (code & CLP_CODE_Y1) CLIP_AND_SWAP( o, n, 1, -1. ); 223 | if (code & CLP_CODE_Y2) CLIP_AND_SWAP( o, n, 1, 1. ); 224 | if (code & CLP_CODE_Z1) CLIP_AND_SWAP( o, n, 2, -1. ); 225 | 226 | _glPOEVertsToScreen( o->verts, o->nVerts ); 227 | 228 | poly2polyi( o, &_clp_poly ); 229 | _clp_poly.materialID = srcpolyP->materialID; 230 | 231 | return &_clp_poly; 232 | } 233 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/CVEC3.HPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // CVEC3.HPP - 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #ifndef __CVEC3_HPP__ 7 | #define __CVEC3_HPP__ 8 | 9 | #include 10 | 11 | //================================ 12 | #define VEC3_OPRVVV(A,B,OP,C) { (A)[0]=(B)[0] OP (C)[0];\ 13 | (A)[1]=(B)[1] OP (C)[1];\ 14 | (A)[2]=(B)[2] OP (C)[2]; } 15 | 16 | #define VEC3_OPRVVS(A,B,OP,C) { (A)[0]=(B)[0] OP (C);\ 17 | (A)[1]=(B)[1] OP (C);\ 18 | (A)[2]=(B)[2] OP (C); } 19 | 20 | //================================ 21 | inline void vec3_div( long *c, const long *b, long a ) 22 | { 23 | VEC3_OPRVVS(c,b,/,a); 24 | } 25 | //================================ 26 | inline void vec3_div( float *c, const float *b, float a ) 27 | { 28 | VEC3_OPRVVS(c,b,/,a); 29 | } 30 | 31 | //================================ 32 | inline void vec3_mul( float *c, const float *b, const float *a ){ VEC3_OPRVVV(c,b,*,a);} 33 | inline void vec3_mul( double *c, const double *b, const double *a ){ VEC3_OPRVVV(c,b,*,a);} 34 | inline void vec3_mul( long *c, const double *b, const double *a ){ VEC3_OPRVVV(c,b,*,a);} 35 | //================================ 36 | inline void vec3_mul( float *c, const float *b, float a ){ VEC3_OPRVVS(c,b,*,a); } 37 | inline void vec3_mul( double *c, const double *b, double a ){ VEC3_OPRVVS(c,b,*,a); } 38 | inline void vec3_mul( long *c, const double *b, double a ){ VEC3_OPRVVS(c,b,*,a); } 39 | 40 | //================================ 41 | inline void vec3_shl( short *c, const short *b, short a ){ VEC3_OPRVVS(c,b,<<,a); } 42 | inline void vec3_shl( long *c, const long *b, long a ){ VEC3_OPRVVS(c,b,<<,a); } 43 | inline void vec3_shr( short *c, const short *b, short a ){ VEC3_OPRVVS(c,b,>>,a); } 44 | inline void vec3_shr( long *c, const long *b, long a ){ VEC3_OPRVVS(c,b,>>,a); } 45 | 46 | //================================ 47 | inline void vec3_set( long *c, long x,long y,long z){ c[0] = x; c[1] = y; c[2] = z; } 48 | inline void vec3_set( float *c, float x,float y,float z){ c[0] = x; c[1] = y; c[2] = z; } 49 | inline void vec3_set( double *c, double x,double y,double z){ c[0] = x; c[1] = y; c[2] = z; } 50 | //================================ 51 | #define VEC3_EQU(D,S) {D[0]=S[0];D[1]=S[1];D[2]=S[2];} 52 | inline void vec3_equ( short *c, const short *a) VEC3_EQU(c,a) 53 | inline void vec3_equ( short *c, const long *a) VEC3_EQU(c,a) 54 | inline void vec3_equ( short *c, const float *a) VEC3_EQU(c,a) 55 | inline void vec3_equ( short *c, const double *a) VEC3_EQU(c,a) 56 | inline void vec3_equ( long *c, const long *a) VEC3_EQU(c,a) 57 | inline void vec3_equ( long *c, const float *a) VEC3_EQU(c,a) 58 | inline void vec3_equ( long *c, const double *a) VEC3_EQU(c,a) 59 | inline void vec3_equ( float *c, const short *a) VEC3_EQU(c,a) 60 | inline void vec3_equ( float *c, const long *a) VEC3_EQU(c,a) 61 | inline void vec3_equ( float *c, const float *a) VEC3_EQU(c,a) 62 | inline void vec3_equ( float *c, const double *a) VEC3_EQU(c,a) 63 | inline void vec3_equ( double *c, const float *a) VEC3_EQU(c,a) 64 | inline void vec3_equ( double *c, const double *a) VEC3_EQU(c,a) 65 | 66 | //================================ 67 | inline void vec3_add( short *c, const short *a, const short *b){ VEC3_OPRVVV(c,a,+,b);} 68 | inline void vec3_add( long *c, const long *a, const long *b){ VEC3_OPRVVV(c,a,+,b);} 69 | inline void vec3_add( float *c, const float *a, const float *b){ VEC3_OPRVVV(c,a,+,b);} 70 | 71 | //================================ 72 | inline void vec3_sub( long *c, const long *a, const long *b){ VEC3_OPRVVV(c,a,-,b); } 73 | inline void vec3_sub( float *c, const float *a, const float *b){ VEC3_OPRVVV(c,a,-,b); } 74 | inline void vec3_sub( double *c, const double *a, const double *b){ VEC3_OPRVVV(c,a,-,b); } 75 | 76 | //--------------------------------- 77 | #define VEC3_XPRD(D,A,B,T)\ 78 | T[0] = A[1] * B[2] - A[2] * B[1]; \ 79 | T[1] = A[2] * B[0] - A[0] * B[2]; \ 80 | T[2] = A[0] * B[1] - A[1] * B[0]; \ 81 | VEC3_EQU(D,T); 82 | 83 | inline void vec3_xprd( long *d, const long *a, const long *b ) 84 | { 85 | long t[3]; VEC3_XPRD(d,a,b,t); 86 | } 87 | //--------------------------------- 88 | inline void vec3_xprd( float *d, const float *a, const float *b ) 89 | { 90 | float t[3]; VEC3_XPRD(d,a,b,t); 91 | } 92 | //--------------------------------- 93 | inline void vec3_xprd( double *d, const double *a, const double *b ) 94 | { 95 | double t[3]; VEC3_XPRD(d,a,b,t); 96 | } 97 | //--------------------------------- 98 | inline void vec3_xprd( float *d, const short *a, const short *b ) 99 | { 100 | float t[3]; VEC3_XPRD(d,a,b,t); 101 | } 102 | //--------------------------------- 103 | inline void vec3_xprd( float *d, const long *a, const long *b ) 104 | { 105 | float t[3]; VEC3_XPRD(d,a,b,t); 106 | } 107 | 108 | //================================= 109 | inline float vec3_dot( const float *a, const float *b ){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2];} 110 | 111 | //================================= 112 | inline long vec3_mag( const long *a ){ return sqrt( (float)(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]) ); } 113 | inline float vec3_mag( const float *a ){ return sqrt( a[0]*a[0] + a[1]*a[1] + a[2]*a[2] ); } 114 | inline double vec3_mag( const double *a ){ return sqrt( a[0]*a[0] + a[1]*a[1] + a[2]*a[2] ); } 115 | 116 | //================================= 117 | inline void vec3_normalize( short *a ) 118 | { 119 | float b[3], mag; 120 | 121 | vec3_equ( b, a ); 122 | 123 | if ( (mag = vec3_mag( b )) == 0. ) 124 | mag = 1e+20; 125 | else 126 | mag = 1024. / mag; 127 | 128 | vec3_mul( b, b, mag ); 129 | vec3_equ( a, b ); 130 | } 131 | //--------------------------------- 132 | inline void vec3_normalize( long *a ) 133 | { 134 | float b[3], mag; 135 | 136 | vec3_equ( b, a ); 137 | 138 | if ( (mag = vec3_mag( b )) == 0. ) 139 | mag = 1e+20; 140 | else 141 | mag = 65536. / mag; 142 | 143 | vec3_mul( b, b, mag ); 144 | vec3_equ( a, b ); 145 | } 146 | //--------------------------------- 147 | #include 148 | #include 149 | inline void vec3_normalize( float *a ) 150 | { 151 | float mag = vec3_mag( a ); 152 | 153 | if ( mag == 0. ) 154 | mag = 1e+10; 155 | else 156 | mag = 1. / mag; 157 | 158 | vec3_mul( a, a, mag ); 159 | } 160 | //--------------------------------- 161 | inline void vec3_normalize( double *a ) 162 | { 163 | double mag = vec3_mag( a ); 164 | 165 | if ( mag == 0. ) 166 | mag = 1e+20; 167 | else 168 | mag = 1. / mag; 169 | 170 | vec3_mul( a, a, mag ); 171 | } 172 | #endif 173 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/TDST_HP.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // TDST_HP.CPP - 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #include "EXTTYPES.HPP" 7 | #include "POLYENG.HPP" 8 | #include "TDSTUFF.HPP" 9 | #include "CLP.HPP" 10 | #include "TDST_HP.HPP" 11 | #include "COLORS.HPP" 12 | #include "MATELIB.HPP" 13 | #include "CVEC3.HPP" 14 | #include "BMP.HPP" 15 | #include "BMP_POLY.HPP" 16 | 17 | #define ACT _W3D_actWorldP 18 | static UB _zBufOn; 19 | 20 | //================================== 21 | /*extern void memcpy4(void *dP, const void *sP, long size ); 22 | #pragma aux memcpy4 = \ 23 | " shr ecx,2"\ 24 | " rep movsd"\ 25 | parm caller [edi][esi][ecx]\ 26 | modify [edi esi ecx]; 27 | */ 28 | 29 | /* extern "C" { 30 | extern int *asm_PolyStart,*asm_PolyEnd; 31 | extern unsigned char *asm_Texture,*asm_Video; 32 | extern int asm_MAXX,asm_MAXY,asm_ROWSZ; 33 | void asm_LinTexturedPoly(void); 34 | }; 35 | */ 36 | 37 | //================================================= 38 | void W3D_HandlePoly( const POE_PolyI_t *polyIP ) 39 | { 40 | if ( polyIP->nVerts < 3 ) 41 | return; 42 | 43 | if ( _zBufOn = ACT->zBufferFlg ) 44 | BMP_ZBufferSet( (UL *)ACT->zBufferP ); 45 | 46 | if ( polyIP->clipCode ) 47 | polyIP = CLP_PolyI4D( polyIP ); 48 | 49 | /* if ( polyIP->nVerts < 3 ) 50 | { 51 | //Cnk_LinePoly16( &ACT->bitMap ); 52 | } 53 | else*/ 54 | { 55 | long pflags = polyIP->flags; 56 | 57 | if ( pflags & POE_FLG_GSHADE ) 58 | { 59 | if ( _zBufOn ) BMP_PolyGouraudZ16( polyIP ); 60 | else BMP_PolyGouraud16( polyIP ); 61 | } 62 | else 63 | if ( pflags & POE_FLG_PSHADE ) 64 | { 65 | //Cnk_polyIPhongSetData( ACT->ActSPaletteP->nShades, ((Obj3D *)polyIP->userLong)->traLight ); 66 | BMP_PolyPhong16( polyIP, 67 | ((O3D_Object_t *)polyIP->userLong)->traLight, 68 | ACT->ActSPaletteP->nShades, 69 | ACT->ActSPaletteP->userColors ); 70 | } 71 | else 72 | if ( pflags & POE_FLG_TEXIS3D ) 73 | { 74 | MLB_Material_t *matP; 75 | 76 | matP = MLB_MaterialGetPtr( polyIP->materialID ); 77 | BMP_PolyTextureLUT3D16( polyIP, 78 | &matP->textureP->origMap, 79 | &MLB_LibraryGetPtr()->levPalP->index[ 256*(31-polyIP->c[0]) ] ); 80 | } 81 | else 82 | if ( pflags & POE_FLG_TEXCHROME ) 83 | { 84 | MLB_Material_t *matP; 85 | 86 | matP = MLB_MaterialGetPtr( polyIP->materialID ); 87 | BMP_PolyTextureChrome16( polyIP, &matP->textureP->origMap ); 88 | } 89 | else 90 | if ( pflags & POE_FLG_TEXTURE ) 91 | { 92 | MLB_Material_t *matP; 93 | 94 | matP = MLB_MaterialGetPtr( polyIP->materialID ); 95 | //BMP_PolyTexture2D16( polyIP, &matP->textureP->origMap ); 96 | BMP_PolyTextureLUT2D16( polyIP, 97 | &matP->textureP->origMap, 98 | &MLB_LibraryGetPtr()->levPalP->index[ 256*(31-polyIP->c[0]) ] ); 99 | /*extern BO _cazzo; 100 | 101 | if ( _cazzo ) 102 | { 103 | BMP_PolyTexture2D16( polyIP, &matP->textureP->origMap ); 104 | } 105 | else 106 | { 107 | long poly[4*16], *polyp, nVerts; 108 | const short *txposp; 109 | const long *vertIdxP; 110 | POE_Vert_t *poep, *vertsP; 111 | 112 | if ( (nVerts=polyIP->nVerts) < 3 ) return; 113 | 114 | vertsP = *polyIP->vertH; 115 | vertIdxP = polyIP->vertIdx; 116 | txposp = (const short *)polyIP->txPos + nVerts * 2; 117 | 118 | polyp = poly; 119 | for (--nVerts; nVerts >= 0; --nVerts, polyp += 4) 120 | { 121 | poep = &vertsP[ vertIdxP[nVerts] ]; 122 | polyp[0] = poep->screen[0] << 12; 123 | polyp[1] = poep->screen[1] << 12; 124 | 125 | txposp -= 2, 126 | polyp[2] = txposp[0] << 12; 127 | polyp[3] = txposp[1] << 12; 128 | } 129 | asm_PolyStart=(int *)poly; asm_PolyEnd=(int *)polyp; 130 | asm_Texture = matP->textureP->origMap.memP; 131 | { 132 | BitMap *bmp = BMP_Get(); 133 | 134 | asm_Video = bmp->memP; 135 | asm_MAXX=bmp->wd; asm_MAXY=bmp->he; asm_ROWSZ=bmp->wd; 136 | //asm_MAXX=320; asm_MAXY=200; asm_ROWSZ=320; 137 | asm_LinTexturedPoly(); 138 | } 139 | }*/ 140 | 141 | } 142 | else 143 | { 144 | if ( _zBufOn ) BMP_PolyFlatZ16( polyIP ); 145 | else BMP_PolyFlat16( polyIP ); 146 | } 147 | } 148 | } 149 | /* else 150 | if ( flags & PD_FLG_WIRE ) 151 | { 152 | if NOT( flags & PD_FLG_WIREFILL ) 153 | { 154 | if ( flags & PD_FLG_PSHADE ){ __POE_standardPoly.verts[1].c = __MLB_actLibP->shadePal.userColors; 155 | Cnk_DrawpolyIPhong16( &ACT->bitMap ); } else 156 | if ( flags & PD_FLG_GSHADE ) Cnk_DrawPolyShaded16( &ACT->bitMap ); else 157 | /* 158 | MLB_LibraryGetMaterial 159 | if ( flags & PD_FLG_TEXTURE ) 160 | { 161 | COL_LevelPalette_t *lp=polyIP->matP->levPalP; 162 | Cnk_DrawPolyTexturedLUT2D16( &ACT->bitMap, &polyIP->matP->texMap, &lp->index[(lp->nLevels-1-polyIP->traColor[0]) * 256] ); 163 | } 164 | else* / 165 | Cnk_DrawPoly16( &ACT->bitMap ); 166 | } 167 | __POE_standardPoly.verts[0].c = 0; 168 | Cnk_LinePoly16( &ACT->bitMap ); 169 | } 170 | */ 171 | /*if ( flags & PD_FLG_TEXTURE ) 172 | { 173 | COL_LevelPalette_t *lp=polyIP->matP->levPalP; 174 | Cnk_DrawPolyTexturedLUT2D16( &ACT->bitMap, &polyIP->matP->texMap, &lp->index[(lp->nLevels-1-polyIP->traColor[0]) * 256] ); 175 | //Cnk_DrawPolyTextured2D16( &ACT->bitMap, &polyIP->matP->texMap ); 176 | } 177 | else*/ 178 | 179 | /* 180 | //================================================= 181 | static inline pi2p_copyvert( POE_Vert_t *d, const POE_Vert_t *s, long col ) 182 | { 183 | vec3_equ( d->scrvert, s->scrvert ); 184 | d->c = col; 185 | } 186 | //------------------------------------------------- 187 | static inline void polyi2poly( const POE_PolyI_t *pi, POE_Poly_t *p ) 188 | { 189 | short i; 190 | const POE_Vert_t *srcVertsP; 191 | const long *srcVertIdxP, *srcColsP; 192 | POE_Vert_t *dstVertP; 193 | 194 | srcColsP = pi->c; 195 | srcVertIdxP = pi->vertIdx; 196 | srcVertsP = *pi->vertH; 197 | dstVertP = p->verts; 198 | 199 | p->userLong = pi->userLong; 200 | p->flags = pi->flags; 201 | p->clipCode = pi->clipCode; 202 | p->nVerts = pi->nVerts; 203 | 204 | switch( p->nVerts ) 205 | { 206 | case 8: copyvert( &dstVertP[7], &srcVertsP[srcVertIdxP[7]], srcColsP[7] ); 207 | case 7: copyvert( &dstVertP[6], &srcVertsP[srcVertIdxP[6]], srcColsP[6] ); 208 | case 6: copyvert( &dstVertP[5], &srcVertsP[srcVertIdxP[5]], srcColsP[5] ); 209 | case 5: copyvert( &dstVertP[4], &srcVertsP[srcVertIdxP[4]], srcColsP[4] ); 210 | case 4: copyvert( &dstVertP[3], &srcVertsP[srcVertIdxP[3]], srcColsP[3] ); 211 | case 3: copyvert( &dstVertP[2], &srcVertsP[srcVertIdxP[2]], srcColsP[2] ); 212 | case 2: copyvert( &dstVertP[1], &srcVertsP[srcVertIdxP[1]], srcColsP[1] ); 213 | case 1: copyvert( &dstVertP[0], &srcVertsP[srcVertIdxP[0]], srcColsP[0] ); 214 | break; 215 | } 216 | } 217 | */ 218 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/COLORS.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // Colors.cpp - color handling routines 3 | // Copyright (C) Davide Pasca 1994 4 | //============================================== 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "COLORS.HPP" 12 | 13 | #define MAKEBIG(x) (x = 1L << (sizeof(x)*8-2)) 14 | 15 | //==================================== 16 | void COL_LevelPalette( COL_LevelPalette_t *fogP ) 17 | { 18 | FREEIF( fogP ); 19 | } 20 | 21 | //==================================== 22 | #define MAX_LVLS 256 23 | 24 | COL_LevelPalette_t *COL_NewDark(const UB *palP, US nLevels, float coe, US nColors ) 25 | { 26 | COL_LevelPalette_t *fogP; 27 | //UB *hashp; 28 | 29 | if ( nLevels == 0 || nLevels > MAX_LVLS ) return 0; 30 | if NOT( fogP = (COL_LevelPalette_t *)malloc( sizeof(COL_LevelPalette_t)+nLevels*256L ) ) 31 | return 0; 32 | 33 | /* 34 | if NOT( NEW(hashp,32768) ) 35 | { 36 | free( fogP ); 37 | return 0; 38 | } 39 | memset( hashp, 0, 32768 ); 40 | */ 41 | 42 | fogP->nLevels = nLevels; 43 | 44 | if NOT( palP ) 45 | return 0; 46 | 47 | UB tmpPal[MAX_LVLS*3], *rTmpPalP; 48 | const UB *rPalP; 49 | UB *indexP; 50 | short i,j; 51 | 52 | rPalP = palP; 53 | for (i=0; i < nColors; ++i) 54 | { 55 | COL_CreateRangeRGB64( tmpPal, 0, nLevels, rPalP[0], rPalP[1], rPalP[2], rPalP[0]*coe, rPalP[1]*coe, rPalP[2]*coe ); 56 | indexP = fogP->index+i; 57 | rTmpPalP = tmpPal; 58 | for(j=nLevels; j; --j) 59 | { 60 | UB r,g,b; 61 | 62 | r = rTmpPalP[0]; 63 | g = rTmpPalP[1]; 64 | b = rTmpPalP[2]; 65 | *indexP = COL_FindBestRGBInPalette( r, g, b, palP, nColors ); 66 | //*indexP = COL_MatchColorHash15( hashp, r, g, b, palP, nColors ); 67 | //hash table = poor resolution + giving me trouble mapping unused colors = 68 | //= fuck it 69 | 70 | indexP += 256; 71 | 72 | rTmpPalP += 3; 73 | } 74 | rPalP += 3; 75 | } 76 | 77 | //free( hashp ); 78 | 79 | return fogP; 80 | } 81 | 82 | //==================================== 83 | COL_LevelPalette_t *COL_NewFog(const UB *palP, US nLevels, UB fr, UB fg, UB fb ) 84 | { 85 | COL_LevelPalette_t *fogP; 86 | 87 | if ( nLevels == 0 || nLevels > MAX_LVLS ) return 0; 88 | if NOT( fogP = (COL_LevelPalette_t *)malloc( sizeof(COL_LevelPalette_t)+nLevels*256L ) ) 89 | return 0; 90 | 91 | fogP->nLevels = nLevels; 92 | 93 | if NOT( palP ) 94 | return 0; 95 | 96 | UB tmpPal[MAX_LVLS*3], *rTmpPalP; 97 | const UB *rPalP; 98 | UB *indexP; 99 | short i,j; 100 | 101 | rPalP = palP; 102 | for (i=0; i < 256; ++i) 103 | { 104 | COL_CreateRangeRGB64( tmpPal, 0, nLevels, rPalP[0], rPalP[1], rPalP[2], fr, fg, fb ); 105 | indexP = fogP->index+i; 106 | rTmpPalP = tmpPal; 107 | for(j=nLevels; j; --j) 108 | { 109 | UB r,g,b; 110 | 111 | r = rTmpPalP[0]; 112 | g = rTmpPalP[1]; 113 | b = rTmpPalP[2]; 114 | *indexP = COL_FindBestRGBInPalette( r, g, b, palP, 256 ); 115 | indexP += 256; 116 | 117 | rTmpPalP += 3; 118 | } 119 | rPalP += 3; 120 | } 121 | 122 | return fogP; 123 | } 124 | 125 | //==================================== 126 | short COL_FindExactRGB( UB r, UB g, UB b, const UB *palP, US palWd ) 127 | { 128 | US i; 129 | 130 | for (i = 0; i < palWd; ++i, palP += 3) 131 | if ( palP[0] == r && palP[1] == g && palP[2] == b ) 132 | return i; 133 | 134 | return -1; 135 | } 136 | 137 | //==================================== 138 | short COL_FindBestRGBInPalette( UB r, UB g, UB b, const UB *palP, US palWd ) 139 | { 140 | US i; 141 | long dr,dg,db; 142 | long rl,gl,bl; 143 | long diff, minDiff, bestI=0; 144 | 145 | rl = r; 146 | gl = g; 147 | bl = b; 148 | MAKEBIG( minDiff ); 149 | for (i = 0; i < palWd && minDiff; ++i, palP += 3) 150 | { 151 | dr = (long)palP[0] - rl; 152 | dg = (long)palP[1] - gl; 153 | db = (long)palP[2] - bl; 154 | 155 | diff = dr * dr + dg * dg + db * db; 156 | //diff = (dr << 16) + (dg << 8) + db; 157 | if (diff < minDiff) 158 | { 159 | minDiff = diff; 160 | bestI = i; 161 | } 162 | } 163 | 164 | return bestI; 165 | } 166 | 167 | //============================================================== 168 | UB COL_MatchColorHash15( UB *hashp, UB r, UB g, UB b, const UB *palP, US palWd ) 169 | { 170 | UL idx; 171 | 172 | idx = ((UL)r << 7) + ((UL)g << 2) + ((UL)b >> 3); 173 | 174 | if ( idx == 0 ) 175 | return 0; 176 | 177 | if ( hashp[idx] == 0 ) 178 | hashp[idx] = COL_FindBestRGBInPalette( r, g, b, palP, palWd ); 179 | 180 | return hashp[idx]; 181 | } 182 | 183 | //============================================ 184 | void COL_CreateShadePalette( COL_ShadePalette_t *spalP, UB *srcPalP, US nColors, US userColors, float minLight, float maxLight) 185 | { 186 | float shadeVal, shadeStep; 187 | US nShades; 188 | US i,j; 189 | 190 | if NOT( nColors ) return; 191 | 192 | spalP->userColors = userColors; 193 | if ( nColors ) nShades = (256-userColors) / nColors; 194 | if ( nShades ) shadeStep = (maxLight-minLight) / nShades; 195 | 196 | UB *desPalP = (UB *)spalP->palette + userColors*3; 197 | for(i=nColors; i; --i) 198 | { 199 | float r,g,b; 200 | 201 | r = srcPalP[0]; g = srcPalP[1]; b = srcPalP[2]; srcPalP += 3; 202 | shadeVal = minLight; 203 | for(j=nShades; j; --j) 204 | { 205 | float t; 206 | t = r * shadeVal; desPalP[0] = MIN(t,63.); 207 | t = g * shadeVal; desPalP[1] = MIN(t,63.); 208 | t = b * shadeVal; desPalP[2] = MIN(t,63.); 209 | desPalP += 3; 210 | shadeVal += shadeStep; 211 | } 212 | } 213 | spalP->nShades = nShades; 214 | spalP->nColors = nColors; 215 | } 216 | 217 | //==================================== 218 | void COL_256to64( UB *p, US cnt ) 219 | { 220 | while( cnt-- ) 221 | *p++ >>= 2; 222 | } 223 | 224 | //==================================== 225 | void COL_CreateRangeRGB64( UB *palP, US i, US n, UB r1, UB g1, UB b1, UB r2, UB g2, UB b2 ) 226 | { 227 | long stp_r, stp_g, stp_b; 228 | long r,g,b; 229 | 230 | if NOT(n) 231 | return; 232 | 233 | stp_r = ((long)r2-r1 << 16) / (long)n; 234 | stp_g = ((long)g2-g1 << 16) / (long)n; 235 | stp_b = ((long)b2-b1 << 16) / (long)n; 236 | 237 | r = (long)r1 << 16; 238 | g = (long)g1 << 16; 239 | b = (long)b1 << 16; 240 | palP += i*3; 241 | do{ 242 | palP[0] = r>>16; 243 | palP[1] = g>>16; 244 | palP[2] = b>>16; 245 | palP += 3; 246 | 247 | r += stp_r; 248 | g += stp_g; 249 | b += stp_b; 250 | }while( --n ); 251 | } 252 | 253 | //============================================ 254 | void COL_CreateTransparencyLUT( long rl, long gl, long bl, const UB *palp, UB *lutp, US nColors ) 255 | { 256 | long i, tr, tg, tb; 257 | const UB *runpalp; 258 | 259 | runpalp = palp; 260 | for(i=nColors; i>0; --i, runpalp += 3) 261 | { 262 | tr = (long)((UL)runpalp[0]) + rl >> 1; 263 | tg = (long)((UL)runpalp[1]) + gl >> 1; 264 | tb = (long)((UL)runpalp[2]) + bl >> 1; 265 | *lutp++ = COL_FindBestRGBInPalette( tr, tg, tb, palp, nColors ); 266 | } 267 | } 268 | 269 | //======================================= 270 | void COL_CreateRemapLUT( UB *lut, const UB *origpal, const UB *newpal) 271 | { 272 | long i; 273 | 274 | for(i=256; i; --i, origpal += 3) 275 | *lut++ = (UB)COL_FindBestRGBInPalette( origpal[0], origpal[1], origpal[2], newpal, 256 ); 276 | } 277 | 278 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/O3DFILE.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // O3DFILE.CPP - 3D file objects 3 | // Copyright (C) Davide Pasca 1994-1995 4 | //============================================== 5 | 6 | #include 7 | #include "O3DFILE.HPP" 8 | #include "MATELIB.HPP" 9 | 10 | #define ACT __O3D_actObjP 11 | extern O3D_Object_t *__O3D_actObjP; 12 | 13 | extern void vec3_normal( float *nor, const float *p0, const float *p1, const float *p2 ); 14 | 15 | //============================================== 16 | static long O3D_ValidatePolys( UB orderPolys ) 17 | { 18 | O3D_VertBase_t *bvertsP; 19 | long *vn; 20 | POE_PolyI_t *polyP; 21 | long badPolys=0; 22 | 23 | polyP = ACT->PolysP; 24 | bvertsP = ACT->baseVertsP; 25 | for(long npol = 0; npol < ACT->curPolyNum; ++npol, ++polyP) 26 | { 27 | long nPVerts = polyP->nVerts; 28 | 29 | if ( nPVerts > 3 ) 30 | { 31 | float nor1[3], nor2[3]; 32 | long j,j1,j2; 33 | 34 | vn = polyP->vertIdx; 35 | vec3_normal( nor1, bvertsP[vn[0]].vert, 36 | bvertsP[vn[1]].vert, 37 | bvertsP[vn[2]].vert ); 38 | for(j=1; j < nPVerts; ++j) 39 | { 40 | long v0,v1,v2; 41 | 42 | if ( (j1 = j+1) >= nPVerts ) j1 -= nPVerts; 43 | if ( (j2 = j+2) >= nPVerts ) j2 -= nPVerts; 44 | v0 = vn[j]; 45 | v1 = vn[j1]; 46 | v2 = vn[j2]; 47 | vec3_normal( nor2, bvertsP[v0].vert, 48 | bvertsP[v1].vert, 49 | bvertsP[v2].vert ); 50 | vec3_sub( nor2, nor2, nor1 ); 51 | if ( ABS(nor2[0]) > .05 || ABS(nor2[1]) > .05 || ABS(nor2[2]) > .05 ) 52 | { 53 | long otherPts; 54 | POE_PolyI_t savePoly = *polyP; 55 | 56 | vec3_set ( vn, v0, v1, v2 ); 57 | polyP->nVerts = 3; 58 | 59 | otherPts = savePoly.nVerts - 3; 60 | if NOT( O3D_PolyBegin( savePoly.materialID, savePoly.flags ) ) 61 | { 62 | while (j2 != j) 63 | { 64 | O3D_PolyVertNew( savePoly.vertIdx[j2] ); 65 | if ( ++j2 >= savePoly.nVerts ) j2 -= savePoly.nVerts; 66 | } 67 | O3D_PolyVertNew( savePoly.vertIdx[j2] ); 68 | O3D_PolyEnd(); 69 | } 70 | ++badPolys; 71 | 72 | if ( orderPolys ) 73 | { 74 | savePoly = ACT->PolysP[ ACT->curPolyNum-1 ]; // salva l'ultimo 75 | memmove( ACT->PolysP + npol+2, ACT->PolysP + npol+1, 76 | (ACT->curPolyNum-npol-2) * sizeof(*ACT->PolysP) ); 77 | ACT->PolysP[ npol+1 ] = savePoly; 78 | } 79 | 80 | polyP = &ACT->PolysP[ npol ]; 81 | break; 82 | } 83 | } 84 | } 85 | } 86 | 87 | return badPolys; 88 | } 89 | 90 | //======================================= 91 | static long createGEOMat( short col ) 92 | { 93 | static UB gpal[16][3]= 94 | { 95 | 0x2f,0x2f,0x2f, 0x00,0x6f,0x9f, 0x00,0x8f,0x00, 0x00,0x7f,0x4f, 96 | 0x9f,0x00,0x00, 0x4f,0x3f,0x4f, 0x9f,0x7f,0x00, 0x7f,0x7f,0x7f, 97 | 0xFf,0xFf,0xFf, 0x1f,0xAf,0xDf, 0x1f,0xCf,0x10, 0x1f,0xBf,0x7f, 98 | 0xDf,0x2f,0x2f, 0x7f,0x6f,0x7f, 0xDf,0xCf,0x1f, 0xCf,0xCf,0xCf 99 | }; 100 | char buf[32]; 101 | long matID; 102 | static float ambient[4]={.2,.2,.25,.05}, diffuse[4]={.1,.1,.1,.95}, specular[]={.4,.4,.4,.5}, shininess=20.; 103 | 104 | sprintf( buf, "GEO%ld", (long)col ); 105 | vec3_set( diffuse, gpal[col][0]/255., gpal[col][1]/255., gpal[col][2]/255. ); 106 | MLB_MaterialSetDefault( MLB_SHININESS_PTR, &shininess, TAG_END ); 107 | if ( (matID = MLB_MaterialAdd( MLB_NAME_PTR, buf, MLB_AMBIENT_PTR, ambient, 108 | MLB_DIFFUSE_PTR, diffuse, MLB_SPECULAR_PTR, specular, 109 | MLB_SHININESS_PTR, &shininess, TAG_END )) < 0 ) 110 | return 0; 111 | 112 | return matID; 113 | } 114 | 115 | //======================================= 116 | #define DFL 16 117 | static long lgeo_loadNextPoly( FILE *fh, UL flags ) 118 | { 119 | long i, cnt, tmpL; 120 | long vertIdx[64]; 121 | UL col; 122 | long havechild; 123 | 124 | if ( fscanf( fh, "%ld", &cnt ) == EOF ) 125 | return 0; 126 | if ( cnt <= 0 ) return -1; 127 | 128 | if ( cnt > 64 ) return 0; 129 | for (i=0; i < cnt; ++i) 130 | if ( fscanf( fh, "%ld", &vertIdx[i] ) == EOF ) 131 | return 0; 132 | 133 | if ( fscanf( fh, "%ld", &tmpL ) == EOF ) 134 | return 0; 135 | 136 | if ( tmpL < 0 ) 137 | { 138 | col = -tmpL; 139 | havechild = 1; 140 | } 141 | else 142 | { 143 | col = tmpL; 144 | havechild = 0; 145 | } 146 | 147 | if ( col & 32 ) flags |= POE_FLG_MAXLITE | POE_FLG_WIRE; 148 | if ( col & DFL ) flags |= POE_FLG_WIREFILL; 149 | O3D_PolyBegin( createGEOMat(col&15), flags ); 150 | for (i=0; i < cnt; ++i) 151 | O3D_PolyVertNew( vertIdx[i] ); 152 | O3D_PolyEnd(); 153 | 154 | return havechild; 155 | } 156 | 157 | //--------------------------------- 158 | long O3D_LoadGEO( const char *fileName, long *badPolysP ) 159 | { 160 | char myStr[10]; 161 | long i, err=0; 162 | FILE *fh; 163 | 164 | if NOT( fh = fopen(fileName, "r") ) 165 | return LGO3D_CANNOTOPENFILE; 166 | 167 | O3D_Init(); 168 | 169 | fscanf( fh, "%5s", myStr ); 170 | if ( strcmp( myStr, "3DG1" ) ) 171 | { 172 | err = LGO3D_UNKNOWFILE; 173 | goto exUnkFile; 174 | } 175 | 176 | fscanf( fh, "%ld", &i ); 177 | if ( O3D_AllocVerts(i) ) 178 | { 179 | err=LGO3D_NOMEM; 180 | goto exNoMem; 181 | } 182 | 183 | for (i=ACT->NVerts; i; --i) 184 | { 185 | float x, y, z; 186 | 187 | fscanf( fh, "%f %f %f", &x, &y, &z); 188 | O3D_VertNew( x, y, -z ); 189 | } 190 | 191 | while NOT( feof(fh) ) 192 | { 193 | long havechild; 194 | 195 | if ( (havechild = lgeo_loadNextPoly(fh,0)) < 0 ) 196 | goto exNoVerts; 197 | 198 | if ( havechild ) 199 | { 200 | long nSub; 201 | 202 | fscanf( fh, "%ld", &nSub ); 203 | for (; nSub; --nSub) 204 | if ( (havechild = lgeo_loadNextPoly(fh,POE_FLG_ISCHILD)) < 0 ) // no more childs !!! 205 | goto exNoVerts; 206 | } 207 | } 208 | 209 | if (badPolysP) *badPolysP = O3D_ValidatePolys(1); 210 | else O3D_ValidatePolys(1); 211 | O3D_Update(); 212 | 213 | goodExit: 214 | fclose( fh ); 215 | return( err ); 216 | 217 | exNoVerts: 218 | exNoMem: 219 | O3D_Free( (long)ACT ); 220 | exUnkFile: 221 | goto goodExit; 222 | } 223 | 224 | //--------------------------------- 225 | long O3D_LoadGEOM( const char *fileName, long *badPolysP ) 226 | { 227 | long i, j, dummy, matID; 228 | long err=0; 229 | FILE *fh; 230 | 231 | if NOT( fh = fopen(fileName, "r") ) 232 | return( LGO3D_CANNOTOPENFILE ); 233 | 234 | O3D_Init(); 235 | matID = MLB_MaterialAdd( MLB_NAME_PTR, "GEOM_MATERIO", TAG_END ); 236 | 237 | fscanf( fh, "%ld %ld %ld", &i, &j, &dummy ); 238 | if ( O3D_AllocVerts(i) || O3D_AllocPolys(j) ) 239 | { 240 | err=LGO3D_NOMEM; 241 | goto exNoMem; 242 | } 243 | 244 | for (i=ACT->NVerts; i; --i) 245 | { 246 | float x, y, z; 247 | 248 | fscanf( fh, "%f %f %f", &x, &y, &z); 249 | O3D_VertNew( x, y, z ); 250 | } 251 | 252 | for (i=ACT->NPolys; i; --i) 253 | { 254 | if ( fscanf( fh, "%ld", &j ) == EOF ) 255 | break; 256 | /*if ( j > POE_MAXVERTS ) 257 | { 258 | err = LGO3D_TOOMUCHVERTS; 259 | goto exNoVerts; 260 | }*/ 261 | 262 | O3D_PolyBegin( matID, 0 ); 263 | for(; j > 0; --j) 264 | { 265 | long vn; 266 | 267 | fscanf( fh, "%ld", &vn ); 268 | O3D_PolyVertNew( vn-1 ); 269 | } 270 | O3D_PolyEnd(); 271 | } 272 | if (badPolysP) *badPolysP = O3D_ValidatePolys(0); 273 | else O3D_ValidatePolys(0); 274 | O3D_Update(); 275 | 276 | goodExit: 277 | fclose( fh ); 278 | return( err ); 279 | 280 | exNoVerts: 281 | exNoMem: 282 | O3D_Free( (long)ACT ); 283 | exUnkFile: 284 | goto goodExit; 285 | } 286 | 287 | -------------------------------------------------------------------------------- /SRC/RTMZMENU.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // RTMZMENU.CPP - menu stuff for rtmz 3 | // Copyright (C) by Davide Pasca 1995 4 | //============================================== 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "EXTTYPES.HPP" 11 | #include "PASCALIB.HPP" 12 | #include "DOSUTIL.HPP" 13 | #include "KBD.HPP" 14 | #include "MNU.HPP" 15 | 16 | extern void openObjMenu( const char *pathP, const char *fnameP ); 17 | extern void openTexMenu( const char *pathP, const char *fnameP ); 18 | 19 | extern void controlModeM(long,long); 20 | extern void renderingM(long,long); 21 | extern void textureM(long,long); 22 | extern void chResM(long,long); 23 | extern void lsrcM(long,long); 24 | extern void lambM(long,long); 25 | extern void mspecularM(long,long); 26 | extern void mshininessM(long,long); 27 | extern void quitProgramM(long,long); 28 | 29 | //============================================== 30 | typedef struct 31 | { 32 | char path[512]; 33 | char extList[16][5]; 34 | void (*userCallBack)(const char *,const char *); 35 | }MFR_Data_t; 36 | 37 | //=========================== 38 | static UB isVolumeName(const char *nameP) 39 | { 40 | long len=strlen(nameP); 41 | 42 | return len >= 2 && nameP[len-2] == ':' && nameP[len-1] == '\\'; 43 | } 44 | 45 | //============================================== 46 | static void substring( char *sub, const char *orig ) 47 | { 48 | long i,len; 49 | 50 | len = strlen( orig ); 51 | for(i=0; i < len; ++i, ++orig) 52 | if ( *orig != ' ' && *orig != '>' ) 53 | break; 54 | 55 | for(; i < len; ++i, ++orig) 56 | if ( *orig != ' ' && *orig != '>' ) 57 | *sub++ = *orig; 58 | else 59 | break; 60 | *sub++ = 0; 61 | } 62 | //---------------------------------------------- 63 | static void _MFR_RebuildMenu(long menuID); 64 | static void _MFR_MenuCallBack(long m, long i) 65 | { 66 | MFR_Data_t *dataP; 67 | char name[MNU_ITM_MAXLEN], filename[20]; 68 | long len; 69 | 70 | 71 | dataP = (MFR_Data_t *)MNU_UserLongGet( m ); 72 | MNU_ItemNameGet( m, i, name ); 73 | substring( filename, name ); 74 | 75 | len = strlen(name); 76 | if ( name[ len-1 ] == '>' ) 77 | { 78 | long objpathlen; 79 | 80 | objpathlen = strlen(dataP->path); 81 | if NOT( strcmp(filename,"..") ) 82 | { 83 | --objpathlen; 84 | while ( --objpathlen >= 0 ) 85 | if ( dataP->path[ objpathlen ] == '\\' ) 86 | { 87 | dataP->path[ objpathlen+1 ] = 0; 88 | goto switchdir; 89 | } 90 | return; 91 | } 92 | else 93 | { 94 | strcat( filename, "\\" ); 95 | if ( isVolumeName(filename) ) 96 | strcpy( dataP->path, filename ); 97 | else 98 | strcat( dataP->path, filename ); 99 | } 100 | switchdir: 101 | _MFR_RebuildMenu( m ); 102 | } 103 | else 104 | dataP->userCallBack( dataP->path, filename ); 105 | } 106 | 107 | //---------------------------------------------------- 108 | static void _MFR_RebuildMenu(long menuID) 109 | { 110 | MFR_Data_t *dataP; 111 | DirElem *deP, *rundeP; 112 | UL cnt; 113 | long i; 114 | char curVol; 115 | 116 | dataP = (MFR_Data_t *)MNU_UserLongGet( menuID ); 117 | 118 | deP = 0; cnt = 0; 119 | KBD_Close(); 120 | ScanDir( dataP->path, "*.*", &deP, &cnt ); 121 | KBD_Open(); 122 | 123 | SortDirElemsByName( deP, cnt ); 124 | 125 | MNU_ItemsReset( menuID ); 126 | 127 | i = strlen( dataP->path ); 128 | if ( dataP->path[i-2] == ':' && dataP->path[i-1] == '\\' ) 129 | { 130 | char drivelist[32], *dlP; 131 | short ndrives; 132 | 133 | curVol = dataP->path[0]; 134 | DOS_DrivesGetList( drivelist, &ndrives ); 135 | for(dlP = drivelist; ndrives > 0; --ndrives, ++dlP) 136 | { 137 | char buf[100]; 138 | 139 | if ( curVol == *dlP ) 140 | sprintf( buf, " >%c: ", *dlP ); 141 | else 142 | sprintf( buf, " %c: ", *dlP ); 143 | MNU_ItemAddCB( menuID, buf, _MFR_MenuCallBack ); 144 | } 145 | } 146 | else 147 | MNU_ItemAddCB( menuID, " .. ", _MFR_MenuCallBack ); 148 | 149 | rundeP = deP; 150 | for(i=cnt; i > 0; --i, ++rundeP) 151 | { 152 | if ( rundeP->size < 0 && strcmp(rundeP->name, ".") && strcmp(rundeP->name, "..") ) 153 | { 154 | char buf[128]; 155 | 156 | sprintf( buf, "%12s ", rundeP->name ); 157 | MNU_ItemAddCB( menuID, buf, _MFR_MenuCallBack ); 158 | } 159 | } 160 | 161 | rundeP = deP; 162 | for(i=cnt; i > 0; --i, ++rundeP) 163 | { 164 | if ( rundeP->size >= 0 && strcmp(rundeP->name, ".") && strcmp(rundeP->name, "..") ) 165 | { 166 | char buf[128], *extP; 167 | long len; 168 | 169 | len = strlen(rundeP->name); 170 | if ( len >= 5 ) 171 | { 172 | char (*extlistp)[5]; 173 | 174 | extP = rundeP->name + (len-4); 175 | extlistp = dataP->extList; 176 | while( **extlistp ) 177 | if NOT( strcmpi( extP, *extlistp++ ) ) 178 | { 179 | sprintf( buf, "%12s %4ldK", rundeP->name, rundeP->size+1023>>10 ); 180 | MNU_ItemAddCB( menuID, buf, _MFR_MenuCallBack ); 181 | } 182 | } 183 | } 184 | } 185 | 186 | if ( deP ) free( deP ); 187 | } 188 | 189 | //---------------------------------------------- 190 | long MFR_Create( long menuID, const char *pathP, 191 | void (*userCallBack)(const char *,const char *), ... ) 192 | { 193 | MFR_Data_t *dataP; 194 | 195 | if NOT( dataP = (MFR_Data_t *)malloc(sizeof(MFR_Data_t)) ) 196 | return -1; 197 | 198 | strcpymaxsize( dataP->path, pathP, sizeof(dataP->path) ); 199 | dataP->userCallBack = userCallBack; 200 | 201 | va_list arg; 202 | char *txtp, (*extlistp)[5]; 203 | 204 | va_start( arg, userCallBack ); 205 | txtp = va_arg( arg, char * ); 206 | extlistp = dataP->extList; 207 | while( *txtp ) 208 | { 209 | strcpy( *extlistp++, txtp ); 210 | txtp = va_arg( arg, char * ); 211 | } 212 | **extlistp = 0; 213 | va_end( arg ); 214 | 215 | MNU_UserLongSet( menuID, (long)dataP ); 216 | _MFR_RebuildMenu( menuID ); 217 | 218 | return 0; 219 | } 220 | //============================================== 221 | void MFR_Dispose( long menuID ) 222 | { 223 | long dataP; 224 | 225 | dataP = MNU_UserLongGet( menuID ); 226 | FREEIF( (void *)dataP ); 227 | } 228 | 229 | //============================================== 230 | static long _liteMID, _lsrcMID, _lambMID, _mateMID, _mspeMID, _mshiMID; 231 | static long _openTxMID; 232 | long _mainMID = 0, _rendMID=0, _textureMID=0, _openMID=0, _resoMID=0, _cmodeMID=0; 233 | 234 | void menuDispose(void) 235 | { 236 | MNU_Dispose( _mainMID, 1 ); 237 | } 238 | 239 | //============================================== 240 | long menuCreate(const char *curPathP) 241 | { 242 | long i; 243 | 244 | static char *valueNCol[]= 245 | { "Low", "Medium", "High", "-", 246 | "Red", "Green", "Blue", "Yellow", "White" }; 247 | 248 | #define TXC 7 249 | #define BKC 5 250 | #define LTC 4 251 | #define DKC 6 252 | 253 | _mainMID = MNU_New(0,TXC,BKC,LTC,DKC); 254 | _openMID = MNU_New(0,TXC,BKC,LTC,DKC); 255 | _cmodeMID = MNU_New(0,TXC,BKC,LTC,DKC); 256 | _resoMID = MNU_New(0,TXC,BKC,LTC,DKC); 257 | 258 | MNU_ItemAddID( _mainMID, "Open", _openMID ); 259 | MFR_Create( _openMID, curPathP, openObjMenu, 260 | ".GEO", ".GEM", ".3DS", "" ); 261 | MNU_ItemAddID( _mainMID, "Control Mode", _cmodeMID ); 262 | MNU_ItemAddCB( _cmodeMID, "Trackball ", controlModeM, MNU_FLG_ICHECKED ); 263 | //MNU_ItemAddCB( _cmodeMID, "Flying Skate", controlModeM ); 264 | MNU_ItemAddCB( _cmodeMID, "Move Light ", controlModeM ); 265 | 266 | MNU_ItemAddID( _mainMID, "Resolution", _resoMID ); 267 | MNU_ItemAddCB( _resoMID, "320 x 200 <1>", chResM, MNU_FLG_ICHECKED ); 268 | MNU_ItemAddCB( _resoMID, "640 x 480 <2>", chResM ); 269 | MNU_ItemAddCB( _resoMID, "800 x 600 <3>", chResM ); 270 | 271 | MNU_ItemAddID( _mainMID, "-", 0 ); 272 | 273 | _rendMID = MNU_New(0,TXC,BKC,LTC,DKC); 274 | MNU_ItemAddID( _mainMID, "Rendering", _rendMID ); 275 | MNU_ItemAddCB( _rendMID, "Flat Shading ", renderingM, MNU_FLG_ICHECKED ); 276 | MNU_ItemAddCB( _rendMID, "Gouraud Shading ", renderingM ); 277 | MNU_ItemAddCB( _rendMID, "Forgotten Shading

", renderingM ); 278 | MNU_ItemAddCB( _rendMID, "Texture-Mapping ", renderingM ); 279 | MNU_ItemAddCB( _rendMID, "Z-Buffer ", renderingM ); 280 | MNU_ItemAddCB( _rendMID, "-", renderingM ); 281 | MNU_ItemFlagsSet( _rendMID, 2, 0 ); 282 | 283 | _textureMID = MNU_New(0,TXC,BKC,LTC,DKC); 284 | MNU_ItemAddID( _rendMID, "Texture Specs", _textureMID ); 285 | _openTxMID = MNU_New(0,TXC,BKC,LTC,DKC); 286 | MNU_ItemAddID( _textureMID, "Open", _openTxMID ); 287 | MFR_Create( _openTxMID, curPathP, openTexMenu, ".PCX", "" ); 288 | MNU_ItemAddCB( _textureMID, "-", textureM ); 289 | MNU_ItemAddCB( _textureMID, "2D Mapping ", textureM, MNU_FLG_ICHECKED ); 290 | MNU_ItemAddCB( _textureMID, "3D Mapping ", textureM ); 291 | MNU_ItemAddCB( _textureMID, "Chrome Mapping ", textureM ); 292 | MNU_ItemAddCB( _textureMID, "-", textureM ); 293 | MNU_ItemAddCB( _textureMID, "Sphere Displacement ", textureM, MNU_FLG_ICHECKED ); 294 | MNU_ItemAddCB( _textureMID, "Cylinder Displacement ", textureM ); 295 | 296 | _liteMID = MNU_New(0,TXC,BKC,LTC,DKC); 297 | MNU_ItemAddID( _mainMID, "Lights", _liteMID ); 298 | 299 | _lsrcMID = MNU_New(0,TXC,BKC,LTC,DKC); 300 | MNU_ItemAddID( _liteMID, "Source", _lsrcMID ); 301 | for (i=0; i < 9; ++i) 302 | MNU_ItemAddCB( _lsrcMID, valueNCol[i], lsrcM ); 303 | 304 | _lambMID = MNU_New(0,TXC,BKC,LTC,DKC); 305 | MNU_ItemAddID( _liteMID, "Ambient", _lambMID ); 306 | for (i=0; i < 9; ++i) 307 | MNU_ItemAddCB( _lambMID, valueNCol[i], lambM ); 308 | 309 | 310 | _mateMID = MNU_New(0,TXC,BKC,LTC,DKC); 311 | MNU_ItemAddID( _mainMID, "Materials", _mateMID ); 312 | _mspeMID = MNU_New(0,TXC,BKC,LTC,DKC); 313 | MNU_ItemAddID( _mateMID, "Specular", _mspeMID ); 314 | for (i=0; i < 9; ++i) 315 | MNU_ItemAddCB( _mspeMID, valueNCol[i], mspecularM ); 316 | 317 | _mshiMID = MNU_New(0,TXC,BKC,LTC,DKC); 318 | MNU_ItemAddID( _mateMID, "Shininess", _mshiMID ); 319 | MNU_ItemAddCB( _mshiMID, "Low - paper", mshininessM ); 320 | MNU_ItemAddCB( _mshiMID, "Medium - plastic", mshininessM ); 321 | MNU_ItemAddCB( _mshiMID, "High - metal", mshininessM ); 322 | MNU_ItemAddCB( _mshiMID, "Super - enamel", mshininessM ); 323 | 324 | 325 | MNU_ItemAddID( _mainMID, "-", 0 ); 326 | MNU_ItemAddCB( _mainMID, "Quit", quitProgramM ); 327 | long aboutMID = MNU_New(0,TXC,BKC,LTC,DKC); 328 | MNU_ItemAddID( _mainMID, "About", aboutMID ); 329 | MNU_ItemAddCB( aboutMID, "RTMZ v3.0 ", 0 ); 330 | MNU_ItemAddCB( aboutMID, "by Davide Pasca ", 0 ); 331 | MNU_ItemAddCB( aboutMID, " dpasca@ix.netcom.com ", 0 ); 332 | MNU_ItemAddCB( aboutMID, " dpasca@val.net ", 0 ); 333 | MNU_ItemAddCB( aboutMID, " http://www.netcom.com/~dpasca", 0 ); 334 | MNU_ItemAddCB( aboutMID, " http://val.net/~dpasca ", 0 ); 335 | MNU_ItemAddCB( aboutMID, "", 0 ); 336 | MNU_ItemAddCB( aboutMID, "ciaox", 0 ); 337 | 338 | MNU_Set( _mainMID ); 339 | 340 | return 0; 341 | } 342 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/MATELIB.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // Matelib.cpp - 3 | // Copyright (C) Davide Pasca 1995 4 | //============================================== 5 | 6 | #include 7 | #include 8 | #include "MATELIB.HPP" 9 | #include "PASCALIB.HPP" 10 | #include "CVEC3.HPP" 11 | 12 | static MLB_Library_t _library; 13 | MLB_Library_t *__MLB_actLibP=&_library; 14 | 15 | #define ACT __MLB_actLibP 16 | 17 | static inline vec4_set(float *d, float x,float y,float z,float w){d[0]=x; d[1]=y; d[2]=z; d[3]=w;} 18 | static inline vec4_equ(float *d, float *s){d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; d[3] = s[3];} 19 | static inline vec4_equ_dck(float *d, float *s){if (d){ d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; d[3] = s[3]; }} 20 | static inline vec4_equ_sck(float *d, float *s){if (s){ d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; d[3] = s[3]; }} 21 | 22 | //============================================== 23 | UB *MLB_PaletteGet(long *stacolp, long *ncolsp) 24 | { 25 | if ( stacolp ) *stacolp = ACT->shadePal.userColors; 26 | if ( ncolsp ) *ncolsp = 256 - ACT->shadePal.userColors; 27 | 28 | return (UB *)ACT->shadePal.palette + ACT->shadePal.userColors * 3; 29 | } 30 | 31 | //============================================== 32 | void MLB_MaterialDisposeAll( void ) 33 | { 34 | US nMats; 35 | MLB_Material_t *matP; 36 | 37 | ACT->nTextures = 0; 38 | for( matP = ACT->materials, nMats = ACT->nMaterials; nMats; ++matP ) 39 | { 40 | if ( matP->active ) 41 | { 42 | SAFE_FREE( matP->textureP ); 43 | matP->active = 0; 44 | --nMats; 45 | } 46 | } 47 | } 48 | 49 | //============================================== 50 | void MLB_LibraryReset(void) 51 | { 52 | MLB_MaterialDisposeAll(); 53 | memset(ACT,0,sizeof(MLB_Library_t)); 54 | vec4_set( ACT->deflight, 1., 1., 1., 1. ); 55 | vec4_set( ACT->defambient, .8, .8, .8, .1 ); 56 | vec4_set( ACT->defdiffuse, .75, .75, .75, .9 ); 57 | vec4_set( ACT->defspecular, .5, .5, .5, .4 ); 58 | ACT->defshininess = 5.; 59 | } 60 | 61 | //============================================== 62 | long MLB_MaterialFind( const char *nameP ) 63 | { 64 | US nMats; 65 | MLB_Material_t *matP; 66 | 67 | for( matP = ACT->materials, nMats = ACT->nMaterials; nMats; ++matP ) 68 | { 69 | if ( matP->active ) 70 | { 71 | --nMats; 72 | if NOT( strncmp( matP->name, nameP, sizeof(matP->name) ) ) 73 | return matP - ACT->materials; 74 | } 75 | } 76 | 77 | return -1; 78 | } 79 | 80 | //============================================== 81 | static void parseMatInfo(va_list arg, long id, char **name, 82 | float **light, float **ambient, float **diffuse, float **specular, float **shininess, 83 | BitMap **txMapP, UB **palP ) 84 | { 85 | *light = *ambient = *diffuse = *specular = 0; 86 | *shininess = 0; 87 | *txMapP = 0; 88 | *palP = 0; 89 | *name = 0; 90 | while ( id != TAG_END ) 91 | { 92 | switch( id ) 93 | { 94 | case MLB_NAME_PTR: *name = va_arg( arg, char * ); break; 95 | case MLB_LIGHT_PTR: *light = va_arg( arg, float * ); break; 96 | case MLB_AMBIENT_PTR: *ambient = va_arg( arg, float * ); break; 97 | case MLB_DIFFUSE_PTR: *diffuse = va_arg( arg, float * ); break; 98 | case MLB_SPECULAR_PTR: *specular = va_arg( arg, float * ); break; 99 | case MLB_SHININESS_PTR: *shininess = va_arg( arg, float * ); break; 100 | case MLB_TXMAP_N_PALETTE_PTR: *txMapP = va_arg( arg, BitMap * ); 101 | *palP = va_arg( arg, UB * ); break; 102 | } 103 | id = va_arg( arg, long ); 104 | } 105 | } 106 | //============================================== 107 | static long checkAndCreateTexture( MLB_Texture_t **texturePP, BitMap *txMapP, UB *palP) 108 | { 109 | if ( txMapP || palP ) 110 | { 111 | MLB_Texture_t *tp; 112 | 113 | if ( *texturePP ) tp = *texturePP; 114 | else 115 | { 116 | if NOT( tp = (MLB_Texture_t *)malloc( sizeof(MLB_Texture_t) ) ) 117 | return -1; 118 | ACT->nTextures = 1; 119 | } 120 | 121 | *texturePP = tp; 122 | if ( txMapP ) tp->origMap = *txMapP; 123 | if ( palP ) memcpy( tp->origPal, palP, 768 ); 124 | } 125 | 126 | return 0; 127 | } 128 | 129 | //============================================== 130 | long MLB_MaterialSetAll( long tag, ... ) 131 | { 132 | char *name; 133 | float *light, *ambient, *diffuse, *specular, *shininess; 134 | BitMap *txMapP; 135 | UB *palP; 136 | MLB_Material_t *matP; 137 | long i, err; 138 | 139 | va_list arg; 140 | va_start( arg, tag ); 141 | parseMatInfo( arg, tag, &name, &light, &ambient, &diffuse, &specular, &shininess, &txMapP, &palP ); 142 | va_end( arg ); 143 | 144 | if ( txMapP ) 145 | ACT->nTextures = 1; 146 | else 147 | ACT->nTextures = 0; 148 | 149 | matP = ACT->materials; 150 | for(i=ACT->nMaterials; i > 0; ++matP) 151 | { 152 | if ( matP->active ) 153 | { 154 | if ( err = checkAndCreateTexture( &matP->textureP, txMapP, palP ) ) 155 | return err; 156 | vec4_equ_sck( matP->light, light ); 157 | vec4_equ_sck( matP->ambient, ambient ); 158 | vec4_equ_sck( matP->diffuse, diffuse ); 159 | vec4_equ_sck( matP->specular, specular ); 160 | if ( shininess ) matP->shininess = *shininess; 161 | --i; 162 | } 163 | } 164 | return 0; 165 | } 166 | //============================================== 167 | void MLB_MaterialGetDefault( long tag, ... ) 168 | { 169 | char *name; 170 | float *light, *ambient, *diffuse, *specular, *shininess; 171 | BitMap *txMapP; 172 | UB *palP; 173 | 174 | va_list arg; 175 | va_start( arg, tag ); 176 | parseMatInfo( arg, tag, &name, &light, &ambient, &diffuse, &specular, &shininess, &txMapP, &palP ); 177 | va_end( arg ); 178 | 179 | vec4_equ_dck( light, ACT->deflight ); 180 | vec4_equ_dck( ambient, ACT->defambient ); 181 | vec4_equ_dck( diffuse, ACT->defdiffuse ); 182 | vec4_equ_dck( specular, ACT->defspecular ); 183 | if ( shininess ) *shininess = ACT->defshininess; 184 | if ( txMapP ) *txMapP = ACT->deftexture.origMap; 185 | if ( palP ) memcpy( palP, ACT->deftexture.origPal, 768 ); 186 | } 187 | //============================================== 188 | void MLB_MaterialSetDefault( long tag, ... ) 189 | { 190 | char *name; 191 | float *light, *ambient, *diffuse, *specular, *shininess; 192 | BitMap *txMapP; 193 | UB *palP; 194 | 195 | va_list arg; 196 | va_start( arg, tag ); 197 | parseMatInfo( arg, tag, &name, &light, &ambient, &diffuse, &specular, &shininess, &txMapP, &palP ); 198 | va_end( arg ); 199 | 200 | vec4_equ_sck( ACT->deflight, light ); 201 | vec4_equ_sck( ACT->defambient, ambient ); 202 | vec4_equ_sck( ACT->defdiffuse, diffuse ); 203 | vec4_equ_sck( ACT->defspecular, specular ); 204 | if ( shininess ) ACT->defshininess = *shininess; 205 | if ( txMapP ) ACT->deftexture.origMap = *txMapP; 206 | if ( palP ) memcpy( ACT->deftexture.origPal, palP, 768 ); 207 | } 208 | 209 | //============================================== 210 | static long materialAddOverwrite( UB doOverWrite, long tag, va_list arg ) 211 | { 212 | char *name; 213 | float *light, *ambient, *diffuse, *specular, *shininess; 214 | BitMap *txMapP; 215 | UB *palP; 216 | long err; 217 | long matID; 218 | MLB_Material_t *matP; 219 | 220 | parseMatInfo( arg, tag, &name, &light, &ambient, &diffuse, &specular, &shininess, &txMapP, &palP ); 221 | 222 | if ( (matID = MLB_MaterialFind( name )) >= 0 ) 223 | { 224 | if ( doOverWrite ) 225 | { 226 | MLB_Material_t *matP; 227 | 228 | matP = &ACT->materials[matID]; 229 | if ( err = checkAndCreateTexture( &matP->textureP, txMapP, palP ) ) 230 | return err; 231 | vec4_equ_sck( matP->light, light ); 232 | vec4_equ_sck( matP->ambient, ambient ); 233 | vec4_equ_sck( matP->diffuse, diffuse ); 234 | vec4_equ_sck( matP->specular, specular ); 235 | if ( shininess ) matP->shininess = *shininess; 236 | } 237 | return matID; 238 | } 239 | 240 | if ( ACT->nMaterials >= MLB_MAXMATERIALS ) 241 | return -1; 242 | 243 | for( matP = ACT->materials; matP->active; ++matP ); 244 | 245 | strcpymaxsize( matP->name, name, sizeof(matP->name) ); 246 | matP->active = 1; 247 | 248 | if ( txMapP ) 249 | ACT->nTextures = 1; 250 | else 251 | ACT->nTextures = 0; 252 | if ( err = checkAndCreateTexture( &matP->textureP, txMapP, palP ) ) 253 | return err; 254 | 255 | if ( light ) vec4_equ( matP->light, light ); else vec4_equ( matP->light, ACT->deflight ); 256 | if ( ambient ) vec4_equ( matP->ambient, ambient ); else vec4_equ( matP->ambient, ACT->defambient ); 257 | if ( diffuse ) vec4_equ( matP->diffuse, diffuse ); else vec4_equ( matP->diffuse, ACT->defdiffuse ); 258 | if ( specular ) vec4_equ( matP->specular, specular ); else vec4_equ( matP->specular, ACT->defspecular ); 259 | if ( shininess ) matP->shininess = *shininess; else matP->shininess = ACT->defshininess; 260 | ++ACT->nMaterials; 261 | 262 | return matP - ACT->materials; 263 | } 264 | //---------------------------------------------- 265 | long MLB_MaterialAdd( long tag, ... ) 266 | { 267 | long err; 268 | va_list arg; 269 | 270 | va_start( arg, tag ); 271 | err = materialAddOverwrite( 0, tag, arg ); 272 | va_end( arg ); 273 | 274 | return err; 275 | } 276 | //---------------------------------------------- 277 | long MLB_MaterialSetOrAdd( long tag, ... ) 278 | { 279 | long err; 280 | va_list arg; 281 | 282 | va_start( arg, tag ); 283 | err = materialAddOverwrite( 1, tag, arg ); 284 | va_end( arg ); 285 | 286 | return err; 287 | } 288 | 289 | //============================================== 290 | void MLB_PaletteCompute( US userColors ) 291 | { 292 | MLB_Material_t *matP=ACT->materials; 293 | COL_ShadePalette_t *spalP=&ACT->shadePal; 294 | UB shadePalCol; 295 | UB *paletteP; 296 | long i; 297 | 298 | shadePalCol = 0; 299 | spalP->userColors = userColors; 300 | 301 | SAFE_FREE( ACT->levPalP ); 302 | if ( ACT->nTextures ) 303 | { 304 | UB *srcPalP; 305 | 306 | spalP->nShades = 1; 307 | spalP->nColors = 256-userColors; 308 | paletteP = (UB *)spalP->palette + userColors*3; 309 | for(i=ACT->nMaterials; i > 0; --i, ++matP) 310 | if ( matP->active && matP->textureP ) 311 | { 312 | memset( matP->textureP->origPal, 0, userColors*3 ); 313 | srcPalP = matP->textureP->origPal + userColors*3; 314 | for(i = spalP->nColors; i > 0; --i) 315 | { 316 | *paletteP++ = *srcPalP++; 317 | *paletteP++ = *srcPalP++; 318 | *paletteP++ = *srcPalP++; 319 | } 320 | break; 321 | } 322 | ACT->levPalP = COL_NewDark( (UB *)spalP->palette, 32, .4, 256 ); 323 | } 324 | else 325 | { 326 | float stepli; 327 | 328 | spalP->nColors = ACT->nMaterials; 329 | if ( spalP->nColors ) 330 | if ( spalP->nShades = (256-userColors) / spalP->nColors ) 331 | stepli = (1.-.3) / spalP->nShades; 332 | 333 | paletteP = (UB *)spalP->palette + userColors*3; 334 | for(i=ACT->nMaterials; i > 0; --i, ++matP) 335 | { 336 | if ( matP->active ) 337 | { 338 | float ia_oa[3],id_od[3], is_os[3], il_ol[3], li, shin; 339 | 340 | vec3_equ(il_ol,matP->light); vec3_mul(il_ol,il_ol,matP->light[3]); 341 | vec3_equ(ia_oa,matP->ambient); vec3_mul(ia_oa,ia_oa,matP->ambient[3]); 342 | vec3_equ(id_od,matP->diffuse); vec3_mul(id_od,id_od,matP->diffuse[3]); 343 | vec3_equ(is_os,matP->specular); vec3_mul(is_os,is_os,matP->specular[3]); 344 | shin = matP->shininess; 345 | li = .3; 346 | for(US j=spalP->nShades; j; --j, li += stepli) 347 | { 348 | long tv[3]; 349 | float ts; 350 | 351 | ts = pow( li, shin ); 352 | tv[0] = (ia_oa[0] + (ts*is_os[0] + il_ol[0]*li*id_od[0])) * 255.; 353 | tv[1] = (ia_oa[1] + (ts*is_os[1] + il_ol[1]*li*id_od[1])) * 255.; 354 | tv[2] = (ia_oa[2] + (ts*is_os[2] + il_ol[2]*li*id_od[2])) * 255.; 355 | CLAMP(tv[0],0,255); CLAMP(tv[1],0,255); CLAMP(tv[2],0,255); 356 | paletteP[0] = tv[0]; 357 | paletteP[1] = tv[1]; 358 | paletteP[2] = tv[2]; 359 | paletteP += 3; 360 | } 361 | ++shadePalCol; 362 | } 363 | } 364 | } 365 | } 366 | 367 | -------------------------------------------------------------------------------- /SRC/RTMZ3D/READ3DS.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // READ3DS.CPP 3 | // Copyright (C) Davide Pasca 1995-97 4 | // 5 | // See "readme.txt" for other credits 6 | // 7 | // TABS=4 8 | //============================================== 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "exttypes.hpp" 16 | #include "OBJ3D.HPP" 17 | #include "PASCALIB.HPP" 18 | #include "MATELIB.HPP" 19 | 20 | #define M3DMAGIC (0x4D4D) 21 | #define COLOR_F (0x0010) 22 | #define COLOR_24 (0x0011) 23 | #define INT_PERCENTAGE (0x0030) 24 | #define FLOAT_PERCENTAGE (0x0031) 25 | #define MDATA (0x3D3D) 26 | #define AMBIENT_LIGHT (0x2100) 27 | #define SOLID_BGND (0x1200) 28 | #define USE_SOLID_BGND (0x1201) 29 | #define FOG (0x2200) 30 | #define FOG_BGND (0x2210) 31 | #define USE_FOG (0x2201) 32 | #define DEFAULT_VIEW (0x3000) 33 | #define VIEW_CAMERA (0x3080) 34 | #define MAT_ENTRY (0xAFFF) 35 | #define NAMED_OBJECT (0x4000) 36 | #define N_TRI_OBJECT (0x4100) 37 | #define N_DIRECT_LIGHT (0x4600) 38 | #define N_CAMERA (0x4700) 39 | #define OBJ_HIDDEN (0x4010) 40 | #define OBJ_DOESNT_CAST (0x4012) 41 | #define POINT_ARRAY (0x4110) 42 | #define FACE_ARRAY (0x4120) 43 | #define MSH_MAT_GROUP (0x4130) 44 | #define SMOOTH_GROUP (0x4150) 45 | #define MESH_MATRIX (0x4160) 46 | #define DL_OFF (0x4620) 47 | #define DL_SPOTLIGHT (0x4610) 48 | #define DL_SHADOWED (0x4630) 49 | #define MAT_NAME (0xA000) 50 | #define MAT_AMBIENT (0xA010) 51 | #define MAT_DIFFUSE (0xA020) 52 | #define MAT_SPECULAR (0xA030) 53 | #define MAT_SHININESS (0xA040) 54 | #define MAT_TRANSPARENCY (0xA050) 55 | 56 | /* A generic list type */ 57 | #define LIST_INSERT(root, node) list_insert ((List **)&root, (List *)node) 58 | #define LIST_FIND(root, name) list_find ((List **)&root, name) 59 | #define LIST_DELETE(root, node) list_delete ((List **)&root, (List *)node) 60 | #define LIST_KILL(root) list_kill ((List **)&root) 61 | 62 | typedef unsigned char byte; 63 | typedef unsigned short word; 64 | typedef unsigned long dword; 65 | 66 | 67 | typedef struct { 68 | dword start; 69 | dword end; 70 | dword length; 71 | word tag; 72 | } Chunk; 73 | 74 | #define ACT __O3D_actObjP 75 | //============================== 76 | static O3D_Object_t *_meshRootP; 77 | static char _obj_name[81]=""; 78 | static FILE *in; 79 | 80 | //============================== 81 | static void list_insert(List **root, List *new_node) 82 | { 83 | new_node->next = *root; 84 | *root = new_node; 85 | } 86 | 87 | //============================== 88 | static byte read_byte(){ byte data; data = fgetc(in); return data; } 89 | static word read_word(){ word data; fread(&data, 2, 1, in); return data; } 90 | static dword read_dword(){ dword data; fread (&data, 4, 1, in); return data; } 91 | static float read_float(){ float data; fread (&data, 4, 1, in); return data; } 92 | 93 | //============================== 94 | static void start_chunk (Chunk *chunk) 95 | { 96 | chunk->start = ftell(in); 97 | chunk->tag = read_word(); 98 | chunk->length = read_dword(); 99 | chunk->end = chunk->start + chunk->length; 100 | } 101 | //------------------------------ 102 | static void end_chunk (Chunk *chunk) 103 | { 104 | fseek (in, chunk->end, SEEK_SET); 105 | } 106 | 107 | //------------------------------ 108 | static void read_point(float *v) 109 | { 110 | v[0] = read_float(); 111 | v[2] = read_float(); 112 | v[1] = read_float(); 113 | } 114 | 115 | //------------------------------ 116 | static char *read_string(void) 117 | { 118 | static char string[80]; 119 | long i; 120 | 121 | for (i = 0; i < 80; ++i) 122 | { 123 | string[i] = read_byte(); 124 | if (string[i] == '\0') break; 125 | } 126 | if (i==80) 127 | string[79] = '\0'; 128 | return string; 129 | } 130 | 131 | //------------------------------- 132 | static long parse_colour(float *col) 133 | { 134 | Chunk chunk; 135 | long err=0; 136 | 137 | start_chunk (&chunk); 138 | switch (chunk.tag) 139 | { 140 | case COLOR_F: col[0] = read_float(); 141 | col[1] = read_float(); 142 | col[2] = read_float(); 143 | break; 144 | 145 | case COLOR_24: col[0] = read_byte()/255.; 146 | col[1] = read_byte()/255.; 147 | col[2] = read_byte()/255.; 148 | break; 149 | 150 | default: err=-1; break; 151 | } 152 | end_chunk (&chunk); 153 | 154 | return err; 155 | } 156 | 157 | //----------------------------------------- 158 | static long parse_point_array(void) 159 | { 160 | if ( O3D_AllocVerts( read_word()) ) return -1; 161 | 162 | ACT->curVertNum = ACT->NVerts; 163 | for (long i = 0; i < ACT->curVertNum; ++i) 164 | read_point( ACT->baseVertsP[ i ].vert ); 165 | 166 | return 0; 167 | } 168 | 169 | //----------------------------------------- 170 | static long parse_msh_mat_group( void ) 171 | { 172 | char name[80]; 173 | long matID; 174 | float diffuse[]={.0,.0,1.,.95}; 175 | 176 | strcpy( name, read_string() ); 177 | if ( (matID = MLB_MaterialAdd( MLB_NAME_PTR,name, MLB_DIFFUSE_PTR,diffuse, TAG_END )) < 0 ) 178 | return -1; 179 | 180 | for (short i=read_word(); i; --i) 181 | { 182 | short face = read_word(); 183 | CLAMP( face, 0, ACT->curPolyNum ); 184 | ACT->PolysP[ face ].materialID = matID; 185 | } 186 | 187 | return 0; 188 | } 189 | 190 | //----------------------------------------- 191 | static long parse_face_array(Chunk *mainchunk) 192 | { 193 | long err; 194 | 195 | if ( O3D_AllocPolys(read_word()) ) return -1; 196 | 197 | for (long i=ACT->NPolys; i; --i) 198 | { 199 | O3D_PolyBegin( 0, 0 ); 200 | _O3D_PolyVertNew( read_word() ); 201 | _O3D_PolyVertNew( read_word() ); 202 | _O3D_PolyVertNew( read_word() ); 203 | O3D_PolyEnd(); 204 | read_word(); 205 | } 206 | 207 | Chunk chunk; 208 | do{ 209 | start_chunk (&chunk); 210 | if (chunk.end <= mainchunk->end) 211 | { 212 | switch (chunk.tag) 213 | { 214 | case MSH_MAT_GROUP: if ( err = parse_msh_mat_group() ) return err; break; 215 | //case SMOOTH_GROUP: parse_smooth_group(); break; 216 | } 217 | } 218 | end_chunk (&chunk); 219 | }while (chunk.end < mainchunk->end); 220 | 221 | return 0; 222 | } 223 | 224 | //----------------------------------------- 225 | static void parse_mesh_matrix(void) 226 | { 227 | /*for (short i = 0; i < 4; i++) 228 | for (short j = 0; j < 3; j++) 229 | ACT->mat.mf[j][i] = read_float();*/ 230 | } 231 | 232 | //----------------------------------------- 233 | static long parse_n_tri_object(Chunk *mainchunk) 234 | { 235 | Chunk chunk; 236 | long err=0; 237 | O3D_Object_t *objP; 238 | 239 | if NOT( objP = (O3D_Object_t *)O3D_New(_obj_name) ) 240 | return -1; 241 | 242 | long old=O3D_Set((long)objP); 243 | do{ 244 | start_chunk(&chunk); 245 | if (chunk.end <= mainchunk->end) 246 | { 247 | switch (chunk.tag) 248 | { 249 | case POINT_ARRAY: if ( err = parse_point_array() ) goto exitErr; break; 250 | case FACE_ARRAY: if ( err = parse_face_array(&chunk)) goto exitErr; break; 251 | case MESH_MATRIX: parse_mesh_matrix(); break; 252 | } 253 | } 254 | end_chunk(&chunk); 255 | }while (chunk.end < mainchunk->end); 256 | 257 | LIST_INSERT( _meshRootP, objP ); 258 | exitErr: 259 | 260 | O3D_Set( old ); 261 | return err; 262 | } 263 | 264 | //----------------------------------------- 265 | static long parse_named_object(Chunk *mainchunk) 266 | { 267 | Chunk chunk; 268 | long err; 269 | 270 | strcpymaxsize(_obj_name, read_string(), 80); 271 | do{ 272 | start_chunk (&chunk); 273 | if (chunk.end <= mainchunk->end) 274 | { 275 | switch (chunk.tag) 276 | { 277 | case N_TRI_OBJECT: if ( err = parse_n_tri_object(&chunk) ) return err; break; 278 | //case OBJ_HIDDEN: if (_meshP) _meshP->hidden = 1; break; 279 | //case OBJ_DOESNT_CAST: if (_meshP) _meshP->shadow = 0; break; 280 | //case N_DIRECT_LIGHT: parse_n_direct_light(&chunk); break; 281 | //case N_CAMERA: parse_n_camera(); break; 282 | } 283 | } 284 | end_chunk (&chunk); 285 | }while (chunk.end < mainchunk->end); 286 | 287 | return 0; 288 | } 289 | 290 | //------------------------------- 291 | static short parse_int_percentage(void){US percent = read_word(); return percent; } 292 | static float parse_float_percentage(void){float percent = read_float(); return percent; } 293 | //------------------------------- 294 | static float parse_percentage(void) 295 | { 296 | Chunk chunk; 297 | float percent = 0.0; 298 | 299 | start_chunk (&chunk); 300 | switch (chunk.tag) { 301 | case 0x0030: percent = parse_int_percentage()/100.0; break; 302 | case 0x0031: percent = parse_float_percentage(); break; 303 | } 304 | end_chunk (&chunk); 305 | return percent; 306 | } 307 | 308 | //------------------------------- 309 | static long parse_mat_entry (Chunk *mainchunk) 310 | { 311 | Chunk chunk; 312 | char name[80]; 313 | static float ambient[]={.2,.2,.2,.05}, diffuse[]={.9,.1,.1,.95}, specular[]={.2,.2,.2,.2}; 314 | float shininess=10., reflection=.2; 315 | 316 | do{ 317 | start_chunk (&chunk); 318 | 319 | if (chunk.end <= mainchunk->end) 320 | { 321 | switch (chunk.tag) 322 | { 323 | case 0xA000: strcpy(name, read_string()); break; 324 | case 0xA010: parse_colour( ambient ); break; 325 | case 0xA020: parse_colour( diffuse ); break; 326 | case 0xA030: parse_colour( specular ); break; 327 | case 0xA040: shininess = 100.0*parse_percentage(); break; 328 | /* case 0xA050: mprop->transparency = parse_percentage(); break; 329 | case 0xA080: mprop->self_illum = TRUE; break; */ 330 | case 0xA220: reflection = parse_percentage(); //(void)parse_mapname (&chunk); 331 | break; 332 | case 0xA310: if (reflection == 0.0) reflection = 1.0; break; 333 | /* case 0xA200: mprop->tex_strength = parse_percentage(); 334 | strcpy (mprop->tex_map, parse_mapname (&chunk)); break; 335 | 336 | case 0xA230: mprop->bump_strength = parse_percentage(); 337 | strcpy (mprop->bump_map, parse_mapname (&chunk)); break; 338 | */ } 339 | } 340 | end_chunk (&chunk); 341 | } while (chunk.end < mainchunk->end); 342 | 343 | specular[3] = reflection; 344 | MLB_MaterialSetOrAdd( MLB_NAME_PTR,name, MLB_AMBIENT_PTR,ambient, MLB_DIFFUSE_PTR,diffuse, 345 | MLB_SPECULAR_PTR,specular, MLB_SHININESS_PTR,&shininess, TAG_END ); 346 | 347 | return 0; 348 | } 349 | 350 | //------------------------------- 351 | static long parse_mdata(Chunk *mainchunk) 352 | { 353 | Chunk chunk; 354 | long err; 355 | float global_amb[]={1.,1.,1.,.1}; 356 | 357 | do{ 358 | start_chunk (&chunk); 359 | if (chunk.end <= mainchunk->end) 360 | { 361 | switch (chunk.tag) 362 | { 363 | case 0x2100: parse_colour( global_amb ); 364 | MLB_MaterialSetDefault( MLB_AMBIENT_PTR, global_amb, TAG_END ); 365 | MLB_MaterialSetAll( MLB_AMBIENT_PTR, global_amb, TAG_END ); 366 | break; 367 | //case SOLID_BGND: if ( err = parse_color(&bgnd_color) ) 368 | // return err; 369 | // break; 370 | 371 | //case USE_SOLID_BGND: write_bgsolid (out, bgnd_color); break; 372 | //case FOG: parse_fog (&chunk); break; 373 | //case FOG_BGND: parse_fog_bgnd(); break; 374 | //case USE_FOG: write_fog (out, fog_color, fog_distance); break; 375 | case MAT_ENTRY: if ( err = parse_mat_entry(&chunk) ) return err; break; 376 | case NAMED_OBJECT: if ( err = parse_named_object(&chunk) ) return err; break; 377 | } 378 | } 379 | end_chunk (&chunk); 380 | }while (chunk.end < mainchunk->end); 381 | 382 | return 0; 383 | } 384 | 385 | //=============================== 386 | static long parse_3ds(Chunk *mainchunk) 387 | { 388 | Chunk chunk; 389 | long err; 390 | 391 | do{ 392 | start_chunk (&chunk); 393 | if (chunk.end <= mainchunk->end) 394 | { 395 | switch (chunk.tag) 396 | { 397 | case MDATA: if ( err = parse_mdata(&chunk) ) return err; break; 398 | } 399 | } 400 | end_chunk (&chunk); 401 | }while (chunk.end < mainchunk->end); 402 | 403 | return 0; 404 | } 405 | 406 | //------------------------------- 407 | static long parse_file(void) 408 | { 409 | Chunk chunk; 410 | long err; 411 | 412 | start_chunk(&chunk); 413 | if (chunk.tag == M3DMAGIC) 414 | err = parse_3ds(&chunk); 415 | else 416 | err = -1; 417 | end_chunk(&chunk); 418 | 419 | return err; 420 | } 421 | 422 | //------------------------------- 423 | long O3D_Load3DS(const char *fnameP) 424 | { 425 | long err=0; 426 | 427 | if NOT( in = fopen( fnameP, "rb" ) ) 428 | return -1; 429 | 430 | _meshRootP = 0; 431 | if NOT( err = parse_file() ) 432 | { 433 | *ACT = *_meshRootP; 434 | POE_PolyI_t *polyP = ACT->PolysP; 435 | for(long i=ACT->curPolyNum; i; --i, ++polyP) 436 | { 437 | polyP->vertH = &ACT->vertsP; 438 | polyP->userLong = (long)ACT; 439 | } 440 | 441 | free( _meshRootP ); 442 | O3D_Update(); 443 | if ( __MLB_actLibP->nMaterials == 0 ) 444 | MLB_MaterialAdd( MLB_NAME_PTR, "NULL", TAG_END ); 445 | } 446 | fclose( in ); 447 | 448 | if ( err ) 449 | { 450 | *ACT = *_meshRootP; 451 | O3D_Free( (long)ACT ); 452 | } 453 | 454 | return err; 455 | } 456 | 457 | -------------------------------------------------------------------------------- /SRC/RTMZOS/VESA.CPP: -------------------------------------------------------------------------------- 1 | //============================================== 2 | // VESA.CPP 3 | // Copyright (C) Davide Pasca 1995-97 4 | // 5 | // See "readme.txt" for other credits 6 | // 7 | // TABS=4 8 | //============================================== 9 | 10 | #include 11 | #include 12 | #include "vesa.hpp" 13 | 14 | //============================================================ 15 | typedef struct 16 | { 17 | US Segment; //The real mode segment (offset is 0). 18 | US Selector; //In protected mode, you need to chuck this dude into a segment register and use an offset 0. 19 | } RealPointer; 20 | 21 | typedef struct 22 | { 23 | char Signature[4]; 24 | US Version; 25 | US OEMNameOffset; 26 | US OEMNameSegment; //Pointer to OEM name? 27 | UB Capabilities[4]; 28 | US SupportedModesOffset; 29 | US SupportedModesSegment; //Pointer to list of supported VESA and OEM modes (terminated with 0xffff). 30 | UB Reserved[238]; 31 | } VesaInfo; 32 | 33 | typedef struct 34 | { 35 | US ModeAttributes; 36 | UB WindowAAttributes; 37 | UB WindowBAttributes; 38 | US WindowGranularity; 39 | US WindowSize; 40 | US StartSegmentWindowA; 41 | US StartSegmentWindowB; 42 | void (*WindowPositioningFunction)(long page); 43 | US BytesPerScanLine; 44 | 45 | //Remainder of this structure is optional for VESA modes in v1.0/1.1, needed for OEM modes. 46 | 47 | US PixelWidth; 48 | US PixelHeight; 49 | UB CharacterCellPixelWidth; 50 | UB CharacterCellPixelHeight; 51 | UB NumberOfMemoryPlanes; 52 | UB BitsPerPixel; 53 | UB NumberOfBanks; 54 | UB MemoryModelType; 55 | UB SizeOfBank; 56 | UB NumberOfImagePages; 57 | UB Reserved1; 58 | 59 | //VBE v1.2+ 60 | 61 | UB RedMaskSize; 62 | UB RedFieldPosition; 63 | UB GreenMaskSize; 64 | UB GreenFieldPosition; 65 | UB BlueMaskSize; 66 | UB BlueFieldPosition; 67 | UB ReservedMaskSize; 68 | UB ReservedFieldPosition; 69 | UB DirectColourModeInfo; 70 | UB Reserved2[216]; 71 | } VesaModeData; 72 | 73 | typedef struct 74 | { 75 | UL edi; 76 | UL esi; 77 | UL ebp; 78 | UL reserved; 79 | UL ebx; 80 | UL edx; 81 | UL ecx; 82 | UL eax; 83 | US flags; 84 | US es,ds,fs,gs,ip,cs,sp,ss; 85 | } RMREGS; 86 | 87 | /****************************************************************************/ 88 | /* Private function prototypes. */ 89 | /****************************************************************************/ 90 | static void far * allocate_dos_memory(RealPointer * rp,UL bytes_to_allocate); 91 | static void free_dos_memory(RealPointer * rp); 92 | 93 | /****************************************************************************/ 94 | /* Private data. */ 95 | /****************************************************************************/ 96 | RealPointer vesa_info_rp; 97 | RealPointer vesa_mode_data_rp; 98 | 99 | /****************************************************************************/ 100 | /* Global data. */ 101 | /****************************************************************************/ 102 | 103 | VesaInfo far *vesa_info =0; 104 | VesaModeData far *vesa_mode_data =0; 105 | long vesa_granularity; 106 | long vesa_page; 107 | long vesa_width; 108 | long vesa_height; 109 | long vesa_bits_per_pixel; 110 | 111 | /****************************************************************************/ 112 | /* Get information about the VESA driver. */ 113 | /* */ 114 | /* Returns: */ 115 | /* 1 - VESA driver present. vesa_info set to point to a */ 116 | /* a structure containing capability info etc. */ 117 | /* 0 - No VESA driver. */ 118 | /* */ 119 | /****************************************************************************/ 120 | BO vesa_get_info(void) 121 | { 122 | union REGS regs; 123 | struct SREGS sregs; 124 | RMREGS rmregs; 125 | BO ok = 0; 126 | 127 | if((vesa_info = (VesaInfo far *)allocate_dos_memory(&vesa_info_rp,sizeof(VesaInfo))) != NULL) 128 | { 129 | memset(&rmregs,0,sizeof(rmregs)); 130 | memset(®s,0,sizeof(regs)); 131 | memset(&sregs,0,sizeof(sregs)); 132 | segread(&sregs); 133 | rmregs.eax = 0x4f00; 134 | rmregs.es = vesa_info_rp.Segment; 135 | rmregs.ds = vesa_info_rp.Segment; 136 | regs.x.eax = 0x300; 137 | regs.x.ebx = 0x10; 138 | regs.x.ecx = 0; 139 | sregs.es = FP_SEG(&rmregs); 140 | regs.x.edi = FP_OFF(&rmregs); 141 | int386x(0x31,®s,®s,&sregs); //Get vesa info. 142 | if(rmregs.eax == 0x4f) 143 | { 144 | ok = 1; 145 | } 146 | } 147 | return(ok); 148 | } 149 | 150 | /****************************************************************************/ 151 | /* Free the information allocated with vesa_get_info() */ 152 | /****************************************************************************/ 153 | void vesa_free_info(void) 154 | { 155 | free_dos_memory(&vesa_info_rp); 156 | } 157 | 158 | /****************************************************************************/ 159 | /* Set VESA video mode. You MUST have previously called vesa_get_info(). */ 160 | /* */ 161 | /* Inputs: */ 162 | /* vmode - The VESA mode that you want. e.g. 0x101 is 640x480 256 */ 163 | /* colours. */ 164 | /* */ 165 | /* Returns: */ 166 | /* 1 - The mode has been set. */ 167 | /* 0 - The mode has not been set, probably not supported. */ 168 | /* */ 169 | /****************************************************************************/ 170 | 171 | BO vesa_set_mode(US vmode) 172 | { 173 | union REGS regs; 174 | 175 | memset(®s,0,sizeof(regs)); 176 | regs.w.ax = 0x4f02; 177 | regs.w.bx = vmode; 178 | int386(0x10,®s,®s); 179 | if (regs.w.ax == 0x004f) 180 | { 181 | vesa_get_mode_info(vmode); 182 | vesa_set_page(0); //Probably not needed, but here for completeness. 183 | return 1; 184 | } 185 | 186 | return 0; 187 | } 188 | 189 | /****************************************************************************/ 190 | /* Get VESA mode information. Information is loaded into vesa_mode_data. */ 191 | /* vesa_get_info() must be called before calling this function. */ 192 | /* Should error check this really. */ 193 | /* */ 194 | /* Inputs: */ 195 | /* vmode - The mode that you wish to get information about. */ 196 | /* */ 197 | /* Returns: */ 198 | /* 1 - vesa_mode_data points to a filled VesaModeData structure. */ 199 | /* 0 - vesa_mode_data probably invalid. Mode probably not */ 200 | /* supported. */ 201 | /* */ 202 | /****************************************************************************/ 203 | BO vesa_get_mode_info(US vmode) 204 | { 205 | union REGS regs; 206 | struct SREGS sregs; 207 | RMREGS rmregs; 208 | BO ok = 0; 209 | 210 | if ( (vesa_mode_data = (VesaModeData far *)allocate_dos_memory(&vesa_mode_data_rp,sizeof(VesaModeData))) ) 211 | { 212 | memset(&rmregs,0,sizeof(rmregs)); 213 | rmregs.es = vesa_mode_data_rp.Segment; 214 | rmregs.ds = vesa_mode_data_rp.Segment; 215 | rmregs.edi = 0; 216 | rmregs.eax = 0x4f01; 217 | rmregs.ecx = vmode; 218 | memset(®s,0,sizeof(regs)); 219 | memset(&sregs,0,sizeof(sregs)); 220 | segread(&sregs); 221 | regs.x.eax = 0x300; 222 | regs.x.ebx = 0x10; 223 | regs.x.edi = (UL)&rmregs; 224 | int386x(0x31,®s,®s,&sregs); 225 | if (regs.h.al == 0) 226 | { 227 | //cache a few important items in protected mode memory area. 228 | vesa_granularity = vesa_mode_data->WindowGranularity; 229 | vesa_width = vesa_mode_data->PixelWidth; 230 | vesa_height = vesa_mode_data->PixelHeight; 231 | vesa_bits_per_pixel = vesa_mode_data->BitsPerPixel; 232 | return 1; 233 | } 234 | } 235 | 236 | return 0; 237 | } 238 | 239 | /****************************************************************************/ 240 | /* Free the info previously allocated with vesa_get_info() */ 241 | /****************************************************************************/ 242 | void vesa_free_mode_info(void) 243 | { 244 | free_dos_memory(&vesa_mode_data_rp); 245 | } 246 | 247 | /****************************************************************************/ 248 | /* Set the current vesa screen page. */ 249 | /* */ 250 | /* Inputs: */ 251 | /* vpage - Page number to set. */ 252 | /* */ 253 | /****************************************************************************/ 254 | void vesa_set_page(long vpage) 255 | { 256 | union REGS regs; 257 | 258 | vesa_page = vpage; 259 | regs.w.ax = 0x4f05; 260 | regs.w.bx = 0; 261 | regs.w.cx = 0; 262 | regs.w.dx = (US)(vpage == 0 ? 0 : (US)((vpage * 64) / vesa_granularity)); 263 | int386(0x10,®s,®s); 264 | /* 265 | regs.w.ax = 0x4f05; 266 | regs.w.bx = 1; 267 | regs.w.cx = 0; 268 | regs.w.dx = (US)(vpage == 0 ? 0 : (US)((vpage * 64) / vesa_granularity)); 269 | int386(0x10,®s,®s); 270 | */ 271 | } 272 | 273 | //======================================================= 274 | void vesa_screen_clear(long swidth,long sheight,long bpp) 275 | { 276 | long page = 0; 277 | long scr_size = (swidth * sheight * bpp); //width * height * bytes per pixel. 278 | 279 | while(scr_size > 0) 280 | { 281 | vesa_set_page(page); 282 | memset((void *)0xa0000,0,(scr_size > 65536 ? 65536 : scr_size)); 283 | scr_size -= 65536; 284 | page++; 285 | } 286 | 287 | } 288 | 289 | //======================================================= 290 | extern void memcpyset2(void *d, const void *s, unsigned long pattern, long size ); 291 | #pragma aux memcpyset2 = \ 292 | " shr ecx,2" \ 293 | " or ecx,ecx" \ 294 | " jz nope" \ 295 | "lupa:"\ 296 | " mov ebx,[esi]"\ 297 | " mov [esi],eax"\ 298 | " mov [edi],ebx"\ 299 | " add esi,4"\ 300 | " add edi,4"\ 301 | " dec ecx"\ 302 | " jnz lupa"\ 303 | "nope:"\ 304 | parm caller [edi][esi][eax][ecx]\ 305 | modify [edi esi ebx ecx edx]; 306 | 307 | void vesa_screen_swap_clear(UB * source, UL pattern, long swidth, long sheight, long bpp) 308 | { 309 | long page = 0; 310 | long bps = vesa_mode_data->BytesPerScanLine; 311 | 312 | swidth *= bpp; 313 | if ( bps == swidth ) 314 | { 315 | long scr_size; 316 | 317 | scr_size = swidth * sheight; 318 | while(scr_size > 0) 319 | { 320 | vesa_set_page( page ); 321 | memcpyset2( (void *)0xa0000, source, pattern, (scr_size > 65536 ? 65536 : scr_size) ); 322 | scr_size -= 65536; 323 | source += 65536; 324 | page++; 325 | } 326 | } 327 | else 328 | { 329 | long y; 330 | long destoff, destoffh, destoffhn; 331 | 332 | vesa_set_page( page ); 333 | destoff = 0; 334 | destoffhn = destoffh = 0; 335 | for(y=0; y < sheight; ++y) 336 | { 337 | destoffhn = (destoff + swidth) & ~65535; 338 | if ( destoffh == destoffhn ) 339 | { 340 | memcpyset2( (void *)(0xa0000 + (destoff & 65535)), source, pattern, swidth ); 341 | if ( destoffh != ((destoff + bps) & ~65535) ) 342 | vesa_set_page( ++page ); 343 | } 344 | else 345 | { 346 | long len1; 347 | 348 | len1 = destoffhn - destoff; 349 | if ( len1 <= swidth ) 350 | memcpyset2( (void *)(0xa0000 + (destoff & 65535)), source, pattern, len1 ); 351 | 352 | vesa_set_page( ++page ); 353 | 354 | if ( len1 < swidth ) 355 | memcpyset2( (void *)0xa0000, source + len1, pattern, swidth - len1 ); 356 | } 357 | 358 | source += swidth; 359 | destoff += bps; 360 | destoffh = destoff & ~65535; 361 | } 362 | } 363 | } 364 | 365 | /* 366 | void vesa_screen_swap_clear(UB * source, UL pattern, long swidth, long sheight, long bpp) 367 | { 368 | void * dest; 369 | long page = 0; 370 | long scr_size = (swidth * sheight * bpp); //width * height * bytes per pixel. 371 | 372 | dest = (void *)source; 373 | while(scr_size > 0) 374 | { 375 | vesa_set_page(page); 376 | memcpyset2( (void *)0xa0000, dest, pattern, (scr_size > 65536 ? 65536 : scr_size) ); 377 | scr_size -= 65536; 378 | dest = (void *)((UL)dest + 65536); 379 | page++; 380 | } 381 | 382 | } 383 | */ 384 | 385 | //============================================================= 386 | void vesa_screen_swap(UB * source,long swidth,long sheight,long bpp) 387 | { 388 | void *dest; 389 | long page = 0; 390 | long scr_size = (swidth * sheight * bpp); //width * height * bytes per pixel. 391 | 392 | dest = (void *)source; 393 | while(scr_size > 0) 394 | { 395 | vesa_set_page(page); 396 | memcpy((void *)0xa0000,dest,(scr_size > 65536 ? 65536 : scr_size)); 397 | scr_size -= 65536; 398 | dest = (void *)((UL)dest + 65536); 399 | page++; 400 | } 401 | 402 | } 403 | 404 | /****************************************************************************/ 405 | /* Allocate a region of DOS memory. */ 406 | /****************************************************************************/ 407 | static void far * allocate_dos_memory(RealPointer * rp,UL bytes_to_allocate) 408 | { 409 | void far * ptr = NULL; 410 | union REGS regs; 411 | 412 | bytes_to_allocate = ((bytes_to_allocate + 15) & 0xfffffff0); //Round up to nearest paragraph. 413 | memset(®s,0,sizeof(regs)); 414 | regs.w.ax = 0x100; 415 | regs.w.bx = (US)(bytes_to_allocate >> 4); //Allocate dos memory in pages, so convert bytes to pages. 416 | int386(0x31,®s,®s); 417 | if(regs.x.cflag == 0) 418 | { //Everything OK. 419 | rp->Segment = regs.w.ax; 420 | rp->Selector = regs.w.dx; 421 | ptr = MK_FP(regs.w.dx,0); 422 | } 423 | return(ptr); 424 | } 425 | 426 | /****************************************************************************/ 427 | /* Free an area of DOS memory. */ 428 | /****************************************************************************/ 429 | static void free_dos_memory(RealPointer * rp) 430 | { 431 | union REGS regs; 432 | 433 | regs.w.ax = 0x101; 434 | regs.w.dx = rp->Selector; 435 | int386(0x31,®s,®s); 436 | } 437 | 438 | --------------------------------------------------------------------------------