Skip to content

Commit cd6cfb2

Browse files
committed
Got Cars working!
1 parent 33684bc commit cd6cfb2

File tree

8 files changed

+276
-20
lines changed

8 files changed

+276
-20
lines changed

bullet3.stub.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public function addConstraint(Constraint $constraint, bool $noCollide = false):
1818
public function removeConstraint(Constraint $constraint): void {}
1919

2020
public function stepSimulation(float $timeStep, int $maxSubSteps = 1, float $fixedTimeStep = 0.01666666): void {}
21+
22+
public function enableDebugDrawing(): void {}
23+
public function debugDrawWorld(): void {}
24+
public function setDebugDrawVP(\GL\Math\Mat4 $viewProjection): void {}
2125
}
2226

2327
interface CollisionShape
@@ -141,6 +145,8 @@ public function setMaxMotorForce(int $index, float $force): void {}
141145
public function enableSpring(int $index, bool $onOff): void {}
142146
public function setStiffness(int $index, float $stiffness, bool $limitIfNeeded = true): void {}
143147
public function setDamping(int $index, float $damping, bool $limitIfNeeded = true): void {}
148+
149+
public function setEquilibriumPoint(): void {}
144150
}
145151

146152
class RigidBody
@@ -171,6 +177,7 @@ public function applyCentralImpulse(\GL\Math\Vec3 $impulse): void {}
171177
public function applyTorqueImpulse(\GL\Math\Vec3 $torque): void {}
172178

173179
public function activate(): void {}
180+
public function disableDeactivation(): void {}
174181
}
175182

176183
function bullet3_test(): void {}

bullet3_arginfo.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 1284a5172e9820d014ed2c4c7ec42ada0b87dddc */
2+
* Stub hash: 127ca9a9fb209aa2f26c59956d95afc1ce3d208d */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Bullet_bullet3_test, 0, 0, IS_VOID, 0)
55
ZEND_END_ARG_INFO()
@@ -30,6 +30,14 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Bullet_World_stepSimulatio
3030
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, fixedTimeStep, IS_DOUBLE, 0, "0.01666666")
3131
ZEND_END_ARG_INFO()
3232

33+
#define arginfo_class_Bullet_World_enableDebugDrawing arginfo_Bullet_bullet3_test
34+
35+
#define arginfo_class_Bullet_World_debugDrawWorld arginfo_Bullet_bullet3_test
36+
37+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Bullet_World_setDebugDrawVP, 0, 1, IS_VOID, 0)
38+
ZEND_ARG_OBJ_INFO(0, viewProjection, GL\\Math\\Mat4, 0)
39+
ZEND_END_ARG_INFO()
40+
3341
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Bullet_SphereShape___construct, 0, 0, 1)
3442
ZEND_ARG_TYPE_INFO(0, radius, IS_DOUBLE, 0)
3543
ZEND_END_ARG_INFO()
@@ -169,6 +177,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Bullet_Generic6DofSpring2C
169177
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, limitIfNeeded, _IS_BOOL, 0, "true")
170178
ZEND_END_ARG_INFO()
171179

180+
#define arginfo_class_Bullet_Generic6DofSpring2Constraint_setEquilibriumPoint arginfo_Bullet_bullet3_test
181+
172182
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Bullet_RigidBody___construct, 0, 0, 1)
173183
ZEND_ARG_OBJ_INFO(0, collisionShape, Bullet\\CollisionShape, 0)
174184
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mass, IS_DOUBLE, 0, "0.0")
@@ -245,6 +255,8 @@ ZEND_END_ARG_INFO()
245255

246256
#define arginfo_class_Bullet_RigidBody_activate arginfo_Bullet_bullet3_test
247257

258+
#define arginfo_class_Bullet_RigidBody_disableDeactivation arginfo_Bullet_bullet3_test
259+
248260

