lift draw transform setup up to the context

master
Robert Norris 2014-02-03 08:11:34 +11:00
parent 2d302089bd
commit 934181ae20
3 changed files with 11 additions and 2 deletions

View File

@ -66,6 +66,12 @@ void CameraContext::EndFrame()
m_camFrame = nullptr;
}
void CameraContext::ApplyDrawTransforms(Graphics::Renderer *r)
{
r->SetPerspectiveProjection(m_fovAng, m_width/m_height, m_zNear, m_zFar);
r->SetTransform(matrix4x4f::Identity());
}
Camera::Camera(RefCountedPtr<CameraContext> context, Graphics::Renderer *renderer) :
m_context(context),
@ -126,8 +132,6 @@ void Camera::Draw(const Body *excludeBody, ShipCockpit* cockpit)
Frame *camFrame = m_context->GetCamFrame();
m_renderer->SetPerspectiveProjection(m_context->GetFovAng(), m_context->GetWidth()/m_context->GetHeight(), m_context->GetZNear(), m_context->GetZFar());
m_renderer->SetTransform(matrix4x4f::Identity());
m_renderer->ClearScreen();
matrix4x4d trans2bg;

View File

@ -47,6 +47,9 @@ public:
// valid between BeginFrame and EndFrame
Frame *GetCamFrame() const { assert(m_camFrame); return m_camFrame; }
// apply projection and modelview transforms to the renderer
void ApplyDrawTransforms(Graphics::Renderer *r);
private:
float m_width;
float m_height;

View File

@ -401,6 +401,8 @@ void WorldView::Draw3D()
assert(Pi::player);
assert(!Pi::player->IsDead());
m_cameraContext->ApplyDrawTransforms(m_renderer);
Body* excludeBody = nullptr;
ShipCockpit* cockpit = nullptr;
if(GetCamType() == CAM_INTERNAL) {