void AccuracyRingRenderable::RenderSpheres(Eegeo::Rendering::GLState &glState) const
            {
                glState.BindTexture2D(0);
                glState.ColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

                glState.DepthMask(GL_FALSE);
                glState.DepthTest.Enable();
                glState.DepthFunc(GL_LESS);

                glState.CullFace.Disable();

                glState.StencilTest.Enable();
                glState.StencilFunc(GL_ALWAYS, 1, 0xFF);
                glState.StencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR_WRAP);
                glState.StencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR_WRAP);

                Eegeo::m44 transform;
                Eegeo::m44 mvp;
                transform.Scale(m_outerRingRadius*2);
                transform.SetRow(3, Eegeo::v4(m_cameraRelativePosition, 1.0f));
                Eegeo::m44::Mul(mvp, m_viewProjection, transform);
                m_sphereRenderable.SetModelViewProjection(mvp);
                m_sphereRenderable.Render(glState);

                transform.Scale(m_innerRingRadius*2);
                transform.SetRow(3, Eegeo::v4(m_cameraRelativePosition, 1.0f));
                Eegeo::m44::Mul(mvp, m_viewProjection, transform);
                m_sphereRenderable.SetModelViewProjection(mvp);
                m_sphereRenderable.Render(glState);
            }
    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();
    }
    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);
 }