249261
ZEND_FUNCTION(Bullet_bullet3_test);
250262
ZEND_METHOD(Bullet_World, setGravity);
@@ -253,6 +265,9 @@ ZEND_METHOD(Bullet_World, addRigidBody);
253265
ZEND_METHOD(Bullet_World, addConstraint);
254266
ZEND_METHOD(Bullet_World, removeConstraint);
255267
ZEND_METHOD(Bullet_World, stepSimulation);
268+
ZEND_METHOD(Bullet_World, enableDebugDrawing);
269+
ZEND_METHOD(Bullet_World, debugDrawWorld);
270+
ZEND_METHOD(Bullet_World, setDebugDrawVP);
256271
ZEND_METHOD(Bullet_SphereShape, __construct);
257272
ZEND_METHOD(Bullet_BoxShape, __construct);
258273
ZEND_METHOD(Bullet_CylinderShape, __construct);
@@ -284,6 +299,7 @@ ZEND_METHOD(Bullet_Generic6DofSpring2Constraint, setMaxMotorForce);
284299
ZEND_METHOD(Bullet_Generic6DofSpring2Constraint, enableSpring);
285300
ZEND_METHOD(Bullet_Generic6DofSpring2Constraint, setStiffness);
286301
ZEND_METHOD(Bullet_Generic6DofSpring2Constraint, setDamping);
302+
ZEND_METHOD(Bullet_Generic6DofSpring2Constraint, setEquilibriumPoint);
287303
ZEND_METHOD(Bullet_RigidBody, __construct);
288304
ZEND_METHOD(Bullet_RigidBody, setPosition);
289305
ZEND_METHOD(Bullet_RigidBody, getPosition);
@@ -305,6 +321,7 @@ ZEND_METHOD(Bullet_RigidBody, applyImpulse);
305321
ZEND_METHOD(Bullet_RigidBody, applyCentralImpulse);
306322
ZEND_METHOD(Bullet_RigidBody, applyTorqueImpulse);
307323
ZEND_METHOD(Bullet_RigidBody, activate);
324+
ZEND_METHOD(Bullet_RigidBody, disableDeactivation);
308325

309326

310327
static const zend_function_entry ext_functions[] = {
@@ -320,6 +337,9 @@ static const zend_function_entry class_Bullet_World_methods[] = {
320337
ZEND_ME(Bullet_World, addConstraint, arginfo_class_Bullet_World_addConstraint, ZEND_ACC_PUBLIC)
321338
ZEND_ME(Bullet_World, removeConstraint, arginfo_class_Bullet_World_removeConstraint, ZEND_ACC_PUBLIC)
322339
ZEND_ME(Bullet_World, stepSimulation, arginfo_class_Bullet_World_stepSimulation, ZEND_ACC_PUBLIC)
340+
ZEND_ME(Bullet_World, enableDebugDrawing, arginfo_class_Bullet_World_enableDebugDrawing, ZEND_ACC_PUBLIC)
341+
ZEND_ME(Bullet_World, debugDrawWorld, arginfo_class_Bullet_World_debugDrawWorld, ZEND_ACC_PUBLIC)
342+
ZEND_ME(Bullet_World, setDebugDrawVP, arginfo_class_Bullet_World_setDebugDrawVP, ZEND_ACC_PUBLIC)
323343
ZEND_FE_END
324344
};
325345

@@ -416,6 +436,7 @@ static const zend_function_entry class_Bullet_Generic6DofSpring2Constraint_metho
416436
ZEND_ME(Bullet_Generic6DofSpring2Constraint, enableSpring, arginfo_class_Bullet_Generic6DofSpring2Constraint_enableSpring, ZEND_ACC_PUBLIC)
417437
ZEND_ME(Bullet_Generic6DofSpring2Constraint, setStiffness, arginfo_class_Bullet_Generic6DofSpring2Constraint_setStiffness, ZEND_ACC_PUBLIC)
418438
ZEND_ME(Bullet_Generic6DofSpring2Constraint, setDamping, arginfo_class_Bullet_Generic6DofSpring2Constraint_setDamping, ZEND_ACC_PUBLIC)
439+
ZEND_ME(Bullet_Generic6DofSpring2Constraint, setEquilibriumPoint, arginfo_class_Bullet_Generic6DofSpring2Constraint_setEquilibriumPoint, ZEND_ACC_PUBLIC)
419440
ZEND_FE_END
420441
};
421442

