大坡3D软件开发

关注3D软件技术

蔡军生ID:caimouse
1114483次访问,排名23好友197人,关注者274
C++,3D,VC++软件开发,写技术文章,操作系统开发
[加为好友] [即时聊天] [发私信]
caimouse的文章
原创 580 篇
翻译 0 篇
转载 41 篇
评论 753 篇
蔡军生的公告

点击这里给我发消息

MSN: caimouse1976 at sina.com

最近评论
linxiaomengdi:太庞大了。呵呵。
linxiaomengdi:太庞大了。呵呵。
linxiaomengdi:太庞大了。呵呵。
linxiaomengdi:太庞大了。呵呵。
linxiaomengdi:太庞大了。呵呵。
文章分类
收藏
相册
3D引擎
第二人生
谷歌浏览器
开发板
历史回忆
常用连接
C++大师Stan Lippman(RSS)
MCU连接(RSS)
REACTOS开发网(中国)
人生历程
存档
软件项目交易
订阅我的博客
XML聚合  FeedSky

原创 第二人生的源码分析(二十三)人物行走的键盘消息处理收藏

新一篇: 第二人生的源码分析(二十四)人物向前走的键盘消息处理 | 旧一篇: 第二人生的源码分析(二十二)调用OpenGL显示人物名称的函数

前面介绍了怎么样显示人物角色,包括名称等等。那么人物角色是怎么样在里面行走的呢?第二人生是通过方向键来控制人物角色的走动,也就是说它是通过接收键盘的消息后不断地计算新的位置来实现移动。下面就是第二人生的消息处理函数代码:
#001 bool LLAppViewer::mainLoop()
#002 {
#003      //-------------------------------------------
#004      // Run main loop until time to quit
#005      //-------------------------------------------
#006 
#007      // Create IO Pump to use for HTTP Requests.
#008      gServicePump = new LLPumpIO(gAPRPoolp);
#009      LLHTTPClient::setPump(*gServicePump);
#010      LLCurl::setCAFile(gDirUtilp->getCAFile());
#011     
#012      // initialize voice stuff here
#013      gLocalSpeakerMgr = new LLLocalSpeakerMgr();
#014      gActiveChannelSpeakerMgr = new LLActiveSpeakerMgr();
#015 
#016      LLVoiceChannel::initClass();
#017      LLVoiceClient::init(gServicePump);
#018                          
#019      LLMemType mt1(LLMemType::MTYPE_MAIN);
#020      LLTimer frameTimer,idleTimer;
#021      LLTimer debugTime;
#022     
#023      // Handle messages
#024      while (!LLApp::isExiting())
#025      {
#026             LLFastTimer::reset(); // Should be outside of any timer instances
#027             {
#028                    LLFastTimer t(LLFastTimer::FTM_FRAME);
#029 
#030                    {
#031                           LLFastTimer t2(LLFastTimer::FTM_MESSAGES);
#032                    #if LL_WINDOWS
#033                           if (!LLWinDebug::setupExceptionHandler())
#034                           {
#035                                  llwarns << " Someone took over my exception handler (post messagehandling)!" << llendl;
#036                           }
#037                    #endif
#038 
#039                           gViewerWindow->mWindow->gatherInput();
#040                    }
#041 
#042 #if 1 && !RELEASE_FOR_DOWNLOAD
#043                    // once per second debug info
#044                    if (debugTime.getElapsedTimeF32() > 1.f)
#045                    {
#046                           debugTime.reset();
#047                    }
#048 #endif
#049 
#050                    if (!LLApp::isExiting())
#051                    {
#052                           // Scan keyboard for movement keys. Command keys and typing
#053                           // are handled by windows callbacks. Don't do this until we're
#054                           // done initializing. JC
#055                           if (gViewerWindow->mWindow->getVisible()
#056                                  && gViewerWindow->getActive()
#057                                  && !gViewerWindow->mWindow->getMinimized()
#058                                  && LLStartUp::getStartupState() == STATE_STARTED
#059                                  && !gViewerWindow->getShowProgress()
#060                                  && !gFocusMgr.focusLocked())
#061                           {
#062                                  gKeyboard->scanKeyboard();
#063                                  LLViewerJoystick::scanJoystick();
#064                           }
#065 
……
#193 
#194      // Save snapshot for next time, if we made it through initialization
#195      if (STATE_STARTED == LLStartUp::getStartupState())
#196      {
#197             saveFinalSnapshot();
#198      }
#199     
#200      delete gServicePump;
#201 
#202      llinfos << "Exiting main_loop" << llendflush;
#203 
#204      return true;
#205 }
 
这里通过调用函数gKeyboard->scanKeyboard()来处理键盘消息的,它实现每个键盘的消息处理,然后调用文件llviewerkeyboard.cpp的函数bind_keyboard_functions()绑定的函数来处理每个事件。比如向前走,就进行如下操作:
gViewerKeyboard.bindNamedFunction("move_forward", camera_move_forward);
当按下向前的按键时,就会调用函数camera_move_forward来处理这个事件,这样就可以调整摄像像的位置,就实现了人物的行走。

 

蔡军生  2008/3/12 QQ:9073204 深圳

发表于 @ 2008年03月12日 21:08:00|评论(loading...)|编辑

新一篇: 第二人生的源码分析(二十四)人物向前走的键盘消息处理 | 旧一篇: 第二人生的源码分析(二十二)调用OpenGL显示人物名称的函数

评论

#soilwork 发表于2008-03-13 10:57:01  IP: 220.249.249.*
哦,刚看到这个blog,不错,期待更多分析^_^
发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © 蔡军生