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