bool PinsWithAttachedJavaUIExample::Event_TouchTap(const AppInterface::TapData& data)
    {
        Eegeo::v2 screenTapPoint = Eegeo::v2(data.point.GetX(), data.point.GetY());

        Eegeo_TTY("Searching for Pins intersecting tap point %d,%d...", (int) screenTapPoint.GetX(), (int) screenTapPoint.GetY());

        Eegeo::Pins::PinController& pinController = m_pPinsModule->GetController();
        std::vector<Eegeo::Pins::Pin*> intersectingPinsClosestToCameraFirst;
        if(pinController.TryGetPinsIntersectingScreenPoint(screenTapPoint, intersectingPinsClosestToCameraFirst))
        {
            Eegeo_TTY("found %ld :\n", intersectingPinsClosestToCameraFirst.size());

            for(std::vector<Eegeo::Pins::Pin*>::const_iterator it = intersectingPinsClosestToCameraFirst.begin(); it != intersectingPinsClosestToCameraFirst.end(); ++it)
            {
                Eegeo::Pins::Pin* pPin = *it;

                Eegeo_TTY("\tId=%d, User Data='%s'\n", pPin->GetId(), ((std::string*) pPin->GetUserData())->c_str());
            }

            return true;
        }
        else
        {
            Eegeo_TTY("none found.\n");
            return false;
        }
    }
