Mercurial > s60_experiments
comparison DemoCube/src/DemoCubeAppView.cpp @ 1:0a2b5a968ce7
Modifications that turn this Nokia-supplied DemoCube demo into a web-browser mockup that uses optical flow for panning operations.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Tue, 12 Feb 2008 17:32:01 -0600 |
parents | 43361e733c66 |
children | f546bb5370c7 |
comparison
equal
deleted
inserted
replaced
0:43361e733c66 | 1:0a2b5a968ce7 |
---|---|
21 #include "ncvImage.h" | 21 #include "ncvImage.h" |
22 #include "ncvCamus.h" | 22 #include "ncvCamus.h" |
23 #include "ncvOpticalFlow.h" | 23 #include "ncvOpticalFlow.h" |
24 #include "ncvEgoMovement.h" | 24 #include "ncvEgoMovement.h" |
25 #include "DemoCube.h" | 25 #include "DemoCube.h" |
26 #include "ImageLoader.h" | |
26 | 27 |
27 #define PADDING_WIDTH 40 | 28 #define PADDING_WIDTH 40 |
28 #define PADDING_HEIGHT 30 | 29 #define PADDING_HEIGHT 30 |
30 | |
31 _LIT( KPicture, "firefox.png" ); | |
29 | 32 |
30 // ============================ MEMBER FUNCTIONS =============================== | 33 // ============================ MEMBER FUNCTIONS =============================== |
31 | 34 |
32 // ----------------------------------------------------------------------------- | 35 // ----------------------------------------------------------------------------- |
33 // CDemoCubeAppView::NewL() | 36 // CDemoCubeAppView::NewL() |
65 for(TInt i = 0; i < 5; i++) | 68 for(TInt i = 0; i < 5; i++) |
66 { | 69 { |
67 TPoint tmp(0, 0); | 70 TPoint tmp(0, 0); |
68 iCubePoints->AppendL(tmp); | 71 iCubePoints->AppendL(tmp); |
69 } | 72 } |
73 | |
70 // Create a window for this application view | 74 // Create a window for this application view |
71 CreateWindowL(); | 75 CreateWindowL(); |
72 | 76 |
73 // Set the windows size | 77 // Set the windows size |
74 SetRect( aRect ); | 78 SetRect( aRect ); |
75 | 79 |
76 // Activate the window, which makes it ready to be drawn | 80 // Activate the window, which makes it ready to be drawn |
77 ActivateL(); | 81 ActivateL(); |
78 } | 82 } |
83 | |
84 void CDemoCubeAppView::StartImgLoader() | |
85 { | |
86 // was 50,50 | |
87 TSize iSize(493, 305); | |
88 TInt color; | |
89 TInt gray; | |
90 TDisplayMode displayMode = CEikonEnv::Static()->WsSession().GetDefModeMaxNumColors( color, gray ); | |
91 | |
92 iPicture = new (ELeave) CFbsBitmap; | |
93 if (iPicture) | |
94 iPicture->Create(iSize, displayMode); //EColor16MA | |
95 iLoader = CImageLoader::NewL( 'c' ); | |
96 iLoader->LoadImage( KPicture, iPicture ); | |
97 } | |
79 | 98 |
80 // ----------------------------------------------------------------------------- | 99 // ----------------------------------------------------------------------------- |
81 // CDemoCubeAppView::CDemoCubeAppView() | 100 // CDemoCubeAppView::CDemoCubeAppView() |
82 // C++ default constructor can NOT contain any code, that might leave. | 101 // C++ default constructor can NOT contain any code, that might leave. |
83 // ----------------------------------------------------------------------------- | 102 // ----------------------------------------------------------------------------- |
87 iCamera(NULL), | 106 iCamera(NULL), |
88 iCamusImage(NULL), | 107 iCamusImage(NULL), |
89 iBitmapSize(25, 18), | 108 iBitmapSize(25, 18), |
90 iCamus(NULL), | 109 iCamus(NULL), |
91 iOpticalFlow(NULL), | 110 iOpticalFlow(NULL), |
92 iCube(NULL) | 111 iCube(NULL), |
112 iLoader(NULL), | |
113 iPicture(NULL) | |
93 { | 114 { |
94 } | 115 } |
95 | 116 |
96 void CDemoCubeAppView::Reset() | 117 void CDemoCubeAppView::Reset() |
97 { | 118 { |
136 if(iCubePoints) | 157 if(iCubePoints) |
137 { | 158 { |
138 delete iCubePoints; | 159 delete iCubePoints; |
139 iCubePoints = NULL; | 160 iCubePoints = NULL; |
140 } | 161 } |
162 if(iLoader) | |
163 { | |
164 delete iLoader; | |
165 iLoader = NULL; | |
166 } | |
167 if(iPicture) | |
168 { | |
169 delete iPicture; | |
170 iPicture = NULL; | |
171 } | |
141 } | 172 } |
142 | 173 |
143 // ----------------------------------------------------------------------------- | 174 // ----------------------------------------------------------------------------- |
144 // CDemoCubeAppView::Draw() | 175 // CDemoCubeAppView::Draw() |
145 // Draws the display. | 176 // Draws the display. |
146 // ----------------------------------------------------------------------------- | 177 // ----------------------------------------------------------------------------- |
147 // | 178 // |
148 void CDemoCubeAppView::Draw(CFbsBitmap& aBitmap, CArrayFixFlat<TPoint>* aCube) const | 179 void CDemoCubeAppView::Draw(CFbsBitmap& aBitmap, CArrayFixFlat<TPoint>* aCube) |
149 { | 180 { |
150 CWindowGc& gc = SystemGc(); | 181 CWindowGc& gc = SystemGc(); |
151 gc.Activate(Window()); | 182 gc.Activate(Window()); |
152 gc.Clear(); | 183 gc.Clear(); |
153 gc.BitBlt(TPoint(PADDING_WIDTH / 2, PADDING_HEIGHT / 2), &aBitmap); | 184 //gc.BitBlt(TPoint(PADDING_WIDTH / 2, PADDING_HEIGHT / 2), &aBitmap); |
154 gc.SetPenColor(TRgb(0xff, 0, 0)); | 185 |
155 gc.DrawPolyLine(aCube); | 186 |
187 //gc.BitBlt(TPoint(PADDING_WIDTH / 2, PADDING_HEIGHT / 2), iPicture); | |
188 gc.BitBlt(TPoint( (TInt)iMove.iY.Real(), (TInt)iMove.iX.Real()), iPicture); | |
189 //gc.SetPenColor(TRgb(0xff, 0, 0)); | |
190 //gc.DrawPolyLine(aCube); | |
156 gc.Deactivate(); | 191 gc.Deactivate(); |
157 iCoeEnv->WsSession().Flush(); | 192 iCoeEnv->WsSession().Flush(); |
158 } | 193 } |
159 | 194 |
160 void CDemoCubeAppView::CameraReady() | 195 void CDemoCubeAppView::CameraReady() |
173 } | 208 } |
174 | 209 |
175 iCamus->GetOpticalFlow(*iOpticalFlow, *iCamusImage, CAMUS_SETCAMUSOPTS(CCamus::EMedium, CCamus::EMedium, 3)); | 210 iCamus->GetOpticalFlow(*iOpticalFlow, *iCamusImage, CAMUS_SETCAMUSOPTS(CCamus::EMedium, CCamus::EMedium, 3)); |
176 CEgoMovement mean = iOpticalFlow->Mean(); | 211 CEgoMovement mean = iOpticalFlow->Mean(); |
177 iMove.iX -= mean.iX * 6.3; | 212 iMove.iX -= mean.iX * 6.3; |
178 iMove.iY += mean.iY * 6.3; | 213 iMove.iY -= mean.iY * 6.3; |
179 iAngle += iOpticalFlow->Rotation().Real() * 10.5; | 214 iAngle += iOpticalFlow->Rotation().Real() * 10.5; |
180 | 215 |
181 // | 216 // |
182 iCubeWidth += (TInt)(iOpticalFlow->Depth().Real() * 5); | 217 iCubeWidth += (TInt)(iOpticalFlow->Depth().Real() * 5); |
183 iCubeWidth = Max(2, iCubeWidth); | 218 iCubeWidth = Max(2, iCubeWidth); |