From 936a5198e46e3c7a8f72959373a69336b1697e76 Mon Sep 17 00:00:00 2001 From: Steven Fuller Date: Thu, 12 Jul 2001 17:22:07 +0000 Subject: lots of small changes that didn't get checked in --- Makefile | 2 +- src/avp/decal.h | 6 +- src/avp/hmodel.h | 1 + src/avp/particle.h | 12 +- src/avp/win95/frontend/avp_menus.h | 2 +- src/avp/win95/frontend/avp_userprofile.h | 2 +- src/avp/win95/pldghost.h | 24 +- src/avp/win95/pldnet.h | 58 +- src/avp/win95/vision.h | 8 +- src/frustrum.c | 1275 ------------------------------ src/frustrum.h | 68 -- src/frustum.c | 1275 ++++++++++++++++++++++++++++++ src/frustum.h | 68 ++ src/kshape.c | 2 +- src/win95/d3_func.h | 42 + src/win95/inline.h | 4 +- src/win95/platform.h | 8 +- 17 files changed, 1468 insertions(+), 1389 deletions(-) delete mode 100644 src/frustrum.c delete mode 100644 src/frustrum.h create mode 100644 src/frustum.c create mode 100644 src/frustum.h diff --git a/Makefile b/Makefile index 9ce2054..08cc774 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ LDLIBS += `sdl-config --libs` AFLAGS = -g -Iinclude/ -w+macro-params -w+orphan-labels -w+number-overflow -ROOT = afont.c frustrum.c kshape.c map.c maths.c mem3dc.c mem3dcpp.cpp module.c morph.c mslhand.c object.c shpanim.c sphere.c tables.c vdb.c version.c +ROOT = afont.c frustum.c kshape.c map.c maths.c mem3dc.c mem3dcpp.cpp module.c morph.c mslhand.c object.c shpanim.c sphere.c tables.c vdb.c version.c # the following should really be autogenerated... diff --git a/src/avp/decal.h b/src/avp/decal.h index ae3d3d8..7e05f72 100644 --- a/src/avp/decal.h +++ b/src/avp/decal.h @@ -3,6 +3,7 @@ #include "d3_func.h" #include "vision.h" + enum DECAL_ID { DECAL_FMV=0, @@ -84,7 +85,9 @@ typedef struct VECTORCH Normal[3]; VECTORCH LightSource; char DotIsOnPlayer; - DPID TargetID; +// DPID TargetID; + int TargetID; + int ShouldBeDrawn; } THREE_LASER_DOT_DESC; @@ -94,6 +97,7 @@ extern void MakeDecal(enum DECAL_ID decalID, VECTORCH *normalPtr, VECTORCH *posi extern void AddDecal(enum DECAL_ID decalID, VECTORCH *normalPtr, VECTORCH *positionPtr, int moduleIndex); extern void HandleDecalSystem(void); +struct section_data; // hmodel.h extern void AddDecalToHModel(VECTORCH *normalPtr, VECTORCH *positionPtr, struct section_data *sectionPtr); extern FIXED_DECAL* AllocateFixedDecal(void); diff --git a/src/avp/hmodel.h b/src/avp/hmodel.h index 404742e..bb46b1d 100644 --- a/src/avp/hmodel.h +++ b/src/avp/hmodel.h @@ -390,6 +390,7 @@ extern int HModel_DepthTest(HMODELCONTROLLER *controller,SECTION_DATA *test_sect extern void DeInitialise_HModel(HMODELCONTROLLER *controller); +struct save_block_header; // savegame.h extern void LoadHierarchy(struct save_block_header* header,HMODELCONTROLLER* controller); extern void SaveHierarchy(HMODELCONTROLLER* controller); diff --git a/src/avp/particle.h b/src/avp/particle.h index 606fac2..6796ffe 100644 --- a/src/avp/particle.h +++ b/src/avp/particle.h @@ -98,12 +98,12 @@ typedef struct VECTORCH Velocity; VECTORCH Offset; - union - { - unsigned int Colour; - - struct ColourComponents ColourComponents; - }; +// union +// { +// unsigned int Colour; +// struct ColourComponents ColourComponents; +// }; + unsigned int Colour; unsigned int Size; diff --git a/src/avp/win95/frontend/avp_menus.h b/src/avp/win95/frontend/avp_menus.h index 2b5ae4d..1437e9b 100644 --- a/src/avp/win95/frontend/avp_menus.h +++ b/src/avp/win95/frontend/avp_menus.h @@ -34,7 +34,7 @@ #define SAVE_GAME_ON 1 -#include "AvP_MenuGfx.hpp" +#include "avp_menugfx.hpp" #include "language.h" enum MENUSSTATE_ID diff --git a/src/avp/win95/frontend/avp_userprofile.h b/src/avp/win95/frontend/avp_userprofile.h index 381c075..dd4355f 100644 --- a/src/avp/win95/frontend/avp_userprofile.h +++ b/src/avp/win95/frontend/avp_userprofile.h @@ -2,7 +2,7 @@ #define _avp_user_profile_h_ 1 #include "usr_io.h" -#include "AvP_EnvInfo.h" +#include "avp_envinfo.h" #include "game_statistics.h" #include "detaillevels.h" /* KJL 14:17:41 10/12/98 - User profile diff --git a/src/avp/win95/pldghost.h b/src/avp/win95/pldghost.h index c866873..1997869 100644 --- a/src/avp/win95/pldghost.h +++ b/src/avp/win95/pldghost.h @@ -16,7 +16,9 @@ extern "C" { typedef struct netghostdatablock { - DPID playerId; +// DPID playerId; + int playerId; + signed int playerObjectId; /* -1 == player, all other numbers used for objects */ AVP_BEHAVIOUR_TYPE type; INANIMATEOBJECT_TYPE IOType; @@ -25,11 +27,11 @@ typedef struct netghostdatablock /* KJL 17:33:41 22/01/99 - I've made this a union because I needed a storage space, and the currentAnimSequence is only used by specific objects */ - union - { + //union + //{ int currentAnimSequence; - int EventCounter; // used by grenades - }; + // int EventCounter; // used by grenades + //}; DISPLAYBLOCK *myGunFlash; SECTION_DATA *GunflashSectionPtr; @@ -70,10 +72,14 @@ typedef struct netghostdatablock ----------------------------------------------------------------------*/ extern void UpdateGhost(STRATEGYBLOCK *sbPtr,VECTORCH *position,EULER *orientation,int sequence, int special); extern void RemoveGhost(STRATEGYBLOCK *sbPtr); -extern void RemovePlayersGhosts(DPID id); -extern void RemovePlayerGhost(DPID id); -extern STRATEGYBLOCK *FindGhost(DPID Id, int obId); -extern STRATEGYBLOCK *CreateNetGhost(DPID playerId, int objectId, VECTORCH *position, EULER* orientation, AVP_BEHAVIOUR_TYPE type, unsigned char IOType, unsigned char subtype); +//extern void RemovePlayersGhosts(DPID id); +//extern void RemovePlayerGhost(DPID id); +//extern STRATEGYBLOCK *FindGhost(DPID Id, int obId); +//extern STRATEGYBLOCK *CreateNetGhost(DPID playerId, int objectId, VECTORCH *position, EULER* orientation, AVP_BEHAVIOUR_TYPE type, unsigned char IOType, unsigned char subtype); +extern void RemovePlayersGhosts(int id); +extern void RemovePlayerGhost(int id); +extern STRATEGYBLOCK *FindGhost(int Id, int obId); +extern STRATEGYBLOCK *CreateNetGhost(int playerId, int objectId, VECTORCH *position, EULER* orientation, AVP_BEHAVIOUR_TYPE type, unsigned char IOType, unsigned char subtype); extern void MakeGhostNear(STRATEGYBLOCK *sbPtr); extern void MakeGhostFar(STRATEGYBLOCK *sbPtr); extern void DamageNetworkGhost(STRATEGYBLOCK *sbPtr, DAMAGE_PROFILE *damage, int multiple, SECTION_DATA *section,VECTORCH* incoming); diff --git a/src/avp/win95/pldnet.h b/src/avp/win95/pldnet.h index 1ffc2cc..9ff1c5a 100644 --- a/src/avp/win95/pldnet.h +++ b/src/avp/win95/pldnet.h @@ -166,7 +166,9 @@ typedef enum netgame_connectiontype ----------------------------------------------------------------------*/ typedef struct netgame_playerdata { - DPID playerId; +// DPID playerId; + int playerId; + char name[NET_PLAYERNAMELENGTH]; NETGAME_CHARACTERTYPE characterType; NETGAME_SPECIALISTCHARACTERTYPE characterSubType; @@ -311,7 +313,9 @@ typedef struct netmessageheader typedef struct gamedescription_playerdata { - DPID playerId; +// DPID playerId; + int playerId; + unsigned char characterType:2; unsigned char characterSubType:6; unsigned char startFlag; @@ -467,7 +471,9 @@ typedef struct netmessage_frametimer typedef struct netmessage_playerkilled { int objectId; - DPID killerId; +// DPID killerId; + int killerId; + NETGAME_CHARACTERTYPE myType; //take character types at time of death , in case they change NETGAME_CHARACTERTYPE killerType; char weaponIcon; @@ -544,7 +550,9 @@ typedef struct netmessage_lobstate //stuff that isn't required typedef struct netmessage_lobdamaged_header { - DPID playerId; +// DPID playerId; + int playerId; + signed int objectId; short ammo_id:11; @@ -620,7 +628,9 @@ typedef struct netmessage_damage_direction typedef struct netmessage_lobdestroyed_request { - DPID playerId; +// DPID playerId; + int playerId; + signed int objectId; }NETMESSAGE_LOBDESTROYED_REQUEST; @@ -736,7 +746,8 @@ typedef struct netmessage_predatorsights signed int zPos: 23; signed int zOrient: 9; - DPID TargetID; + // DPID TargetID; + int TargetID; // 16 bytes (DPID 4 bytes?) @@ -744,7 +755,9 @@ typedef struct netmessage_predatorsights typedef struct netmessage_lobonfire { - DPID playerId; +// DPID playerId; + int playerId; + signed int objectId; }NETMESSAGE_LOBONFIRE; @@ -798,7 +811,9 @@ typedef struct netmessage_alienaikilled int death_time; int GibbFactor; - DPID killerId; +// DPID killerId; + int killerId; + int killCount; unsigned char AlienType: 2;//alien/predalien/praetorian @@ -814,16 +829,14 @@ typedef struct netmessage_faralienposition unsigned int indexIsModuleIndex:1; unsigned int alienType:2; - - -}NETMESSAGE_FARALIENPOSITION; +} NETMESSAGE_FARALIENPOSITION; typedef struct netmessage_gibbing { signed int Guid; int gibbFactor; int seed; -}NETMESSAGE_GIBBING; +} NETMESSAGE_GIBBING; typedef struct netmessage_spotaliensound { @@ -866,12 +879,16 @@ typedef struct netmessage_strategysynch //for messages that just require a player id typedef struct netmessage_playerid { - DPID playerID; +// DPID playerID; + int playerID; + }NETMESSAGE_PLAYERID; typedef struct netmessage_lms_restart { - DPID playerID; +// DPID playerID; + int playerID; + int seed; }NETMESSAGE_LMS_RESTART; @@ -912,13 +929,15 @@ extern void InitAVPNetGame(void); extern void NetCollectMessages(void); extern void NetSendMessages(void); extern void EndAVPNetGame(void); -extern int PlayerIdInPlayerList(DPID Id); +//extern int PlayerIdInPlayerList(DPID Id); +extern int PlayerIdInPlayerList(int Id); //use assignnewsbname instead of addnetgameobjectid #define AddNetGameObjectID AssignNewSBName extern void AddNetGameObjectID(STRATEGYBLOCK *sbPtr); extern void RecordFinalNetGameScores(void); extern void DoNetScoresForHostDeath(NETGAME_CHARACTERTYPE myType,NETGAME_CHARACTERTYPE killerType); -extern void RemovePlayerFromGame(DPID id); +//extern void RemovePlayerFromGame(DPID id); +extern void RemovePlayerFromGame(int id); extern int EmptySlotInPlayerList(void); extern void TeleportNetPlayerToAStartingPosition(STRATEGYBLOCK *playerSbPtr, int startOfGame); extern int AddUpPlayerFrags(int playerId); @@ -967,9 +986,11 @@ extern void AddNetMsg_SpotAlienSound(int soundCategory,int alienType,int pitch,V extern void AddNetMsg_LocalObjectDestroyed_Request(STRATEGYBLOCK *sbPtr); extern void AddNetMsg_ScoreChange(int killerIndex,int victimIndex); -extern void AddNetMsg_PlayerID(DPID playerID,unsigned char message); +//extern void AddNetMsg_PlayerID(DPID playerID,unsigned char message); +extern void AddNetMsg_PlayerID(int playerID,unsigned char message); extern void AddNetMsg_LastManStanding_RestartTimer(unsigned char time); -extern void AddNetMsg_LastManStanding_Restart(DPID alienID,int seed); +//extern void AddNetMsg_LastManStanding_Restart(DPID alienID,int seed); +extern void AddNetMsg_LastManStanding_Restart(int alienID,int seed); extern void AddNetMsg_CreateWeapon(char* objectName,int type,VECTORCH* location); @@ -1019,5 +1040,6 @@ extern int LobbiedGame; #ifdef __cplusplus } + #endif #endif diff --git a/src/avp/win95/vision.h b/src/avp/win95/vision.h index 0d7e523..0e2aa00 100644 --- a/src/avp/win95/vision.h +++ b/src/avp/win95/vision.h @@ -5,7 +5,7 @@ extern "C" { #endif -#include "d3_func.h" +//#include "d3_func.h" /*KJL**************************************************************************************** * P R O T O T Y P E S * @@ -61,14 +61,16 @@ struct D3DLightColourControl extern struct D3DLightColourControl d3d_light_ctrl; /* JH 6/4/97 - define a structure to control an alpha channelled coloured overlay */ -extern D3DINFO d3d; -#define d3d_overlays_available ((d3d.ThisDriver.dpcTriCaps.dwSrcBlendCaps & (D3DPBLENDCAPS_SRCALPHA|D3DPBLENDCAPS_INVSRCALPHA))==(D3DPBLENDCAPS_SRCALPHA|D3DPBLENDCAPS_INVSRCALPHA)) +//extern D3DINFO d3d; +//#define d3d_overlays_available ((d3d.ThisDriver.dpcTriCaps.dwSrcBlendCaps & (D3DPBLENDCAPS_SRCALPHA|D3DPBLENDCAPS_INVSRCALPHA))==(D3DPBLENDCAPS_SRCALPHA|D3DPBLENDCAPS_INVSRCALPHA)) +#define d3d_overlays_available 1 enum D3DOCC_Mode { OCCM_NORMAL, /* default behaviour - all other parms ignored */ OCCM_ON, /* r,g,b,alpha specify a colour of a light to use instead of white */ }; + struct D3DOverlayColourControl { enum D3DOCC_Mode ctrl; diff --git a/src/frustrum.c b/src/frustrum.c deleted file mode 100644 index d3e929d..0000000 --- a/src/frustrum.c +++ /dev/null @@ -1,1275 +0,0 @@ -/* - * KJL 15:13:43 7/17/97 - frustrum.c - * - * Contains all the functions connected - * to the view frustrum and clipping - * - */ -#include "3dc.h" -#include "module.h" -#include "inline.h" - -#include "stratdef.h" -#include "gamedef.h" - -#include "kshape.h" -#include "kzsort.h" -#include "frustrum.h" - -#include "particle.h" - -#define UseLocalAssert Yes -#include "ourasert.h" - -/*KJL**************************************************************************************** -* G L O B A L S * -****************************************************************************************KJL*/ -extern VECTORCH RotatedPts[]; - -extern DISPLAYBLOCK *Global_ODB_Ptr; -extern SHAPEHEADER *Global_ShapeHeaderPtr; -extern int *Global_ShapePoints; -extern int *Global_ShapeNormals; - -extern VECTORCH LocalView; - -#define FAR_Z_CLIP 0 -#define FAR_Z_CLIP_RANGE 49000 -/*KJL**************************************************************************************** -* P R O T O T Y P E S * -****************************************************************************************KJL*/ -/* GOURAUD POLYGON CLIPPING */ -void (*GouraudPolygon_ClipWithNegativeX)(void); -void (*GouraudPolygon_ClipWithPositiveY)(void); -void (*GouraudPolygon_ClipWithNegativeY)(void); -void (*GouraudPolygon_ClipWithPositiveX)(void); - -/* TEXTURED POLYGON CLIPPING */ -void (*TexturedPolygon_ClipWithNegativeX)(void); -void (*TexturedPolygon_ClipWithPositiveY)(void); -void (*TexturedPolygon_ClipWithNegativeY)(void); -void (*TexturedPolygon_ClipWithPositiveX)(void); - -/* GOURAUD TEXTURED POLYGON CLIPPING */ -void (*GouraudTexturedPolygon_ClipWithNegativeX)(void); -void (*GouraudTexturedPolygon_ClipWithPositiveY)(void); -void (*GouraudTexturedPolygon_ClipWithNegativeY)(void); -void (*GouraudTexturedPolygon_ClipWithPositiveX)(void); - -/* FRUSTRUM TESTS */ -int (*ObjectWithinFrustrum)(DISPLAYBLOCK *dbPtr); -int (*ObjectCompletelyWithinFrustrum)(DISPLAYBLOCK *dbPtr); -int (*VertexWithinFrustrum)(RENDERVERTEX *vertexPtr); -void (*TestVerticesWithFrustrum)(void); - - -static void GouraudPolygon_Norm_ClipWithNegativeX(void); -static void GouraudPolygon_Wide_ClipWithNegativeX(void); -static void GouraudPolygon_Norm_ClipWithPositiveY(void); -static void GouraudPolygon_Wide_ClipWithPositiveY(void); -static void GouraudPolygon_Norm_ClipWithNegativeY(void); -static void GouraudPolygon_Wide_ClipWithNegativeY(void); -static void GouraudPolygon_Norm_ClipWithPositiveX(void); -static void GouraudPolygon_Wide_ClipWithPositiveX(void); - -static void TexturedPolygon_Norm_ClipWithNegativeX(void); -static void TexturedPolygon_Wide_ClipWithNegativeX(void); -static void TexturedPolygon_Norm_ClipWithPositiveY(void); -static void TexturedPolygon_Wide_ClipWithPositiveY(void); -static void TexturedPolygon_Norm_ClipWithNegativeY(void); -static void TexturedPolygon_Wide_ClipWithNegativeY(void); -static void TexturedPolygon_Norm_ClipWithPositiveX(void); -static void TexturedPolygon_Wide_ClipWithPositiveX(void); - -static void GouraudTexturedPolygon_Norm_ClipWithNegativeX(void); -static void GouraudTexturedPolygon_Wide_ClipWithNegativeX(void); -static void GouraudTexturedPolygon_Norm_ClipWithPositiveY(void); -static void GouraudTexturedPolygon_Wide_ClipWithPositiveY(void); -static void GouraudTexturedPolygon_Norm_ClipWithNegativeY(void); -static void GouraudTexturedPolygon_Wide_ClipWithNegativeY(void); -static void GouraudTexturedPolygon_Norm_ClipWithPositiveX(void); -static void GouraudTexturedPolygon_Wide_ClipWithPositiveX(void); - -static int VertexWithin_Norm_Frustrum(RENDERVERTEX *vertexPtr); -static int VertexWithin_Wide_Frustrum(RENDERVERTEX *vertexPtr); -static int ObjectWithin_Norm_Frustrum(DISPLAYBLOCK *dbPtr); -static int ObjectWithin_Wide_Frustrum(DISPLAYBLOCK *dbPtr); -static int ObjectCompletelyWithin_Norm_Frustrum(DISPLAYBLOCK *dbPtr); -static int ObjectCompletelyWithin_Wide_Frustrum(DISPLAYBLOCK *dbPtr); -static void TestVerticesWith_Norm_Frustrum(void); -static void TestVerticesWith_Wide_Frustrum(void); - -/*KJL**************************************************************************************** -* F U N C T I O N S * -****************************************************************************************KJL*/ -void SetFrustrumType(enum FrustrumType frustrumType) -{ - switch (frustrumType) - { - default: - case FRUSTRUM_TYPE_NORMAL: - { - /* GOURAUD POLYGON CLIPPING */ - GouraudPolygon_ClipWithNegativeX = GouraudPolygon_Norm_ClipWithNegativeX; - GouraudPolygon_ClipWithPositiveY = GouraudPolygon_Norm_ClipWithPositiveY; - GouraudPolygon_ClipWithNegativeY = GouraudPolygon_Norm_ClipWithNegativeY; - GouraudPolygon_ClipWithPositiveX = GouraudPolygon_Norm_ClipWithPositiveX; - - /* TEXTURED POLYGON CLIPPING */ - TexturedPolygon_ClipWithNegativeX = TexturedPolygon_Norm_ClipWithNegativeX; - TexturedPolygon_ClipWithPositiveY = TexturedPolygon_Norm_ClipWithPositiveY; - TexturedPolygon_ClipWithNegativeY = TexturedPolygon_Norm_ClipWithNegativeY; - TexturedPolygon_ClipWithPositiveX = TexturedPolygon_Norm_ClipWithPositiveX; - - /* GOURAUD TEXTURED POLYGON CLIPPING */ - GouraudTexturedPolygon_ClipWithNegativeX = GouraudTexturedPolygon_Norm_ClipWithNegativeX; - GouraudTexturedPolygon_ClipWithPositiveY = GouraudTexturedPolygon_Norm_ClipWithPositiveY; - GouraudTexturedPolygon_ClipWithNegativeY = GouraudTexturedPolygon_Norm_ClipWithNegativeY; - GouraudTexturedPolygon_ClipWithPositiveX = GouraudTexturedPolygon_Norm_ClipWithPositiveX; - - /* FRUSTRUM TESTS */ - TestVerticesWithFrustrum = TestVerticesWith_Norm_Frustrum; - ObjectWithinFrustrum = ObjectWithin_Norm_Frustrum; - ObjectCompletelyWithinFrustrum = ObjectCompletelyWithin_Norm_Frustrum; - VertexWithinFrustrum = VertexWithin_Norm_Frustrum; - - break; - } - - case FRUSTRUM_TYPE_WIDE: - { - /* GOURAUD POLYGON CLIPPING */ - GouraudPolygon_ClipWithNegativeX = GouraudPolygon_Wide_ClipWithNegativeX; - GouraudPolygon_ClipWithPositiveY = GouraudPolygon_Wide_ClipWithPositiveY; - GouraudPolygon_ClipWithNegativeY = GouraudPolygon_Wide_ClipWithNegativeY; - GouraudPolygon_ClipWithPositiveX = GouraudPolygon_Wide_ClipWithPositiveX; - - /* TEXTURED POLYGON CLIPPING */ - TexturedPolygon_ClipWithNegativeX = TexturedPolygon_Wide_ClipWithNegativeX; - TexturedPolygon_ClipWithPositiveY = TexturedPolygon_Wide_ClipWithPositiveY; - TexturedPolygon_ClipWithNegativeY = TexturedPolygon_Wide_ClipWithNegativeY; - TexturedPolygon_ClipWithPositiveX = TexturedPolygon_Wide_ClipWithPositiveX; - - /* GOURAUD TEXTURED POLYGON CLIPPING */ - GouraudTexturedPolygon_ClipWithNegativeX = GouraudTexturedPolygon_Wide_ClipWithNegativeX; - GouraudTexturedPolygon_ClipWithPositiveY = GouraudTexturedPolygon_Wide_ClipWithPositiveY; - GouraudTexturedPolygon_ClipWithNegativeY = GouraudTexturedPolygon_Wide_ClipWithNegativeY; - GouraudTexturedPolygon_ClipWithPositiveX = GouraudTexturedPolygon_Wide_ClipWithPositiveX; - - /* FRUSTRUM TESTS */ - TestVerticesWithFrustrum = TestVerticesWith_Wide_Frustrum; - ObjectWithinFrustrum = ObjectWithin_Wide_Frustrum; - ObjectCompletelyWithinFrustrum = ObjectCompletelyWithin_Wide_Frustrum; - VertexWithinFrustrum = VertexWithin_Wide_Frustrum; - - break; - } - } -} - -/* clipping code macros - these are used as building blocks to assemble -clipping fns for different polygon types with the minimum of fuss */ -#define ZCLIPPINGVALUE 4 -//64 -#define Clip_Z_Test(v) (ZCLIPPINGVALUE <= (v)->Z) -#define Clip_NX_Test(v) (-(v)->X <= (v)->Z) -#define Clip_PX_Test(v) ((v)->X <= (v)->Z) -#define Clip_NY_Test(v) (-(v)->Y <= (v)->Z) -#define Clip_PY_Test(v) ((v)->Y <= (v)->Z) - - -#define Clip_LoopStart(b) \ - do \ - { \ - RENDERVERTEX *nextVertexPtr; \ - int nextVertexInside; \ - \ - /* setup pointer to next vertex, wrapping round if necessary */ \ - if (!--verticesLeft) \ - { \ - nextVertexPtr = (b); \ - } \ - else \ - { \ - nextVertexPtr = curVertexPtr+1; \ - } \ - \ - /* if current vertex is inside the plane, output it */ \ - if (curVertexInside) \ - { \ - numberOfPointsOutputted++; \ - *outputVerticesPtr++ = *curVertexPtr; \ - } \ - \ - /* test if next vertex is inside the plane */ \ - nextVertexInside = - -#define Clip_Z_OutputXYZ \ - /* if one is in, and the other is out, output a clipped vertex */ \ - if (nextVertexInside != curVertexInside) \ - { \ - int lambda; \ - \ - lambda = DIV_FIXED \ - ( \ - (ZCLIPPINGVALUE - curVertexPtr->Z), \ - (nextVertexPtr->Z - curVertexPtr->Z) \ - ); \ - \ - outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ - outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); \ - outputVerticesPtr->Z = ZCLIPPINGVALUE; - -#define Clip_NX_OutputXYZ \ - /* if one is in, and the other is out, output a clipped vertex */ \ - if (nextVertexInside != curVertexInside) \ - { \ - int lambda; \ - \ - lambda = DIV_FIXED \ - ( \ - (curVertexPtr->Z + curVertexPtr->X), \ - -(nextVertexPtr->X-curVertexPtr->X) - (nextVertexPtr->Z-curVertexPtr->Z) \ - ); \ - \ - outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ - outputVerticesPtr->Z = -outputVerticesPtr->X; \ - outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); - -#define Clip_PX_OutputXYZ \ - /* if one is in, and the other is out, output a clipped vertex */ \ - if (nextVertexInside != curVertexInside) \ - { \ - int lambda; \ - \ - lambda = DIV_FIXED \ - ( \ - (curVertexPtr->Z - curVertexPtr->X), \ - (nextVertexPtr->X-curVertexPtr->X) - (nextVertexPtr->Z-curVertexPtr->Z) \ - ); \ - \ - outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ - outputVerticesPtr->Z = outputVerticesPtr->X; \ - outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); - -#define Clip_NY_OutputXYZ \ - /* if one is in, and the other is out, output a clipped vertex */ \ - if (nextVertexInside != curVertexInside) \ - { \ - int lambda; \ - \ - lambda = DIV_FIXED \ - ( \ - (curVertexPtr->Z + curVertexPtr->Y), \ - -(nextVertexPtr->Y-curVertexPtr->Y) - (nextVertexPtr->Z-curVertexPtr->Z) \ - ); \ - \ - outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda,nextVertexPtr->Z-curVertexPtr->Z); \ - outputVerticesPtr->Y = -(outputVerticesPtr->Z); \ - outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); - -#define Clip_PY_OutputXYZ \ - /* if one is in, and the other is out, output a clipped vertex */ \ - if (nextVertexInside != curVertexInside) \ - { \ - int lambda; \ - \ - lambda = DIV_FIXED \ - ( \ - (curVertexPtr->Z - curVertexPtr->Y), \ - (nextVertexPtr->Y-curVertexPtr->Y) - (nextVertexPtr->Z-curVertexPtr->Z) \ - ); \ - \ - outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda,nextVertexPtr->Z-curVertexPtr->Z); \ - outputVerticesPtr->Y = (outputVerticesPtr->Z); \ - outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); - -#define Clip_OutputUV \ - outputVerticesPtr->U = curVertexPtr->U + MUL_FIXED(lambda,nextVertexPtr->U-curVertexPtr->U); \ - outputVerticesPtr->V = curVertexPtr->V + MUL_FIXED(lambda,nextVertexPtr->V-curVertexPtr->V); - -#define Clip_OutputI \ - outputVerticesPtr->A = curVertexPtr->A + MUL_FIXED(lambda,nextVertexPtr->A-curVertexPtr->A); \ - outputVerticesPtr->R = curVertexPtr->R + MUL_FIXED(lambda,nextVertexPtr->R-curVertexPtr->R); \ - outputVerticesPtr->G = curVertexPtr->G + MUL_FIXED(lambda,nextVertexPtr->G-curVertexPtr->G); \ - outputVerticesPtr->B = curVertexPtr->B + MUL_FIXED(lambda,nextVertexPtr->B-curVertexPtr->B); \ - outputVerticesPtr->SpecularR = curVertexPtr->SpecularR + MUL_FIXED(lambda,nextVertexPtr->SpecularR-curVertexPtr->SpecularR); \ - outputVerticesPtr->SpecularG = curVertexPtr->SpecularG + MUL_FIXED(lambda,nextVertexPtr->SpecularG-curVertexPtr->SpecularG); \ - outputVerticesPtr->SpecularB = curVertexPtr->SpecularB + MUL_FIXED(lambda,nextVertexPtr->SpecularB-curVertexPtr->SpecularB); - -#define Clip_LoopEnd(b) \ - numberOfPointsOutputted++; \ - outputVerticesPtr++; \ - } \ - \ - /* okay, now the current vertex becomes what was the next vertex */ \ - curVertexPtr = nextVertexPtr; \ - curVertexInside = nextVertexInside; \ - } \ - while(verticesLeft); \ - \ - RenderPolygon.NumberOfVertices = numberOfPointsOutputted; - -/* Wide screen versions of clip macros */ - -#define Clip_Wide_NX_Test(v) (-(v)->X <= (v)->Z*2) -#define Clip_Wide_PX_Test(v) ((v)->X <= (v)->Z*2) -#define Clip_Wide_NY_Test(v) (-(v)->Y <= (v)->Z*2) -#define Clip_Wide_PY_Test(v) ((v)->Y <= (v)->Z*2) -#define Clip_Wide_NX_OutputXYZ \ - /* if one is in, and the other is out, output a clipped vertex */ \ - if (nextVertexInside != curVertexInside) \ - { \ - int lambda; \ - \ - lambda = DIV_FIXED \ - ( \ - (-2*curVertexPtr->Z - curVertexPtr->X), \ - (nextVertexPtr->X-curVertexPtr->X) - (-2)*(nextVertexPtr->Z-curVertexPtr->Z) \ - ); \ - \ - outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ - outputVerticesPtr->Z = -outputVerticesPtr->X/2; \ - outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); - -#define Clip_Wide_PX_OutputXYZ \ - /* if one is in, and the other is out, output a clipped vertex */ \ - if (nextVertexInside != curVertexInside) \ - { \ - int lambda; \ - \ - lambda = DIV_FIXED \ - ( \ - (2*curVertexPtr->Z - curVertexPtr->X), \ - (nextVertexPtr->X-curVertexPtr->X) - 2*(nextVertexPtr->Z-curVertexPtr->Z) \ - ); \ - \ - outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ - outputVerticesPtr->Z = outputVerticesPtr->X/2; \ - outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); - -#define Clip_Wide_NY_OutputXYZ \ - /* if one is in, and the other is out, output a clipped vertex */ \ - if (nextVertexInside != curVertexInside) \ - { \ - int lambda; \ - \ - lambda = DIV_FIXED \ - ( \ - (2*curVertexPtr->Z + curVertexPtr->Y), \ - -(nextVertexPtr->Y-curVertexPtr->Y) - 2*(nextVertexPtr->Z-curVertexPtr->Z) \ - ); \ - \ - outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda,nextVertexPtr->Z-curVertexPtr->Z); \ - outputVerticesPtr->Y = -(outputVerticesPtr->Z*2); \ - outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); - -#define Clip_Wide_PY_OutputXYZ \ - /* if one is in, and the other is out, output a clipped vertex */ \ - if (nextVertexInside != curVertexInside) \ - { \ - int lambda; \ - \ - lambda = DIV_FIXED \ - ( \ - (2*curVertexPtr->Z - curVertexPtr->Y), \ - (nextVertexPtr->Y-curVertexPtr->Y) - 2*(nextVertexPtr->Z-curVertexPtr->Z) \ - ); \ - \ - outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda,nextVertexPtr->Z-curVertexPtr->Z); \ - outputVerticesPtr->Y = (outputVerticesPtr->Z*2); \ - outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); - - -/*KJL************** -* GOURAUD POLYGON * -**************KJL*/ - -/* Clip against Z plane */ -void GouraudPolygon_ClipWithZ(void) -{ - RENDERVERTEX *curVertexPtr = VerticesBuffer; - RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_Z_Test(curVertexPtr); - - Clip_LoopStart(VerticesBuffer) - Clip_Z_Test(nextVertexPtr); - Clip_Z_OutputXYZ - Clip_OutputI - Clip_LoopEnd((RenderPolygon.Vertices)) -} - - -/* Clip against negative X plane */ -static void GouraudPolygon_Norm_ClipWithNegativeX(void) -{ - RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); - RENDERVERTEX *outputVerticesPtr = VerticesBuffer; - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_NX_Test(curVertexPtr); - - Clip_LoopStart((RenderPolygon.Vertices)) - Clip_NX_Test(nextVertexPtr); - Clip_NX_OutputXYZ - Clip_OutputI - Clip_LoopEnd(VerticesBuffer) -} -static void GouraudPolygon_Wide_ClipWithNegativeX(void) -{ - RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); - RENDERVERTEX *outputVerticesPtr = VerticesBuffer; - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_Wide_NX_Test(curVertexPtr); - - Clip_LoopStart((RenderPolygon.Vertices)) - Clip_Wide_NX_Test(nextVertexPtr); - Clip_Wide_NX_OutputXYZ - Clip_OutputI - Clip_LoopEnd(VerticesBuffer) -} - -/* Clip against positive Y plane*/ -static void GouraudPolygon_Norm_ClipWithPositiveY(void) -{ - RENDERVERTEX *curVertexPtr = VerticesBuffer; - RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_PY_Test(curVertexPtr); - - Clip_LoopStart(VerticesBuffer) - Clip_PY_Test(nextVertexPtr); - Clip_PY_OutputXYZ - Clip_OutputI - Clip_LoopEnd((RenderPolygon.Vertices)) -} -static void GouraudPolygon_Wide_ClipWithPositiveY(void) -{ - RENDERVERTEX *curVertexPtr = VerticesBuffer; - RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_Wide_PY_Test(curVertexPtr); - - Clip_LoopStart(VerticesBuffer) - Clip_Wide_PY_Test(nextVertexPtr); - Clip_Wide_PY_OutputXYZ - Clip_OutputI - Clip_LoopEnd((RenderPolygon.Vertices)) -} - -/* Clip against negative Y plane*/ -static void GouraudPolygon_Norm_ClipWithNegativeY(void) -{ - RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); - RENDERVERTEX *outputVerticesPtr = VerticesBuffer; - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_NY_Test(curVertexPtr); - - Clip_LoopStart((RenderPolygon.Vertices)) - Clip_NY_Test(nextVertexPtr); - Clip_NY_OutputXYZ - Clip_OutputI - Clip_LoopEnd(VerticesBuffer) -} -static void GouraudPolygon_Wide_ClipWithNegativeY(void) -{ - RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); - RENDERVERTEX *outputVerticesPtr = VerticesBuffer; - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_Wide_NY_Test(curVertexPtr); - - Clip_LoopStart((RenderPolygon.Vertices)) - Clip_Wide_NY_Test(nextVertexPtr); - Clip_Wide_NY_OutputXYZ - Clip_OutputI - Clip_LoopEnd(VerticesBuffer) -} - -/* Clip against positive X plane */ -static void GouraudPolygon_Norm_ClipWithPositiveX(void) -{ - RENDERVERTEX *curVertexPtr = VerticesBuffer; - RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_PX_Test(curVertexPtr); - - Clip_LoopStart(VerticesBuffer) - Clip_PX_Test(nextVertexPtr); - Clip_PX_OutputXYZ - Clip_OutputI - Clip_LoopEnd((RenderPolygon.Vertices)) -} -static void GouraudPolygon_Wide_ClipWithPositiveX(void) -{ - RENDERVERTEX *curVertexPtr = VerticesBuffer; - RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_Wide_PX_Test(curVertexPtr); - - Clip_LoopStart(VerticesBuffer) - Clip_Wide_PX_Test(nextVertexPtr); - Clip_Wide_PX_OutputXYZ - Clip_OutputI - Clip_LoopEnd((RenderPolygon.Vertices)) -} - -/*KJL*************** -* TEXTURED POLYGON * -***************KJL*/ - -/* Clip against Z plane */ -void TexturedPolygon_ClipWithZ(void) -{ - RENDERVERTEX *curVertexPtr = VerticesBuffer; - RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_Z_Test(curVertexPtr); - - Clip_LoopStart(VerticesBuffer) - Clip_Z_Test(nextVertexPtr); - Clip_Z_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd((RenderPolygon.Vertices)) -} - -/* Clip against negative X plane */ -static void TexturedPolygon_Norm_ClipWithNegativeX(void) -{ - RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); - RENDERVERTEX *outputVerticesPtr = VerticesBuffer; - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_NX_Test(curVertexPtr); - - Clip_LoopStart((RenderPolygon.Vertices)) - Clip_NX_Test(nextVertexPtr); - Clip_NX_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd(VerticesBuffer) -} -static void TexturedPolygon_Wide_ClipWithNegativeX(void) -{ - RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); - RENDERVERTEX *outputVerticesPtr = VerticesBuffer; - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_Wide_NX_Test(curVertexPtr); - - Clip_LoopStart((RenderPolygon.Vertices)) - Clip_Wide_NX_Test(nextVertexPtr); - Clip_Wide_NX_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd(VerticesBuffer) -} - -/* Clip against positive Y plane*/ -static void TexturedPolygon_Norm_ClipWithPositiveY(void) -{ - RENDERVERTEX *curVertexPtr = VerticesBuffer; - RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_PY_Test(curVertexPtr); - - Clip_LoopStart(VerticesBuffer) - Clip_PY_Test(nextVertexPtr); - Clip_PY_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd((RenderPolygon.Vertices)) -} -static void TexturedPolygon_Wide_ClipWithPositiveY(void) -{ - RENDERVERTEX *curVertexPtr = VerticesBuffer; - RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_Wide_PY_Test(curVertexPtr); - - Clip_LoopStart(VerticesBuffer) - Clip_Wide_PY_Test(nextVertexPtr); - Clip_Wide_PY_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd((RenderPolygon.Vertices)) -} - -/* Clip against negative Y plane*/ -static void TexturedPolygon_Norm_ClipWithNegativeY(void) -{ - RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); - RENDERVERTEX *outputVerticesPtr = VerticesBuffer; - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_NY_Test(curVertexPtr); - - Clip_LoopStart((RenderPolygon.Vertices)) - Clip_NY_Test(nextVertexPtr); - Clip_NY_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd(VerticesBuffer) -} -static void TexturedPolygon_Wide_ClipWithNegativeY(void) -{ - RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); - RENDERVERTEX *outputVerticesPtr = VerticesBuffer; - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_Wide_NY_Test(curVertexPtr); - - Clip_LoopStart((RenderPolygon.Vertices)) - Clip_Wide_NY_Test(nextVertexPtr); - Clip_Wide_NY_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd(VerticesBuffer) -} - -/* Clip against positive X plane */ -static void TexturedPolygon_Norm_ClipWithPositiveX(void) -{ - RENDERVERTEX *curVertexPtr = VerticesBuffer; - RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_PX_Test(curVertexPtr); - - Clip_LoopStart(VerticesBuffer) - Clip_PX_Test(nextVertexPtr); - Clip_PX_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd((RenderPolygon.Vertices)) -} -static void TexturedPolygon_Wide_ClipWithPositiveX(void) -{ - RENDERVERTEX *curVertexPtr = VerticesBuffer; - RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_Wide_PX_Test(curVertexPtr); - - Clip_LoopStart(VerticesBuffer) - Clip_Wide_PX_Test(nextVertexPtr); - Clip_Wide_PX_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd((RenderPolygon.Vertices)) -} - - - - -/*KJL************************ -* GOURAUD TEXTURED POLYGONS * -************************KJL*/ - -/* Clip against Z plane */ -void GouraudTexturedPolygon_ClipWithZ(void) -{ - RENDERVERTEX *curVertexPtr = VerticesBuffer; - RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_Z_Test(curVertexPtr); - - Clip_LoopStart(VerticesBuffer) - Clip_Z_Test(nextVertexPtr); - Clip_Z_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd((RenderPolygon.Vertices)) -} - -/* Clip against negative X plane */ -static void GouraudTexturedPolygon_Norm_ClipWithNegativeX(void) -{ - RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); - RENDERVERTEX *outputVerticesPtr = VerticesBuffer; - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_NX_Test(curVertexPtr); - - Clip_LoopStart((RenderPolygon.Vertices)) - Clip_NX_Test(nextVertexPtr); - Clip_NX_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd(VerticesBuffer) -} -static void GouraudTexturedPolygon_Wide_ClipWithNegativeX(void) -{ - RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); - RENDERVERTEX *outputVerticesPtr = VerticesBuffer; - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_Wide_NX_Test(curVertexPtr); - - Clip_LoopStart((RenderPolygon.Vertices)) - Clip_Wide_NX_Test(nextVertexPtr); - Clip_Wide_NX_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd(VerticesBuffer) -} - -/* Clip against positive Y plane*/ -static void GouraudTexturedPolygon_Norm_ClipWithPositiveY(void) -{ - RENDERVERTEX *curVertexPtr = VerticesBuffer; - RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_PY_Test(curVertexPtr); - - Clip_LoopStart(VerticesBuffer) - Clip_PY_Test(nextVertexPtr); - Clip_PY_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd((RenderPolygon.Vertices)) -} -static void GouraudTexturedPolygon_Wide_ClipWithPositiveY(void) -{ - RENDERVERTEX *curVertexPtr = VerticesBuffer; - RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_Wide_PY_Test(curVertexPtr); - - Clip_LoopStart(VerticesBuffer) - Clip_Wide_PY_Test(nextVertexPtr); - Clip_Wide_PY_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd((RenderPolygon.Vertices)) -} - -/* Clip against negative Y plane*/ -static void GouraudTexturedPolygon_Norm_ClipWithNegativeY(void) -{ - RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); - RENDERVERTEX *outputVerticesPtr = VerticesBuffer; - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_NY_Test(curVertexPtr); - - Clip_LoopStart((RenderPolygon.Vertices)) - Clip_NY_Test(nextVertexPtr); - Clip_NY_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd(VerticesBuffer) -} -static void GouraudTexturedPolygon_Wide_ClipWithNegativeY(void) -{ - RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); - RENDERVERTEX *outputVerticesPtr = VerticesBuffer; - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_Wide_NY_Test(curVertexPtr); - - Clip_LoopStart((RenderPolygon.Vertices)) - Clip_Wide_NY_Test(nextVertexPtr); - Clip_Wide_NY_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd(VerticesBuffer) -} - -/* Clip against positive X plane */ -static void GouraudTexturedPolygon_Norm_ClipWithPositiveX(void) -{ - RENDERVERTEX *curVertexPtr = VerticesBuffer; - RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_PX_Test(curVertexPtr); - - Clip_LoopStart(VerticesBuffer) - Clip_PX_Test(nextVertexPtr); - Clip_PX_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd((RenderPolygon.Vertices)) -} -static void GouraudTexturedPolygon_Wide_ClipWithPositiveX(void) -{ - RENDERVERTEX *curVertexPtr = VerticesBuffer; - RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); - int verticesLeft = RenderPolygon.NumberOfVertices; - int numberOfPointsOutputted=0; - - int curVertexInside = Clip_Wide_PX_Test(curVertexPtr); - - Clip_LoopStart(VerticesBuffer) - Clip_Wide_PX_Test(nextVertexPtr); - Clip_Wide_PX_OutputXYZ - Clip_OutputUV - Clip_OutputI - Clip_LoopEnd((RenderPolygon.Vertices)) -} - - - - - - - -int PolygonWithinFrustrum(POLYHEADER *polyPtr) -{ - char inFrustrumFlag=0; - char noClippingFlag=INSIDE_FRUSTRUM; - int *vertexNumberPtr = &polyPtr->Poly1stPt; - - if (polyPtr->PolyFlags & iflag_notvis) return 0; - - RenderPolygon.NumberOfVertices=0; - while(*vertexNumberPtr != Term) - { - int vertexNumber = *vertexNumberPtr++; - - inFrustrumFlag |= FrustrumFlagForVertex[vertexNumber]; - noClippingFlag &= FrustrumFlagForVertex[vertexNumber]; - - /* count the number of points in the polygon; this is used for all the loops that follow */ - RenderPolygon.NumberOfVertices++; - } - - if (inFrustrumFlag != INSIDE_FRUSTRUM) return 0; - - /* at this point we know that the poly is inside the view frustrum */ - - /* if not a sprite, test direction of poly */ - if (!( (Global_ShapeHeaderPtr->shapeflags&ShapeFlag_Sprite) || (polyPtr->PolyFlags & iflag_no_bfc) )) - { - VECTORCH pop; - VECTORCH *normalPtr = (VECTORCH*)(Global_ShapeNormals + polyPtr->PolyNormalIndex); - - #if 1 - if(Global_ODB_Ptr->ObMorphCtrl) - { - extern MORPHDISPLAY MorphDisplay; - SHAPEHEADER *shape1Ptr; - VECTORCH *shape1PointsPtr; - VECTORCH *shape2PointsPtr; - - /* Set up the morph data */ - GetMorphDisplay(&MorphDisplay, Global_ODB_Ptr); - - shape1Ptr = MorphDisplay.md_sptr1; - - if(MorphDisplay.md_lerp == 0x0000) - { - shape1PointsPtr = (VECTORCH *)*shape1Ptr->points; - pop = shape1PointsPtr[polyPtr->Poly1stPt]; - - } - else if(MorphDisplay.md_lerp == 0xffff) - { - SHAPEHEADER *shape2Ptr = MorphDisplay.md_sptr2; - - shape2PointsPtr = (VECTORCH *)*shape2Ptr->points; - pop = shape2PointsPtr[polyPtr->Poly1stPt]; - } - else - { - SHAPEHEADER *shape2Ptr = MorphDisplay.md_sptr2; - - shape1PointsPtr = (VECTORCH *)(*shape1Ptr->points); - shape2PointsPtr = (VECTORCH *)(*shape2Ptr->points); - - { - VECTORCH vertex1 = shape1PointsPtr[polyPtr->Poly1stPt]; - VECTORCH vertex2 = shape2PointsPtr[polyPtr->Poly1stPt]; - - if( (vertex1.vx == vertex2.vx && vertex1.vy == vertex2.vy && vertex1.vz == vertex2.vz) ) - { - pop = vertex1; - } - else - { - /* KJL 15:27:20 05/22/97 - I've changed this to speed things up, If a vertex - component has a magnitude greater than 32768 things will go wrong. */ - pop.vx = vertex1.vx + (((vertex2.vx-vertex1.vx)*MorphDisplay.md_lerp)>>16); - pop.vy = vertex1.vy + (((vertex2.vy-vertex1.vy)*MorphDisplay.md_lerp)>>16); - pop.vz = vertex1.vz + (((vertex2.vz-vertex1.vz)*MorphDisplay.md_lerp)>>16); - } - } - } - } - else - #endif - { - /* Get the 1st polygon point as the POP */ - VECTORCH *pointsArray = (VECTORCH*)(Global_ShapePoints); - pop = pointsArray[polyPtr->Poly1stPt]; - } - pop.vx -= LocalView.vx; - pop.vy -= LocalView.vy; - pop.vz -= LocalView.vz; - - if (Dot(&pop, normalPtr)>0) return 0; - } - - if (noClippingFlag == INSIDE_FRUSTRUM) return 2; - - /* yes, we need to draw poly */ - return 1; -} - -int PolygonShouldBeDrawn(POLYHEADER *polyPtr) -{ - - /* at this point we know that the poly is inside the view frustrum */ - if (polyPtr->PolyFlags & iflag_notvis) return 0; - - #if 1 - /* if not a sprite, test direction of poly */ - if (!( (Global_ShapeHeaderPtr->shapeflags&ShapeFlag_Sprite) || (polyPtr->PolyFlags & iflag_no_bfc) )) - { - /* KJL 16:49:14 7/10/97 - - - ***** MORPHED NORMALS SUPPORT NOT YET ADDED ***** - - */ - VECTORCH pop; - VECTORCH *normalPtr = (VECTORCH*)(Global_ShapeNormals + polyPtr->PolyNormalIndex); - VECTORCH *pointsArray = (VECTORCH*)(Global_ShapePoints); - /* Get the 1st polygon point as the POP */ - - pop.vx = pointsArray[polyPtr->Poly1stPt].vx - LocalView.vx; - pop.vy = pointsArray[polyPtr->Poly1stPt].vy - LocalView.vy; - pop.vz = pointsArray[polyPtr->Poly1stPt].vz - LocalView.vz; - - if (Dot(&pop, normalPtr)>0) return 0; - } - #endif - #if 0 - { - int *vertexNumberPtr = &polyPtr->Poly1stPt; - RenderPolygon.NumberOfVertices=0; - while(*vertexNumberPtr++ != Term) - { - /* count the number of points in the polygon; this is used for all the loops that follow */ - RenderPolygon.NumberOfVertices++; - } - } - #elif 0 - RenderPolygon.NumberOfVertices = 3; - #else - { - int *vertexNumberPtr = &polyPtr->Poly1stPt; - if (vertexNumberPtr[3] == Term) - { - RenderPolygon.NumberOfVertices = 3; - } - else - { - RenderPolygon.NumberOfVertices = 4; - } - } - #endif - - return 2; -} - -/* KJL 16:18:59 7/7/97 - simple vertex test to be used in first -pass of subdividing code */ -static int VertexWithin_Norm_Frustrum(RENDERVERTEX *vertexPtr) -{ - int vertexFlag = 0; - - if(Clip_Z_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; - if(Clip_PX_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; - if(Clip_NX_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; - if(Clip_PY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; - if(Clip_NY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; - - return vertexFlag; -} - -static int VertexWithin_Wide_Frustrum(RENDERVERTEX *vertexPtr) -{ - int vertexFlag = 0; - - if(Clip_Z_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; - if(Clip_Wide_PX_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; - if(Clip_Wide_NX_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; - if(Clip_Wide_PY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; - if(Clip_Wide_NY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; - - return vertexFlag; -} - - -/* KJL 15:32:52 7/17/97 - Test to see if an object is in the view frustrum */ -static int ObjectWithin_Norm_Frustrum(DISPLAYBLOCK *dbPtr) -{ - // LOCALASSERT(dbPtr->ObShapeData->shaperadius); - -#if FAR_Z_CLIP - if(dbPtr->ObView.vz-dbPtr->ObShapeData->shaperadius<=FAR_Z_CLIP_RANGE) -#endif - if (dbPtr->ObView.vz+dbPtr->ObShapeData->shaperadius>=ZCLIPPINGVALUE) - { - /* scale radius by square root of 2 */ - int radius = MUL_FIXED(92682,dbPtr->ObShapeData->shaperadius); - - if ((dbPtr->ObView.vx-dbPtr->ObView.vz)<=radius) - if ((-dbPtr->ObView.vx-dbPtr->ObView.vz)<=radius) - if ((dbPtr->ObView.vy-dbPtr->ObView.vz)<=radius) - if ((-dbPtr->ObView.vy-dbPtr->ObView.vz)<=radius) - return 1; - } - return 0; -} -static int ObjectCompletelyWithin_Norm_Frustrum(DISPLAYBLOCK *dbPtr) -{ - // LOCALASSERT(dbPtr->ObShapeData->shaperadius); - if (dbPtr->ObView.vz-dbPtr->ObShapeData->shaperadius>=ZCLIPPINGVALUE) - { - /* scale radius by square root of 2 */ - int radius = MUL_FIXED(92682,dbPtr->ObShapeData->shaperadius); - - if ((dbPtr->ObView.vz-dbPtr->ObView.vx)>=radius) - if ((dbPtr->ObView.vz+dbPtr->ObView.vx)>=radius) - if ((dbPtr->ObView.vz-dbPtr->ObView.vy)>=radius) - if ((dbPtr->ObView.vz+dbPtr->ObView.vy)>=radius) - return 1; - } - return 0; -} -static int ObjectCompletelyWithin_Wide_Frustrum(DISPLAYBLOCK *dbPtr) -{ - return 0; -} - -static int ObjectWithin_Wide_Frustrum(DISPLAYBLOCK *dbPtr) -{ - if (dbPtr->ObView.vz+dbPtr->ObShapeData->shaperadius>=ZCLIPPINGVALUE) - { - /* scale radius by square root of 5 */ - int radius = MUL_FIXED(146543,dbPtr->ObShapeData->shaperadius); - - if ((dbPtr->ObView.vx-2*dbPtr->ObView.vz)<=radius) - if ((-dbPtr->ObView.vx-2*dbPtr->ObView.vz)<=radius) - if ((dbPtr->ObView.vy-2*dbPtr->ObView.vz)<=radius) - if ((-dbPtr->ObView.vy-2*dbPtr->ObView.vz)<=radius) - return 1; - } - return 0; -} - - -char FrustrumFlagForVertex[maxrotpts]; - -void TestVerticesWith_Norm_Frustrum(void) -{ - int v = Global_ShapeHeaderPtr->numpoints; - - GLOBALASSERT(v>0); - - while(v--) - { - char vertexFlag = 0; - -#if FAR_Z_CLIP - if(ZCLIPPINGVALUE <= RotatedPts[v].vz && RotatedPts[v].vz<=FAR_Z_CLIP_RANGE) -#else - if(ZCLIPPINGVALUE <= RotatedPts[v].vz) -#endif - vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; - - if(-RotatedPts[v].vx <= RotatedPts[v].vz) - vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; - - if(RotatedPts[v].vx <= RotatedPts[v].vz) - vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; - - if(-RotatedPts[v].vy <= RotatedPts[v].vz) - vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; - - if(RotatedPts[v].vy <= RotatedPts[v].vz) - vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; - - FrustrumFlagForVertex[v] = vertexFlag; - } -} -void TestVerticesWith_Wide_Frustrum(void) -{ - int v = Global_ShapeHeaderPtr->numpoints; - - GLOBALASSERT(v>0); - - while(v--) - { - char vertexFlag = 0; - - if(ZCLIPPINGVALUE <= RotatedPts[v].vz) - vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; - - if(-RotatedPts[v].vx <= RotatedPts[v].vz*2) - vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; - - if(RotatedPts[v].vx <= RotatedPts[v].vz*2) - vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; - - if(-RotatedPts[v].vy <= RotatedPts[v].vz*2) - vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; - - if(RotatedPts[v].vy <= RotatedPts[v].vz*2) - vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; - - FrustrumFlagForVertex[v] = vertexFlag; - } -} - - - -int DecalWithinFrustrum(DECAL *decalPtr) -{ - char inFrustrumFlag; - char noClippingFlag; - - if(ModuleCurrVisArray[decalPtr->ModuleIndex] != 2) return 0; - - inFrustrumFlag=0; - noClippingFlag=INSIDE_FRUSTRUM; - - { - int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[0]); - inFrustrumFlag |= vertexFlag; - noClippingFlag &= vertexFlag; - } - { - int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[1]); - inFrustrumFlag |= vertexFlag; - noClippingFlag &= vertexFlag; - } - { - int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[2]); - inFrustrumFlag |= vertexFlag; - noClippingFlag &= vertexFlag; - } - { - int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[3]); - inFrustrumFlag |= vertexFlag; - noClippingFlag &= vertexFlag; - } - - if (inFrustrumFlag != INSIDE_FRUSTRUM) return 0; - if (noClippingFlag == INSIDE_FRUSTRUM) return 2; - - /* yes, we need to draw poly */ - return 1; -} - -int QuadWithinFrustrum(void) -{ - char inFrustrumFlag; - char noClippingFlag; - - inFrustrumFlag=0; - noClippingFlag=INSIDE_FRUSTRUM; - - { - int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[0]); - inFrustrumFlag |= vertexFlag; - noClippingFlag &= vertexFlag; - } - { - int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[1]); - inFrustrumFlag |= vertexFlag; - noClippingFlag &= vertexFlag; - } - { - int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[2]); - inFrustrumFlag |= vertexFlag; - noClippingFlag &= vertexFlag; - } - { - int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[3]); - inFrustrumFlag |= vertexFlag; - noClippingFlag &= vertexFlag; - } - - if (inFrustrumFlag != INSIDE_FRUSTRUM) return 0; - if (noClippingFlag == INSIDE_FRUSTRUM) return 2; - - /* yes, we need to draw poly */ - return 1; -} - -int TriangleWithinFrustrum(void) -{ - char inFrustrumFlag; - char noClippingFlag; - - inFrustrumFlag=0; - noClippingFlag=INSIDE_FRUSTRUM; - - { - int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[0]); - inFrustrumFlag |= vertexFlag; - noClippingFlag &= vertexFlag; - } - { - int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[1]); - inFrustrumFlag |= vertexFlag; - noClippingFlag &= vertexFlag; - } - { - int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[2]); - inFrustrumFlag |= vertexFlag; - noClippingFlag &= vertexFlag; - } - - if (inFrustrumFlag != INSIDE_FRUSTRUM) return 0; - if (noClippingFlag == INSIDE_FRUSTRUM) return 2; - - /* yes, we need to draw poly */ - return 1; -} - - \ No newline at end of file diff --git a/src/frustrum.h b/src/frustrum.h deleted file mode 100644 index faf7795..0000000 --- a/src/frustrum.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef _frustrum_h_ /* Is this your first time? */ -#define _frustrum_h_ 1 - -#include "kshape.h" -/* - * KJL 15:13:43 7/17/97 - frustrum.h - * - * function prototypes & pointers for things connected - * to the view frustrum and clipping - * - */ - -enum FrustrumType -{ - FRUSTRUM_TYPE_NORMAL, - FRUSTRUM_TYPE_WIDE -}; - -extern void SetFrustrumType(enum FrustrumType frustrumType); - -/* GOURAUD POLYGON CLIPPING */ -extern void GouraudPolygon_ClipWithZ(void); -extern void (*GouraudPolygon_ClipWithNegativeX)(void); -extern void (*GouraudPolygon_ClipWithPositiveY)(void); -extern void (*GouraudPolygon_ClipWithNegativeY)(void); -extern void (*GouraudPolygon_ClipWithPositiveX)(void); - -/* TEXTURED POLYGON CLIPPING */ -extern void TexturedPolygon_ClipWithZ(void); -extern void (*TexturedPolygon_ClipWithNegativeX)(void); -extern void (*TexturedPolygon_ClipWithPositiveY)(void); -extern void (*TexturedPolygon_ClipWithNegativeY)(void); -extern void (*TexturedPolygon_ClipWithPositiveX)(void); - -/* GOURAUD TEXTURED POLYGON CLIPPING */ -extern void GouraudTexturedPolygon_ClipWithZ(void); -extern void (*GouraudTexturedPolygon_ClipWithNegativeX)(void); -extern void (*GouraudTexturedPolygon_ClipWithPositiveY)(void); -extern void (*GouraudTexturedPolygon_ClipWithNegativeY)(void); -extern void (*GouraudTexturedPolygon_ClipWithPositiveX)(void); - -/* FRUSTRUM TESTS */ -extern int PolygonWithinFrustrum(POLYHEADER *polyPtr); -extern int PolygonShouldBeDrawn(POLYHEADER *polyPtr); -extern int (*ObjectWithinFrustrum)(DISPLAYBLOCK *dbPtr); -extern int (*ObjectCompletelyWithinFrustrum)(DISPLAYBLOCK *dbPtr); -extern int (*VertexWithinFrustrum)(RENDERVERTEX *vertexPtr); -extern void (*TestVerticesWithFrustrum)(void); - -extern int DecalWithinFrustrum(DECAL *decalPtr); -extern int QuadWithinFrustrum(void); -extern int TriangleWithinFrustrum(void); - - -/* pass a pointer to a vertex to be tested; results are returned in an int, -using the following defines */ -#define INSIDE_FRUSTRUM_Z_PLANE 1 -#define INSIDE_FRUSTRUM_PX_PLANE 2 -#define INSIDE_FRUSTRUM_NX_PLANE 4 -#define INSIDE_FRUSTRUM_PY_PLANE 8 -#define INSIDE_FRUSTRUM_NY_PLANE 16 -#define INSIDE_FRUSTRUM 31 - -extern char FrustrumFlagForVertex[maxrotpts]; - -#define USE_FOV_53 0 - -#endif diff --git a/src/frustum.c b/src/frustum.c new file mode 100644 index 0000000..a2bc3c1 --- /dev/null +++ b/src/frustum.c @@ -0,0 +1,1275 @@ +/* + * KJL 15:13:43 7/17/97 - frustrum.c + * + * Contains all the functions connected + * to the view frustrum and clipping + * + */ +#include "3dc.h" +#include "module.h" +#include "inline.h" + +#include "stratdef.h" +#include "gamedef.h" + +#include "kshape.h" +#include "kzsort.h" +#include "frustum.h" + +#include "particle.h" + +#define UseLocalAssert Yes +#include "ourasert.h" + +/*KJL**************************************************************************************** +* G L O B A L S * +****************************************************************************************KJL*/ +extern VECTORCH RotatedPts[]; + +extern DISPLAYBLOCK *Global_ODB_Ptr; +extern SHAPEHEADER *Global_ShapeHeaderPtr; +extern int *Global_ShapePoints; +extern int *Global_ShapeNormals; + +extern VECTORCH LocalView; + +#define FAR_Z_CLIP 0 +#define FAR_Z_CLIP_RANGE 49000 +/*KJL**************************************************************************************** +* P R O T O T Y P E S * +****************************************************************************************KJL*/ +/* GOURAUD POLYGON CLIPPING */ +void (*GouraudPolygon_ClipWithNegativeX)(void); +void (*GouraudPolygon_ClipWithPositiveY)(void); +void (*GouraudPolygon_ClipWithNegativeY)(void); +void (*GouraudPolygon_ClipWithPositiveX)(void); + +/* TEXTURED POLYGON CLIPPING */ +void (*TexturedPolygon_ClipWithNegativeX)(void); +void (*TexturedPolygon_ClipWithPositiveY)(void); +void (*TexturedPolygon_ClipWithNegativeY)(void); +void (*TexturedPolygon_ClipWithPositiveX)(void); + +/* GOURAUD TEXTURED POLYGON CLIPPING */ +void (*GouraudTexturedPolygon_ClipWithNegativeX)(void); +void (*GouraudTexturedPolygon_ClipWithPositiveY)(void); +void (*GouraudTexturedPolygon_ClipWithNegativeY)(void); +void (*GouraudTexturedPolygon_ClipWithPositiveX)(void); + +/* FRUSTRUM TESTS */ +int (*ObjectWithinFrustrum)(DISPLAYBLOCK *dbPtr); +int (*ObjectCompletelyWithinFrustrum)(DISPLAYBLOCK *dbPtr); +int (*VertexWithinFrustrum)(RENDERVERTEX *vertexPtr); +void (*TestVerticesWithFrustrum)(void); + + +static void GouraudPolygon_Norm_ClipWithNegativeX(void); +static void GouraudPolygon_Wide_ClipWithNegativeX(void); +static void GouraudPolygon_Norm_ClipWithPositiveY(void); +static void GouraudPolygon_Wide_ClipWithPositiveY(void); +static void GouraudPolygon_Norm_ClipWithNegativeY(void); +static void GouraudPolygon_Wide_ClipWithNegativeY(void); +static void GouraudPolygon_Norm_ClipWithPositiveX(void); +static void GouraudPolygon_Wide_ClipWithPositiveX(void); + +static void TexturedPolygon_Norm_ClipWithNegativeX(void); +static void TexturedPolygon_Wide_ClipWithNegativeX(void); +static void TexturedPolygon_Norm_ClipWithPositiveY(void); +static void TexturedPolygon_Wide_ClipWithPositiveY(void); +static void TexturedPolygon_Norm_ClipWithNegativeY(void); +static void TexturedPolygon_Wide_ClipWithNegativeY(void); +static void TexturedPolygon_Norm_ClipWithPositiveX(void); +static void TexturedPolygon_Wide_ClipWithPositiveX(void); + +static void GouraudTexturedPolygon_Norm_ClipWithNegativeX(void); +static void GouraudTexturedPolygon_Wide_ClipWithNegativeX(void); +static void GouraudTexturedPolygon_Norm_ClipWithPositiveY(void); +static void GouraudTexturedPolygon_Wide_ClipWithPositiveY(void); +static void GouraudTexturedPolygon_Norm_ClipWithNegativeY(void); +static void GouraudTexturedPolygon_Wide_ClipWithNegativeY(void); +static void GouraudTexturedPolygon_Norm_ClipWithPositiveX(void); +static void GouraudTexturedPolygon_Wide_ClipWithPositiveX(void); + +static int VertexWithin_Norm_Frustrum(RENDERVERTEX *vertexPtr); +static int VertexWithin_Wide_Frustrum(RENDERVERTEX *vertexPtr); +static int ObjectWithin_Norm_Frustrum(DISPLAYBLOCK *dbPtr); +static int ObjectWithin_Wide_Frustrum(DISPLAYBLOCK *dbPtr); +static int ObjectCompletelyWithin_Norm_Frustrum(DISPLAYBLOCK *dbPtr); +static int ObjectCompletelyWithin_Wide_Frustrum(DISPLAYBLOCK *dbPtr); +static void TestVerticesWith_Norm_Frustrum(void); +static void TestVerticesWith_Wide_Frustrum(void); + +/*KJL**************************************************************************************** +* F U N C T I O N S * +****************************************************************************************KJL*/ +void SetFrustrumType(enum FrustrumType frustrumType) +{ + switch (frustrumType) + { + default: + case FRUSTRUM_TYPE_NORMAL: + { + /* GOURAUD POLYGON CLIPPING */ + GouraudPolygon_ClipWithNegativeX = GouraudPolygon_Norm_ClipWithNegativeX; + GouraudPolygon_ClipWithPositiveY = GouraudPolygon_Norm_ClipWithPositiveY; + GouraudPolygon_ClipWithNegativeY = GouraudPolygon_Norm_ClipWithNegativeY; + GouraudPolygon_ClipWithPositiveX = GouraudPolygon_Norm_ClipWithPositiveX; + + /* TEXTURED POLYGON CLIPPING */ + TexturedPolygon_ClipWithNegativeX = TexturedPolygon_Norm_ClipWithNegativeX; + TexturedPolygon_ClipWithPositiveY = TexturedPolygon_Norm_ClipWithPositiveY; + TexturedPolygon_ClipWithNegativeY = TexturedPolygon_Norm_ClipWithNegativeY; + TexturedPolygon_ClipWithPositiveX = TexturedPolygon_Norm_ClipWithPositiveX; + + /* GOURAUD TEXTURED POLYGON CLIPPING */ + GouraudTexturedPolygon_ClipWithNegativeX = GouraudTexturedPolygon_Norm_ClipWithNegativeX; + GouraudTexturedPolygon_ClipWithPositiveY = GouraudTexturedPolygon_Norm_ClipWithPositiveY; + GouraudTexturedPolygon_ClipWithNegativeY = GouraudTexturedPolygon_Norm_ClipWithNegativeY; + GouraudTexturedPolygon_ClipWithPositiveX = GouraudTexturedPolygon_Norm_ClipWithPositiveX; + + /* FRUSTRUM TESTS */ + TestVerticesWithFrustrum = TestVerticesWith_Norm_Frustrum; + ObjectWithinFrustrum = ObjectWithin_Norm_Frustrum; + ObjectCompletelyWithinFrustrum = ObjectCompletelyWithin_Norm_Frustrum; + VertexWithinFrustrum = VertexWithin_Norm_Frustrum; + + break; + } + + case FRUSTRUM_TYPE_WIDE: + { + /* GOURAUD POLYGON CLIPPING */ + GouraudPolygon_ClipWithNegativeX = GouraudPolygon_Wide_ClipWithNegativeX; + GouraudPolygon_ClipWithPositiveY = GouraudPolygon_Wide_ClipWithPositiveY; + GouraudPolygon_ClipWithNegativeY = GouraudPolygon_Wide_ClipWithNegativeY; + GouraudPolygon_ClipWithPositiveX = GouraudPolygon_Wide_ClipWithPositiveX; + + /* TEXTURED POLYGON CLIPPING */ + TexturedPolygon_ClipWithNegativeX = TexturedPolygon_Wide_ClipWithNegativeX; + TexturedPolygon_ClipWithPositiveY = TexturedPolygon_Wide_ClipWithPositiveY; + TexturedPolygon_ClipWithNegativeY = TexturedPolygon_Wide_ClipWithNegativeY; + TexturedPolygon_ClipWithPositiveX = TexturedPolygon_Wide_ClipWithPositiveX; + + /* GOURAUD TEXTURED POLYGON CLIPPING */ + GouraudTexturedPolygon_ClipWithNegativeX = GouraudTexturedPolygon_Wide_ClipWithNegativeX; + GouraudTexturedPolygon_ClipWithPositiveY = GouraudTexturedPolygon_Wide_ClipWithPositiveY; + GouraudTexturedPolygon_ClipWithNegativeY = GouraudTexturedPolygon_Wide_ClipWithNegativeY; + GouraudTexturedPolygon_ClipWithPositiveX = GouraudTexturedPolygon_Wide_ClipWithPositiveX; + + /* FRUSTRUM TESTS */ + TestVerticesWithFrustrum = TestVerticesWith_Wide_Frustrum; + ObjectWithinFrustrum = ObjectWithin_Wide_Frustrum; + ObjectCompletelyWithinFrustrum = ObjectCompletelyWithin_Wide_Frustrum; + VertexWithinFrustrum = VertexWithin_Wide_Frustrum; + + break; + } + } +} + +/* clipping code macros - these are used as building blocks to assemble +clipping fns for different polygon types with the minimum of fuss */ +#define ZCLIPPINGVALUE 4 +//64 +#define Clip_Z_Test(v) (ZCLIPPINGVALUE <= (v)->Z) +#define Clip_NX_Test(v) (-(v)->X <= (v)->Z) +#define Clip_PX_Test(v) ((v)->X <= (v)->Z) +#define Clip_NY_Test(v) (-(v)->Y <= (v)->Z) +#define Clip_PY_Test(v) ((v)->Y <= (v)->Z) + + +#define Clip_LoopStart(b) \ + do \ + { \ + RENDERVERTEX *nextVertexPtr; \ + int nextVertexInside; \ + \ + /* setup pointer to next vertex, wrapping round if necessary */ \ + if (!--verticesLeft) \ + { \ + nextVertexPtr = (b); \ + } \ + else \ + { \ + nextVertexPtr = curVertexPtr+1; \ + } \ + \ + /* if current vertex is inside the plane, output it */ \ + if (curVertexInside) \ + { \ + numberOfPointsOutputted++; \ + *outputVerticesPtr++ = *curVertexPtr; \ + } \ + \ + /* test if next vertex is inside the plane */ \ + nextVertexInside = + +#define Clip_Z_OutputXYZ \ + /* if one is in, and the other is out, output a clipped vertex */ \ + if (nextVertexInside != curVertexInside) \ + { \ + int lambda; \ + \ + lambda = DIV_FIXED \ + ( \ + (ZCLIPPINGVALUE - curVertexPtr->Z), \ + (nextVertexPtr->Z - curVertexPtr->Z) \ + ); \ + \ + outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ + outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); \ + outputVerticesPtr->Z = ZCLIPPINGVALUE; + +#define Clip_NX_OutputXYZ \ + /* if one is in, and the other is out, output a clipped vertex */ \ + if (nextVertexInside != curVertexInside) \ + { \ + int lambda; \ + \ + lambda = DIV_FIXED \ + ( \ + (curVertexPtr->Z + curVertexPtr->X), \ + -(nextVertexPtr->X-curVertexPtr->X) - (nextVertexPtr->Z-curVertexPtr->Z) \ + ); \ + \ + outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ + outputVerticesPtr->Z = -outputVerticesPtr->X; \ + outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); + +#define Clip_PX_OutputXYZ \ + /* if one is in, and the other is out, output a clipped vertex */ \ + if (nextVertexInside != curVertexInside) \ + { \ + int lambda; \ + \ + lambda = DIV_FIXED \ + ( \ + (curVertexPtr->Z - curVertexPtr->X), \ + (nextVertexPtr->X-curVertexPtr->X) - (nextVertexPtr->Z-curVertexPtr->Z) \ + ); \ + \ + outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ + outputVerticesPtr->Z = outputVerticesPtr->X; \ + outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); + +#define Clip_NY_OutputXYZ \ + /* if one is in, and the other is out, output a clipped vertex */ \ + if (nextVertexInside != curVertexInside) \ + { \ + int lambda; \ + \ + lambda = DIV_FIXED \ + ( \ + (curVertexPtr->Z + curVertexPtr->Y), \ + -(nextVertexPtr->Y-curVertexPtr->Y) - (nextVertexPtr->Z-curVertexPtr->Z) \ + ); \ + \ + outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda,nextVertexPtr->Z-curVertexPtr->Z); \ + outputVerticesPtr->Y = -(outputVerticesPtr->Z); \ + outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); + +#define Clip_PY_OutputXYZ \ + /* if one is in, and the other is out, output a clipped vertex */ \ + if (nextVertexInside != curVertexInside) \ + { \ + int lambda; \ + \ + lambda = DIV_FIXED \ + ( \ + (curVertexPtr->Z - curVertexPtr->Y), \ + (nextVertexPtr->Y-curVertexPtr->Y) - (nextVertexPtr->Z-curVertexPtr->Z) \ + ); \ + \ + outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda,nextVertexPtr->Z-curVertexPtr->Z); \ + outputVerticesPtr->Y = (outputVerticesPtr->Z); \ + outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); + +#define Clip_OutputUV \ + outputVerticesPtr->U = curVertexPtr->U + MUL_FIXED(lambda,nextVertexPtr->U-curVertexPtr->U); \ + outputVerticesPtr->V = curVertexPtr->V + MUL_FIXED(lambda,nextVertexPtr->V-curVertexPtr->V); + +#define Clip_OutputI \ + outputVerticesPtr->A = curVertexPtr->A + MUL_FIXED(lambda,nextVertexPtr->A-curVertexPtr->A); \ + outputVerticesPtr->R = curVertexPtr->R + MUL_FIXED(lambda,nextVertexPtr->R-curVertexPtr->R); \ + outputVerticesPtr->G = curVertexPtr->G + MUL_FIXED(lambda,nextVertexPtr->G-curVertexPtr->G); \ + outputVerticesPtr->B = curVertexPtr->B + MUL_FIXED(lambda,nextVertexPtr->B-curVertexPtr->B); \ + outputVerticesPtr->SpecularR = curVertexPtr->SpecularR + MUL_FIXED(lambda,nextVertexPtr->SpecularR-curVertexPtr->SpecularR); \ + outputVerticesPtr->SpecularG = curVertexPtr->SpecularG + MUL_FIXED(lambda,nextVertexPtr->SpecularG-curVertexPtr->SpecularG); \ + outputVerticesPtr->SpecularB = curVertexPtr->SpecularB + MUL_FIXED(lambda,nextVertexPtr->SpecularB-curVertexPtr->SpecularB); + +#define Clip_LoopEnd(b) \ + numberOfPointsOutputted++; \ + outputVerticesPtr++; \ + } \ + \ + /* okay, now the current vertex becomes what was the next vertex */ \ + curVertexPtr = nextVertexPtr; \ + curVertexInside = nextVertexInside; \ + } \ + while(verticesLeft); \ + \ + RenderPolygon.NumberOfVertices = numberOfPointsOutputted; + +/* Wide screen versions of clip macros */ + +#define Clip_Wide_NX_Test(v) (-(v)->X <= (v)->Z*2) +#define Clip_Wide_PX_Test(v) ((v)->X <= (v)->Z*2) +#define Clip_Wide_NY_Test(v) (-(v)->Y <= (v)->Z*2) +#define Clip_Wide_PY_Test(v) ((v)->Y <= (v)->Z*2) +#define Clip_Wide_NX_OutputXYZ \ + /* if one is in, and the other is out, output a clipped vertex */ \ + if (nextVertexInside != curVertexInside) \ + { \ + int lambda; \ + \ + lambda = DIV_FIXED \ + ( \ + (-2*curVertexPtr->Z - curVertexPtr->X), \ + (nextVertexPtr->X-curVertexPtr->X) - (-2)*(nextVertexPtr->Z-curVertexPtr->Z) \ + ); \ + \ + outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ + outputVerticesPtr->Z = -outputVerticesPtr->X/2; \ + outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); + +#define Clip_Wide_PX_OutputXYZ \ + /* if one is in, and the other is out, output a clipped vertex */ \ + if (nextVertexInside != curVertexInside) \ + { \ + int lambda; \ + \ + lambda = DIV_FIXED \ + ( \ + (2*curVertexPtr->Z - curVertexPtr->X), \ + (nextVertexPtr->X-curVertexPtr->X) - 2*(nextVertexPtr->Z-curVertexPtr->Z) \ + ); \ + \ + outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ + outputVerticesPtr->Z = outputVerticesPtr->X/2; \ + outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); + +#define Clip_Wide_NY_OutputXYZ \ + /* if one is in, and the other is out, output a clipped vertex */ \ + if (nextVertexInside != curVertexInside) \ + { \ + int lambda; \ + \ + lambda = DIV_FIXED \ + ( \ + (2*curVertexPtr->Z + curVertexPtr->Y), \ + -(nextVertexPtr->Y-curVertexPtr->Y) - 2*(nextVertexPtr->Z-curVertexPtr->Z) \ + ); \ + \ + outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda,nextVertexPtr->Z-curVertexPtr->Z); \ + outputVerticesPtr->Y = -(outputVerticesPtr->Z*2); \ + outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); + +#define Clip_Wide_PY_OutputXYZ \ + /* if one is in, and the other is out, output a clipped vertex */ \ + if (nextVertexInside != curVertexInside) \ + { \ + int lambda; \ + \ + lambda = DIV_FIXED \ + ( \ + (2*curVertexPtr->Z - curVertexPtr->Y), \ + (nextVertexPtr->Y-curVertexPtr->Y) - 2*(nextVertexPtr->Z-curVertexPtr->Z) \ + ); \ + \ + outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda,nextVertexPtr->Z-curVertexPtr->Z); \ + outputVerticesPtr->Y = (outputVerticesPtr->Z*2); \ + outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); + + +/*KJL************** +* GOURAUD POLYGON * +**************KJL*/ + +/* Clip against Z plane */ +void GouraudPolygon_ClipWithZ(void) +{ + RENDERVERTEX *curVertexPtr = VerticesBuffer; + RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_Z_Test(curVertexPtr); + + Clip_LoopStart(VerticesBuffer) + Clip_Z_Test(nextVertexPtr); + Clip_Z_OutputXYZ + Clip_OutputI + Clip_LoopEnd((RenderPolygon.Vertices)) +} + + +/* Clip against negative X plane */ +static void GouraudPolygon_Norm_ClipWithNegativeX(void) +{ + RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); + RENDERVERTEX *outputVerticesPtr = VerticesBuffer; + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_NX_Test(curVertexPtr); + + Clip_LoopStart((RenderPolygon.Vertices)) + Clip_NX_Test(nextVertexPtr); + Clip_NX_OutputXYZ + Clip_OutputI + Clip_LoopEnd(VerticesBuffer) +} +static void GouraudPolygon_Wide_ClipWithNegativeX(void) +{ + RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); + RENDERVERTEX *outputVerticesPtr = VerticesBuffer; + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_Wide_NX_Test(curVertexPtr); + + Clip_LoopStart((RenderPolygon.Vertices)) + Clip_Wide_NX_Test(nextVertexPtr); + Clip_Wide_NX_OutputXYZ + Clip_OutputI + Clip_LoopEnd(VerticesBuffer) +} + +/* Clip against positive Y plane*/ +static void GouraudPolygon_Norm_ClipWithPositiveY(void) +{ + RENDERVERTEX *curVertexPtr = VerticesBuffer; + RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_PY_Test(curVertexPtr); + + Clip_LoopStart(VerticesBuffer) + Clip_PY_Test(nextVertexPtr); + Clip_PY_OutputXYZ + Clip_OutputI + Clip_LoopEnd((RenderPolygon.Vertices)) +} +static void GouraudPolygon_Wide_ClipWithPositiveY(void) +{ + RENDERVERTEX *curVertexPtr = VerticesBuffer; + RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_Wide_PY_Test(curVertexPtr); + + Clip_LoopStart(VerticesBuffer) + Clip_Wide_PY_Test(nextVertexPtr); + Clip_Wide_PY_OutputXYZ + Clip_OutputI + Clip_LoopEnd((RenderPolygon.Vertices)) +} + +/* Clip against negative Y plane*/ +static void GouraudPolygon_Norm_ClipWithNegativeY(void) +{ + RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); + RENDERVERTEX *outputVerticesPtr = VerticesBuffer; + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_NY_Test(curVertexPtr); + + Clip_LoopStart((RenderPolygon.Vertices)) + Clip_NY_Test(nextVertexPtr); + Clip_NY_OutputXYZ + Clip_OutputI + Clip_LoopEnd(VerticesBuffer) +} +static void GouraudPolygon_Wide_ClipWithNegativeY(void) +{ + RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); + RENDERVERTEX *outputVerticesPtr = VerticesBuffer; + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_Wide_NY_Test(curVertexPtr); + + Clip_LoopStart((RenderPolygon.Vertices)) + Clip_Wide_NY_Test(nextVertexPtr); + Clip_Wide_NY_OutputXYZ + Clip_OutputI + Clip_LoopEnd(VerticesBuffer) +} + +/* Clip against positive X plane */ +static void GouraudPolygon_Norm_ClipWithPositiveX(void) +{ + RENDERVERTEX *curVertexPtr = VerticesBuffer; + RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_PX_Test(curVertexPtr); + + Clip_LoopStart(VerticesBuffer) + Clip_PX_Test(nextVertexPtr); + Clip_PX_OutputXYZ + Clip_OutputI + Clip_LoopEnd((RenderPolygon.Vertices)) +} +static void GouraudPolygon_Wide_ClipWithPositiveX(void) +{ + RENDERVERTEX *curVertexPtr = VerticesBuffer; + RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_Wide_PX_Test(curVertexPtr); + + Clip_LoopStart(VerticesBuffer) + Clip_Wide_PX_Test(nextVertexPtr); + Clip_Wide_PX_OutputXYZ + Clip_OutputI + Clip_LoopEnd((RenderPolygon.Vertices)) +} + +/*KJL*************** +* TEXTURED POLYGON * +***************KJL*/ + +/* Clip against Z plane */ +void TexturedPolygon_ClipWithZ(void) +{ + RENDERVERTEX *curVertexPtr = VerticesBuffer; + RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_Z_Test(curVertexPtr); + + Clip_LoopStart(VerticesBuffer) + Clip_Z_Test(nextVertexPtr); + Clip_Z_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd((RenderPolygon.Vertices)) +} + +/* Clip against negative X plane */ +static void TexturedPolygon_Norm_ClipWithNegativeX(void) +{ + RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); + RENDERVERTEX *outputVerticesPtr = VerticesBuffer; + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_NX_Test(curVertexPtr); + + Clip_LoopStart((RenderPolygon.Vertices)) + Clip_NX_Test(nextVertexPtr); + Clip_NX_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd(VerticesBuffer) +} +static void TexturedPolygon_Wide_ClipWithNegativeX(void) +{ + RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); + RENDERVERTEX *outputVerticesPtr = VerticesBuffer; + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_Wide_NX_Test(curVertexPtr); + + Clip_LoopStart((RenderPolygon.Vertices)) + Clip_Wide_NX_Test(nextVertexPtr); + Clip_Wide_NX_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd(VerticesBuffer) +} + +/* Clip against positive Y plane*/ +static void TexturedPolygon_Norm_ClipWithPositiveY(void) +{ + RENDERVERTEX *curVertexPtr = VerticesBuffer; + RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_PY_Test(curVertexPtr); + + Clip_LoopStart(VerticesBuffer) + Clip_PY_Test(nextVertexPtr); + Clip_PY_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd((RenderPolygon.Vertices)) +} +static void TexturedPolygon_Wide_ClipWithPositiveY(void) +{ + RENDERVERTEX *curVertexPtr = VerticesBuffer; + RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_Wide_PY_Test(curVertexPtr); + + Clip_LoopStart(VerticesBuffer) + Clip_Wide_PY_Test(nextVertexPtr); + Clip_Wide_PY_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd((RenderPolygon.Vertices)) +} + +/* Clip against negative Y plane*/ +static void TexturedPolygon_Norm_ClipWithNegativeY(void) +{ + RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); + RENDERVERTEX *outputVerticesPtr = VerticesBuffer; + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_NY_Test(curVertexPtr); + + Clip_LoopStart((RenderPolygon.Vertices)) + Clip_NY_Test(nextVertexPtr); + Clip_NY_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd(VerticesBuffer) +} +static void TexturedPolygon_Wide_ClipWithNegativeY(void) +{ + RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); + RENDERVERTEX *outputVerticesPtr = VerticesBuffer; + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_Wide_NY_Test(curVertexPtr); + + Clip_LoopStart((RenderPolygon.Vertices)) + Clip_Wide_NY_Test(nextVertexPtr); + Clip_Wide_NY_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd(VerticesBuffer) +} + +/* Clip against positive X plane */ +static void TexturedPolygon_Norm_ClipWithPositiveX(void) +{ + RENDERVERTEX *curVertexPtr = VerticesBuffer; + RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_PX_Test(curVertexPtr); + + Clip_LoopStart(VerticesBuffer) + Clip_PX_Test(nextVertexPtr); + Clip_PX_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd((RenderPolygon.Vertices)) +} +static void TexturedPolygon_Wide_ClipWithPositiveX(void) +{ + RENDERVERTEX *curVertexPtr = VerticesBuffer; + RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_Wide_PX_Test(curVertexPtr); + + Clip_LoopStart(VerticesBuffer) + Clip_Wide_PX_Test(nextVertexPtr); + Clip_Wide_PX_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd((RenderPolygon.Vertices)) +} + + + + +/*KJL************************ +* GOURAUD TEXTURED POLYGONS * +************************KJL*/ + +/* Clip against Z plane */ +void GouraudTexturedPolygon_ClipWithZ(void) +{ + RENDERVERTEX *curVertexPtr = VerticesBuffer; + RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_Z_Test(curVertexPtr); + + Clip_LoopStart(VerticesBuffer) + Clip_Z_Test(nextVertexPtr); + Clip_Z_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd((RenderPolygon.Vertices)) +} + +/* Clip against negative X plane */ +static void GouraudTexturedPolygon_Norm_ClipWithNegativeX(void) +{ + RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); + RENDERVERTEX *outputVerticesPtr = VerticesBuffer; + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_NX_Test(curVertexPtr); + + Clip_LoopStart((RenderPolygon.Vertices)) + Clip_NX_Test(nextVertexPtr); + Clip_NX_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd(VerticesBuffer) +} +static void GouraudTexturedPolygon_Wide_ClipWithNegativeX(void) +{ + RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); + RENDERVERTEX *outputVerticesPtr = VerticesBuffer; + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_Wide_NX_Test(curVertexPtr); + + Clip_LoopStart((RenderPolygon.Vertices)) + Clip_Wide_NX_Test(nextVertexPtr); + Clip_Wide_NX_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd(VerticesBuffer) +} + +/* Clip against positive Y plane*/ +static void GouraudTexturedPolygon_Norm_ClipWithPositiveY(void) +{ + RENDERVERTEX *curVertexPtr = VerticesBuffer; + RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_PY_Test(curVertexPtr); + + Clip_LoopStart(VerticesBuffer) + Clip_PY_Test(nextVertexPtr); + Clip_PY_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd((RenderPolygon.Vertices)) +} +static void GouraudTexturedPolygon_Wide_ClipWithPositiveY(void) +{ + RENDERVERTEX *curVertexPtr = VerticesBuffer; + RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_Wide_PY_Test(curVertexPtr); + + Clip_LoopStart(VerticesBuffer) + Clip_Wide_PY_Test(nextVertexPtr); + Clip_Wide_PY_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd((RenderPolygon.Vertices)) +} + +/* Clip against negative Y plane*/ +static void GouraudTexturedPolygon_Norm_ClipWithNegativeY(void) +{ + RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); + RENDERVERTEX *outputVerticesPtr = VerticesBuffer; + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_NY_Test(curVertexPtr); + + Clip_LoopStart((RenderPolygon.Vertices)) + Clip_NY_Test(nextVertexPtr); + Clip_NY_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd(VerticesBuffer) +} +static void GouraudTexturedPolygon_Wide_ClipWithNegativeY(void) +{ + RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); + RENDERVERTEX *outputVerticesPtr = VerticesBuffer; + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_Wide_NY_Test(curVertexPtr); + + Clip_LoopStart((RenderPolygon.Vertices)) + Clip_Wide_NY_Test(nextVertexPtr); + Clip_Wide_NY_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd(VerticesBuffer) +} + +/* Clip against positive X plane */ +static void GouraudTexturedPolygon_Norm_ClipWithPositiveX(void) +{ + RENDERVERTEX *curVertexPtr = VerticesBuffer; + RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_PX_Test(curVertexPtr); + + Clip_LoopStart(VerticesBuffer) + Clip_PX_Test(nextVertexPtr); + Clip_PX_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd((RenderPolygon.Vertices)) +} +static void GouraudTexturedPolygon_Wide_ClipWithPositiveX(void) +{ + RENDERVERTEX *curVertexPtr = VerticesBuffer; + RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); + int verticesLeft = RenderPolygon.NumberOfVertices; + int numberOfPointsOutputted=0; + + int curVertexInside = Clip_Wide_PX_Test(curVertexPtr); + + Clip_LoopStart(VerticesBuffer) + Clip_Wide_PX_Test(nextVertexPtr); + Clip_Wide_PX_OutputXYZ + Clip_OutputUV + Clip_OutputI + Clip_LoopEnd((RenderPolygon.Vertices)) +} + + + + + + + +int PolygonWithinFrustrum(POLYHEADER *polyPtr) +{ + char inFrustrumFlag=0; + char noClippingFlag=INSIDE_FRUSTRUM; + int *vertexNumberPtr = &polyPtr->Poly1stPt; + + if (polyPtr->PolyFlags & iflag_notvis) return 0; + + RenderPolygon.NumberOfVertices=0; + while(*vertexNumberPtr != Term) + { + int vertexNumber = *vertexNumberPtr++; + + inFrustrumFlag |= FrustrumFlagForVertex[vertexNumber]; + noClippingFlag &= FrustrumFlagForVertex[vertexNumber]; + + /* count the number of points in the polygon; this is used for all the loops that follow */ + RenderPolygon.NumberOfVertices++; + } + + if (inFrustrumFlag != INSIDE_FRUSTRUM) return 0; + + /* at this point we know that the poly is inside the view frustrum */ + + /* if not a sprite, test direction of poly */ + if (!( (Global_ShapeHeaderPtr->shapeflags&ShapeFlag_Sprite) || (polyPtr->PolyFlags & iflag_no_bfc) )) + { + VECTORCH pop; + VECTORCH *normalPtr = (VECTORCH*)(Global_ShapeNormals + polyPtr->PolyNormalIndex); + + #if 1 + if(Global_ODB_Ptr->ObMorphCtrl) + { + extern MORPHDISPLAY MorphDisplay; + SHAPEHEADER *shape1Ptr; + VECTORCH *shape1PointsPtr; + VECTORCH *shape2PointsPtr; + + /* Set up the morph data */ + GetMorphDisplay(&MorphDisplay, Global_ODB_Ptr); + + shape1Ptr = MorphDisplay.md_sptr1; + + if(MorphDisplay.md_lerp == 0x0000) + { + shape1PointsPtr = (VECTORCH *)*shape1Ptr->points; + pop = shape1PointsPtr[polyPtr->Poly1stPt]; + + } + else if(MorphDisplay.md_lerp == 0xffff) + { + SHAPEHEADER *shape2Ptr = MorphDisplay.md_sptr2; + + shape2PointsPtr = (VECTORCH *)*shape2Ptr->points; + pop = shape2PointsPtr[polyPtr->Poly1stPt]; + } + else + { + SHAPEHEADER *shape2Ptr = MorphDisplay.md_sptr2; + + shape1PointsPtr = (VECTORCH *)(*shape1Ptr->points); + shape2PointsPtr = (VECTORCH *)(*shape2Ptr->points); + + { + VECTORCH vertex1 = shape1PointsPtr[polyPtr->Poly1stPt]; + VECTORCH vertex2 = shape2PointsPtr[polyPtr->Poly1stPt]; + + if( (vertex1.vx == vertex2.vx && vertex1.vy == vertex2.vy && vertex1.vz == vertex2.vz) ) + { + pop = vertex1; + } + else + { + /* KJL 15:27:20 05/22/97 - I've changed this to speed things up, If a vertex + component has a magnitude greater than 32768 things will go wrong. */ + pop.vx = vertex1.vx + (((vertex2.vx-vertex1.vx)*MorphDisplay.md_lerp)>>16); + pop.vy = vertex1.vy + (((vertex2.vy-vertex1.vy)*MorphDisplay.md_lerp)>>16); + pop.vz = vertex1.vz + (((vertex2.vz-vertex1.vz)*MorphDisplay.md_lerp)>>16); + } + } + } + } + else + #endif + { + /* Get the 1st polygon point as the POP */ + VECTORCH *pointsArray = (VECTORCH*)(Global_ShapePoints); + pop = pointsArray[polyPtr->Poly1stPt]; + } + pop.vx -= LocalView.vx; + pop.vy -= LocalView.vy; + pop.vz -= LocalView.vz; + + if (Dot(&pop, normalPtr)>0) return 0; + } + + if (noClippingFlag == INSIDE_FRUSTRUM) return 2; + + /* yes, we need to draw poly */ + return 1; +} + +int PolygonShouldBeDrawn(POLYHEADER *polyPtr) +{ + + /* at this point we know that the poly is inside the view frustrum */ + if (polyPtr->PolyFlags & iflag_notvis) return 0; + + #if 1 + /* if not a sprite, test direction of poly */ + if (!( (Global_ShapeHeaderPtr->shapeflags&ShapeFlag_Sprite) || (polyPtr->PolyFlags & iflag_no_bfc) )) + { + /* KJL 16:49:14 7/10/97 - + + ***** MORPHED NORMALS SUPPORT NOT YET ADDED ***** + + */ + VECTORCH pop; + VECTORCH *normalPtr = (VECTORCH*)(Global_ShapeNormals + polyPtr->PolyNormalIndex); + VECTORCH *pointsArray = (VECTORCH*)(Global_ShapePoints); + /* Get the 1st polygon point as the POP */ + + pop.vx = pointsArray[polyPtr->Poly1stPt].vx - LocalView.vx; + pop.vy = pointsArray[polyPtr->Poly1stPt].vy - LocalView.vy; + pop.vz = pointsArray[polyPtr->Poly1stPt].vz - LocalView.vz; + + if (Dot(&pop, normalPtr)>0) return 0; + } + #endif + #if 0 + { + int *vertexNumberPtr = &polyPtr->Poly1stPt; + RenderPolygon.NumberOfVertices=0; + while(*vertexNumberPtr++ != Term) + { + /* count the number of points in the polygon; this is used for all the loops that follow */ + RenderPolygon.NumberOfVertices++; + } + } + #elif 0 + RenderPolygon.NumberOfVertices = 3; + #else + { + int *vertexNumberPtr = &polyPtr->Poly1stPt; + if (vertexNumberPtr[3] == Term) + { + RenderPolygon.NumberOfVertices = 3; + } + else + { + RenderPolygon.NumberOfVertices = 4; + } + } + #endif + + return 2; +} + +/* KJL 16:18:59 7/7/97 - simple vertex test to be used in first +pass of subdividing code */ +static int VertexWithin_Norm_Frustrum(RENDERVERTEX *vertexPtr) +{ + int vertexFlag = 0; + + if(Clip_Z_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; + if(Clip_PX_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; + if(Clip_NX_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; + if(Clip_PY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; + if(Clip_NY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; + + return vertexFlag; +} + +static int VertexWithin_Wide_Frustrum(RENDERVERTEX *vertexPtr) +{ + int vertexFlag = 0; + + if(Clip_Z_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; + if(Clip_Wide_PX_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; + if(Clip_Wide_NX_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; + if(Clip_Wide_PY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; + if(Clip_Wide_NY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; + + return vertexFlag; +} + + +/* KJL 15:32:52 7/17/97 - Test to see if an object is in the view frustrum */ +static int ObjectWithin_Norm_Frustrum(DISPLAYBLOCK *dbPtr) +{ + // LOCALASSERT(dbPtr->ObShapeData->shaperadius); + +#if FAR_Z_CLIP + if(dbPtr->ObView.vz-dbPtr->ObShapeData->shaperadius<=FAR_Z_CLIP_RANGE) +#endif + if (dbPtr->ObView.vz+dbPtr->ObShapeData->shaperadius>=ZCLIPPINGVALUE) + { + /* scale radius by square root of 2 */ + int radius = MUL_FIXED(92682,dbPtr->ObShapeData->shaperadius); + + if ((dbPtr->ObView.vx-dbPtr->ObView.vz)<=radius) + if ((-dbPtr->ObView.vx-dbPtr->ObView.vz)<=radius) + if ((dbPtr->ObView.vy-dbPtr->ObView.vz)<=radius) + if ((-dbPtr->ObView.vy-dbPtr->ObView.vz)<=radius) + return 1; + } + return 0; +} +static int ObjectCompletelyWithin_Norm_Frustrum(DISPLAYBLOCK *dbPtr) +{ + // LOCALASSERT(dbPtr->ObShapeData->shaperadius); + if (dbPtr->ObView.vz-dbPtr->ObShapeData->shaperadius>=ZCLIPPINGVALUE) + { + /* scale radius by square root of 2 */ + int radius = MUL_FIXED(92682,dbPtr->ObShapeData->shaperadius); + + if ((dbPtr->ObView.vz-dbPtr->ObView.vx)>=radius) + if ((dbPtr->ObView.vz+dbPtr->ObView.vx)>=radius) + if ((dbPtr->ObView.vz-dbPtr->ObView.vy)>=radius) + if ((dbPtr->ObView.vz+dbPtr->ObView.vy)>=radius) + return 1; + } + return 0; +} +static int ObjectCompletelyWithin_Wide_Frustrum(DISPLAYBLOCK *dbPtr) +{ + return 0; +} + +static int ObjectWithin_Wide_Frustrum(DISPLAYBLOCK *dbPtr) +{ + if (dbPtr->ObView.vz+dbPtr->ObShapeData->shaperadius>=ZCLIPPINGVALUE) + { + /* scale radius by square root of 5 */ + int radius = MUL_FIXED(146543,dbPtr->ObShapeData->shaperadius); + + if ((dbPtr->ObView.vx-2*dbPtr->ObView.vz)<=radius) + if ((-dbPtr->ObView.vx-2*dbPtr->ObView.vz)<=radius) + if ((dbPtr->ObView.vy-2*dbPtr->ObView.vz)<=radius) + if ((-dbPtr->ObView.vy-2*dbPtr->ObView.vz)<=radius) + return 1; + } + return 0; +} + + +char FrustrumFlagForVertex[maxrotpts]; + +void TestVerticesWith_Norm_Frustrum(void) +{ + int v = Global_ShapeHeaderPtr->numpoints; + + GLOBALASSERT(v>0); + + while(v--) + { + char vertexFlag = 0; + +#if FAR_Z_CLIP + if(ZCLIPPINGVALUE <= RotatedPts[v].vz && RotatedPts[v].vz<=FAR_Z_CLIP_RANGE) +#else + if(ZCLIPPINGVALUE <= RotatedPts[v].vz) +#endif + vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; + + if(-RotatedPts[v].vx <= RotatedPts[v].vz) + vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; + + if(RotatedPts[v].vx <= RotatedPts[v].vz) + vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; + + if(-RotatedPts[v].vy <= RotatedPts[v].vz) + vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; + + if(RotatedPts[v].vy <= RotatedPts[v].vz) + vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; + + FrustrumFlagForVertex[v] = vertexFlag; + } +} +void TestVerticesWith_Wide_Frustrum(void) +{ + int v = Global_ShapeHeaderPtr->numpoints; + + GLOBALASSERT(v>0); + + while(v--) + { + char vertexFlag = 0; + + if(ZCLIPPINGVALUE <= RotatedPts[v].vz) + vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; + + if(-RotatedPts[v].vx <= RotatedPts[v].vz*2) + vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; + + if(RotatedPts[v].vx <= RotatedPts[v].vz*2) + vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; + + if(-RotatedPts[v].vy <= RotatedPts[v].vz*2) + vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; + + if(RotatedPts[v].vy <= RotatedPts[v].vz*2) + vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; + + FrustrumFlagForVertex[v] = vertexFlag; + } +} + + + +int DecalWithinFrustrum(DECAL *decalPtr) +{ + char inFrustrumFlag; + char noClippingFlag; + + if(ModuleCurrVisArray[decalPtr->ModuleIndex] != 2) return 0; + + inFrustrumFlag=0; + noClippingFlag=INSIDE_FRUSTRUM; + + { + int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[0]); + inFrustrumFlag |= vertexFlag; + noClippingFlag &= vertexFlag; + } + { + int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[1]); + inFrustrumFlag |= vertexFlag; + noClippingFlag &= vertexFlag; + } + { + int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[2]); + inFrustrumFlag |= vertexFlag; + noClippingFlag &= vertexFlag; + } + { + int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[3]); + inFrustrumFlag |= vertexFlag; + noClippingFlag &= vertexFlag; + } + + if (inFrustrumFlag != INSIDE_FRUSTRUM) return 0; + if (noClippingFlag == INSIDE_FRUSTRUM) return 2; + + /* yes, we need to draw poly */ + return 1; +} + +int QuadWithinFrustrum(void) +{ + char inFrustrumFlag; + char noClippingFlag; + + inFrustrumFlag=0; + noClippingFlag=INSIDE_FRUSTRUM; + + { + int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[0]); + inFrustrumFlag |= vertexFlag; + noClippingFlag &= vertexFlag; + } + { + int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[1]); + inFrustrumFlag |= vertexFlag; + noClippingFlag &= vertexFlag; + } + { + int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[2]); + inFrustrumFlag |= vertexFlag; + noClippingFlag &= vertexFlag; + } + { + int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[3]); + inFrustrumFlag |= vertexFlag; + noClippingFlag &= vertexFlag; + } + + if (inFrustrumFlag != INSIDE_FRUSTRUM) return 0; + if (noClippingFlag == INSIDE_FRUSTRUM) return 2; + + /* yes, we need to draw poly */ + return 1; +} + +int TriangleWithinFrustrum(void) +{ + char inFrustrumFlag; + char noClippingFlag; + + inFrustrumFlag=0; + noClippingFlag=INSIDE_FRUSTRUM; + + { + int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[0]); + inFrustrumFlag |= vertexFlag; + noClippingFlag &= vertexFlag; + } + { + int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[1]); + inFrustrumFlag |= vertexFlag; + noClippingFlag &= vertexFlag; + } + { + int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[2]); + inFrustrumFlag |= vertexFlag; + noClippingFlag &= vertexFlag; + } + + if (inFrustrumFlag != INSIDE_FRUSTRUM) return 0; + if (noClippingFlag == INSIDE_FRUSTRUM) return 2; + + /* yes, we need to draw poly */ + return 1; +} + + \ No newline at end of file diff --git a/src/frustum.h b/src/frustum.h new file mode 100644 index 0000000..faf7795 --- /dev/null +++ b/src/frustum.h @@ -0,0 +1,68 @@ +#ifndef _frustrum_h_ /* Is this your first time? */ +#define _frustrum_h_ 1 + +#include "kshape.h" +/* + * KJL 15:13:43 7/17/97 - frustrum.h + * + * function prototypes & pointers for things connected + * to the view frustrum and clipping + * + */ + +enum FrustrumType +{ + FRUSTRUM_TYPE_NORMAL, + FRUSTRUM_TYPE_WIDE +}; + +extern void SetFrustrumType(enum FrustrumType frustrumType); + +/* GOURAUD POLYGON CLIPPING */ +extern void GouraudPolygon_ClipWithZ(void); +extern void (*GouraudPolygon_ClipWithNegativeX)(void); +extern void (*GouraudPolygon_ClipWithPositiveY)(void); +extern void (*GouraudPolygon_ClipWithNegativeY)(void); +extern void (*GouraudPolygon_ClipWithPositiveX)(void); + +/* TEXTURED POLYGON CLIPPING */ +extern void TexturedPolygon_ClipWithZ(void); +extern void (*TexturedPolygon_ClipWithNegativeX)(void); +extern void (*TexturedPolygon_ClipWithPositiveY)(void); +extern void (*TexturedPolygon_ClipWithNegativeY)(void); +extern void (*TexturedPolygon_ClipWithPositiveX)(void); + +/* GOURAUD TEXTURED POLYGON CLIPPING */ +extern void GouraudTexturedPolygon_ClipWithZ(void); +extern void (*GouraudTexturedPolygon_ClipWithNegativeX)(void); +extern void (*GouraudTexturedPolygon_ClipWithPositiveY)(void); +extern void (*GouraudTexturedPolygon_ClipWithNegativeY)(void); +extern void (*GouraudTexturedPolygon_ClipWithPositiveX)(void); + +/* FRUSTRUM TESTS */ +extern int PolygonWithinFrustrum(POLYHEADER *polyPtr); +extern int PolygonShouldBeDrawn(POLYHEADER *polyPtr); +extern int (*ObjectWithinFrustrum)(DISPLAYBLOCK *dbPtr); +extern int (*ObjectCompletelyWithinFrustrum)(DISPLAYBLOCK *dbPtr); +extern int (*VertexWithinFrustrum)(RENDERVERTEX *vertexPtr); +extern void (*TestVerticesWithFrustrum)(void); + +extern int DecalWithinFrustrum(DECAL *decalPtr); +extern int QuadWithinFrustrum(void); +extern int TriangleWithinFrustrum(void); + + +/* pass a pointer to a vertex to be tested; results are returned in an int, +using the following defines */ +#define INSIDE_FRUSTRUM_Z_PLANE 1 +#define INSIDE_FRUSTRUM_PX_PLANE 2 +#define INSIDE_FRUSTRUM_NX_PLANE 4 +#define INSIDE_FRUSTRUM_PY_PLANE 8 +#define INSIDE_FRUSTRUM_NY_PLANE 16 +#define INSIDE_FRUSTRUM 31 + +extern char FrustrumFlagForVertex[maxrotpts]; + +#define USE_FOV_53 0 + +#endif diff --git a/src/kshape.c b/src/kshape.c index 6f6ef94..c7d4883 100644 --- a/src/kshape.c +++ b/src/kshape.c @@ -11,7 +11,7 @@ #include "kshape.h" #include "kzsort.h" -#include "frustrum.h" +#include "frustum.h" #define UseLocalAssert Yes #include "ourasert.h" diff --git a/src/win95/d3_func.h b/src/win95/d3_func.h index eedbd5e..b369add 100644 --- a/src/win95/d3_func.h +++ b/src/win95/d3_func.h @@ -5,6 +5,47 @@ extern "C" { #endif + +/* KJL 14:24:45 12/4/97 - render state information */ +enum TRANSLUCENCY_TYPE +{ + TRANSLUCENCY_OFF, + TRANSLUCENCY_NORMAL, + TRANSLUCENCY_INVCOLOUR, + TRANSLUCENCY_COLOUR, + TRANSLUCENCY_GLOWING, + TRANSLUCENCY_DARKENINGCOLOUR, + TRANSLUCENCY_JUSTSETZ, + TRANSLUCENCY_NOT_SET +}; + +enum FILTERING_MODE_ID +{ + FILTERING_BILINEAR_OFF, + FILTERING_BILINEAR_ON, + FILTERING_NOT_SET +}; + +typedef struct +{ + enum TRANSLUCENCY_TYPE TranslucencyMode; + enum FILTERING_MODE_ID FilteringMode; + int FogDistance; + unsigned int FogIsOn :1; + unsigned int WireFrameModeIsOn :1; + +} RENDERSTATES; + +typedef struct D3DTextureFormat { +// DDSURFACEDESC ddsd; /* DDSURFACEDESC for the surface description */ + BOOL Palette; /* is Palettized? */ + int RedBPP; /* #red bits per pixel */ + int BlueBPP; /* #blue bits per pixel */ + int GreenBPP; /* #green bits per pixel */ + int IndexBPP; /* number of bits in palette index */ +} D3DTEXTUREFORMAT; + +#if 0 // disabled direct3d stuff /* Direct3D globals */ @@ -95,6 +136,7 @@ typedef struct } RENDERSTATES; +#endif diff --git a/src/win95/inline.h b/src/win95/inline.h index 30b7faa..719daf3 100644 --- a/src/win95/inline.h +++ b/src/win95/inline.h @@ -1228,7 +1228,9 @@ int NarrowDivide(LONGLONGCH *a, int b); int WideMulNarrowDiv(int a, int b, int c); void RotateVector_ASM(VECTORCH *v, MATRIXCH *m); void RotateAndCopyVector_ASM(VECTORCH *v1, VECTORCH *v2, MATRIXCH *m); -int f2i(float f); + +int FloatToInt(float); +#define f2i(a, b) { a = FloatToInt(b); } #endif diff --git a/src/win95/platform.h b/src/win95/platform.h index 6198d94..cefebf1 100644 --- a/src/win95/platform.h +++ b/src/win95/platform.h @@ -817,11 +817,11 @@ void ReleaseDirectMouse(void); /* Internal */ -#ifdef AVP_DEBUG_VERSION +//#ifdef AVP_DEBUG_VERSION int textprint(const char* t, ...); -#else -#define textprint(ignore) -#endif +//#else +//#define textprint(ignore) +//#endif void MakePaletteShades(VGAPALETTEENTRY *vga_palptr, int hue, int pal_shades_per_hue); -- cgit v1.3