void Camera::Update() { if (!m_frame) return; // make temporary camera frame m_camFrame = new Frame(m_frame, "camera", Frame::FLAG_ROTATING); // move and orient it to the camera position m_camFrame->SetOrient(m_orient); m_camFrame->SetPosition(m_pos); // make sure old orient and interpolated orient (rendering orient) are not rubbish m_camFrame->ClearMovement(); m_camFrame->UpdateInterpTransform(1.0); // update root-relative pos/orient // evaluate each body and determine if/where/how to draw it m_sortedBodies.clear(); for (Space::BodyIterator i = Pi::game->GetSpace()->BodiesBegin(); i != Pi::game->GetSpace()->BodiesEnd(); ++i) { Body *b = *i; // prepare attrs for sorting and drawing BodyAttrs attrs; attrs.body = b; Frame::GetFrameRenderTransform(b->GetFrame(), m_camFrame, attrs.viewTransform); attrs.viewCoords = attrs.viewTransform * b->GetInterpPosition(); attrs.camDist = attrs.viewCoords.Length(); attrs.bodyFlags = b->GetFlags(); m_sortedBodies.push_back(attrs); } // depth sort m_sortedBodies.sort(); }
void Camera::Update() { if (!m_body) return; // make temporary camera frame at the body m_camFrame = new Frame(m_body->GetFrame(), "camera", Frame::TEMP_VIEWING | Frame::FLAG_ROTATING); // interpolate between last physics tick position and current one, // to remove temporal aliasing const matrix3x3d &m = m_body->GetInterpOrient(); m_camFrame->SetOrient(m * m_orient); m_camFrame->SetPosition(m * m_pos + m_body->GetInterpPosition()); // make sure old orient and interpolated orient (rendering orient) are not rubbish m_camFrame->ClearMovement(); m_camFrame->UpdateInterpTransform(1.0); // update root-relative pos/orient // evaluate each body and determine if/where/how to draw it m_sortedBodies.clear(); for (Space::BodyIterator i = Pi::game->GetSpace()->BodiesBegin(); i != Pi::game->GetSpace()->BodiesEnd(); ++i) { Body *b = *i; // prepare attrs for sorting and drawing BodyAttrs attrs; attrs.body = b; Frame::GetFrameRenderTransform(b->GetFrame(), m_camFrame, attrs.viewTransform); attrs.viewCoords = attrs.viewTransform * b->GetInterpPosition(); attrs.camDist = attrs.viewCoords.Length(); attrs.bodyFlags = b->GetFlags(); m_sortedBodies.push_back(attrs); } // depth sort m_sortedBodies.sort(); }