void WebRequestExample::Start()
{
	Eegeo_TTY("Making 4 Http GETs, with integer labels as user data, using a member as the handler...\n");
    m_webRequestFactory.Begin(Eegeo::Web::HttpVerbs::GET, "http://apikey.eegeo.com", externalGetHandler.GetRequestHandler())
        .SetUserData(new int(1))
        .Build()->Load();
    
    m_webRequestFactory.Begin(Eegeo::Web::HttpVerbs::GET, "http://non-existent-example-host-1234.com", externalGetHandler.GetRequestHandler())
        .SetUserData(new int(2))
        .Build()->Load();
    
    m_webRequestFactory.Begin(Eegeo::Web::HttpVerbs::GET, "http://wikipedia.org", externalGetHandler.GetRequestHandler())
        .SetUserData(new int(3))
        .Build()->Load();
    
    m_webRequestFactory.Begin(Eegeo::Web::HttpVerbs::GET, "http://d2xvsc8j92rfya.cloudfront.net/non_existent_resource.hcff", externalGetHandler.GetRequestHandler())
        .SetUserData(new int(4))
        .Build()->Load();

	Eegeo_TTY("Making Https POST to Eegeo apikey service with invalid key (123456789), with integer labels as user data using a non-member as the handler...\n");
    m_webRequestFactory.Begin(Eegeo::Web::HttpVerbs::POST, "https://apikey.eegeo.com/validate", externalPostHandler)
        .AddFormData("token", "123456789")
        .SetUserData(new int(5678))
        .Build()->Load();
    
    m_webRequestFactory.Begin(Eegeo::Web::HttpVerbs::GET, "http://wikipedia.org", externalGetHandler.GetRequestHandler())
        .AddHeader("X-MyCustom-Header", "Hello World")
        .SetUserData(new int(4))
        .Build()->Load();
}
    void LoadModelExample::Start()
    {
        pModel = Eegeo::Model::CreateFromPODFile("sanfrancisco_vehicles_alpha.POD", fileIO, renderContext.GetGLState(), &textureRequestor, "");
        
        //the layout of this resource is assumed - a "Vehicles" node should exist
        Eegeo::Node* parentNode = pModel->FindNode("Vehicles");
        Eegeo_ASSERT(parentNode);
        
        // Print details of the materials in the POD.
        for(int i = 0; i < pModel->GetNumMaterials(); i++)
        {
            Eegeo::ModelMaterial* pMaterial = pModel->GetMaterial(i);
            Eegeo_TTY(
                      "Material: %s %s alpha=%f\n",
                      pMaterial->GetName().c_str(),
                      (pMaterial->GetMaterialFlags() & Eegeo::kMaterialFlag_Blend) ? "blended" : "opaque",
                      pMaterial->GetAlpha()
                      );
        }

        // Look up the material for the disc so that we can animate its alpha value.
        if(!pModel->TryGetMaterialByName("alpha_disc_material", discMaterial))
        {
        	Eegeo_TTY("Failed to find disc material.\n");
        }
        
        //it should have some children, which are the vehicle meshes...
        Eegeo_ASSERT(parentNode->GetNumChildNodes() > 0);

        //select a vehicle.
        mesh.node = parentNode->GetChildNode(0);
    }
            bool MyPinsFileIO::TryCacheImageToDisk(Byte* imageData,
                                                   size_t imageSize,
                                                   int myPinId,
                                                   std::string& out_filename)
            {
                out_filename = "";

                std::stringstream ss;
                ss << MyPinImagePrefix << myPinId << ".jpg";

                std::string imagePath = ss.str();

                if (m_fileIO.Exists(imagePath))
                {
                    Eegeo_TTY("%s already exists\n", imagePath.c_str());
                    return false;
                }

                if (m_fileIO.WriteFile(imageData, imageSize, imagePath))
                {
                    out_filename = imagePath;
                    return true;
                }

                Eegeo_TTY("Couldn't write %s to file\n", imagePath.c_str());

                return false;
            }
                void YelpBusinessQuery::HandleWebResponseComplete(Eegeo::Web::IWebResponse& webResponse)
                {
                    Eegeo_ASSERT(!webResponse.IsCancelled());
                    
                    size_t resultSize = webResponse.GetBodyData().size();
                    const std::string& responseString = resultSize > 0 ? std::string(reinterpret_cast<char const*>(&(webResponse.GetBodyData().front())), resultSize) : "<empty>";

                    bool parseSuccess = false;
                    Search::SdkModel::SearchResultModel result;
                    
                    if (webResponse.IsSucceeded())
                    {
                        parseSuccess = m_yelpBusinessParser.TryParse(responseString, result);
                    }
                    else
                    {
                        Eegeo_TTY("YelpBusinessQuery failed: %s", responseString.c_str());
                    }
                    
                    const Search::SdkModel::IdentitySearchCallbackData& callbackData = parseSuccess
                        ? Search::SdkModel::IdentitySearchCallbackData::CreateSucceeded(result)
                        : Search::SdkModel::IdentitySearchCallbackData::CreateFailed(result);

                    m_completionCallback(callbackData);

                    Eegeo_DELETE this;
                }
 void BoundsVisualiser::CompileShaders()
 {
     std::string vertexShaderCode = VertexShader();
     std::string fragmentShaderCode = FragmentShader();
     
     GLuint vertexShader = Eegeo::Helpers::ShaderCompiler::CompileShader(vertexShaderCode, GL_VERTEX_SHADER);
     GLuint fragmentShader = Eegeo::Helpers::ShaderCompiler::CompileShader(fragmentShaderCode, GL_FRAGMENT_SHADER);
     
     m_pShader = new Shader;
     m_pShader->m_programHandle = glCreateProgram();
     glAttachShader(m_pShader->m_programHandle, vertexShader);
     glAttachShader(m_pShader->m_programHandle, fragmentShader);
     glLinkProgram(m_pShader->m_programHandle);
     
     GLint linkSuccess;
     glGetProgramiv(m_pShader->m_programHandle, GL_LINK_STATUS, &linkSuccess);
     if (linkSuccess == GL_FALSE)
     {
         GLchar messages[256];
         glGetProgramInfoLog(m_pShader->m_programHandle, sizeof(messages), 0, &messages[0]);
         Eegeo_TTY("%s\n", &messages[0]);
         return;
     }
     
     Eegeo_GL(glUseProgram(m_pShader->m_programHandle));
     
     m_pShader->m_positionSlot = glGetAttribLocation(m_pShader->m_programHandle, "pos");
     m_pShader->m_mvpUniform = glGetUniformLocation(m_pShader->m_programHandle, "mvp");
 }