@@ -442,6 +463,7 @@ static const zend_function_entry class_Bullet_RigidBody_methods[] = {
442463
ZEND_ME(Bullet_RigidBody, applyCentralImpulse, arginfo_class_Bullet_RigidBody_applyCentralImpulse, ZEND_ACC_PUBLIC)
443464
ZEND_ME(Bullet_RigidBody, applyTorqueImpulse, arginfo_class_Bullet_RigidBody_applyTorqueImpulse, ZEND_ACC_PUBLIC)
444465
ZEND_ME(Bullet_RigidBody, activate, arginfo_class_Bullet_RigidBody_activate, ZEND_ACC_PUBLIC)
466+
ZEND_ME(Bullet_RigidBody, disableDeactivation, arginfo_class_Bullet_RigidBody_disableDeactivation, ZEND_ACC_PUBLIC)
445467
ZEND_FE_END
446468
};
447469

bullet3_bridge.cpp

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#include "btBulletDynamicsCommon.h"
33
#include "BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.h"
44

5+
#include <iostream>
6+
#include <vector>
7+
#include <string>
8+
59
struct btDynamicsWorldWrapper {
610
btDefaultCollisionConfiguration* collisionConfiguration;
711
btCollisionDispatcher *dispatcher;
@@ -137,6 +141,35 @@ void btDynamicsWorld_stepSimulation(btDynamicsWorldWrapper *worldWrapper, float
137141
worldWrapper->dynamicsWorld->stepSimulation(timeStep);
138142
}
139143

144+
void btDynamicsWorld_setDebugRenderer(btDynamicsWorldWrapper *world, btDebugRendererWrapper *renderer)
145+
{
146+
world->dynamicsWorld->setDebugDrawer(renderer->debugDrawer);
147+
}
148+
149+
void btDynamicsWorld_debugDrawWorld(btDynamicsWorldWrapper *world)
150+
{
151+
world->dynamicsWorld->debugDrawWorld();
152+
}
153+
154+
void btDynamicsWorld_enableDebugDrawing(btDynamicsWorldWrapper *world)
155+
{
156+
phpglfwBtDebugDraw *debugDrawer = new phpglfwBtDebugDraw();
157+
debugDrawer->setDebugMode(
158+
btIDebugDraw::DBG_DrawWireframe |
159+
btIDebugDraw::DBG_DrawConstraints
160+
// btIDebugDraw::DBG_DrawAabb |
161+
// btIDebugDraw::DBG_DrawContactPoints |
162+
// btIDebugDraw::DBG_DrawNormals
163+
);
164+
world->dynamicsWorld->setDebugDrawer(debugDrawer);
165+
}
166+
167+
void btDynamicsWorld_setDebugDrawVP(btDynamicsWorldWrapper *world, mat4x4 *vpMatrix)
168+
{
169+
phpglfwBtDebugDraw *debugDrawer = static_cast<phpglfwBtDebugDraw *>(world->dynamicsWorld->getDebugDrawer());
170+
debugDrawer->setViewProjection(&(*vpMatrix)[0][0]);
171+
}
172+
140173
/**
141174
* Collision shape
142175
*
@@ -355,6 +388,11 @@ void btGeneric6DofSpring2Constraint_setDamping(btTypedConstraintWrapper *constra
355388
g6dof->setDamping(index, damping, limitIfNeeded);
356389
}
357390

391+
void btGeneric6DofSpring2Constraint_setEquilibriumPoint(btTypedConstraintWrapper *constraint)
392+
{
393+
btGeneric6DofSpring2Constraint *g6dof = static_cast<btGeneric6DofSpring2Constraint *>(constraint->constraint);
394+
g6dof->setEquilibriumPoint();
395+
}
358396

359397
/**
360398
* Rigid body
@@ -472,4 +510,34 @@ void btRigidBody_applyTorqueImpulse(btRigidBodyWrapper *body, vec3 *torque) {
472510

473511
void btRigidBody_activate(btRigidBodyWrapper *body) {
474512
body->rigidBody->activate();
475-
}
513+
}
514+
515+
void btRigidBody_disableDeactivation(btRigidBodyWrapper *body) {
516+
body->rigidBody->setActivationState(DISABLE_DEACTIVATION);
517+
}
518+
519+
/**
520+
* Debug renderer
521+
*
522+
* ----------------------------------------------------------------------------
523+
*/
524+
525+
526+
btDebugRendererWrapper *btDebugRenderer_create()
527+
{
528+
btDebugRendererWrapper *wrapper = new btDebugRendererWrapper;
529+
wrapper->debugDrawer = new phpglfwBtDebugDraw();
530+
return wrapper;
531+
}
532+
533+
534+
void btDebugRenderer_destroy(btDebugRendererWrapper *renderer)
535+
{
536+
delete renderer->debugDrawer;
537+
delete renderer;
538+
}
539+
540+
void btDebugRenderer_setVP(btDebugRendererWrapper *renderer, mat4x4 *vpMatrix)
541+
{
542+
renderer->debugDrawer->setViewProjection(&(*vpMatrix)[0][0]);
543+
}

bullet3_bridge.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define BULLET3_BRIDGE_H
33

44
#include "glfw/linmath.h"
5+
#include "glfw/phpglfw_buffer.h"
56

67
#ifdef __cplusplus
78
extern "C" {
@@ -11,6 +12,7 @@ typedef struct btDynamicsWorldWrapper btDynamicsWorldWrapper;
1112
typedef struct btRigidBodyWrapper btRigidBodyWrapper;
1213
typedef struct btCollisionShapeWrapper btCollisionShapeWrapper;
1314
typedef struct btTypedConstraintWrapper btTypedConstraintWrapper;
15+
typedef struct btDebugRendererWrapper btDebugRendererWrapper;
1416

1517
/**
1618
* Physics world
@@ -30,6 +32,12 @@ void btDynamicsWorld_removeConstraint(btDynamicsWorldWrapper *world, btTypedCons
3032

3133
void btDynamicsWorld_stepSimulation(btDynamicsWorldWrapper *world, float timeStep);
3234

35+
// attach debug renderer
36+
void btDynamicsWorld_setDebugRenderer(btDynamicsWorldWrapper *world, btDebugRendererWrapper *renderer);
37+
void btDynamicsWorld_debugDrawWorld(btDynamicsWorldWrapper *world);
38+
void btDynamicsWorld_enableDebugDrawing(btDynamicsWorldWrapper *world);
39+
void btDynamicsWorld_setDebugDrawVP(btDynamicsWorldWrapper *world, mat4x4 *vpMatrix);
40+
3341
/**
3442
* Collision shape
3543
*
@@ -104,6 +112,8 @@ void btGeneric6DofSpring2Constraint_enableSpring(btTypedConstraintWrapper *const
104112
void btGeneric6DofSpring2Constraint_setStiffness(btTypedConstraintWrapper *constraint, int index, float stiffness, bool limitIfNeeded);
105113
void btGeneric6DofSpring2Constraint_setDamping(btTypedConstraintWrapper *constraint, int index, float damping, bool limitIfNeeded);
106114

115+
void btGeneric6DofSpring2Constraint_setEquilibriumPoint(btTypedConstraintWrapper *constraint);
116+
107117
/**
108118
* Rigid body
109119
*
@@ -137,6 +147,18 @@ void btRigidBody_applyCentralImpulse(btRigidBodyWrapper *body, vec3 *impulse);
137147
void btRigidBody_applyTorqueImpulse(btRigidBodyWrapper *body, vec3 *torque);
138148

139149
void btRigidBody_activate(btRigidBodyWrapper *body);
150+
void btRigidBody_disableDeactivation(btRigidBodyWrapper *body);
151+
152+
/**
153+
* Debug renderer
154+
*
155+
* ----------------------------------------------------------------------------
156+
*/
157+
btDebugRendererWrapper *btDebugRenderer_create();
158+
void btDebugRenderer_destroy(btDebugRendererWrapper *renderer);
159+
160+
// methods
161+
void btDebugRenderer_setVP(btDebugRendererWrapper *renderer, mat4x4 *vpMatrix);
140162

141163

142164
#ifdef __cplusplus

bullet3_constraint.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,14 @@ PHP_METHOD(Bullet_Generic6DofSpring2Constraint, setDamping)
740740
);
741741
}
742742

