void PinOverModelExample::MyModelRenderable::Render(Eegeo::Rendering::GLState& glState) const
    {
        Eegeo::m44 transform;
        Eegeo::dv3 location = Eegeo::Space::LatLong::FromDegrees(37.7858,-122.401).ToECEF();
        Eegeo::v3 up(location.Norm().ToSingle());
        Eegeo::v3 forward = (location  - Eegeo::v3(0.f, 1.f, 0.f)).Norm().ToSingle();
        Eegeo::v3 right(Eegeo::v3::Cross(up, forward).Norm());
        forward = Eegeo::v3::Cross(up, right);
        Eegeo::v3 cameraRelativePos = (location - m_renderContext.GetCameraOriginEcef()).ToSingle();
        Eegeo::m44 scaleMatrix;
        scaleMatrix.Scale(1.f);
        Eegeo::m44 cameraRelativeTransform;
        cameraRelativeTransform.SetFromBasis(right, up, forward, cameraRelativePos);
        Eegeo::m44::Mul(transform, cameraRelativeTransform, scaleMatrix);
        transform.SetRow(3, Eegeo::v4(cameraRelativePos, 1.f));

        glState.DepthTest.Enable();
        glState.DepthFunc(GL_LEQUAL);

        //loaded model faces are ccw
        glState.FrontFace(GL_CCW);

        m_model.GetRootNode()->SetVisible(true);
        m_model.GetRootNode()->SetLocalMatrix(transform);
        m_model.GetRootNode()->UpdateRecursive();
        m_model.GetRootNode()->UpdateSphereRecursive();
        m_model.GetRootNode()->DrawRecursive(m_renderContext, m_globalFogging, NULL, true, false);

        glState.FrontFace(GL_CW);

        Eegeo::EffectHandler::Reset();
    }
    Eegeo::m44 ExampleMeshRenderable::CalcModelViewProjection(const Eegeo::dv3& ecefCameraPosition, const Eegeo::m44& viewProjection, const float environmentFlatteningScale) const
    {
        const Eegeo::dv3& flattenedEcefPosition = m_environmentFlattenTranslate
            ? Eegeo::Rendering::EnvironmentFlatteningService::GetScaledPointEcef(GetEcefPosition(), environmentFlatteningScale)
            : GetEcefPosition();
        
        const Eegeo::v3& cameraRelativeModelOrigin = (flattenedEcefPosition - ecefCameraPosition).ToSingle();
        Eegeo::m44 translateRotate;
        translateRotate.SetFromBasis(m_orientationEcef.GetRow(0), m_orientationEcef.GetRow(1), m_orientationEcef.GetRow(2), cameraRelativeModelOrigin);

        Eegeo::m44 scale;
        if (m_environmentFlattenScale)
        {
            scale.Scale(Eegeo::v3(1.0f, environmentFlatteningScale, 1.0f));
        }
        else
        {
            scale.Identity();
        }
        
        Eegeo::m44 orientedCameraRelativeModel;
        Eegeo::m44::Mul(orientedCameraRelativeModel, translateRotate, scale);
        
        
        Eegeo::m44 modelViewProjection;
        Eegeo::m44::Mul(modelViewProjection, viewProjection, orientedCameraRelativeModel);
        return modelViewProjection;
    }
    void PODAnimationExample::Draw()
    {
        //create basis around a known location off coast of SF
        Eegeo::m44 transform;
        Eegeo::dv3 location = Eegeo::dv3(4256955.9749164,3907407.6184668,-2700108.75541722);
        Eegeo::v3 up(location.Norm().ToSingle());
        Eegeo::v3 forward = (location  - Eegeo::v3(0.f, 1.f, 0.f)).Norm().ToSingle();
        Eegeo::v3 right(Eegeo::v3::Cross(up, forward).Norm());
        forward = Eegeo::v3::Cross(up, right);
        Eegeo::v3 cameraRelativePos = (location - cameraModel.GetWorldPosition()).ToSingle();
        Eegeo::m44 scaleMatrix;
        scaleMatrix.Scale(1.f);
        Eegeo::m44 cameraRelativeTransform;
        cameraRelativeTransform.SetFromBasis(right, up, forward, cameraRelativePos);
        Eegeo::m44::Mul(transform, cameraRelativeTransform, scaleMatrix);
        transform.SetRow(3, Eegeo::v4(cameraRelativePos, 1.f));
        
        //loaded model faces are ccw
        renderContext.GetGLState().FrontFace(GL_CCW);
        
        pModel->GetRootNode()->SetVisible(true);
        pModel->GetRootNode()->SetLocalMatrix(transform);
        pModel->GetRootNode()->UpdateRecursive();
        pModel->GetRootNode()->UpdateSphereRecursive();
        pModel->GetRootNode()->DrawRecursive(renderContext, globalFogging, NULL, true, false);
       
        renderContext.GetGLState().FrontFace(GL_CW);

    }
 void LoadModelExample::Draw()
 {
     //form basis
     Eegeo::v3 up(mesh.up);
     Eegeo::v3 forward = -mesh.forward; //model is facing reverse (-ve z)
     Eegeo::v3 right(Eegeo::v3::Cross(up, forward).Norm());
     up = Eegeo::v3::Cross(forward, right);
     
    
     //compute a camera local position
     Eegeo::v3 cameraRelativePos = (mesh.positionEcef - renderContext.GetCameraOriginEcef()).ToSingle();
     
     //generate a transform from this basis and position...
     Eegeo::m44 cameraRelativeTransform;
     cameraRelativeTransform.SetFromBasis(right, up, forward, cameraRelativePos);
     
     Eegeo::m44 scaleMatrix;
     scaleMatrix.Scale(mesh.scale);
     
     //...and scale
     Eegeo::m44 transform;
     Eegeo::m44::Mul(transform, cameraRelativeTransform, scaleMatrix);
     transform.SetRow(3, Eegeo::v4(cameraRelativePos, 1.0f));
     
     //update the mesh instance with the transform
     mesh.node->SetLocalMatrix(transform);
     mesh.node->UpdateRecursive();
     mesh.node->UpdateSphereRecursive();
     mesh.node->UpdateBBRecursive();
     
     // Enable z buffering.
     Eegeo::Rendering::GLState& glState = renderContext.GetGLState();
     glState.DepthTest.Enable();
     glState.DepthFunc(GL_LEQUAL);
     glState.DepthMask(GL_TRUE);
     
     //draw the mesh
     mesh.node->DrawRecursive(renderContext, globalFogging, NULL, true, true);
     
     Eegeo::v3 min, max;
     mesh.node->GetMinExtent(min);
     mesh.node->GetMaxExtent(max);
     boundsVisualiser.Draw(min, max);
 }