/************************************************************ * * * tunnel.h * * * * * LPGE 1997 * * * * Copyright (C) 1996 Sony Computer Entertainment Inc. * * All Rights Reserved * * * ***********************************************************/ #ifndef TUNNEL_H_INCLUDED /**************************************************************************** includes ****************************************************************************/ #include "sys_libs.h" #include "asssert.h" #include "general.h" #include "dump.h" #include "trig.h" #include "tmd.h" #include "text_str.h" #include "object.h" #include "vector.h" #include "matrix.h" #include "coord.h" #include "main.h" #include "geom.h" #include "tunnel2.h" #include "tracks.h" /**************************************************************************** constants, structures, globals ****************************************************************************/ // main tunnel data #define MAX_TUNNEL_SECTIONS 256 #define DEFAULT_NUMBER_SHAPES_PER_SECTION 12 #define MAX_NUMBER_SHAPES_PER_SECTION 16 #define DEFAULT_TRACK_SECTION_LENGTH (SQUARE_SIZE * 16) #define DEFAULT_TRACK_OUTER_RADIUS (SQUARE_SIZE * 16) #define SUBDIVISION_LOOKAHEAD 2 #define SUBDIVISION_EXTENT 2 // for the twist flags of tunnel textures #define TWIST_NINETY_DEGREES 1 #define TWIST_ONE_EIGHTY_DEGREES 2 #define TWIST_TWO_SEVENTY_DEGREES 3 #define FULL_FLIP (1<<16) // to remove: circle coords, after calculate circle points // and inside and outside points; // thetaX, Y, Z; only keep those when inferring rotations from spline, // could use the global TunnelSectionRotations instead; // turn spline vector into svector; // points on circle and polygons can ALSO be dumped // ie COULD make this very small structure // ==> lots of sections, long and intricate tracks typedef struct { VECTOR splinePoint; VECTOR sectionCentre; // rotation angles from previous section short thetaX, thetaY, thetaZ; short totalAngle; GsCOORDINATE2 coordinateData; // own coords // vertices of points on circumference of circle VECTOR pointsOnCircle[MAX_NUMBER_SHAPES_PER_SECTION]; GsDOBJ2 singleHandler; int miscFlags; } TunnelSection; extern int NumberTunnelSections; extern int TunnelSectionShapeAngle; extern int TunnelSectionLength; extern int TunnelOuterRadius; extern int TunnelMiddleRadius; extern int TunnelInnerRadius; extern int NumberShapesPerSection; extern int NumberTunnelSectionsDrawn; extern int NumberTunnelSectionsSubdivided; #define MAX_NUMBER_SECTIONS_DRAWN 32 #define MAX_NUMBER_SECTIONS_SUBDIVIDED 6 extern int StartDrawingSectionId; extern int EndDrawingSectionId; extern int StartDrawingSectionBaseShift; extern int StartSubdividingSectionId; extern int EndSubdividingSectionId; #define VISIBLE_FROM_INSIDE 0 #define VISIBLE_FROM_OUTSIDE 1 #define VIEW_IS_SIDEWAYS 545 extern int TunnelSideAppearanceFlag; extern int TunnelSectionClippingFlag; // used to be four ways of describing the tunnel // now always use section rotations extern int TunnelBaseDescription; extern SVECTOR TunnelSectionRotations[MAX_TUNNEL_SECTIONS]; // starting conditions extern VECTOR TunnelStartPoint; extern MATRIX TunnelInitialOrientation; extern TunnelTotalDistance; extern VECTOR TunnelCentrePoint; // average centre point of whole track extern TunnelSection TheTunnel[MAX_TUNNEL_SECTIONS]; extern TunnelDescription TheTunnelDescription; // ways to describe the tunnel #define SPLINE_POINTS 0 #define SPLINE_VECTORS 1 #define SECTION_ROTATIONS 2 #define SPLINE_POINTS_AND_ROTATIONS 3 // error limits: when finding rotations from spline points #define Y_ROTATION_TOLERANCE_ERROR 25 #define X_ROTATION_TOLERANCE_ERROR 25 #define ANGLE_CHANGE 1 // checking a given spline #define SPLINE_POINT_DISTANCE_TOLERANCE 35 #define MAXIMUM_SECTION_ROTATION (ONE/8) #define MAXIMUM_PURE_X_ROTATION (ONE/8) #define MAXIMUM_PURE_Y_ROTATION (ONE/8) #define MAXIMUM_MIXED_X_ROTATION (ONE/8) #define MAXIMUM_MIXED_Y_ROTATION (ONE/8) #define MAXIMUM_Z_ROTATION (ONE/8) // ways to move along a tunnel #define FORWARDS 0 #define BACKWARDS 1 // eight pie-slices of circle /** \6|7/ 5\|/8 ----|---- 4/|\1 /3|2\ **/ #define FIRST_EIGHTH 0 #define SECOND_EIGHTH 1 #define THIRD_EIGHTH 2 #define FOURTH_EIGHTH 3 #define FIFTH_EIGHTH 4 #define SIXTH_EIGHTH 5 #define SEVENTH_EIGHTH 6 #define EIGHTH_EIGHTH 7 /**************************************************************************** prototypes ****************************************************************************/ void InitialiseTheTunnel (void); void InitTunnelToVoid (void); void SetBasicTunnelParameters (void); void CalculateCirclePointsOfTunnel (void); void FindCompoundRotationAngles (int dx, int dy, int dz, int* thetaX, int* thetaY); void ProperFindCompoundRotationAngles (GsCOORDINATE2* coord, int dx, int dy, int dz, int* thetaX, int* thetaY, int* thetaZ); int GetEightSector (int x, int y); void GenerateSplineFromListOfRotations (int numberOfSections, SVECTOR* rotationList, VECTOR* outputSpline, int sectionDistance, VECTOR* startingPosition, MATRIX* startingMatrix); void FindSplineCentralPoints (void); void CreateTheTunnel (void); void CreateTheTunnel2 (void); void CreateWholeSectionTMD (u_long* address, int sectionID, int numberShapesInThisSection, VECTOR *normalsToPolygons); void UpdateTheTunnel (void); void CycleLightsAroundAxes (void); void CycleLightsBrightlyAroundAxes (void); void CycleLightsBrightness (void); void CycleLightsDirectionAndColour(); int GetNextFreePolygonID (void); void CountNumberLivingPolys (int* nonDivided, int* divided); u_long CreateAnotherPolygonTMD (int clutX, int clutY, int tPageID, int pixelMode, u_char u0, u_char v0, u_char u1, u_char v1, u_char u2, u_char v2, u_char u3, u_char v3, TMD_NORM* norm0, TMD_VERT* vert0, TMD_VERT* vert1, TMD_VERT* vert2, TMD_VERT* vert3); u_long MakeGivenPolygonTMD (int sectionID, int polygonRef, TMD_NORM* norm0, TMD_VERT* vert0, TMD_VERT* vert1, TMD_VERT* vert2, TMD_VERT* vert3); void DestroyAllCreatedTMDs (void); void ProperCreateFirstTunnel (void); void BuildTheTunnel (void); void SortTunnelMainDescriptionsFromSplinePoints (void); void CreateRotationListFromSplineList (int numberOfSections, VECTOR* splineList, SVECTOR* outputRotationList, VECTOR* startPoint, MATRIX* initialOrientation, int sectionLength); void SortTunnelMainDescriptionsFromRotationsList (void); void CreateSplineListFromRotationList (int numberOfSections, SVECTOR* rotationList, VECTOR* outputSpline, VECTOR* startPoint, MATRIX* initialOrientation, int sectionLength); void SortTunnelMainDescriptionsFromCombinedDescription (void); void VerifySectionRotationDescription (void); int TestIfTunnelIsCircular (void); void PrintTunnelSplinePoints (void); void FindSectionSplineVector (int sectionID, VECTOR *splineVector); void PrintTunnelSplineVectors (void); void PrintTunnelSectionRotations (void); void FleshOutTunnelFromItsDescriptions (void); void FindCentreOfTunnel (void); void PutObjectInTunnel (ObjectHandler *object, int sectionID, VECTOR *relativeVector, MATRIX *relativeMatrix); void BringAliveLocalTunnelAroundShip (ObjectHandler* object); void HandleShipsMovementInTunnel (ObjectHandler* object); void TurnSectionSubdivisionOff (int sectionID); void TurnSectionSubdivisionOn (int sectionID); void HandleViewSectionChanging (int viewSectionBefore, int viewSectionAfter, int viewDirection); void HandleViewDirectionChanging (int viewSection, int directionBefore, int directionAfter); void DealWithShipRotation (VECTOR* twist, GsCOORDINATE2* coordSystem, MATRIX* matrix); void SortShipAdvancing (ObjectHandler* object, int sectionBefore, int sectionAfter); void HandleShipFinishingRace (ObjectHandler* object); void HandleEndOfRace (void); int FindSectionPointIsIn (VECTOR* point, int mainGuess); int FindViewPointSection (int guess); int FindWhichWayShipPointsInSection (ObjectHandler* object, TunnelSection* section); void FindPositionAndDirectionOfView (VECTOR* position, VECTOR* direction); int FindWhichWayViewLooksInSection (int section); void FindPositionAndDirectionOfView2 (void); void FindViewPointSection2 (void); void FindWhichWayViewLooksInSection2 (void); void FindViewAngleToSplinePath (void); int FindWhichWayVectorGoesInSection (VECTOR *vector, int sectionID); int GetRelativeSection (int first, int numberOn, int direction); int ConvertIdToRealID (int id); int DistanceBetweenSections (int first, int second, int direction); void FindShortestDistance (int first, int second, int* distance, int* direction); int SectionBetweenLimits (int sectionID, int start, int end); void DrawTheTunnelPolygons (GsOT* ot, int otShift); void HandleSectionHighlightEffect (TunnelSection *section, MATRIX *lightMatrix); void FindSectionOfView (int *viewSection); int CalculateNumberDisplayedPolygons (void); void CreateCombinedDescriptionOfTrackOne (void); void DetectAndHandleCollisionWithTunnel (ObjectHandler* object, int newSection, VECTOR* oldPos, VECTOR* newPos, VECTOR* worldVelocity); int SolveThisQuadratic (VECTOR* relativeOldPos, VECTOR* relativeVelocity, int radius); void FindCollisionPointGivenObjectSize (ObjectHandler* object, VECTOR* oldPos, VECTOR* velocityBeforeCollision, VECTOR* totalVelocity, VECTOR* collisionPoint); void HandleLackOfCollision (ObjectHandler* object, VECTOR* newPosition); void HandleTheCollision (ObjectHandler* object, int effectiveRadius, VECTOR* worldVelocity, TunnelSection* section, VECTOR* relativeOldPos, int dampingFactor); int RelativePointInTunnel (VECTOR* point, int effectiveRadius); void ReflectDirectionOffTunnelWall (VECTOR* directionBeforeCollision, VECTOR* collisionPoint, VECTOR* directionAfterCollision, int originalSpeed, SVECTOR* newTwist); void HandleTheCollision2 (ObjectHandler* object, int effectiveRadius, VECTOR* worldVelocity, TunnelSection* section, VECTOR* relativeOldPos, int reflectionFactor); void HandleTheCollision3 (ObjectHandler* object, TunnelSection* section); void HandleTheCollision4 (ObjectHandler *object, TunnelSection *section, VECTOR *oldPos, VECTOR *worldVelocity); #define TUNNEL_H_INCLUDED 1 #endif