Changeset 12982 for OpenSceneGraph
- Timestamp:
- 02/10/12 18:24:08 (3 months ago)
- Location:
- OpenSceneGraph/trunk/src/osgViewer
- Files:
-
- 2 modified
-
GraphicsWindowIOS.mm (modified) (15 diffs)
-
IOSUtils.mm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowIOS.mm
r12870 r12982 86 86 // ---------------------------------------------------------------------------------------------------------- 87 87 88 typedef std::map<void*, unsigned int> TouchPointsIdMapping; 89 88 90 @interface GraphicsWindowIOSGLView : UIView 89 91 { … … 108 110 // for multisampled antialiased rendering 109 111 GLuint _msaaFramebuffer, _msaaRenderBuffer, _msaaDepthBuffer; 112 113 TouchPointsIdMapping* _touchPointsIdMapping; 114 unsigned int _lastTouchPointId; 115 116 110 117 111 118 } … … 156 163 } 157 164 165 166 - (unsigned int)computeTouchId: (UITouch*) touch 167 { 168 unsigned int result(0); 169 170 if (!_touchPointsIdMapping) { 171 _lastTouchPointId = 0; 172 _touchPointsIdMapping = new TouchPointsIdMapping(); 173 } 174 175 switch([touch phase]) 176 { 177 178 case UITouchPhaseBegan: 179 { 180 TouchPointsIdMapping::iterator itr = _touchPointsIdMapping->find(touch); 181 // std::cout << "new: " << touch << " num: " << _touchPointsIdMapping->size() << " found: " << (itr != _touchPointsIdMapping->end()) << std::endl; 182 183 if (itr == _touchPointsIdMapping->end()) 184 { 185 (*_touchPointsIdMapping)[touch] = result = _lastTouchPointId; 186 _lastTouchPointId++; 187 break; 188 } 189 190 } 191 // missing "break" by intention! 192 193 case UITouchPhaseMoved: 194 case UITouchPhaseStationary: 195 { 196 result = (*_touchPointsIdMapping)[touch]; 197 } 198 break; 199 200 case UITouchPhaseEnded: 201 case UITouchPhaseCancelled: 202 { 203 TouchPointsIdMapping::iterator itr = _touchPointsIdMapping->find(touch); 204 // std::cout<< "remove: " << touch << " num: " << _touchPointsIdMapping->size() << " found: " << (itr != _touchPointsIdMapping->end()) << std::endl; 205 206 if (itr != _touchPointsIdMapping->end()) { 207 result = itr->second; 208 _touchPointsIdMapping->erase(itr); 209 } 210 if(_touchPointsIdMapping->size() == 0) { 211 _lastTouchPointId = 0; 212 } 213 // std::cout<< "remove: " << touch << " num: " << _touchPointsIdMapping->size() << std::endl; 214 } 215 break; 216 217 default: 218 break; 219 } 220 221 return result; 222 } 223 224 158 225 - (osg::Vec2) convertPointToPixel: (osg::Vec2) point 159 226 { … … 161 228 float scale = 1.0f; 162 229 163 #if def __IPHONE_4_0&& (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0)230 #if defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0) 164 231 scale = self.contentScaleFactor; 165 232 #endif … … 171 238 { 172 239 _win = win; 240 _touchPointsIdMapping = new TouchPointsIdMapping(); 241 _lastTouchPointId = 0; 173 242 } 174 243 … … 223 292 { 224 293 OSG_INFO << "GraphicsWindowIOSGLView::dealloc" << std::endl; 225 294 if(_touchPointsIdMapping) 295 delete _touchPointsIdMapping; 296 _touchPointsIdMapping = NULL; 226 297 [super dealloc]; 227 298 } … … 284 355 //MSAA only available for >= 4.0 sdk 285 356 286 #if def __IPHONE_4_0&& (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0)357 #if defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0) 287 358 288 359 if(_win->getTraits()->sampleBuffers > 0) … … 365 436 366 437 367 #if def __IPHONE_4_0&& (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0)438 #if defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0) 368 439 if(_msaaFramebuffer) 369 440 { … … 390 461 glBindFramebufferOES(GL_FRAMEBUFFER_OES, _viewFramebuffer); 391 462 392 #if def __IPHONE_4_0&& (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0)463 #if defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0) 393 464 if (_msaaFramebuffer) 394 465 glBindFramebufferOES(GL_FRAMEBUFFER_OES, _msaaFramebuffer);; … … 404 475 glBindFramebufferOES(GL_FRAMEBUFFER_OES, _viewFramebuffer); 405 476 406 #if def __IPHONE_4_0&& (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0)477 #if defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0) 407 478 if (_msaaFramebuffer) 408 479 glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, _msaaFramebuffer); … … 441 512 CGPoint pos = [touch locationInView:touch.view]; 442 513 osg::Vec2 pixelPos = [self convertPointToPixel: osg::Vec2(pos.x,pos.y)]; 514 unsigned int touch_id = [self computeTouchId: touch]; 443 515 444 516 if (!osg_event) { 445 osg_event = _win->getEventQueue()->touchBegan( i, [self convertTouchPhase: [touch phase]], pixelPos.x(), pixelPos.y());517 osg_event = _win->getEventQueue()->touchBegan(touch_id, [self convertTouchPhase: [touch phase]], pixelPos.x(), pixelPos.y()); 446 518 } else { 447 osg_event->addTouchPoint( i, [self convertTouchPhase: [touch phase]], pixelPos.x(), pixelPos.y());519 osg_event->addTouchPoint(touch_id, [self convertTouchPhase: [touch phase]], pixelPos.x(), pixelPos.y()); 448 520 } 449 521 } … … 462 534 CGPoint pos = [touch locationInView:touch.view]; 463 535 osg::Vec2 pixelPos = [self convertPointToPixel: osg::Vec2(pos.x,pos.y)]; 464 536 unsigned int touch_id = [self computeTouchId: touch]; 537 465 538 if (!osg_event) { 466 osg_event = _win->getEventQueue()->touchMoved( i, [self convertTouchPhase: [touch phase]], pixelPos.x(), pixelPos.y());539 osg_event = _win->getEventQueue()->touchMoved(touch_id, [self convertTouchPhase: [touch phase]], pixelPos.x(), pixelPos.y()); 467 540 } else { 468 osg_event->addTouchPoint( i, [self convertTouchPhase: [touch phase]], pixelPos.x(), pixelPos.y());541 osg_event->addTouchPoint(touch_id, [self convertTouchPhase: [touch phase]], pixelPos.x(), pixelPos.y()); 469 542 } 470 543 … … 485 558 CGPoint pos = [touch locationInView:touch.view]; 486 559 osg::Vec2 pixelPos = [self convertPointToPixel: osg::Vec2(pos.x,pos.y)]; 487 560 unsigned int touch_id = [self computeTouchId: touch]; 488 561 if (!osg_event) { 489 osg_event = _win->getEventQueue()->touchEnded( i, [self convertTouchPhase: [touch phase]], pixelPos.x(), pixelPos.y(), [touch tapCount]);562 osg_event = _win->getEventQueue()->touchEnded(touch_id, [self convertTouchPhase: [touch phase]], pixelPos.x(), pixelPos.y(), [touch tapCount]); 490 563 } else { 491 osg_event->addTouchPoint( i, [self convertTouchPhase: [touch phase]], pixelPos.x(), pixelPos.y(), [touch tapCount]);564 osg_event->addTouchPoint(touch_id, [self convertTouchPhase: [touch phase]], pixelPos.x(), pixelPos.y(), [touch tapCount]); 492 565 } 493 566 … … 495 568 } 496 569 570 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event 571 { 572 [self touchesEnded: touches withEvent:event]; 573 } 497 574 498 575 @end … … 731 808 //Apply our content scale factor to our view, this is what converts the views points 732 809 //size to our desired context size. 733 #if def __IPHONE_4_0&& (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0)810 #if defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0) 734 811 theView.contentScaleFactor = _viewContentScaleFactor; 735 812 #endif -
OpenSceneGraph/trunk/src/osgViewer/IOSUtils.mm
r12520 r12982 73 73 float scale = 1.0f; 74 74 75 #if def __IPHONE_4_0&& (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0)75 #if defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0) 76 76 scale = [screen scale]; 77 77 #endif … … 124 124 125 125 float scale = 1.0f; 126 #if def __IPHONE_4_0&& (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0)126 #if defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0) 127 127 scale = [screen scale]; 128 128 #endif … … 257 257 { 258 258 scaleFactor = 1.0f; 259 #if def __IPHONE_4_0&& (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0)259 #if defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0) 260 260 CGFloat scale = [screen scale]; 261 261 scaleFactor = scale;
