HoverRace  2.0
Viewport3D.h
Go to the documentation of this file.
1 // Viewport3D.h
2 //
3 // Copyright (c) 1995-1998 - Richard Langlois and Grokksoft Inc.
4 //
5 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
6 // you may not use this file except in compliance with the License.
7 //
8 // A copy of the license should have been attached to the package from which
9 // you have taken this file. If you can not find the license you can not use
10 // this file.
11 //
12 //
13 // The author makes no representations about the suitability of
14 // this software for any purpose. It is provided "as is" "AS IS",
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16 // implied.
17 //
18 // See the License for the specific language governing permissions
19 // and limitations under the License.
20 //
21 
22 #pragma once
23 
24 #include "Viewport2D.h"
25 #include "ColorPalette.h"
26 #include "Bitmap.h"
27 #include "Patch.h"
28 
29 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
30 # ifdef MR_ENGINE
31 # define MR_DllDeclare __declspec( dllexport )
32 # else
33 # define MR_DllDeclare __declspec( dllimport )
34 # endif
35 #else
36 # define MR_DllDeclare
37 #endif
38 
39 namespace HoverRace {
40 namespace VideoServices {
41 
42 // define
43 #define MR_BACK_X_RES 2048
44 #define MR_BACK_Y_RES 256
45 
46 // Helper class
48 {
51 };
52 
53 class Viewport3D : public Viewport2D
54 {
55 protected:
56  struct BackColumn
57  {
60  };
61 
62  //Camera setting
64  MR_Angle mOrientation; // Angle from the XAxis
65  int mScroll; // Offset to YCenter
66  MR_Angle mVAngle; // Vertical field angle width
67  MR_Int32 mPlanDist; // ProjectionPlan (screen) distance
68  MR_Int32 mPlanHW; // Horizontal Half
69  MR_Int32 mPlanVW; // Vertical Half
70 
72  int mZLineLen;
73 
76 
77  // Usefull pre-defined constants
78  MR_Int32 mHVarPerDInc_16384; // Ray divergence by HPixel
79  MR_Int32 mVVarPerDInc_16384; // Ray divergence by VPixel
82 
83  MR_Int32 mPlanHW_PlanDist_2_XRes_16384; // 16384*mPlanHW/(mPlanDist*2*mXRes)
84  MR_Int32 mXRes_PlanDist_2PlanHW_4096; // mXRes*mPlanDist*2048/mPlanHW
85 
86  BackColumn *mBackgroundConst; // Constants used to display each bitmap column
87 
88  MR_Int32 mRotationMatrix[3][3];
89 
90  void ComputeRotationMatrix();
91  void ComputeBackgroundConst();
92 
93  void ApplyRotationMatrix(const MR_3DCoordinate & pSrc, MR_3DCoordinate & pDest) const;
94  void ApplyRotationMatrix(const MR_2DCoordinate & pSrc, MR_2DCoordinate & pDest) const;
95  void ApplyPositionMatrix(const PositionMatrix & pMatrix, const MR_3DCoordinate & pSrc, MR_3DCoordinate & pDest) const;
96 
97  MR_DllDeclare void OnMetricsChange(int pMetrics);
98 
99 public:
100 
103 
104  MR_DllDeclare void Setup(VideoBuffer *pBuffer, int pX0, int pY0, int pSizeX, int pSizeY, MR_Angle pApperture, int pMetrics = eNone);
105 
106  MR_DllDeclare void SetupCameraPosition(const MR_3DCoordinate & pPosition, MR_Angle pOrientation, int pScroll);
107 
108  MR_DllDeclare void ClearZ();
109 
110  MR_DllDeclare BOOL ComputePositionMatrix(PositionMatrix & pMatrix, const MR_3DCoordinate & pPosition, MR_Angle pOrientation, MR_Int32 pMaxObjRay);
111 
112  // WireFrame services
113  MR_DllDeclare void DrawWFLine(const MR_3DCoordinate & pP0, const MR_3DCoordinate & pP1, MR_UInt8 pColor);
114 
115  // Rendering services ( availlable in the file 3DViewportRendering.cpp )
116  MR_DllDeclare void RenderWallSurface(const MR_3DCoordinate & pUpperLeft, const MR_3DCoordinate & pLowerRight, MR_Int32 pLen, const Bitmap * pBitmap);
117  MR_DllDeclare void RenderAlternateWallSurface(const MR_3DCoordinate & pUpperLeft, const MR_3DCoordinate & pLowerRight, MR_Int32 pLen, const Bitmap * pBitmap, const Bitmap * pBitmap2, int pSerialLen, int pSerialStart);
118 
119  MR_DllDeclare void RenderHorizontalSurface(int lNbVertex, const MR_2DCoordinate * pVertexList, MR_Int32 pLevel, BOOL lTop, const Bitmap * pBitmap);
120 
121  MR_DllDeclare void RenderPatch(const Patch & pPatch, const PositionMatrix & pMatrix, const Bitmap * pBitmap);
122  MR_DllDeclare void RenderPatch(const Patch & pPatch, const PositionMatrix & pMatrix, MR_UInt8 pColor);
123 
124  MR_DllDeclare void RenderBackground(const MR_UInt8 * pBitmap);
125 };
126 
127 // Local constants (Used by the cpp of this module)
128 #define MR_ZBUFFER_LIMIT 0xFFFE
129 #define MR_ZBUFFER_UNIT 4 // Each increment is 4 mm
130 // max deep of field is 260m
131 #define MR_MAX_POLYGON_VERTEX 16
132 
133 } // namespace VideoServices
134 } // namespace HoverRace
135 
136 #undef MR_DllDeclare
MR_Int32 mPlanHW_PlanDist_2_XRes_16384
Definition: Viewport3D.h:83
MR_Int32 mPlanDist
Definition: Viewport3D.h:67
uint16_t MR_UInt16
Definition: MR_Types.h:42
Definition: WorldCoordinates.h:46
MR_Int32 mHVarPerDInc_16384
Definition: Viewport3D.h:78
MR_UInt16 ** mZBufferLine
Definition: Viewport3D.h:75
MR_3DCoordinate mPosition
Definition: Viewport3D.h:63
MR_Int32 mRotation[2][2]
Definition: Viewport3D.h:49
MR_Int32 mXRes_PlanDist
Definition: Viewport3D.h:80
Definition: Viewport3D.h:53
Definition: WorldCoordinates.h:75
Definition: Viewport2D.h:42
Definition: Patch.h:39
MR_Int32 mYRes_PlanDist
Definition: Viewport3D.h:81
MR_Int16 MR_Angle
Definition: WorldCoordinates.h:96
MR_Angle mOrientation
Definition: Viewport3D.h:64
int mScroll
Definition: Viewport3D.h:65
#define MR_DllDeclare
Definition: Viewport3D.h:36
Video framebuffer for legacy (8-bit, palettized) rendering.
Definition: VideoBuffer.h:54
MR_Angle mVAngle
Definition: Viewport3D.h:66
Definition: Viewport3D.h:47
MR_Int32 mVVarPerDInc_16384
Definition: Viewport3D.h:79
int32_t MR_Int32
Definition: MR_Types.h:43
MR_Int32 mLineIncrement_1024
Definition: Viewport3D.h:59
MR_Int32 mBitmapColumn
Definition: Viewport3D.h:58
MR_UInt8 ** mBufferLine
Definition: Viewport3D.h:74
BackColumn * mBackgroundConst
Definition: Viewport3D.h:86
int mZLineLen
Definition: Viewport3D.h:72
MR_UInt16 * mZBuffer
Definition: Viewport3D.h:71
MR_Int32 mPlanVW
Definition: Viewport3D.h:69
Definition: Bitmap.h:40
Definition: Announcement.h:24
MR_Int32 mPlanHW
Definition: Viewport3D.h:68
MR_3DCoordinate mDisplacement
Definition: Viewport3D.h:50
uint8_t MR_UInt8
Definition: MR_Types.h:40
MR_Int32 mXRes_PlanDist_2PlanHW_4096
Definition: Viewport3D.h:84