void PinsExample::AddRemovePin0()
{
	Eegeo::Pins::PinRepository& pinRepository = m_pPinsModule->GetRepository();

	Eegeo::Pins::Pin* pPin0 = pinRepository.GetPinById(m_pPin0->GetId());
	if(pPin0)
	{
		Eegeo_TTY("Remove Pin 0 from repository.\n");
		pinRepository.RemovePin(*m_pPin0);
	}
	else
	{
		Eegeo_TTY("Add Pin 0 to repository.\n");
		pinRepository.AddPin(*m_pPin0);
	}
}
    void WebRequestExample::Start()
    {
        Eegeo_TTY("Making 3 Http GETs with integer labels as user data using a member as the handler...\n");
        webRequestFactory.CreateGet("http://appstore.eegeo.com", *this, new int(1))->Load();
        webRequestFactory.CreateGet("http://non-existent-example-host-1234.com", *this, new int(2))->Load();
        webRequestFactory.CreateGet("http://wikipedia.org", *this, new int(3))->Load();
        webRequestFactory.CreateGet("http://d2xvsc8j92rfya.cloudfront.net/non_existent_resource.hcff", *this, new int(4))->Load();
        
        std::map<std::string, std::string> postData;
        postData["token"] = "123456789";
        Eegeo_TTY("Making Https POST to Eegeo appstore with invalid key (123456789), with integer labels as user data using a non-member as the handler...\n");
        webRequestFactory.CreatePost("https://appstore.eegeo.com/validate", externalHandler, new int(5678), postData)->Load();

        std::map<std::string, std::string> httpHeaders;
        httpHeaders["X-MyCustom-Header"] = "Hello World";
        webRequestFactory.CreateGet("http://wikipedia.org", *this, new int(4), httpHeaders)->Load();
    }
            void MyPinsFileIO::SavePinModelToDisk(const MyPinModel& pinModel)
            {
                std::fstream stream;
                size_t size;

                if (m_fileIO.OpenFile(stream, size, MyPinsDataFilename))
                {
                    std::string json((std::istreambuf_iterator<char>(stream)),
                                     (std::istreambuf_iterator<char>()));

                    rapidjson::Document jsonDoc;
                    if (jsonDoc.Parse<0>(json.c_str()).HasParseError())
                    {
                        Eegeo_TTY("Parse error in MyPins JSON.\n");
                        return;
                    }

                    Eegeo_ASSERT(jsonDoc.IsObject(), "JSON document is not of object type");

                    rapidjson::Document::AllocatorType& allocator = jsonDoc.GetAllocator();
                    rapidjson::Value& myPinsArray = jsonDoc[MyPinsJsonArrayName.c_str()];

                    rapidjson::Value pinModelJson;
                    MyPinModelToJson(pinModel, allocator, m_myPinBoundObjectRepository, pinModelJson);
                    
                    myPinsArray.PushBack(pinModelJson, allocator);

                    rapidjson::StringBuffer strbuf;
                    rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf);
                    jsonDoc.Accept(writer);
                    std::string jsonString = strbuf.GetString();

                    if (WriteJsonToDisk(jsonString))
                    {
                        m_persistentSettings.SetValue(MyPins_LastMyPinModelIdKey, pinModel.Identifier());
                    }
                }
                else
                {
                    Eegeo_TTY("Couldn't open file:%s\n", MyPinsDataFilename.c_str());
                }
            }
 void WebRequestExample::RequestComplete(IWebLoadRequest& webLoadRequest)
 {
     int* userData = (int*)webLoadRequest.GetUserData();
     const std::string& url = webLoadRequest.GetUrl();
     size_t responseBodySize = webLoadRequest.GetResourceData().size();
     int result = webLoadRequest.HttpStatusCode();
     
     Eegeo_TTY("\nFinished Http GET of %s in a member function of calling type, result was %d, with user data %d - resource size of %ld\n",
               url.c_str(), result, *userData, responseBodySize);
     
     delete userData;
 }