743+
PHP_METHOD(Bullet_Generic6DofSpring2Constraint, setEquilibriumPoint)
744+
{
745+
phpbullet3_constraint_wrapper_object *intern = phpbullet3_constraint_from_zobj_p(Z_OBJ_P(getThis()));
743746

747+
btGeneric6DofSpring2Constraint_setEquilibriumPoint(
748+
intern->bt_constraint
749+
);
750+
}
744751

745752
/**
746753
* Register the “Constraint” module

bullet3_world.c

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,43 @@ PHP_METHOD(Bullet_World, stepSimulation)
258258
}
259259
}
260260

261+
/**
262+
* Bullet\World::enableDebugDrawing
263+
*/
264+
PHP_METHOD(Bullet_World, enableDebugDrawing)
265+
{
266+
phpbullet3_world_object *intern = phpbullet3_world_from_zobj_p(Z_OBJ_P(getThis()));
267+
268+
btDynamicsWorld_enableDebugDrawing(intern->bt_world);
269+
}
270+
271+
/**
272+
* Bullet\World::debugDrawWorld
273+
*/
274+
PHP_METHOD(Bullet_World, debugDrawWorld)
275+
{
276+
phpbullet3_world_object *intern = phpbullet3_world_from_zobj_p(Z_OBJ_P(getThis()));
277+
278+
btDynamicsWorld_debugDrawWorld(intern->bt_world);
279+
}
280+
281+
/**
282+
* Bullet\World::setDebugDrawVP
283+
*/
284+
PHP_METHOD(Bullet_World, setDebugDrawVP)
285+
{
286+
zval *viewProjection;
287+
phpbullet3_world_object *intern = phpbullet3_world_from_zobj_p(Z_OBJ_P(getThis()));
288+
289+
if (zend_parse_parameters(ZEND_NUM_ARGS() , "O", &viewProjection, phpglfw_get_math_mat4_ce()) == FAILURE) {
290+
return;
291+
}
292+
293+
phpglfw_math_mat4_object *mat4_ptr = phpglfw_math_mat4_objectptr_from_zobj_p(Z_OBJ_P(viewProjection));
294+
295+
btDynamicsWorld_setDebugDrawVP(intern->bt_world, &mat4_ptr->data);
296+
}
297+
261298
/**
262299
* Bullet\CollisionShape
263300
*
@@ -710,8 +747,6 @@ PHP_METHOD(Bullet_RigidBody, applyTorqueImpulse)
710747
btRigidBody_applyTorqueImpulse(intern->bt_rigidbody, &vec3_ptr->data);
711748
}
712749

713-
714-
715750
/**
716751
* Bullet\RigidBody::activate
717752
*/
@@ -722,6 +757,16 @@ PHP_METHOD(Bullet_RigidBody, activate)
722757
btRigidBody_activate(intern->bt_rigidbody);
723758
}
724759

