@@ -15,7 +15,7 @@ namespace physics
15
15
static btSequentialImpulseConstraintSolver* solver;
16
16
static btDiscreteDynamicsWorld* dynamicsWorld;
17
17
static btSphereShape sphere (10 .0f );
18
- static btTransform transform ;
18
+ static btTransform identityTransform ;
19
19
20
20
void init ()
21
21
{
@@ -37,12 +37,16 @@ namespace physics
37
37
dynamicsWorld->setGravity (btVector3 (0 , -10 , 0 ));
38
38
dynamicsWorld->debugDrawWorld ();
39
39
40
- transform .setFromOpenGLMatrix (glm::value_ptr (glm::identity<glm::mat4>()));
40
+ identityTransform .setFromOpenGLMatrix (glm::value_ptr (glm::identity<glm::mat4>()));
41
41
IG_CORE_INFO (" Physics Initialized" );
42
42
}
43
43
44
- btRigidBody* createRigidBody ( float mass, const btTransform& startTransform, btCollisionShape* shape, const btVector4& color = btVector4( 1 , 0 , 0 , 1 ) )
44
+ RigidBodyHandle loadRigidBody (std::string path )
45
45
{
46
+ btScalar mass = 10 .0f ;
47
+ btCollisionShape* shape = &sphere;
48
+ btTransform transform = identityTransform;
49
+
46
50
assert ((!shape || shape->getShapeType () != INVALID_SHAPE_PROXYTYPE));
47
51
48
52
// rigidbody is dynamic if and only if mass is non zero, otherwise static
@@ -56,7 +60,7 @@ namespace physics
56
60
57
61
#define USE_MOTIONSTATE 1
58
62
#ifdef USE_MOTIONSTATE
59
- btDefaultMotionState * myMotionState = new btDefaultMotionState (startTransform );
63
+ btDefaultMotionState * myMotionState = new btDefaultMotionState (transform );
60
64
61
65
btRigidBody::btRigidBodyConstructionInfo cInfo (mass, myMotionState, shape, localInertia);
62
66
@@ -73,24 +77,13 @@ namespace physics
73
77
return body;
74
78
}
75
79
76
- RigidBodyHandle loadRigidBody (std::string path)
77
- {
78
- return createRigidBody (10 .0f , transform, &sphere);
79
- }
80
-
81
80
void update (float dt)
82
81
{
83
82
dynamicsWorld->stepSimulation (dt);
84
83
ecs::registry.view <RigidBodyHandle, Transformation>().each ([&](const auto , auto & rigidBody, auto & transformation)
85
84
{
86
85
btTransform t = rigidBody->getWorldTransform ();
87
86
t.getOpenGLMatrix (glm::value_ptr (transformation));
88
- /*
89
- btVector3 origin = rigidBody->getWorldTransform().getOrigin();
90
- transformation[3][0] = origin.getX();
91
- transformation[3][1] = origin.getY();
92
- transformation[3][2] = origin.getZ();
93
- */
94
87
});
95
88
}
96
89
0 commit comments