Beispiel #11
0
void RouteSimulationExampleObserver::OnLinkReached(const Eegeo::Routes::Simulation::RouteSimulationSession& session) const
{
    // At each new link, we change the model being drawn
    int vehicleIndex = rand() % (int)(m_vehicleModels.size());
    Eegeo::Rendering::SceneModels::SceneModel* vehicleModel = m_vehicleModels.at(vehicleIndex);
    m_pModelBinding->SetModel(vehicleModel);

    const dv3& ecef = session.GetCurrentPositionEcef();

    Eegeo::Space::LatLongAltitude latLongAltitude = Eegeo::Space::LatLongAltitude::FromECEF(ecef);
    Eegeo_TTY("New link reached at %f, %f\n", latLongAltitude.GetLatitudeInDegrees(), latLongAltitude.GetLongitudeInDegrees());

}
    void TrafficCongestionExample::Update(float dt)
    {
        if(!m_hasCalled && !m_world.Initialising())
        {
            m_hasCalled = true;

            const int roadId = 0;

            Eegeo::Streaming::MortonKey key = Eegeo::Streaming::MortonKey::CreateFromString("01131232132001");

            bool success = m_trafficCongestionService.TrySetCongestionFor(
                    key,
                    roadId,
                    Eegeo::TrafficCongestion::CongestionLevel::Heavy);

            Eegeo_TTY("%s congestion level on road id %d for morton key %s\n",
                    success ? "Successfully set" : "Failed to set",
                    roadId,
                    key.ToString().c_str());
        }
    }
void LoadModelExample::Start()
{
    m_pModel = m_sceneModelLoader.LoadPOD("load_model_example/sanfrancisco_vehicles_alpha.POD");

    // Look up the material for the disc so that we can animate its alpha value.
    // Materials will be loaded into the material resource repository and id' by 'filename/materials/material name'
    std::string materialId = "load_model_example/sanfrancisco_vehicles_alpha.POD/materials/alpha_disc_material";
    
	if(!m_sceneModelMaterials.HasResource(materialId))
	{
		Eegeo_TTY("Failed to find disc material.\n");
	}
    else
    {
        // This action increments the material resource's reference count.  When suspending, decrement it again to release.
        m_pDiscMaterialResource = &m_sceneModelMaterials.UseResource(materialId);
    }

	//it should have some children, which are the vehicle meshes...
	Eegeo_ASSERT(m_pModel->GetRootNode().GetChildCount() > 0);
    
    //To render a scene model, add it to the SceneModelRenderableFilter
    m_sceneModelRenderableFilter.AddSceneModel(*m_pModel);
}
 void SearchResultPinBoundObject::SubmitPinToWebService(const MyPinModel& pinModel)
 {
     Eegeo_TTY("Here is where you submit pin to web service\n");
 }
 void CompassModel::OnFailedToGetLocation()
 {
     Eegeo_TTY("Failed to get compass location");
 }