760+
/**
761+
* Bullet\RigidBody::disableDeactivation
762+
*/
763+
PHP_METHOD(Bullet_RigidBody, disableDeactivation)
764+
{
765+
phpbullet3_rigidbody_object *intern = phpbullet3_rigidbody_from_zobj_p(Z_OBJ_P(getThis()));
766+
767+
btRigidBody_disableDeactivation(intern->bt_rigidbody);
768+
}
769+
725770
/**
726771
* Module registration
727772
*

config.m4

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ if test "$PHP_BULLET3" != "no"; then
5959

6060
# dependes on glfw
6161
PHP_ADD_EXTENSION_DEP([bullet3], [glfw], [true])
62+
PHP_ADD_INCLUDE([`php-config --include-dir`/ext/glfw/vendor/glad/include])
63+
PHP_ADD_INCLUDE([`php-config --include-dir`/ext/glfw/vendor/GLFW/include])
64+
PHP_ADD_INCLUDE([`php-config --include-dir`/ext/glfw/vendor/cvector])
6265

6366
# add bullet libs
6467
PHP_ADD_LIBRARY_WITH_PATH([BulletDynamics], [$BULLET3_BUILD_DIR/lib], [BULLET3_SHARED_LIBADD])

0 commit comments

Comments
 (0)