Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
sr_util.h
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/* $Header: /Commando/Code/ww3d/sr_util.h 16 5/09/00 1:10p Jani_p $ */
20/***********************************************************************************************
21 *** Confidential - Westwood Studios ***
22 ***********************************************************************************************
23 * *
24 * Project Name : Commando / G 3D Library *
25 * *
26 * $Archive:: /Commando/Code/ww3d/sr_util.h $*
27 * *
28 * $Author:: Jani_p $*
29 * *
30 * $Modtime:: 5/09/00 10:23a $*
31 * *
32 * $Revision:: 16 $*
33 * *
34 *---------------------------------------------------------------------------------------------*
35 * Functions: *
36 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
37
38
39#if defined(_MSC_VER)
40#pragma once
41#endif
42
43#ifndef SR_UTIL_H
44#define SR_UTIL_H
45
46#include "always.h"
47#include "matrix3d.h"
48#include "vector3i.h"
49
50#include <srVector3i.hpp>
51#include <srVector3.hpp>
52#include <srVector2.hpp>
53#include <srMatrix4x3.hpp>
54
55class srNode;
56class srMeshModel;
57class srCamera;
58class srGERD;
59class CameraClass;
60
61
62/*
63** Macros for setting and clearing a pointer to a surrender object. There are
64** similar macros for our ref-counting system in refcount.h...
65*/
66#define SR_REF_PTR_SET(dst,src) { if (dst) dst->release(); dst = src; if(dst) dst->addReference(); }
67#define SR_REF_PTR_RELEASE(x) { if (x) x->release(); x = NULL; }
68
69
70/*
71** PUSH_TRANSFORM, POP_TRANSFORM macros. These are just some macros that push
72** and pop a render object's transform in/out of the GERD. I made them macros
73** so that they could be inline without greatly increasing dependencies.
74*/
75#define PUSH_TRANSFORM(renderinfo,tm) \
76 srMatrix4x3 srtm;\
77 Convert_Westwood_Matrix(tm,&srtm); \
78 renderinfo.Gerd.matrixMode(srGERD::MODELVIEW); \
79 renderinfo.Gerd.pushMultMatrix(srtm);
80
81#define POP_TRANSFORM(renderinfo) \
82 renderinfo.Gerd.matrixMode(srGERD::MODELVIEW); \
83 renderinfo.Gerd.popMatrix();
84
85
86/*
87** These functions convert between "westwood" (we use right-handed and column vectors)
88** and "surrender" (left-handed, column vector) matrices. Object and cameras are
89** treated separately.
90*/
91void Set_SR_Transform(srNode * obj,const Matrix3D & tm);
93
94void Set_SR_Camera_Transform(srCamera * obj,const Matrix3D & transform);
96
97/*
98** This function is used to "pushmultiply" a W3D matrix into the given GERD
99*/
100void Push_Multiply_Westwood_Matrix(srGERD * gerd,const Matrix3D & tm);
101
102/*
103** Functions for converting between Matrix3D's and srMatrix4's
104** Only does the "type" conversion, no coordinate system changes...
105*/
106void Convert_Westwood_Matrix(const Matrix3D & wtm,srMatrix4 * set_sr_tm);
107void Convert_Westwood_Matrix(const Matrix3D & wtm,srMatrix4d * set_sr_tm);
108void Convert_Westwood_Matrix(const Matrix3D & wtm,srMatrix4x3 * set_sr_tm);
109void Convert_Westwood_Matrix(const Matrix3D & wtm,srMatrix3 * set_sr_tm,srVector3 * set_sr_translation);
110void Convert_Westwood_Matrix(const Matrix4 & wtm,srMatrix4 * set_sr_tm);
111
112void Convert_Surrender_Matrix(const srMatrix4 & srtm,Matrix3D * set_w3d_tm);
113void Convert_Surrender_Matrix(const srMatrix4x3 & srtm,Matrix3D * set_w3d_tm);
114
115void Multiply_Westwood_And_Surrender_Matrix(const Matrix3D& w3d_tm,const srMatrix4& srtm_s,srMatrix4 & srtm_d);
116
117/*
118** This function will "convert" a pointer to an srVector3 into a pointer to a Vector3.
119** Yes, this sucks. In places where we are dealing with surrender vectors a lot,
120** we should probably just use the surrender math functions.
121*/
122
123
124inline Vector3 * As_Vector3(srVector3 * v) { return (Vector3 *)v; }
125inline Vector3 & As_Vector3(srVector3 & v) { return (Vector3 &) v; }
126inline srVector3 * As_srVector3(Vector3 * v) { return (srVector3 *)v; }
127inline srVector3 & As_srVector3(Vector3 & v) { return (srVector3 &) v; }
128inline const srVector3 * As_srVector3(const Vector3 * v) { return (const srVector3 *)v; }
129inline const srVector3 & As_srVector3(const Vector3 & v) { return (const srVector3 &) v; }
130
131/*
132** Here's a set of equally sucky functions for dealing with srVector4 and Vector4's.
133*/
134
135inline Vector4 * As_Vector4(srVector4 * v) { return (Vector4 *)v; }
136inline Vector4 & As_Vector4(srVector4 & v) { return (Vector4 &) v; }
137inline srVector4 * As_srVector4(Vector4 * v) { return (srVector4 *)v; }
138inline srVector4 & As_srVector4(Vector4 & v) { return (srVector4 &) v; }
139inline const srVector4 * As_srVector4(const Vector4 * v) { return (const srVector4 *)v; }
140inline const srVector4 & As_srVector4(const Vector4 & v) { return (const srVector4 &) v; }
141
142/*
143** More suckage, but now with 2's!
144*/
145
146inline Vector2 * As_Vector2(srVector2 * v) { return (Vector2 *)v; }
147inline Vector2 & As_Vector2(srVector2 & v) { return (Vector2 &) v; }
148inline srVector2 * As_srVector2(Vector2 * v) { return (srVector2 *)v; }
149inline srVector2 & As_srVector2(Vector2 & v) { return (srVector2 &) v; }
150inline const srVector2 * As_srVector2(const Vector2 * v) { return (const srVector2 *)v; }
151inline const srVector2 & As_srVector2(const Vector2 & v) { return (const srVector2 &) v; }
152
153/*
154** Yahoo, here is some more. If they break this we're gonna really be hurting!!!!
155*/
156
157inline Vector3i * As_Vector3i(srVector3i * v) { return (Vector3i *)v; }
158inline Vector3i & As_Vector3i(srVector3i & v) { return (Vector3i &) v; }
159inline srVector3i * As_srVector3i(Vector3i * v) { return (srVector3i *)v; }
160inline srVector3i & As_srVector3i(Vector3i & v) { return (srVector3i &) v; }
161inline const srVector3i * As_srVector3i(const Vector3i * v) { return (const srVector3i *)v; }
162inline const srVector3i & As_srVector3i(const Vector3i & v) { return (const srVector3i &)v; }
163
164/*
165** This function returns the worldspace coordinates of the eight frustum
166** corners of the given camera.
167*/
168void Get_Camera_Frustum_Corners(const CameraClass * camera, Vector3 points[8]);
169
170/*
171** This function returns the worldspace coordinates of the eight frustum
172** corners of the given camera, with the depth (z distance) clamped to two
173** given values.
174*/
176 Vector3 points[8], float minz, float maxz);
177
178
179// the SRMeshClass is used to store all the information neccessary to perform intersection
180// testing on a particular mesh. It is used by the Intersection class within WW3D, and
181// elsewhere within G's planet mode.
182// feel free to extend this to store other srTriMesh data members as needed
183class RenderObjClass;
184typedef unsigned short POLYGONINDEX;
185
187public:
188 RenderObjClass *RenderObject; // what initialized this structure
189
191
192 srVector3i *PolygonVertices;
194 srVector3 *VertexLocations;
195 srVector3 *VertexNormals;
196
205
206 void Initialize(RenderObjClass *renderObject, srMeshModel *meshmodel);
207};
208
209#endif
void Initialize(RenderObjClass *renderObject, srMeshModel *meshmodel)
srVector3 * VertexLocations
Definition sr_util.h:194
RenderObjClass * RenderObject
Definition sr_util.h:188
void Copy(SRMeshClass &info)
Definition sr_util.h:197
srVector4 * PolygonEquations
Definition sr_util.h:193
srVector3 * VertexNormals
Definition sr_util.h:195
srVector3i * PolygonVertices
Definition sr_util.h:192
POLYGONINDEX PolygonCount
Definition sr_util.h:190
unsigned short POLYGONINDEX
Definition intersec.h:65
void Push_Multiply_Westwood_Matrix(srGERD *gerd, const Matrix3D &tm)
srVector3 * As_srVector3(Vector3 *v)
Definition sr_util.h:126
void Convert_Westwood_Matrix(const Matrix3D &wtm, srMatrix4 *set_sr_tm)
bool Get_ZClamped_Camera_Frustum_Corners(const CameraClass *camera, Vector3 points[8], float minz, float maxz)
void Multiply_Westwood_And_Surrender_Matrix(const Matrix3D &w3d_tm, const srMatrix4 &srtm_s, srMatrix4 &srtm_d)
void Get_Camera_Frustum_Corners(const CameraClass *camera, Vector3 points[8])
Vector3 * As_Vector3(srVector3 *v)
Definition sr_util.h:124
void Set_SR_Camera_Transform(srCamera *obj, const Matrix3D &transform)
void Convert_Surrender_Matrix(const srMatrix4 &srtm, Matrix3D *set_w3d_tm)
Vector3i * As_Vector3i(srVector3i *v)
Definition sr_util.h:157
Vector2 * As_Vector2(srVector2 *v)
Definition sr_util.h:146
void Set_SR_Transform(srNode *obj, const Matrix3D &tm)
srVector3i * As_srVector3i(Vector3i *v)
Definition sr_util.h:159
srVector4 * As_srVector4(Vector4 *v)
Definition sr_util.h:137
srVector2 * As_srVector2(Vector2 *v)
Definition sr_util.h:148
Matrix3D Get_SR_Camera_Transform(srCamera *obj)
Vector4 * As_Vector4(srVector4 *v)
Definition sr_util.h:135
Matrix3D Get_SR_Transform(srNode *obj)