void EnvironmentNotifierExampleTerrainStreamObserver::RemovedStreamingResourceFromSceneGraph(const Eegeo::Streaming::MortonKey& key)
{
	Eegeo_TTY("Removing Terrain Resource :: %s\n", key.ToString().c_str());
	m_spheres.erase(key);
}
void EnvironmentNotifierExampleTerrainStreamObserver::AddedStreamingResourceToSceneGraph(const Eegeo::Streaming::MortonKey& key)
{
	Eegeo_TTY("Adding Terrain Resource :: %s\n", key.ToString().c_str());
	AddSphere(key);
}
            void MyPinsFileIO::LoadPinModelsFromDisk(std::vector<std::pair<MyPinModel*, IMyPinBoundObject*> >& out_pinModelBindings, IMyPinsService& myPinService)
            {
                out_pinModelBindings.clear();

                std::fstream stream;
                size_t size;

                if (m_fileIO.OpenFile(stream, size, MyPinsDataFilename))
                {
                    std::string json((std::istreambuf_iterator<char>(stream)),
                                     (std::istreambuf_iterator<char>()));

                    rapidjson::Document jsonDoc;
                    if (jsonDoc.Parse<0>(json.c_str()).HasParseError())
                    {
                        Eegeo_TTY("Parse error in MyPins JSON.\n");
                        return;
                    }

                    Eegeo_ASSERT(jsonDoc.IsObject(), "JSON document is not of object type");

                    const rapidjson::Value& myPinsArray = jsonDoc[MyPinsJsonArrayName.c_str()];
                    size_t numEntries = myPinsArray.Size();

                    for(int i = 0; i < numEntries; ++i)
                    {
                        const rapidjson::Value& entry = myPinsArray[i];
                        
                        Eegeo_ASSERT(entry.HasMember("version"),
                                     "Old MyPinModel version detected. Please delete and reinstall the application.\n");
                        
                        const int version = entry["version"].GetInt();
                        
                        const int earliestSupportedVersion = 1;
                        Eegeo_ASSERT(version >= earliestSupportedVersion, "Old MyPinModel version detected: tried to deserialize version %d but current version is %d. Please delete and reinstall the application.\n", version, MyPinModel::CurrentVersion);
                        
                        
                        
                        MyPinModel::TPinIdType pinId = entry["id"].GetInt();
                        std::string title = entry["title"].GetString();
                        std::string description = entry["description"].GetString();
                        int sdkMapPinIconIndex = entry["icon"].GetInt();
                        double latitude = entry["latitude"].GetDouble();
                        double longitude = entry["longitude"].GetDouble();
                        MyPinsSemanticPinType semanticPinType = static_cast<MyPinsSemanticPinType>(entry["type"].GetInt());
                        std::string pinTypeMetadata = entry["metadata"].GetString();
                        
                        std::string ratingsImage = "";
                        int reviewCount = 0;
                        
                        if(version == 1)
                        {
                            // MB: Cannot infer review count therefore cannot show ratings by Yelp branding rules.
                            if(description.find("stars_") == 0)
                            {
                                description = "";
                            }
                        }
                        else if(version == MyPinModel::CurrentVersion)
                        {
                            ratingsImage = entry["ratingsImage"].GetString();
                            reviewCount = entry["reviewCount"].GetInt();
                        }
                        
                        float heightAboveTerrainMetres = 0;
                        if(entry.HasMember("heightAboveTerrain"))
                        {
                            heightAboveTerrainMetres = entry["heightAboveTerrain"].GetDouble();
                        }
                        
                        bool interior = false;
                        if(entry.HasMember("interior"))
                        {
                            interior = entry["interior"].GetBool();
                        }
                        
                        std::string buildingId("");
                        if(entry.HasMember("building"))
                        {
                            buildingId = entry["building"].GetString();
                        }
                        
                        int floor = 0;
                        if(entry.HasMember("floor"))
                        {
                            floor = entry["floor"].GetInt();
                        }
                        
                        IMyPinBoundObject* pPinBoundObject(m_myPinBoundObjectFactory.CreatePinBoundObjectFromSerialized(*this,
                                                                                                                        pinId,
                                                                                                                        semanticPinType,
                                                                                                                        pinTypeMetadata,
                                                                                                                        myPinService));
                        
                        MyPinModel* pModel(Eegeo_NEW(MyPinModel)(version,
                                                                 pinId,
                                                                 title,
                                                                 description,
                                                                 ratingsImage,
                                                                 reviewCount,
                                                                 sdkMapPinIconIndex,
                                                                 Eegeo::Space::LatLong::FromDegrees(latitude, longitude),
                                                                 heightAboveTerrainMetres,
                                                                 interior,
                                                                 buildingId,
                                                                 floor));
                        
                        out_pinModelBindings.push_back(std::make_pair(pModel, pPinBoundObject));
                    }
                }
            }
 void MyPinsWebService::WebRequestCompleteCallback(Eegeo::Web::IWebResponse& webResponse)
 {
     size_t resultSize = webResponse.GetBodyData().size();
     std::string responseString = resultSize > 0 ? std::string(reinterpret_cast<char const*>(&(webResponse.GetBodyData().front())), resultSize) : "<empty>";
     Eegeo_TTY("Web Request Completed, code: %d response: %s\n", webResponse.GetHttpStatusCode(), responseString.c_str());
 }