Isle
Loading...
Searching...
No Matches
lego3dview.cpp
Go to the documentation of this file.
1// Lego3DView.cpp : implementation file
2//
3
4#include "lego3dview.h"
5
7
9
10
11// Lego3DView
12
13// FUNCTION: LEGO1 0x100aae90
15{
16 m_pViewManager = 0;
17 m_previousRenderTime = 0;
18 m_unk0x98 = 0;
19 m_pPointOfView = 0;
20}
21
22// FUNCTION: LEGO1 0x100aaf30
24{
25 Destroy();
26}
27
28// FUNCTION: LEGO1 0x100aaf90
30{
31 double viewAngle = 45;
32 if (rCreateStruct.m_isWideViewAngle) {
33 viewAngle = 90;
34 }
35
36 float frontClippingDistance = 0.1;
37 float backClippingDistance = 500;
38
39 if (!LegoView1::Create(rCreateStruct, pRenderer)) {
40 return FALSE;
41 }
42
43 assert(GetView());
44 GetView()->SetFrustrum(frontClippingDistance, backClippingDistance, viewAngle);
45
46 assert(GetScene());
47 assert(!m_pViewManager);
48
49 m_pViewManager = new ViewManager(pRenderer, GetScene(), 0);
50 m_pViewManager->SetResolution(GetWidth(), GetHeight());
51 m_pViewManager->SetFrustrum(viewAngle, frontClippingDistance, backClippingDistance);
52 m_previousRenderTime = 0;
53 m_unk0x98 = 0;
54
55 // // NOTE: a derived class must inform view manager when it configures
56 // // its (Tgl) view: calling Tgl::View::SetFrustrum() should be
57 // // accompanied by calling ViewManager::SetFrustrum()
58
59 return TRUE;
60}
61
62// FUNCTION: LEGO1 0x100ab0b0
64{
65 if (m_pPointOfView) {
66 m_pPointOfView = 0;
67 m_pViewManager->SetPOVSource(0);
68 }
69
70 delete m_pViewManager;
71 m_pViewManager = 0;
72
74}
75
76// FUNCTION: LEGO1 0x100ab100
77// FUNCTION: BETA10 0x1017d038
79{
80 assert(m_pViewManager);
81
82 m_pViewManager->Add(&rROI);
83
84 return TRUE;
85}
86
87// FUNCTION: LEGO1 0x100ab170
88// FUNCTION: BETA10 0x1017d096
90{
91 assert(m_pViewManager);
92
93 m_pViewManager->Remove(&rROI);
94
95 if (m_pPointOfView == &rROI) {
96 m_pPointOfView = 0;
97 m_pViewManager->SetPOVSource(0);
98 }
99
100 return TRUE;
101}
102
103// FUNCTION: LEGO1 0x100ab1b0
104// FUNCTION: BETA10 0x1017d123
106{
107 Tgl::FloatMatrix4 transformation;
108 Matrix4 mat(transformation);
109 Tgl::Result result;
110
111 m_pPointOfView = &rROI;
112
113 assert(m_pViewManager);
114 m_pViewManager->SetPOVSource(m_pPointOfView);
115
116 assert(GetCamera());
117 rROI.GetLocalTransform(mat);
118 result = GetCamera()->SetTransformation(transformation);
119 assert(Tgl::Succeeded(result));
120
121 return TRUE;
122}
123
124// FUNCTION: LEGO1 0x100ab210
125// FUNCTION: BETA10 0x1017d230
127{
128 assert(m_pViewManager);
129
130 if (m_pPointOfView == &rROI) {
131 // move the camera
132 Tgl::FloatMatrix4 transformation;
133 Matrix4 mat(transformation);
134 Tgl::Result result;
135
136 assert(GetCamera());
137
138 rROI.GetLocalTransform(mat);
139 result = GetCamera()->SetTransformation(transformation);
140 assert(Tgl::Succeeded(result));
141 m_pViewManager->SetPOVSource(&rROI);
142 }
143
144 return TRUE;
145}
146
147// FUNCTION: LEGO1 0x100ab270
148double Lego3DView::Render(double p_und)
149{
150 assert(m_pViewManager);
151 m_pViewManager->Update(m_previousRenderTime, p_und);
152 m_previousRenderTime = TglSurface::Render();
153 return m_previousRenderTime;
154}
155
156// FUNCTION: LEGO1 0x100ab2b0
157ViewROI* Lego3DView::Pick(unsigned long x, unsigned long y)
158{
159 return m_pViewManager->Pick(GetView(), x, y);
160}
[AI] Represents a 3D view for rendering and managing LEGO game objects in a 3D scene.
Definition: lego3dview.h:20
BOOL Create(const CreateStruct &rCreateStruct, Tgl::Renderer *pRenderer)
[AI] Initializes the 3D view with the specified surface creation parameters and renderer interface.
Definition: lego3dview.cpp:29
BOOL Add(ViewROI &rROI)
[AI] Adds a ViewROI (renderable object instance) to the scene.
Definition: lego3dview.cpp:78
BOOL SetPointOfView(ViewROI &rROI)
[AI] Sets the current point of view to the specified ViewROI and updates the camera transformation.
Definition: lego3dview.cpp:105
void Destroy() override
[AI] Cleans up resources allocated by the view, including the ViewManager, unset the point of view,...
Definition: lego3dview.cpp:63
~Lego3DView() override
[AI] Destroys the Lego3DView instance and all associated resources via Destroy().
Definition: lego3dview.cpp:23
BOOL Moved(ViewROI &rROI)
[AI] Notifies the view that a ViewROI has moved.
Definition: lego3dview.cpp:126
ViewROI * Pick(unsigned long x, unsigned long y)
[AI] Picks (selects) a ViewROI in the scene by screen-space coordinates.
Definition: lego3dview.cpp:157
BOOL Remove(ViewROI &rROI)
[AI] Removes a ViewROI from the scene.
Definition: lego3dview.cpp:89
void Destroy() override
[AI] Safely removes all lights from the scene, deletes them, and nulls pointers.
Definition: legoview1.cpp:175
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
Tgl::Group * GetScene() const
[AI] Accessor for the root scene group.
Definition: legoview1.h:79
Tgl::Camera * GetCamera() const
[AI] Accessor for the view's main camera.
Definition: legoview1.h:84
4x4 Matrix class with virtual interface for manipulation and transformation.
Definition: matrix.h:24
void GetLocalTransform(Matrix4 &p_transform)
Retrieves the local-to-world transformation, or if there is a parent, computes the transform relative...
Tgl::View * GetView() const
[AI] Gets the current view/camera for this surface.
Definition: tglsurface.h:108
virtual double Render()
[AI] Renders a single frame and returns the render time for that frame.
Definition: tglsurface.cpp:179
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
virtual Result SetTransformation(FloatMatrix4 &)=0
[AI] Sets the transformation matrix for the camera.
[AI] Main interface/factory for rendering resources and scene graphs.
Definition: tgl.h:188
virtual Result SetFrustrum(float frontClippingDistance, float backClippingDistance, float degrees)=0
[AI] Sets front and back clipping planes and view field in degrees.
[AI] Manages all ViewROI objects that are rendered in a given scene, handles frustum culling,...
Definition: viewmanager.h:16
void SetFrustrum(float fov, float front, float back)
[AI] Sets the projection frustum parameters and marks the frustum as needing recalculation.
void SetPOVSource(const OrientableROI *point_of_view)
[AI] Sets the OrientableROI to use as the camera's point-of-view; updates the transformation matrix a...
ViewROI * Pick(Tgl::View *p_view, unsigned long x, unsigned long y)
[AI] Using a screen coordinate and viewport, finds the ViewROI (if any) under the given coordinates b...
void Update(float p_previousRenderTime, float)
[AI] Performs the per-frame update: applies frustum/view updates if needed and recurses the ROI graph...
void SetResolution(int width, int height)
[AI] Sets the viewport resolution and marks the frustum as needing recalculation.
void Remove(ViewROI *p_roi)
[AI] Removes a single ViewROI from the managed ROI list, also detaching any associated LOD data from ...
Definition: viewmanager.cpp:95
void Add(ViewROI *p_roi)
[AI] Adds a ViewROI object to the list of managed ROI objects.
Definition: viewmanager.h:161
[AI] ViewROI objects represent viewable and placeable objects in the scene, each holding their own tr...
Definition: viewroi.h:13
#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
int Succeeded(Result result)
[AI] Returns whether a Tgl::Result indicates success.
Definition: tgl.h:136
Result
[AI] Result type used throughout the Tgl API to report operation success or failure.
Definition: tgl.h:126
float FloatMatrix4[4][4]
[AI] Represents a 4x4 matrix of single-precision floating point values.
Definition: tglvector.h:53
[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