MCPcopy Create free account
hub / github.com/defold/defold / UpdateRenderCamera

Function UpdateRenderCamera

engine/render/src/render/camera.cpp:122–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120 }
121
122 void UpdateRenderCamera(HRenderContext render_context, HRenderCamera camera, const dmVMath::Point3* position, const dmVMath::Quat* rotation)
123 {
124 RenderCamera* c = render_context->m_RenderCameras.Get(camera);
125 if (!c)
126 {
127 return;
128 }
129
130 dmGraphics::HContext graphics_context = GetGraphicsContext(render_context);
131 float width = (float) dmGraphics::GetWindowWidth(graphics_context);
132 float height = (float) dmGraphics::GetWindowHeight(graphics_context);
133 float aspect_ratio = c->m_Data.m_AspectRatio;
134
135 if (c->m_Data.m_AutoAspectRatio)
136 {
137 aspect_ratio = width / height;
138 }
139
140 c->m_OrthographicAutoZoom = 1.0f;
141
142 if (c->m_Data.m_OrthographicProjection)
143 {
144 float display_scale = dmGraphics::GetDisplayScaleFactor(graphics_context);
145
146 // Determine zoom
147 float zoom = c->m_Data.m_OrthographicZoom;
148
149 // Project (reference) size from game.project
150 float proj_width = (float) dmGraphics::GetWidth(graphics_context);
151 float proj_height = (float) dmGraphics::GetHeight(graphics_context);
152
153 // Fallbacks to avoid division by zero
154 if (proj_width <= 0.0f)
155 {
156 proj_width = 1.0f;
157 }
158 if (proj_height <= 0.0f)
159 {
160 proj_height = 1.0f;
161 }
162
163 // Compute auto zoom if requested
164 if (c->m_Data.m_OrthographicMode == ORTHO_MODE_AUTO_FIT || c->m_Data.m_OrthographicMode == ORTHO_MODE_AUTO_COVER)
165 {
166 float zx = width / (display_scale * proj_width);
167 float zy = height / (display_scale * proj_height);
168
169 if (c->m_Data.m_OrthographicMode == ORTHO_MODE_AUTO_FIT)
170 {
171 c->m_OrthographicAutoZoom = (zx < zy) ? zx : zy;
172 }
173 else if (c->m_Data.m_OrthographicMode == ORTHO_MODE_AUTO_COVER)
174 {
175 c->m_OrthographicAutoZoom = (zx > zy) ? zx : zy;
176 }
177
178 if (c->m_OrthographicAutoZoom <= 0.0f)
179 {

Callers 4

TEST_FFunction · 0.85
TEST_FFunction · 0.85
DrawRenderListFunction · 0.85

Calls 9

GetGraphicsContextFunction · 0.85
GetWindowWidthFunction · 0.50
GetWindowHeightFunction · 0.50
GetDisplayScaleFactorFunction · 0.50
GetWidthFunction · 0.50
GetHeightFunction · 0.50
RotateFunction · 0.50
Vector3Class · 0.50
GetMethod · 0.45

Tested by 2

TEST_FFunction · 0.68
TEST_FFunction · 0.68