plugin/poi/landmarks/overlay/src/Manager.cpp
changeset 0 c316ab048e9d
equal deleted inserted replaced
-1:000000000000 0:c316ab048e9d
       
     1 /*
       
     2  * Name        : Manager.cpp
       
     3  * Description : 
       
     4  * Project     : This file is part of OpenMAR, an Open Mobile Augmented Reality browser
       
     5  * Website     : http://OpenMAR.org
       
     6  *
       
     7  * Copyright (c) 2010 David Caabeiro
       
     8  *
       
     9  * All rights reserved. This program and the accompanying materials are made available 
       
    10  * under the terms of the Eclipse Public License v1.0 which accompanies this 
       
    11  * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
       
    12  *
       
    13  */
       
    14 
       
    15 #include "Manager.h"
       
    16 
       
    17 #include <e32math.h>
       
    18 
       
    19 #include "Logger.h"
       
    20 
       
    21 CManager* CManager::NewL()
       
    22 {
       
    23     CManager* self = new(ELeave) CManager;
       
    24     CleanupStack::PushL(self);
       
    25     self->ConstructL();
       
    26     CleanupStack::Pop(self);
       
    27 
       
    28     return self;
       
    29 }
       
    30 
       
    31 CManager::~CManager()
       
    32 {
       
    33     iObjectList.ResetAndDestroy();
       
    34     iObjectList.Close();
       
    35 
       
    36     iProviderList.ResetAndDestroy();
       
    37     iProviderList.Close();
       
    38 }
       
    39 
       
    40 CManager::CManager()
       
    41 {}
       
    42 
       
    43 void CManager::ConstructL()
       
    44 {
       
    45     _LIT8(KUri, "");
       
    46 
       
    47     _LIT8(KLMXProvider, "lmx");
       
    48     OpenMAR::CPOIProvider* lmx = OpenMAR::CPOIProvider::NewL(KLMXProvider, KUri);
       
    49     lmx->SetObserver(this);
       
    50     iProviderList.AppendL(lmx);
       
    51 
       
    52     _LIT8(KGeonamesProvider, "geonames");
       
    53     OpenMAR::CPOIProvider* geonames = OpenMAR::CPOIProvider::NewL(KGeonamesProvider, KUri);
       
    54     geonames->SetObserver(this);
       
    55     iProviderList.AppendL(geonames);
       
    56 }
       
    57 
       
    58 void CManager::POIProviderLoadedL(OpenMAR::CPOIProvider* aProvider, TInt aError)
       
    59 {
       
    60     LOGARG("Landmark resource %x loaded with error %d", aProvider, aError);
       
    61 
       
    62     // Handle error in some way
       
    63 }
       
    64 
       
    65 void CManager::POIObjectCreatedL(OpenMAR::CPOIObject* aPOIObject)
       
    66 {
       
    67     CleanupStack::PushL(aPOIObject);
       
    68 
       
    69     // Check if this POI already exists
       
    70     TInt index = iObjectList.Find(aPOIObject, OpenMAR::CPOIObject::IdentityRelation);
       
    71 
       
    72     if (index == KErrNotFound)
       
    73     {
       
    74         // Set world position
       
    75         TCoordinate coordinate = aPOIObject->GetCoordinate();
       
    76         aPOIObject->SetPosition(Transform(coordinate));
       
    77 
       
    78         LOGARG("Appending new POI (%d)", aPOIObject->GetIdentifier());
       
    79 
       
    80         iObjectList.AppendL(aPOIObject);
       
    81 
       
    82         CleanupStack::Pop(aPOIObject);
       
    83     }
       
    84     else
       
    85     {
       
    86         LOGARG("POI already exists (%d). Destroying..", aPOIObject->GetIdentifier());
       
    87 
       
    88         CleanupStack::PopAndDestroy(aPOIObject);
       
    89     }
       
    90 }
       
    91 
       
    92 void CManager::POIObjectUpdatedL(OpenMAR::CPOIObject* aPOIObject)
       
    93 {}
       
    94 
       
    95 /**
       
    96  * @brief Transform between WGS84 to Euclidean space
       
    97  * 
       
    98  * Our Euclidean space will be determined by:
       
    99  * +X : tangential to the ground and pointing to the EAST
       
   100  * +Y : tangential to the ground and pointing to the NORTH
       
   101  * +Z : perpendicular to the ground (pointing to the sky)
       
   102  */
       
   103 const Vector3d CManager::Transform(const TCoordinate& aCoordinate)
       
   104 {
       
   105     TReal32 distance = 0;
       
   106     iOrigin.Distance(aCoordinate, distance);
       
   107 
       
   108     TReal32 bearing = 0;
       
   109     iOrigin.BearingTo(aCoordinate, bearing);
       
   110 
       
   111     TReal32 angle = bearing * KDegToRad;
       
   112 
       
   113     TReal cos = 0;
       
   114     TReal sin = 0;
       
   115     Math::Cos(cos, angle);
       
   116     Math::Sin(sin, angle);
       
   117 
       
   118     // X = sin(bearing) * d = cos(90 - bearing) * d = sin(bearing) * d
       
   119     // Y = cos(bearing) * d = sin(90 - bearing) * d = cos(bearing) * d
       
   120 
       
   121     TReal x = sin * distance;
       
   122     TReal y = cos * distance;
       
   123     TReal z = aCoordinate.Altitude();
       
   124 
       
   125     return Vector3d(x, y, z);
       
   126 }
       
   127 
       
   128 void CManager::SetOrigin(const TCoordinate& aCoordinate)
       
   129 {
       
   130     iOrigin = aCoordinate;
       
   131 }
       
   132 
       
   133 void CManager::RequestL(const TCoordinate& aCoordinate)
       
   134 {
       
   135     const TReal32 radius = 3000;
       
   136 
       
   137     for (TInt i = 0; i < iProviderList.Count(); ++i)
       
   138         iProviderList[i]->RetrieveL(aCoordinate, radius);
       
   139 }
       
   140 
       
   141 void CManager::Render() const
       
   142 {
       
   143     for (TInt i = 0; i < iObjectList.Count(); ++i)
       
   144         iObjectList[i]->Render();
       
   145 }