﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-野猪世界 专注图形技术-随笔分类-Bullet</title><link>http://www.cppblog.com/zhuyeaini/category/14139.html</link><description>ogre cegui wxWidgets bullet python lua</description><language>zh-cn</language><lastBuildDate>Fri, 11 Jan 2013 20:36:13 GMT</lastBuildDate><pubDate>Fri, 11 Jan 2013 20:36:13 GMT</pubDate><ttl>60</ttl><item><title>bullet setp 流程</title><link>http://www.cppblog.com/zhuyeaini/archive/2013/01/10/197179.html</link><dc:creator>野猪红</dc:creator><author>野猪红</author><pubDate>Thu, 10 Jan 2013 12:06:00 GMT</pubDate><guid>http://www.cppblog.com/zhuyeaini/archive/2013/01/10/197179.html</guid><wfw:comment>http://www.cppblog.com/zhuyeaini/comments/197179.html</wfw:comment><comments>http://www.cppblog.com/zhuyeaini/archive/2013/01/10/197179.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhuyeaini/comments/commentRss/197179.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhuyeaini/services/trackbacks/197179.html</trackback:ping><description><![CDATA[好的 <img border="0" src="http://www.cppblog.com/Emoticons/QQ/icon11.gif" width="22" height="29" alt="" /><br />我要开始新篇了<br />新篇是Bullet的<br />刚开始看Bullet时 代码不熟 看后忘前 不过 怎么说呢 那我就每天看 草<br />于是 我就明白了<br />先看看那个step函数： 
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" alt="" /><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;btDiscreteDynamicsWorld::internalSingleStepSimulation(btScalar&nbsp;timeStep)<br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img id="Codehighlighter1_78_1003_Open_Image" onclick="this.style.display='none'; Codehighlighter1_78_1003_Open_Text.style.display='none'; Codehighlighter1_78_1003_Closed_Image.style.display='inline'; Codehighlighter1_78_1003_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_78_1003_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_78_1003_Closed_Text.style.display='none'; Codehighlighter1_78_1003_Open_Image.style.display='inline'; Codehighlighter1_78_1003_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_78_1003_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_78_1003_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;BT_PROFILE(</span><span style="color: #000000">"</span><span style="color: #000000">internalSingleStepSimulation</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img id="Codehighlighter1_164_215_Open_Image" onclick="this.style.display='none'; Codehighlighter1_164_215_Open_Text.style.display='none'; Codehighlighter1_164_215_Closed_Image.style.display='inline'; Codehighlighter1_164_215_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_164_215_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_164_215_Closed_Text.style.display='none'; Codehighlighter1_164_215_Open_Image.style.display='inline'; Codehighlighter1_164_215_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;m_internalPreTickCallback)&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_164_215_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_164_215_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(</span><span style="color: #000000">*</span><span style="color: #000000">m_internalPreTickCallback)(</span><span style="color: #0000ff">this</span><span style="color: #000000">,&nbsp;timeStep);<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /></span><span style="color: #008080">10</span><span style="color: #000000"><img id="Codehighlighter1_220_252_Open_Image" onclick="this.style.display='none'; Codehighlighter1_220_252_Open_Text.style.display='none'; Codehighlighter1_220_252_Closed_Image.style.display='inline'; Codehighlighter1_220_252_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_220_252_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_220_252_Closed_Text.style.display='none'; Codehighlighter1_220_252_Open_Image.style.display='inline'; Codehighlighter1_220_252_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_220_252_Closed_Text">/**/</span><span id="Codehighlighter1_220_252_Open_Text"><span style="color: #808080">///</span><span style="color: #008000">apply&nbsp;gravity,&nbsp;predict&nbsp;motion</span><span style="color: #808080"></span></span><br /><span style="color: #008080">11</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><span style="color: #000000">&nbsp;&nbsp;&nbsp;</span><span style="color: red;">&nbsp;predictUnconstraintMotion(timeStep);</span><span style="color: #000000"><br /></span><span style="color: #008080">12</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /></span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;btDispatcherInfo</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;dispatchInfo&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;getDispatchInfo();<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /></span><span style="color: #008080">15</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;dispatchInfo.m_timeStep&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;timeStep;<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;dispatchInfo.m_stepCount&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;dispatchInfo.m_debugDraw&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;getDebugDrawer();<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /></span><span style="color: #008080">20</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;createPredictiveContacts(timeStep);<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img id="Codehighlighter1_508_538_Open_Image" onclick="this.style.display='none'; Codehighlighter1_508_538_Open_Text.style.display='none'; Codehighlighter1_508_538_Closed_Image.style.display='inline'; Codehighlighter1_508_538_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_508_538_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_508_538_Closed_Text.style.display='none'; Codehighlighter1_508_538_Open_Image.style.display='inline'; Codehighlighter1_508_538_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_508_538_Closed_Text">/**/</span><span id="Codehighlighter1_508_538_Open_Text"><span style="color: #808080">///</span><span style="color: #008000">perform&nbsp;collision&nbsp;detection</span><span style="color: #808080"></span></span><br /><span style="color: #008080">23</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: red;">performDiscreteCollisionDetection();</span><span style="color: #000000"><br /></span><span style="color: #008080">24</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /></span><span style="color: #008080">25</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;</span><span style="color: red;">&nbsp;calculateSimulationIslands();</span><span style="color: #000000"><br /></span><span style="color: #008080">26</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /></span><span style="color: #008080">27</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;getSolverInfo().m_timeStep&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;timeStep;<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /></span><span style="color: #008080">31</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /></span><span style="color: #008080">32</span><span style="color: #000000"><img id="Codehighlighter1_657_701_Open_Image" onclick="this.style.display='none'; Codehighlighter1_657_701_Open_Text.style.display='none'; Codehighlighter1_657_701_Closed_Image.style.display='inline'; Codehighlighter1_657_701_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_657_701_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_657_701_Closed_Text.style.display='none'; Codehighlighter1_657_701_Open_Image.style.display='inline'; Codehighlighter1_657_701_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_657_701_Closed_Text">/**/</span><span id="Codehighlighter1_657_701_Open_Text"><span style="color: #808080">///</span><span style="color: #008000">solve&nbsp;contact&nbsp;and&nbsp;other&nbsp;joint&nbsp;constraints</span><span style="color: #808080"></span></span><br /><span style="color: #008080">33</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;solveConstraints(getSolverInfo());<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">35</span><span style="color: #000000"><img id="Codehighlighter1_741_789_Open_Image" onclick="this.style.display='none'; Codehighlighter1_741_789_Open_Text.style.display='none'; Codehighlighter1_741_789_Closed_Image.style.display='inline'; Codehighlighter1_741_789_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_741_789_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_741_789_Closed_Text.style.display='none'; Codehighlighter1_741_789_Open_Image.style.display='inline'; Codehighlighter1_741_789_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_741_789_Closed_Text">/**/</span><span id="Codehighlighter1_741_789_Open_Text"><span style="color: #808080">///</span><span style="color: #008000">CallbackTriggers();<br /></span><span style="color: #008080">36</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /></span><span style="color: #008080">37</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #808080">///</span><span style="color: #008000">integrate&nbsp;transforms</span><span style="color: #808080"></span></span><br /><span style="color: #008080">38</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><span style="color: #000000"><br /></span><span style="color: #008080">39</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;integrateTransforms(timeStep);<br /></span><span style="color: #008080">40</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /></span><span style="color: #008080">41</span><span style="color: #000000"><img id="Codehighlighter1_825_853_Open_Image" onclick="this.style.display='none'; Codehighlighter1_825_853_Open_Text.style.display='none'; Codehighlighter1_825_853_Closed_Image.style.display='inline'; Codehighlighter1_825_853_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_825_853_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_825_853_Closed_Text.style.display='none'; Codehighlighter1_825_853_Open_Image.style.display='inline'; Codehighlighter1_825_853_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_825_853_Closed_Text">/**/</span><span id="Codehighlighter1_825_853_Open_Text"><span style="color: #808080">///</span><span style="color: #008000">update&nbsp;vehicle&nbsp;simulation</span><span style="color: #808080"></span></span><br /><span style="color: #008080">42</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;updateActions(timeStep);<br /></span><span style="color: #008080">43</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">44</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;updateActivationState(&nbsp;timeStep&nbsp;);<br /></span><span style="color: #008080">45</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /></span><span style="color: #008080">46</span><span style="color: #000000"><img id="Codehighlighter1_952_1000_Open_Image" onclick="this.style.display='none'; Codehighlighter1_952_1000_Open_Text.style.display='none'; Codehighlighter1_952_1000_Closed_Image.style.display='inline'; Codehighlighter1_952_1000_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_952_1000_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_952_1000_Closed_Text.style.display='none'; Codehighlighter1_952_1000_Open_Image.style.display='inline'; Codehighlighter1_952_1000_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">0</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;m_internalTickCallback)&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_952_1000_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_952_1000_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">47</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(</span><span style="color: #000000">*</span><span style="color: #000000">m_internalTickCallback)(</span><span style="color: #0000ff">this</span><span style="color: #000000">,&nbsp;timeStep);<br /></span><span style="color: #008080">48</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">49</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">50</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" alt="" /></span></div><br />看看里面几个重要的函数：<br />1 predictUnconstraintMotion(timeStep) ：给每个物体加重力作用力<br />2&nbsp;createPredictiveContacts(timeStep) ：和ccd有关 处理物体在高速运动时的碰撞<br />3 performDiscreteCollisionDetection()：此函数做碰撞 我们来看看<br /><br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" alt="" /><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;btCollisionWorld::performDiscreteCollisionDetection()<br /><img id="Codehighlighter1_59_444_Open_Image" onclick="this.style.display='none'; Codehighlighter1_59_444_Open_Text.style.display='none'; Codehighlighter1_59_444_Closed_Image.style.display='inline'; Codehighlighter1_59_444_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_59_444_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_59_444_Closed_Text.style.display='none'; Codehighlighter1_59_444_Open_Image.style.display='inline'; Codehighlighter1_59_444_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_59_444_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_59_444_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;BT_PROFILE(</span><span style="color: #000000">"</span><span style="color: #000000">performDiscreteCollisionDetection</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;btDispatcherInfo</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;dispatchInfo&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;getDispatchInfo();<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: red;">updateAabbs();<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: red;">computeOverlappingPairs();</span><span style="color: #000000"><br /></span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;dispatcher&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;getDispatcher();<br /><img id="Codehighlighter1_258_441_Open_Image" onclick="this.style.display='none'; Codehighlighter1_258_441_Open_Text.style.display='none'; Codehighlighter1_258_441_Closed_Image.style.display='inline'; Codehighlighter1_258_441_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_258_441_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_258_441_Closed_Text.style.display='none'; Codehighlighter1_258_441_Open_Image.style.display='inline'; Codehighlighter1_258_441_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_258_441_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_258_441_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BT_PROFILE(</span><span style="color: #000000">"</span><span style="color: #000000">dispatchAllCollisionPairs</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(dispatcher)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: red;">dispatcher</span><span style="color: red;">-&gt;</span><span style="color: red;">dispatchAllCollisionPairs(m_broadphasePairCache</span><span style="color: red;">-&gt;</span><span style="color: red;">getOverlappingPairCache(),dispatchInfo,m_dispatcher1);&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #000000">&nbsp; &nbsp; &nbsp; &nbsp;}<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" /></span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" alt="" /></span></div><br />1)&nbsp;&nbsp;&nbsp;updateAabbs()：<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;把要参加broad碰撞的物体放进paircache，此时没有进行任何碰撞检测，仅仅是把物体加进paircache（addOverlappingPair）同时，放进ghost的paircache里<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (m_ghostPairCallback)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_ghostPairCallback-&gt;addOverlappingPair(proxy0,proxy1);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;在这个阶段可以设置一个回调函数，用于过滤一些特定物体<br />
<p>&nbsp;&nbsp;&nbsp;&nbsp;SIMD_FORCE_INLINE bool needsBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">&nbsp;if (m_overlapFilterCallback)</span><br /><span style="color: red;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return m_overlapFilterCallback-&gt;needBroadphaseCollision(proxy0,proxy1);</span></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bool collides = (proxy0-&gt;m_collisionFilterGroup &amp; proxy1-&gt;m_collisionFilterMask) != 0;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;collides = collides &amp;&amp; (proxy1-&gt;m_collisionFilterGroup &amp; proxy0-&gt;m_collisionFilterMask);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return collides;<br />&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;m_overlapFilterCallback就是那个回调函数<br /><br />2)&nbsp;&nbsp;&nbsp; computeOverlappingPairs()：<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;该函数执行broad碰撞，也就是类似于AABB的粗线条碰撞，以此过滤paircache中不用进行narrow碰撞的pair<br /><br />3)&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;">dispatcher-&gt;dispatchAllCollisionPairs</span><span style="color: red;">(m_broadphasePairCache-&gt;getOverlappingPairCache(),dispatchInfo,m_dispatcher1):</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;该函数进行narrow碰撞，也就是精确碰撞，在这里，我们也可以设置回调，以过滤掉某些物体的精确碰撞<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" alt="" /><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;btCollisionDispatcher::</span><span style="color: red;">defaultNearCallback</span><span style="color: #000000">(btBroadphasePair</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;collisionPair,&nbsp;btCollisionDispatcher</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;dispatcher,&nbsp;</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;btDispatcherInfo</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;dispatchInfo)<br /><img id="Codehighlighter1_154_1453_Open_Image" onclick="this.style.display='none'; Codehighlighter1_154_1453_Open_Text.style.display='none'; Codehighlighter1_154_1453_Closed_Image.style.display='inline'; Codehighlighter1_154_1453_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_154_1453_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_154_1453_Closed_Text.style.display='none'; Codehighlighter1_154_1453_Open_Image.style.display='inline'; Codehighlighter1_154_1453_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_154_1453_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_154_1453_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btCollisionObject</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;colObj0&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(btCollisionObject</span><span style="color: #000000">*</span><span style="color: #000000">)collisionPair.m_pProxy0</span><span style="color: #000000">-&gt;</span><span style="color: #000000">m_clientObject;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btCollisionObject</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;colObj1&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(btCollisionObject</span><span style="color: #000000">*</span><span style="color: #000000">)collisionPair.m_pProxy1</span><span style="color: #000000">-&gt;</span><span style="color: #000000">m_clientObject;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /></span><span style="color: red;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: red;">if</span><span style="color: red;">&nbsp;(dispatcher.needsCollision(colObj0,colObj1))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000"><br /><img id="Codehighlighter1_393_1450_Open_Image" onclick="this.style.display='none'; Codehighlighter1_393_1450_Open_Text.style.display='none'; Codehighlighter1_393_1450_Closed_Image.style.display='inline'; Codehighlighter1_393_1450_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_393_1450_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_393_1450_Closed_Text.style.display='none'; Codehighlighter1_393_1450_Open_Image.style.display='inline'; Codehighlighter1_393_1450_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_393_1450_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_393_1450_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btCollisionObjectWrapper&nbsp;obj0Wrap(</span><span style="color: #000000">0</span><span style="color: #000000">,colObj0</span><span style="color: #000000">-&gt;</span><span style="color: #000000">getCollisionShape(),colObj0,colObj0</span><span style="color: #000000">-&gt;</span><span style="color: #000000">getWorldTransform());<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btCollisionObjectWrapper&nbsp;obj1Wrap(</span><span style="color: #000000">0</span><span style="color: #000000">,colObj1</span><span style="color: #000000">-&gt;</span><span style="color: #000000">getCollisionShape(),colObj1,colObj1</span><span style="color: #000000">-&gt;</span><span style="color: #000000">getWorldTransform());<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">dispatcher&nbsp;will&nbsp;keep&nbsp;algorithms&nbsp;persistent&nbsp;in&nbsp;the&nbsp;collision&nbsp;pair</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(</span><span style="color: #000000">!</span><span style="color: #000000">collisionPair.m_algorithm)<br /><img id="Codehighlighter1_719_803_Open_Image" onclick="this.style.display='none'; Codehighlighter1_719_803_Open_Text.style.display='none'; Codehighlighter1_719_803_Closed_Image.style.display='inline'; Codehighlighter1_719_803_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_719_803_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_719_803_Closed_Text.style.display='none'; Codehighlighter1_719_803_Open_Image.style.display='inline'; Codehighlighter1_719_803_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_719_803_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_719_803_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;collisionPair.m_algorithm&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;dispatcher.findAlgorithm(</span><span style="color: #000000">&amp;</span><span style="color: #000000">obj0Wrap,</span><span style="color: #000000">&amp;</span><span style="color: #000000">obj1Wrap);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(collisionPair.m_algorithm)<br /><img id="Codehighlighter1_843_1446_Open_Image" onclick="this.style.display='none'; Codehighlighter1_843_1446_Open_Text.style.display='none'; Codehighlighter1_843_1446_Closed_Image.style.display='inline'; Codehighlighter1_843_1446_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_843_1446_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_843_1446_Closed_Text.style.display='none'; Codehighlighter1_843_1446_Open_Image.style.display='inline'; Codehighlighter1_843_1446_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_843_1446_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_843_1446_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btManifoldResult&nbsp;contactPointResult(</span><span style="color: #000000">&amp;</span><span style="color: #000000">obj0Wrap,</span><span style="color: #000000">&amp;</span><span style="color: #000000">obj1Wrap);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(dispatchInfo.m_dispatchFunc&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btDispatcherInfo::DISPATCH_DISCRETE)<br /><img id="Codehighlighter1_994_1152_Open_Image" onclick="this.style.display='none'; Codehighlighter1_994_1152_Open_Text.style.display='none'; Codehighlighter1_994_1152_Closed_Image.style.display='inline'; Codehighlighter1_994_1152_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_994_1152_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_994_1152_Closed_Text.style.display='none'; Codehighlighter1_994_1152_Open_Image.style.display='inline'; Codehighlighter1_994_1152_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_994_1152_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_994_1152_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">discrete&nbsp;collision&nbsp;detection&nbsp;query</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;collisionPair.m_algorithm</span><span style="color: #000000">-&gt;</span><span style="color: #000000">processCollision(</span><span style="color: #000000">&amp;</span><span style="color: #000000">obj0Wrap,</span><span style="color: #000000">&amp;</span><span style="color: #000000">obj1Wrap,dispatchInfo,</span><span style="color: #000000">&amp;</span><span style="color: #000000">contactPointResult);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /><img id="Codehighlighter1_1163_1441_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1163_1441_Open_Text.style.display='none'; Codehighlighter1_1163_1441_Closed_Image.style.display='inline'; Codehighlighter1_1163_1441_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1163_1441_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1163_1441_Closed_Text.style.display='none'; Codehighlighter1_1163_1441_Open_Image.style.display='inline'; Codehighlighter1_1163_1441_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1163_1441_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_1163_1441_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">continuous&nbsp;collision&nbsp;detection&nbsp;query,&nbsp;time&nbsp;of&nbsp;impact&nbsp;(toi)</span><span style="color: #008000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btScalar&nbsp;toi&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;collisionPair.m_algorithm</span><span style="color: #000000">-&gt;</span><span style="color: #000000">calculateTimeOfImpact(colObj0,colObj1,dispatchInfo,</span><span style="color: #000000">&amp;</span><span style="color: #000000">contactPointResult);<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(dispatchInfo.m_timeOfImpact&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;toi)<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dispatchInfo.m_timeOfImpact&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;toi;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" alt="" /></span></div>
<p><br />这个是默认的callback所做的活，正如bulletManual上所说，可以换成我们自己的callback<br /><span style="color: red;">&nbsp;void&nbsp;setNearCallback(btNearCallback&nbsp;nearCallback)</span><br /><span style="color: red;">&nbsp;{</span><br /><span style="color: red;">&nbsp;&nbsp;m_nearCallback = nearCallback; </span><br /><span style="color: red;">&nbsp;}</span><br />另外，还可以重载btCollisionDispatcher，重写其<br /><span style="color: red;">&nbsp;virtual bool&nbsp;needsCollision(const btCollisionObject* body0,const btCollisionObject* body1);</span><br /><span style="color: red;">&nbsp;virtual bool&nbsp;needsResponse(const btCollisionObject* body0,const btCollisionObject* body1);</span><br /><span style="color: red;">&nbsp;virtual void&nbsp;dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,const btDispatcherInfo&amp; dispatchInfo,btDispatcher* dispatcher) ;</span><br />从而完全定制其行为<br /><br />好 暂时over<br /><br /><br /><br /><br /><br /><br /></p><img src ="http://www.cppblog.com/zhuyeaini/aggbug/197179.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhuyeaini/" target="_blank">野猪红</a> 2013-01-10 20:06 <a href="http://www.cppblog.com/zhuyeaini/archive/2013/01/10/197179.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>bullet 中的stepSimulation和MotionState</title><link>http://www.cppblog.com/zhuyeaini/archive/2011/12/10/161862.html</link><dc:creator>野猪红</dc:creator><author>野猪红</author><pubDate>Sat, 10 Dec 2011 02:27:00 GMT</pubDate><guid>http://www.cppblog.com/zhuyeaini/archive/2011/12/10/161862.html</guid><wfw:comment>http://www.cppblog.com/zhuyeaini/comments/161862.html</wfw:comment><comments>http://www.cppblog.com/zhuyeaini/archive/2011/12/10/161862.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/zhuyeaini/comments/commentRss/161862.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/zhuyeaini/services/trackbacks/161862.html</trackback:ping><description><![CDATA[<div><span style="widows: 2; text-transform: none; text-indent: 0px; font: 14px/21px verdana,'courier new'; white-space: normal; orphans: 2; letter-spacing: normal; color: #000000; word-spacing: 0px">最近看bullet，有源码就是看得明白点，有时候文档真的是无法说清的<br />就比如这个函数：<br /></span>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">1</span>&nbsp;<span style="color: #0000ff">virtual</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;stepSimulation(&nbsp;btScalar&nbsp;timeStep,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;maxSubSteps</span><span style="color: #000000">=</span><span style="color: #000000">1</span><span style="color: #000000">,&nbsp;btScalar&nbsp;fixedTimeStep</span><span style="color: #000000">=</span><span style="color: #000000">btScalar(</span><span style="color: #000000">1</span><span style="color: #000000">.)</span><span style="color: #000000">/</span><span style="color: #000000">btScalar(</span><span style="color: #000000">60</span><span style="color: #000000">.));</span></div>非要看看源码才行的<br />默认情况下，最大执行步骤为1，固定步长为1/60，第一个参数为实际步长<br />这是一个放大的时间步长：0~2/60，物体在0时间为A状态，1/60为B状态，2/60为C状态<br />物体状态A &nbsp; &nbsp; &nbsp; &nbsp; 物体状态B&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 物体状态C &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />0----------------1/60--------------2/60<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -timeStep <span style="color: red">//在0~1/60以内，bullet并不执行物理模拟，剩余时间motionstate会进行进一步模拟</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -timeStep<span style="color: red"> //在1/60~2/60以内，bullet执行一个物理模拟，bullet中物体处于B状态，但实际上物体应该还要在后面一个时间点，于是剩<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 余时间为总时间减去一个固定步长的时间，motionstate会根据这个剩余时间基于状态B进行进一步模拟<br /></span>所谓进一步模拟 看代码 注意函数中的timeStep参数 该参数就是那个剩余时间：
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;integrateTransform(</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;btTransform</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;curTrans,</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;btVector3</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;linvel,</span><span style="color: #0000ff">const</span><span style="color: #000000">&nbsp;btVector3</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;angvel,btScalar&nbsp;timeStep,btTransform</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;predictedTransform)<br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img id="Codehighlighter1_159_1368_Open_Image" onclick="this.style.display='none'; Codehighlighter1_159_1368_Open_Text.style.display='none'; Codehighlighter1_159_1368_Closed_Image.style.display='inline'; Codehighlighter1_159_1368_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_159_1368_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_159_1368_Closed_Text.style.display='none'; Codehighlighter1_159_1368_Open_Image.style.display='inline'; Codehighlighter1_159_1368_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_159_1368_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_159_1368_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;predictedTransform.setOrigin(curTrans.getOrigin()&nbsp;</span><span style="color: #000000">+</span><span style="color: #000000">&nbsp;linvel&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;timeStep);<br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;&nbsp;&nbsp;&nbsp;#define&nbsp;QUATERNION_DERIVATIVE</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;#ifdef&nbsp;QUATERNION_DERIVATIVE<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btQuaternion&nbsp;predictedOrn&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;curTrans.getRotation();<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;predictedOrn&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;(angvel&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;predictedOrn)&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;(timeStep&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;btScalar(</span><span style="color: #000000">0.5</span><span style="color: #000000">));<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;predictedOrn.normalize();<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">#else</span><span style="color: #000000"><br /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">Exponential&nbsp;map<br /></span><span style="color: #008080">11</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">google&nbsp;for&nbsp;"Practical&nbsp;Parameterization&nbsp;of&nbsp;Rotations&nbsp;Using&nbsp;the&nbsp;Exponential&nbsp;Map",&nbsp;F.&nbsp;Sebastian&nbsp;Grassia</span><span style="color: #008000"><br /></span><span style="color: #008080">12</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000"><br /></span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btVector3&nbsp;axis;<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btScalar&nbsp;&nbsp;&nbsp;&nbsp;fAngle&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;angvel.length();&nbsp;<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">limit&nbsp;the&nbsp;angular&nbsp;motion</span><span style="color: #008000"><br /></span><span style="color: #008080">16</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(fAngle</span><span style="color: #000000">*</span><span style="color: #000000">timeStep&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;ANGULAR_MOTION_THRESHOLD)<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img id="Codehighlighter1_722_775_Open_Image" onclick="this.style.display='none'; Codehighlighter1_722_775_Open_Text.style.display='none'; Codehighlighter1_722_775_Closed_Image.style.display='inline'; Codehighlighter1_722_775_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_722_775_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_722_775_Closed_Text.style.display='none'; Codehighlighter1_722_775_Open_Image.style.display='inline'; Codehighlighter1_722_775_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_722_775_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_722_775_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fAngle&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;ANGULAR_MOTION_THRESHOLD&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;timeStep;<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">20</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">21</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(&nbsp;fAngle&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;btScalar(</span><span style="color: #000000">0.001</span><span style="color: #000000">)&nbsp;)<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img id="Codehighlighter1_814_982_Open_Image" onclick="this.style.display='none'; Codehighlighter1_814_982_Open_Text.style.display='none'; Codehighlighter1_814_982_Closed_Image.style.display='inline'; Codehighlighter1_814_982_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_814_982_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_814_982_Closed_Text.style.display='none'; Codehighlighter1_814_982_Open_Image.style.display='inline'; Codehighlighter1_814_982_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_814_982_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_814_982_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;use&nbsp;Taylor's&nbsp;expansions&nbsp;of&nbsp;sync&nbsp;function</span><span style="color: #008000"><br /></span><span style="color: #008080">24</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;axis&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;angvel</span><span style="color: #000000">*</span><span style="color: #000000">(&nbsp;btScalar(</span><span style="color: #000000">0.5</span><span style="color: #000000">)</span><span style="color: #000000">*</span><span style="color: #000000">timeStep</span><span style="color: #000000">-</span><span style="color: #000000">(timeStep</span><span style="color: #000000">*</span><span style="color: #000000">timeStep</span><span style="color: #000000">*</span><span style="color: #000000">timeStep)</span><span style="color: #000000">*</span><span style="color: #000000">(btScalar(</span><span style="color: #000000">0.020833333333</span><span style="color: #000000">))</span><span style="color: #000000">*</span><span style="color: #000000">fAngle</span><span style="color: #000000">*</span><span style="color: #000000">fAngle&nbsp;);<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">26</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">27</span><span style="color: #000000"><img id="Codehighlighter1_993_1102_Open_Image" onclick="this.style.display='none'; Codehighlighter1_993_1102_Open_Text.style.display='none'; Codehighlighter1_993_1102_Closed_Image.style.display='inline'; Codehighlighter1_993_1102_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_993_1102_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_993_1102_Closed_Text.style.display='none'; Codehighlighter1_993_1102_Open_Image.style.display='inline'; Codehighlighter1_993_1102_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_993_1102_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_993_1102_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;sync(fAngle)&nbsp;=&nbsp;sin(c*fAngle)/t</span><span style="color: #008000"><br /></span><span style="color: #008080">29</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;axis&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;angvel</span><span style="color: #000000">*</span><span style="color: #000000">(&nbsp;btSin(btScalar(</span><span style="color: #000000">0.5</span><span style="color: #000000">)</span><span style="color: #000000">*</span><span style="color: #000000">fAngle</span><span style="color: #000000">*</span><span style="color: #000000">timeStep)</span><span style="color: #000000">/</span><span style="color: #000000">fAngle&nbsp;);<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">31</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btQuaternion&nbsp;dorn&nbsp;(axis.x(),axis.y(),axis.z(),btCos(&nbsp;fAngle</span><span style="color: #000000">*</span><span style="color: #000000">timeStep</span><span style="color: #000000">*</span><span style="color: #000000">btScalar(</span><span style="color: #000000">0.5</span><span style="color: #000000">)&nbsp;));<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btQuaternion&nbsp;orn0&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;curTrans.getRotation();<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">34</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btQuaternion&nbsp;predictedOrn&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;dorn&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;orn0;<br /></span><span style="color: #008080">35</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;predictedOrn.normalize();<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">#endif</span><span style="color: #000000"><br /></span><span style="color: #008080">37</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;predictedTransform.setRotation(predictedOrn);<br /></span><span style="color: #008080">38</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></div><br /><br />所以，motionstate总是以插值的形态出现，代表物体的实际运动位置，可以用在实际游戏模拟中<br />靠，现在应该清楚的吧，如果还不清楚，请看源代码<br />到点了 请女人吃饭去了 附上相关代码：<br /><br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span>&nbsp;<span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;btDiscreteDynamicsWorld::stepSimulation(&nbsp;btScalar&nbsp;timeStep,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;maxSubSteps,&nbsp;btScalar&nbsp;fixedTimeStep)<br /></span><span style="color: #008080">&nbsp;2</span>&nbsp;<span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;3</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;startProfiling(timeStep);<br /></span><span style="color: #008080">&nbsp;4</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;BT_PROFILE(</span><span style="color: #000000">"</span><span style="color: #000000">stepSimulation</span><span style="color: #000000">"</span><span style="color: #000000">);<br /></span><span style="color: #008080">&nbsp;6</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;7</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;numSimulationSubSteps&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">&nbsp;8</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;9</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(maxSubSteps)<br /></span><span style="color: #008080">10</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br /></span><span style="color: #008080">11</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">fixed&nbsp;timestep&nbsp;with&nbsp;interpolation</span><span style="color: #008000"><br /></span><span style="color: #008080">12</span>&nbsp;<span style="color: #008000"></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_localTime&nbsp;</span><span style="color: #000000">+=</span><span style="color: #000000">&nbsp;timeStep;<br /></span><span style="color: #008080">13</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(m_localTime&nbsp;</span><span style="color: #000000">&gt;=</span><span style="color: #000000">&nbsp;fixedTimeStep)<br /></span><span style="color: #008080">14</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /></span><span style="color: #008080">15</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;numSimulationSubSteps&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">(&nbsp;m_localTime&nbsp;</span><span style="color: #000000">/</span><span style="color: #000000">&nbsp;fixedTimeStep);<br /></span><span style="color: #008080">16</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_localTime&nbsp;</span><span style="color: #000000">-=</span><span style="color: #000000">&nbsp;numSimulationSubSteps&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;fixedTimeStep;<br /></span><span style="color: #008080">17</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">18</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">19</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br /></span><span style="color: #008080">20</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">variable&nbsp;timestep</span><span style="color: #008000"><br /></span><span style="color: #008080">21</span>&nbsp;<span style="color: #008000"></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fixedTimeStep&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;timeStep;<br /></span><span style="color: #008080">22</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_localTime&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;timeStep;<br /></span><span style="color: #008080">23</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(btFuzzyZero(timeStep))<br /></span><span style="color: #008080">24</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /></span><span style="color: #008080">25</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;numSimulationSubSteps&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">26</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maxSubSteps&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">27</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">28</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /></span><span style="color: #008080">29</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;numSimulationSubSteps&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">30</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maxSubSteps&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">1</span><span style="color: #000000">;<br /></span><span style="color: #008080">31</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">32</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">33</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">34</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">process&nbsp;some&nbsp;debugging&nbsp;flags</span><span style="color: #008000"><br /></span><span style="color: #008080">35</span>&nbsp;<span style="color: #008000"></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(getDebugDrawer())<br /></span><span style="color: #008080">36</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br /></span><span style="color: #008080">37</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btIDebugDraw</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;debugDrawer&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;getDebugDrawer&nbsp;();<br /></span><span style="color: #008080">38</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gDisableDeactivation&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(debugDrawer</span><span style="color: #000000">-&gt;</span><span style="color: #000000">getDebugMode()&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;btIDebugDraw::DBG_NoDeactivation)&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">39</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">40</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(numSimulationSubSteps)<br /></span><span style="color: #008080">41</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br /></span><span style="color: #008080">42</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">43</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">clamp&nbsp;the&nbsp;number&nbsp;of&nbsp;substeps,&nbsp;to&nbsp;prevent&nbsp;simulation&nbsp;grinding&nbsp;spiralling&nbsp;down&nbsp;to&nbsp;a&nbsp;halt</span><span style="color: #008000"><br /></span><span style="color: #008080">44</span>&nbsp;<span style="color: #008000"></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;clampedSimulationSteps&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(numSimulationSubSteps&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;maxSubSteps)</span><span style="color: #000000">?</span><span style="color: #000000">&nbsp;maxSubSteps&nbsp;:&nbsp;numSimulationSubSteps;<br /></span><span style="color: #008080">45</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">46</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;saveKinematicState(fixedTimeStep</span><span style="color: #000000">*</span><span style="color: #000000">clampedSimulationSteps);<br /></span><span style="color: #008080">47</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">48</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;applyGravity();<br /></span><span style="color: #008080">49</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">50</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">51</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">52</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">clampedSimulationSteps;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /></span><span style="color: #008080">53</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /></span><span style="color: #008080">54</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;internalSingleStepSimulation(fixedTimeStep);<br /></span><span style="color: #008080">55</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;synchronizeMotionStates();<br /></span><span style="color: #008080">56</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">57</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">58</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000"><br /></span><span style="color: #008080">59</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;{<br /></span><span style="color: #008080">60</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;synchronizeMotionStates();<br /></span><span style="color: #008080">61</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<br /></span><span style="color: #008080">62</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">63</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;clearForces();<br /></span><span style="color: #008080">64</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">65</span>&nbsp;<span style="color: #000000">#ifndef&nbsp;BT_NO_PROFILE<br /></span><span style="color: #008080">66</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;CProfileManager::Increment_Frame_Counter();<br /></span><span style="color: #008080">67</span>&nbsp;<span style="color: #000000"></span><span style="color: #0000ff">#endif</span><span style="color: #000000">&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">BT_NO_PROFILE</span><span style="color: #000000"><br /></span><span style="color: #008080">68</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">69</span>&nbsp;<span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;numSimulationSubSteps;<br /></span><span style="color: #008080">70</span>&nbsp;<span style="color: #000000">}<br /></span><span style="color: #008080">71</span>&nbsp;<span style="color: #000000"><br /></span><span style="color: #008080">72</span>&nbsp;<span style="color: #000000"></span></div><br /><span style="widows: 2; text-transform: none; text-indent: 0px; font: 14px/21px verdana,'courier new'; white-space: normal; orphans: 2; letter-spacing: normal; color: #000000; word-spacing: 0px"><br /></span></div><img src ="http://www.cppblog.com/zhuyeaini/aggbug/161862.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/zhuyeaini/" target="_blank">野猪红</a> 2011-12-10 10:27 <a href="http://www.cppblog.com/zhuyeaini/archive/2011/12/10/161862.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>