Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btSolverBody.h @ 1963

Last change on this file since 1963 was 1963, checked in by rgrieder, 16 years ago

Added Bullet physics engine.

  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#ifndef BT_SOLVER_BODY_H
17#define BT_SOLVER_BODY_H
18
19class   btRigidBody;
20#include "LinearMath/btVector3.h"
21#include "LinearMath/btMatrix3x3.h"
22#include "BulletDynamics/Dynamics/btRigidBody.h"
23#include "LinearMath/btAlignedAllocator.h"
24#include "LinearMath/btTransformUtil.h"
25
26
27///btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packed to increase cache coherence/performance.
28ATTRIBUTE_ALIGNED16 (struct)    btSolverBody
29{
30        BT_DECLARE_ALIGNED_ALLOCATOR();
31       
32        btVector3               m_angularVelocity;
33        float                   m_angularFactor;
34        float                   m_invMass;
35        float                   m_friction;
36        btRigidBody*    m_originalBody;
37        btVector3               m_linearVelocity;
38        btVector3               m_centerOfMassPosition;
39       
40        btVector3               m_pushVelocity;
41        btVector3               m_turnVelocity;
42       
43       
44        SIMD_FORCE_INLINE void  getVelocityInLocalPoint(const btVector3& rel_pos, btVector3& velocity ) const
45        {
46                velocity = m_linearVelocity + m_angularVelocity.cross(rel_pos);
47        }
48
49        //Optimization for the iterative solver: avoid calculating constant terms involving inertia, normal, relative position
50        SIMD_FORCE_INLINE void internalApplyImpulse(const btVector3& linearComponent, const btVector3& angularComponent,btScalar impulseMagnitude)
51        {
52                if (m_invMass)
53                {
54                        m_linearVelocity += linearComponent*impulseMagnitude;
55                        m_angularVelocity += angularComponent*(impulseMagnitude*m_angularFactor);
56                }
57        }
58       
59        SIMD_FORCE_INLINE void internalApplyPushImpulse(const btVector3& linearComponent, const btVector3& angularComponent,btScalar impulseMagnitude)
60        {
61                if (m_invMass)
62                {
63                        m_pushVelocity += linearComponent*impulseMagnitude;
64                        m_turnVelocity += angularComponent*(impulseMagnitude*m_angularFactor);
65                }
66        }
67
68       
69        void    writebackVelocity()
70        {
71                if (m_invMass)
72                {
73                        m_originalBody->setLinearVelocity(m_linearVelocity);
74                        m_originalBody->setAngularVelocity(m_angularVelocity);
75                       
76                        //m_originalBody->setCompanionId(-1);
77                }
78        }
79       
80
81        void    writebackVelocity(btScalar timeStep)
82        {
83                if (m_invMass)
84                {
85                        m_originalBody->setLinearVelocity(m_linearVelocity);
86                        m_originalBody->setAngularVelocity(m_angularVelocity);
87                       
88                        //correct the position/orientation based on push/turn recovery
89                        btTransform newTransform;
90                        btTransformUtil::integrateTransform(m_originalBody->getWorldTransform(),m_pushVelocity,m_turnVelocity,timeStep,newTransform);
91                        m_originalBody->setWorldTransform(newTransform);
92                       
93                        //m_originalBody->setCompanionId(-1);
94                }
95        }
96
97        void    readVelocity()
98        {
99                if (m_invMass)
100                {
101                        m_linearVelocity = m_originalBody->getLinearVelocity();
102                        m_angularVelocity = m_originalBody->getAngularVelocity();
103                }
104        }
105
106       
107
108
109};
110
111#endif //BT_SOLVER_BODY_H
112
113
Note: See TracBrowser for help on using the repository browser.