Isle
Loading...
Searching...
No Matches
legoview1.cpp
Go to the documentation of this file.
1// LegoView1.cpp : implementation file
2//
3
4#include "legoview1.h"
5
6#include "decomp.h"
9#include "realtime/realtime.h"
10
11#include <vec.h>
12
15
16// GLOBAL: LEGO1 0x101013e4
17float g_sunLightRGB = 1.0;
18
19// GLOBAL: LEGO1 0x101013e8
21
22// GLOBAL: LEGO1 0x101013ec
24
26// LegoView
27
28// FUNCTION: LEGO1 0x100ab510
29// FUNCTION: BETA10 0x1017bb90
31{
32 m_pScene = 0;
33 m_pCamera = 0;
34}
35
36// FUNCTION: LEGO1 0x100ab5a0
37// FUNCTION: BETA10 0x1017bc19
39{
40 Destroy();
41}
42
43// FUNCTION: LEGO1 0x100ab600
44// FUNCTION: BETA10 0x1017bc89
46{
47 float viewAngle = 45;
48
49 float frontClippingDistance = 0.1;
50 float backClippingDistance = 500;
51
52 assert(!m_pScene);
53 assert(!m_pCamera);
54 assert(pRenderer);
55
56 if (rCreateStruct.m_isWideViewAngle) {
57 viewAngle = 90;
58 }
59
60 m_pScene = pRenderer->CreateGroup();
61 assert(m_pScene);
62 // TglSurface::Create() calls CreateView(), and we need the camera in
63 // CreateView(), so create camera before calling TglSurface::Create()
64 m_pCamera = pRenderer->CreateCamera();
65 assert(m_pCamera);
66
67 if (!TglSurface::Create(rCreateStruct, pRenderer, m_pScene)) {
68 delete m_pScene;
69 m_pScene = 0;
70
71 delete m_pCamera;
72 m_pCamera = 0;
73
74 return FALSE;
75 }
76
77 assert(GetView());
78 GetView()->SetFrustrum(frontClippingDistance, backClippingDistance, viewAngle);
79 GetView()->SetBackgroundColor(.223, .639, .851);
80
81 return TRUE;
82}
83
84// FUNCTION: LEGO1 0x100ab6c0
85// FUNCTION: BETA10 0x1017befd
87{
88 assert(pRenderer);
89 assert(pDevice);
90
91 return pRenderer->CreateView(pDevice, m_pCamera, 0, 0, GetWidth(), GetHeight());
92}
93
94// FUNCTION: LEGO1 0x100ab6f0
95// FUNCTION: BETA10 0x1017bf96
97{
98 delete m_pScene;
99 m_pScene = 0;
100
101 delete m_pCamera;
102 m_pCamera = 0;
103
105}
106
108// LegoView1
109
110// FUNCTION: LEGO1 0x100ab730
111// FUNCTION: BETA10 0x1017c028
113{
114 m_pSunLight = 0;
115 m_pDirectionalLight = 0;
116 m_pAmbientLight = 0;
117}
118
119// FUNCTION: LEGO1 0x100ab7c0
120// FUNCTION: BETA10 0x1017c0be
122{
123 Destroy();
124}
125
126// FUNCTION: LEGO1 0x100ab820
127// FUNCTION: BETA10 0x1017c12e
129{
130 assert(GetView());
131 GetView()->Add(m_pSunLight);
132 GetView()->Add(m_pDirectionalLight);
133 GetView()->Add(m_pAmbientLight);
134 return TRUE;
135}
136
137// FUNCTION: LEGO1 0x100ab860
138// FUNCTION: BETA10 0x1017c1ea
140{
141 if (!LegoView::Create(rCreateStruct, pRenderer)) {
142 return FALSE;
143 }
144
145 // lights
147 m_pDirectionalLight =
150
151 Mx3DPointFloat position(0.0, 0.0, 0.0);
152 Mx3DPointFloat direction(0.0, -1.0, 0.0);
153 Mx3DPointFloat up(1.0, 0.0, 0.0);
154
155 Tgl::FloatMatrix4 matrix;
156 Matrix4 in(matrix);
157 MxMatrix transform;
158
159 CalcLocalTransform(position, direction, up, transform);
160 SETMAT4(in, transform);
161 m_pDirectionalLight->SetTransformation(matrix);
162
163 position[0] = 0, position[1] = 150, position[2] = -150;
164 CalcLocalTransform(position, direction, up, transform);
165 SETMAT4(in, transform);
166 m_pSunLight->SetTransformation(matrix);
167
168 // assert(GetView());
169
170 return AddLightsToViewport();
171}
172
173// FUNCTION: LEGO1 0x100abad0
174// FUNCTION: BETA10 0x1017c912
176{
177 if (m_pSunLight) {
178 GetView()->Remove(m_pSunLight);
179 delete m_pSunLight;
180 m_pSunLight = 0;
181 }
182
183 if (m_pDirectionalLight) {
184 GetView()->Remove(m_pDirectionalLight);
185 delete m_pDirectionalLight;
186 m_pDirectionalLight = 0;
187 }
188
189 if (m_pAmbientLight) {
190 GetView()->Remove(m_pAmbientLight);
191 delete m_pAmbientLight;
192 m_pAmbientLight = 0;
193 }
194
196}
197
198// FUNCTION: LEGO1 0x100abb60
199// FUNCTION: BETA10 0x1017ca80
200void LegoView1::SetLightTransform(BOOL bDirectionalLight, Tgl::FloatMatrix4& rMatrix)
201{
202 Tgl::Light* pLight;
203
204 if (bDirectionalLight == FALSE) {
205 pLight = m_pSunLight;
206 }
207 else {
208 pLight = m_pDirectionalLight;
209 }
210
211 SetLightTransform(pLight, rMatrix);
212}
213
214// FUNCTION: LEGO1 0x100abb80
215// FUNCTION: BETA10 0x1017cacf
217{
218 pLight->SetTransformation(rMatrix);
219}
220
221// FUNCTION: LEGO1 0x100abba0
222// FUNCTION: BETA10 0x1017caf6
223void LegoView1::SetLightColor(BOOL bDirectionalLight, float red, float green, float blue)
224{
225 Tgl::Light* pLight;
226
227 if (bDirectionalLight == FALSE) {
228 pLight = m_pSunLight;
229 }
230 else {
231 pLight = m_pDirectionalLight;
232 }
233
234 SetLightColor(pLight, red, green, blue);
235}
236
237// FUNCTION: LEGO1 0x100abbd0
238// FUNCTION: BETA10 0x1017cb4d
239void LegoView1::SetLightColor(Tgl::Light* pLight, float red, float green, float blue)
240{
241 pLight->SetColor(red, green, blue);
242}
[AI] 3D view that supports advanced lighting for scene rendering.
Definition: legoview1.h:105
~LegoView1() override
[AI] Destructor.
Definition: legoview1.cpp:121
void Destroy() override
[AI] Safely removes all lights from the scene, deletes them, and nulls pointers.
Definition: legoview1.cpp:175
void SetLightTransform(BOOL bDirectionalLight, Tgl::FloatMatrix4 &rMatrix)
[AI] Sets the transformation matrix (position/orientation) for either the sun or directional light.
Definition: legoview1.cpp:200
BOOL AddLightsToViewport()
[AI] Adds the view's lights (sun, directional, ambient) to the active Tgl view for rendering.
Definition: legoview1.cpp:128
BOOL Create(const TglSurface::CreateStruct &rCreateStruct, Tgl::Renderer *pRenderer)
[AI] Initializes scene, camera, and three types of lights (sun, directional, ambient) using supplied ...
Definition: legoview1.cpp:139
void SetLightColor(BOOL bDirectionalLight, float red, float green, float blue)
[AI] Sets the RGB color for either the sun or directional light.
Definition: legoview1.cpp:223
LegoView1()
[AI] Constructs the view and zeros out all light pointers (sun, directional, ambient).
Definition: legoview1.cpp:112
[AI] Represents a 3D rendering surface holding the main scene group and camera for rendering.
Definition: legoview1.h:24
LegoView()
[AI] Constructs an empty LegoView with uninitialized scene and camera.
Definition: legoview1.cpp:30
~LegoView() override
[AI] Destructor.
Definition: legoview1.cpp:38
Tgl::View * CreateView(Tgl::Renderer *pRenderer, Tgl::Device *pDevice) override
[AI] Create and return the Tgl::View object for this surface.
Definition: legoview1.cpp:86
BOOL Create(const CreateStruct &rCreateStruct, Tgl::Renderer *pRenderer)
[AI] Initialize the LegoView with a scene root and camera using the provided creation parameters and ...
Definition: legoview1.cpp:45
void Destroy() override
[AI] Release all scene and camera resources, call TglSurface cleanup.
Definition: legoview1.cpp:96
4x4 Matrix class with virtual interface for manipulation and transformation.
Definition: matrix.h:24
[AI] Represents a 3D point with floating-point precision, inheriting from Vector3.
Definition: mxgeometry3d.h:14
[AI] Represents a 4x4 transformation matrix, specialized for the LEGO Island engine and derived from ...
Definition: mxmatrix.h:16
Tgl::View * GetView() const
[AI] Gets the current view/camera for this surface.
Definition: tglsurface.h:108
virtual BOOL Create(const CreateStruct &, Tgl::Renderer *, Tgl::Group *pScene)
[AI] Creates and initializes the surface, rendering device, and optionally installs scene graph.
Definition: tglsurface.cpp:76
virtual void Destroy()
[AI] Destroys all resources (view, device), releasing scene and renderer references.
Definition: tglsurface.cpp:45
unsigned long GetWidth() const
[AI] Returns the width (in pixels) of the rendered surface.
Definition: tglsurface.h:120
unsigned long GetHeight() const
[AI] Returns the height (in pixels) of the rendered surface.
Definition: tglsurface.h:126
[AI] Represents a rendering device/context for the Tgl renderer.
Definition: tgl.h:318
[AI] Represents a source of lighting in the 3D scene.
Definition: tgl.h:559
virtual Result SetTransformation(FloatMatrix4 &)=0
[AI] Sets the transformation matrix for the light source.
virtual Result SetColor(float r, float g, float b)=0
[AI] Sets the light's color.
[AI] Main interface/factory for rendering resources and scene graphs.
Definition: tgl.h:188
virtual View * CreateView(const Device *, const Camera *, unsigned long x, unsigned long y, unsigned long width, unsigned long height)=0
[AI] Creates a rendering view associated with the given device and camera.
virtual Light * CreateLight(LightType, float r, float g, float b)=0
[AI] Creates a new light of the given type and color.
virtual Camera * CreateCamera()=0
[AI] Creates a new camera.
virtual Group * CreateGroup(const Group *pParent=0)=0
[AI] Creates a new group (scene graph node), optionally parented.
[AI] Represents a rendering viewport and drawing context.
Definition: tgl.h:397
virtual Result SetBackgroundColor(float r, float g, float b)=0
[AI] Sets the background color for the view.
virtual Result Remove(const Light *)=0
[AI] Removes a light from the view.
virtual Result SetFrustrum(float frontClippingDistance, float backClippingDistance, float degrees)=0
[AI] Sets front and back clipping planes and view field in degrees.
virtual Result Add(const Light *)=0
[AI] Adds a light to the view for rendering.
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
typedef BOOL(FAR PASCAL *LPDIENUMDEVICEOBJECTSCALLBACKA)(LPCDIDEVICEOBJECTINSTANCEA
float g_directionalLightRGB
Definition: legoview1.cpp:20
float g_sunLightRGB
Definition: legoview1.cpp:17
float g_ambientLightRGB
Definition: legoview1.cpp:23
float FloatMatrix4[4][4]
[AI] Represents a 4x4 matrix of single-precision floating point values.
Definition: tglvector.h:53
@ Point
[AI] Light emitted from a point in all directions. [AI]
Definition: tgl.h:44
@ Directional
[AI] Parallel light rays, such as sunlight. [AI]
Definition: tgl.h:46
@ Ambient
[AI] Non-directional lighting applied equally everywhere. [AI]
Definition: tgl.h:43
void CalcLocalTransform(const Vector3 &p_posVec, const Vector3 &p_dirVec, const Vector3 &p_upVec, Matrix4 &p_outMatrix)
[AI] Computes a transformation matrix based on a position, direction, and up vector.
Definition: realtime.cpp:7
[AI] Contains initialization parameters for creating a TglSurface and its underlying DDraw/D3D resour...
Definition: tglsurface.h:40
BOOL m_isWideViewAngle
[AI] Enables wide or default field-of-view projection.
Definition: tglsurface.h:48
#define SETMAT4(to, from)
Definition: vec.h:547