Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
projector.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WW3D *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/projector.cpp $*
26 * *
27 * Original Author:: Greg Hjelstrom *
28 * *
29 * $Author:: Kenny Mitchell *
30 * *
31 * $Modtime:: 06/26/02 4:04p $*
32 * *
33 * $Revision:: 6 $*
34 * *
35 * 06/26/02 KM Matrix name change to avoid MAX conflicts *
36 *---------------------------------------------------------------------------------------------*
37 * Functions: *
38 * ProjectorClass::ProjectorClass -- Constructor *
39 * ProjectorClass::~ProjectorClass -- Destructor *
40 * ProjectorClass::Set_Transform -- Set the transform for the projector *
41 * ProjectorClass::Get_Transform -- Returns the current transform *
42 * ProjectorClass::Set_Perspective_Projection -- Set up a perspective projection *
43 * ProjectorClass::Set_Ortho_Projection -- Set up an orthographic projection *
44 * ProjectorClass::Compute_Texture_Coordinate -- computes texcoord for given world-space poi *
45 * ProjectorClass::Update_WS_Bounding_Volume -- Recalculate the world-space bounding box *
46 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
47
48#include "projector.h"
49#include "refcount.h"
50#include "matrixmapper.h"
51
52
53/***********************************************************************************************
54 * ProjectorClass::ProjectorClass -- Constructor *
55 * *
56 * INPUT: *
57 * *
58 * OUTPUT: *
59 * *
60 * WARNINGS: *
61 * *
62 * HISTORY: *
63 *=============================================================================================*/
72
73
74/***********************************************************************************************
75 * ProjectorClass::~ProjectorClass -- Destructor *
76 * *
77 * INPUT: *
78 * *
79 * OUTPUT: *
80 * *
81 * WARNINGS: *
82 * *
83 * HISTORY: *
84 *=============================================================================================*/
89
90/***********************************************************************************************
91 * ProjectorClass::Set_Transform -- Set the transform for the projector *
92 * *
93 * Projectors can be positioned in world space just like cameras! Just point the -Z axis *
94 * at the target. *
95 * *
96 * INPUT: *
97 * *
98 * OUTPUT: *
99 * *
100 * WARNINGS: *
101 * *
102 * HISTORY: *
103 * 1/11/00 gth : Created. *
104 * 1/27/00 gth : Created. *
105 *=============================================================================================*/
111
112
113/***********************************************************************************************
114 * ProjectorClass::Get_Transform -- Returns the current transform *
115 * *
116 * INPUT: *
117 * *
118 * OUTPUT: *
119 * *
120 * WARNINGS: *
121 * *
122 * HISTORY: *
123 * 1/11/00 gth : Created. *
124 *=============================================================================================*/
126{
127 return Transform;
128}
129
130
131/***********************************************************************************************
132 * ProjectorClass::Set_Perspective_Projection -- Set up a perspective projection *
133 * *
134 * INPUT: *
135 * hfov - radians, horizontal field of view of the projection *
136 * vfov - radians, vertical field of view of the projection *
137 * znear - distance to near clipping plane *
138 * zfar - distance to far clipping plane *
139 * *
140 * OUTPUT: *
141 * *
142 * WARNINGS: *
143 * Remember that znear and zfar are *distances*. They are positive numbers as in the OpenGL *
144 * convention even though the coordinates will be negative. *
145 * *
146 * HISTORY: *
147 * 1/11/00 gth : Created. *
148 *=============================================================================================*/
149void ProjectorClass::Set_Perspective_Projection(float hfov,float vfov,float znear,float zfar)
150{
152 Projection.Init_Perspective(hfov,vfov,0.1f,zfar); // don't use znear for the projection matrix
153
154 float tan_hfov2 = tan(hfov) * 0.5f;
155 float tan_vfov2 = tan(vfov) * 0.5f;
156
157 LocalBoundingVolume.Center.Set(0.0f,0.0f,-(zfar+znear)*0.5f); // note, zcenter is negative
158 LocalBoundingVolume.Extent.X = zfar * tan_hfov2;
159 LocalBoundingVolume.Extent.Y = zfar * tan_vfov2;
160 LocalBoundingVolume.Extent.Z = (zfar-znear)*0.5f;
161
163}
164
165
166/***********************************************************************************************
167 * ProjectorClass::Set_Ortho_Projection -- Set up an orthographic projection *
168 * *
169 * INPUT: *
170 * xmin - "left" x coordinate in texture (camera) space *
171 * xmax - "right" x coordinate *
172 * ymin - "bottom" y coordinate *
173 * ymax - "top" y coordinate *
174 * znear - distance to near clipping plane *
175 * zfar - distance to far clipping plane *
176 * *
177 * OUTPUT: *
178 * *
179 * WARNINGS: *
180 * Remember that znear and zfar are *distances*. They are positive numbers as in the OpenGL *
181 * convention even though the coordinates will be negative. *
182 * *
183 * HISTORY: *
184 * 1/11/00 gth : Created. *
185 *=============================================================================================*/
186void ProjectorClass::Set_Ortho_Projection(float xmin,float xmax,float ymin,float ymax,float znear,float zfar)
187{
189 Projection.Init_Ortho(xmin,xmax,ymin,ymax,0.1f,zfar); // don't use znear for the projection matrix
190
191 LocalBoundingVolume.Center.Set((xmax+xmin)*0.5f, (ymax+ymin)*0.5f, -(zfar+znear)*0.5f);
192 LocalBoundingVolume.Extent.Set((xmax-xmin)*0.5f, (ymax-ymin)*0.5f, (zfar-znear)*0.5f);
193
195}
196
197
198/***********************************************************************************************
199 * ProjectorClass::Compute_Texture_Coordinate -- computes texcoord for given world-space point *
200 * *
201 * INPUT: *
202 * *
203 * OUTPUT: *
204 * *
205 * WARNINGS: *
206 * *
207 * HISTORY: *
208 * 1/27/00 gth : Created. *
209 *=============================================================================================*/
211{
212 Mapper->Compute_Texture_Coordinate(point,set_stq);
213}
214
215
216/***********************************************************************************************
217 * ProjectorClass::Update_WS_Bounding_Volume -- Recalculate the world-space bounding box *
218 * *
219 * INPUT: *
220 * *
221 * OUTPUT: *
222 * *
223 * WARNINGS: *
224 * *
225 * HISTORY: *
226 * 1/11/00 gth : Created. *
227 *=============================================================================================*/
229{
230 /*
231 ** Recompute our world-space bounding volume
232 */
235}
236
static void Transform(const Matrix3D &tm, const OBBoxClass &in, OBBoxClass *out)
Definition obbox.h:161
OBBoxClass WorldBoundingVolume
Definition projector.h:84
void Compute_Texture_Coordinate(const Vector3 &point, Vector3 *set_stq)
virtual void Set_Perspective_Projection(float hfov, float vfov, float znear, float zfar)
ProjectorClass(void)
Definition projector.cpp:64
MatrixMapperClass * Mapper
Definition projector.h:86
virtual void Set_Ortho_Projection(float xmin, float xmax, float ymin, float ymax, float znear, float zfar)
virtual ~ProjectorClass(void)
Definition projector.cpp:85
Matrix3D Transform
Definition projector.h:80
virtual void Update_WS_Bounding_Volume(void)
virtual const Matrix3D & Get_Transform(void) const
Matrix4x4 Projection
Definition projector.h:81
AABoxClass LocalBoundingVolume
Definition projector.h:83
virtual void Set_Transform(const Matrix3D &tm)
#define REF_PTR_RELEASE(x)
Definition refcount.h:80
#define NEW_REF(C, P)
Definition refcount.h:62