| 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 | { |