OSDN Git Service

Made separate Teleport camera function
[skyscrapersim/skyscraper.git] / bullet-changes.old.patch
1 diff -urN a/src/BulletDynamics/Character/btCharacterControllerInterface.h b/src/BulletDynamics/Character/btCharacterControllerInterface.h
2 --- a/src/BulletDynamics/Character/btCharacterControllerInterface.h     2013-01-22 17:54:25.468670949 -0600
3 +++ b/src/BulletDynamics/Character/btCharacterControllerInterface.h     2011-04-28 12:53:37.000000000 -0500
4 @@ -31,7 +31,7 @@
5         
6         virtual void    setWalkDirection(const btVector3& walkDirection) = 0;
7         virtual void    setVelocityForTimeInterval(const btVector3& velocity, btScalar timeInterval) = 0;
8 -       virtual void    reset () = 0;
9 +       virtual void    reset ( btCollisionWorld* collisionWorld ) = 0;
10         virtual void    warp (const btVector3& origin) = 0;
11  
12         virtual void    preStep ( btCollisionWorld* collisionWorld) = 0;
13 @@ -40,6 +40,7 @@
14         virtual void    jump () = 0;
15  
16         virtual bool    onGround () const = 0;
17 +       virtual void    setUpInterpolate (bool value) = 0;
18  };
19  
20  #endif //BT_CHARACTER_CONTROLLER_INTERFACE_H
21 diff -urN a/src/BulletDynamics/Character/btKinematicCharacterController.cpp b/src/BulletDynamics/Character/btKinematicCharacterController.cpp
22 --- a/src/BulletDynamics/Character/btKinematicCharacterController.cpp   2013-01-22 17:54:25.444670455 -0600
23 +++ b/src/BulletDynamics/Character/btKinematicCharacterController.cpp   2013-01-22 17:17:47.583541659 -0600
24 @@ -14,6 +14,7 @@
25  */
26  
27  
28 +#include <stdio.h>
29  #include "LinearMath/btIDebugDraw.h"
30  #include "BulletCollision/CollisionDispatch/btGhostObject.h"
31  #include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
32 @@ -77,6 +78,9 @@
33                 if (convexResult.m_hitCollisionObject == m_me)
34                         return btScalar(1.0);
35  
36 +               if (!convexResult.m_hitCollisionObject->hasContactResponse())
37 +                       return btScalar(1.0);
38 +
39                 btVector3 hitNormalWorld;
40                 if (normalInWorldSpace)
41                 {
42 @@ -146,7 +150,11 @@
43         m_jumpSpeed = 10.0; // ?
44         m_wasOnGround = false;
45         m_wasJumping = false;
46 +       m_interpolateUp = true;
47         setMaxSlope(btRadians(45.0));
48 +       m_currentStepOffset = 0;
49 +       full_drop = false;
50 +       bounce_fix = false;
51  }
52  
53  btKinematicCharacterController::~btKinematicCharacterController ()
54 @@ -187,6 +195,12 @@
55                 m_manifoldArray.resize(0);
56  
57                 btBroadphasePair* collisionPair = &m_ghostObject->getOverlappingPairCache()->getOverlappingPairArray()[i];
58 +
59 +               btCollisionObject* obj0 = static_cast<btCollisionObject*>(collisionPair->m_pProxy0->m_clientObject);
60 +                btCollisionObject* obj1 = static_cast<btCollisionObject*>(collisionPair->m_pProxy1->m_clientObject);
61 +
62 +               if ((obj0 && !obj0->hasContactResponse()) || (obj1 && !obj1->hasContactResponse()))
63 +                       continue;
64                 
65                 if (collisionPair->m_algorithm)
66                         collisionPair->m_algorithm->getAllContactManifolds(m_manifoldArray);
67 @@ -260,7 +274,10 @@
68                 {
69                         // we moved up only a fraction of the step height
70                         m_currentStepOffset = m_stepHeight * callback.m_closestHitFraction;
71 -                       m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction);
72 +                       if (m_interpolateUp == true)
73 +                               m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction);
74 +                       else
75 +                               m_currentPosition = m_targetPosition;
76                 }
77                 m_verticalVelocity = 0.0;
78                 m_verticalOffset = 0.0;
79 @@ -325,7 +342,8 @@
80         {
81                 if (m_normalizedDirection.dot(m_touchingNormal) > btScalar(0.0))
82                 {
83 -                       updateTargetPositionBasedOnCollision (m_touchingNormal);
84 +                       //interferes with step movement
85 +                       //updateTargetPositionBasedOnCollision (m_touchingNormal);
86                 }
87         }
88  
89 @@ -397,7 +415,8 @@
90  
91  void btKinematicCharacterController::stepDown ( btCollisionWorld* collisionWorld, btScalar dt)
92  {
93 -       btTransform start, end;
94 +       btTransform start, end, end_double;
95 +       bool runonce = false;
96  
97         // phase 3: down
98         /*btScalar additionalDownStep = (m_wasOnGround && !onGround()) ? m_stepHeight : 0.0;
99 @@ -406,44 +425,124 @@
100         btVector3 gravity_drop = getUpAxisDirections()[m_upAxis] * downVelocity; 
101         m_targetPosition -= (step_drop + gravity_drop);*/
102  
103 +       btVector3 orig_position = m_targetPosition;
104 +       
105         btScalar downVelocity = (m_verticalVelocity<0.f?-m_verticalVelocity:0.f) * dt;
106 -       if(downVelocity > 0.0 && downVelocity < m_stepHeight
107 +
108 +       if(downVelocity > 0.0 && downVelocity > m_fallSpeed
109                 && (m_wasOnGround || !m_wasJumping))
110 -       {
111 -               downVelocity = m_stepHeight;
112 -       }
113 +               downVelocity = m_fallSpeed;
114  
115         btVector3 step_drop = getUpAxisDirections()[m_upAxis] * (m_currentStepOffset + downVelocity);
116         m_targetPosition -= step_drop;
117  
118 -       start.setIdentity ();
119 -       end.setIdentity ();
120 +       btKinematicClosestNotMeConvexResultCallback callback (m_ghostObject, getUpAxisDirections()[m_upAxis], m_maxSlopeCosine);
121 +        callback.m_collisionFilterGroup = getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup;
122 +        callback.m_collisionFilterMask = getGhostObject()->getBroadphaseHandle()->m_collisionFilterMask;
123  
124 -       start.setOrigin (m_currentPosition);
125 -       end.setOrigin (m_targetPosition);
126 +        btKinematicClosestNotMeConvexResultCallback callback2 (m_ghostObject, getUpAxisDirections()[m_upAxis], m_maxSlopeCosine);
127 +        callback2.m_collisionFilterGroup = getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup;
128 +        callback2.m_collisionFilterMask = getGhostObject()->getBroadphaseHandle()->m_collisionFilterMask;
129  
130 -       btKinematicClosestNotMeConvexResultCallback callback (m_ghostObject, getUpAxisDirections()[m_upAxis], m_maxSlopeCosine);
131 -       callback.m_collisionFilterGroup = getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup;
132 -       callback.m_collisionFilterMask = getGhostObject()->getBroadphaseHandle()->m_collisionFilterMask;
133 -       
134 -       if (m_useGhostObjectSweepTest)
135 +       while (1)
136         {
137 -               m_ghostObject->convexSweepTest (m_convexShape, start, end, callback, collisionWorld->getDispatchInfo().m_allowedCcdPenetration);
138 -       } else
139 -       {
140 -               collisionWorld->convexSweepTest (m_convexShape, start, end, callback, collisionWorld->getDispatchInfo().m_allowedCcdPenetration);
141 +               start.setIdentity ();
142 +               end.setIdentity ();
143 +
144 +               end_double.setIdentity ();
145 +
146 +               start.setOrigin (m_currentPosition);
147 +               end.setOrigin (m_targetPosition);
148 +
149 +               //set double test for 2x the step drop, to check for a large drop vs small drop
150 +               end_double.setOrigin (m_targetPosition - step_drop);
151 +
152 +               if (m_useGhostObjectSweepTest)
153 +               {
154 +                       m_ghostObject->convexSweepTest (m_convexShape, start, end, callback, collisionWorld->getDispatchInfo().m_allowedCcdPenetration);
155 +
156 +                       if (!callback.hasHit())
157 +                       {
158 +                               //test a double fall height, to see if the character should interpolate it's fall (full) or not (partial)
159 +                               m_ghostObject->convexSweepTest (m_convexShape, start, end_double, callback2, collisionWorld->getDispatchInfo().m_allowedCcdPenetration);
160 +                       }
161 +               } else
162 +               {
163 +                       collisionWorld->convexSweepTest (m_convexShape, start, end, callback, collisionWorld->getDispatchInfo().m_allowedCcdPenetration);
164 +
165 +                       if (!callback.hasHit())
166 +                                       {
167 +                                                       //test a double fall height, to see if the character should interpolate it's fall (large) or not (small)
168 +                                                       collisionWorld->convexSweepTest (m_convexShape, start, end_double, callback2, collisionWorld->getDispatchInfo().m_allowedCcdPenetration);
169 +                                       }
170 +               }
171 +       
172 +               btScalar downVelocity2 = (m_verticalVelocity<0.f?-m_verticalVelocity:0.f) * dt;
173 +               bool has_hit = false;
174 +               if (bounce_fix == true)
175 +                       has_hit = callback.hasHit() || callback2.hasHit();
176 +               else
177 +                       has_hit = callback2.hasHit();
178 +
179 +               if(downVelocity2 > 0.0 && downVelocity2 < m_stepHeight && has_hit == true && runonce == false
180 +                                       && (m_wasOnGround || !m_wasJumping))
181 +               {
182 +                       //redo the velocity calculation when falling a small amount, for fast stairs motion
183 +                       //for larger falls, use the smoother/slower interpolated movement by not touching the target position
184 +
185 +                       m_targetPosition = orig_position;
186 +                                       downVelocity = m_stepHeight;
187 +
188 +                               btVector3 step_drop = getUpAxisDirections()[m_upAxis] * (m_currentStepOffset + downVelocity);
189 +                       m_targetPosition -= step_drop;
190 +                       runonce = true;
191 +                       continue; //re-run previous tests
192 +               }
193 +               break;
194         }
195  
196 -       if (callback.hasHit())
197 +       if (callback.hasHit() || runonce == true)
198         {
199                 // we dropped a fraction of the height -> hit floor
200 -               m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction);
201 +
202 +               btScalar fraction = (m_currentPosition.getY() - callback.m_hitPointWorld.getY()) / 2;
203 +
204 +               //printf("hitpoint: %g - pos %g\n", callback.m_hitPointWorld.getY(), m_currentPosition.getY());
205 +
206 +               if (bounce_fix == true)
207 +               {
208 +                       if (full_drop == true)
209 +                                m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction);
210 +                        else
211 +                                //due to errors in the closestHitFraction variable when used with large polygons, calculate the hit fraction manually
212 +                                m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, fraction);
213 +               }
214 +               else
215 +                       m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction);
216 +
217 +               full_drop = false;
218 +
219                 m_verticalVelocity = 0.0;
220                 m_verticalOffset = 0.0;
221                 m_wasJumping = false;
222         } else {
223                 // we dropped the full height
224                 
225 +               full_drop = true;
226 +
227 +               if (bounce_fix == true)
228 +               {
229 +                       downVelocity = (m_verticalVelocity<0.f?-m_verticalVelocity:0.f) * dt;
230 +                       if (downVelocity > m_fallSpeed && (m_wasOnGround || !m_wasJumping))
231 +                       {
232 +                               m_targetPosition += step_drop; //undo previous target change
233 +                               downVelocity = m_fallSpeed;
234 +                               step_drop = getUpAxisDirections()[m_upAxis] * (m_currentStepOffset + downVelocity);
235 +                               m_targetPosition -= step_drop;
236 +                       }
237 +               }
238 +               //printf("full drop - %g, %g\n", m_currentPosition.getY(), m_targetPosition.getY());
239 +
240                 m_currentPosition = m_targetPosition;
241         }
242  }
243 @@ -479,10 +578,21 @@
244         m_velocityTimeInterval = timeInterval;
245  }
246  
247 -
248 -
249 -void btKinematicCharacterController::reset ()
250 +void btKinematicCharacterController::reset ( btCollisionWorld* collisionWorld )
251  {
252 +        m_verticalVelocity = 0.0;
253 +        m_verticalOffset = 0.0;
254 +        m_wasOnGround = false;
255 +        m_wasJumping = false;
256 +        m_walkDirection.setValue(0,0,0);
257 +        m_velocityTimeInterval = 0.0;
258 +
259 +        //clear pair cache
260 +        btHashedOverlappingPairCache *cache = m_ghostObject->getOverlappingPairCache();
261 +        while (cache->getOverlappingPairArray().size() > 0)
262 +        {
263 +                cache->removeOverlappingPair(cache->getOverlappingPairArray()[0].m_pProxy0, cache->getOverlappingPairArray()[0].m_pProxy1, collisionWorld->getDispatcher());
264 +        }
265  }
266  
267  void btKinematicCharacterController::warp (const btVector3& origin)
268 @@ -653,3 +763,8 @@
269  void btKinematicCharacterController::debugDraw(btIDebugDraw* debugDrawer)
270  {
271  }
272 +
273 +void btKinematicCharacterController::setUpInterpolate(bool value)
274 +{
275 +       m_interpolateUp = value;
276 +}
277 diff -urN a/src/BulletDynamics/Character/btKinematicCharacterController.h b/src/BulletDynamics/Character/btKinematicCharacterController.h
278 --- a/src/BulletDynamics/Character/btKinematicCharacterController.h     2013-01-22 17:54:25.440670373 -0600
279 +++ b/src/BulletDynamics/Character/btKinematicCharacterController.h     2013-01-13 14:33:42.262892731 -0600
280 @@ -81,6 +81,9 @@
281         int m_upAxis;
282  
283         static btVector3* getUpAxisDirections();
284 +       bool  m_interpolateUp;
285 +       bool  full_drop;
286 +       bool  bounce_fix;
287  
288         btVector3 computeReflectionDirection (const btVector3& direction, const btVector3& normal);
289         btVector3 parallelComponent (const btVector3& direction, const btVector3& normal);
290 @@ -133,7 +136,7 @@
291         virtual void setVelocityForTimeInterval(const btVector3& velocity,
292                                 btScalar timeInterval);
293  
294 -       void reset ();
295 +       void reset ( btCollisionWorld* collisionWorld );
296         void warp (const btVector3& origin);
297  
298         void preStep (  btCollisionWorld* collisionWorld);
299 @@ -161,6 +164,7 @@
300         }
301  
302         bool onGround () const;
303 +       void setUpInterpolate (bool value);
304  };
305  
306  #endif // BT_KINEMATIC_CHARACTER_CONTROLLER_H