create a physics joint * * Create a physics joint between two collision object components. * * Note: Currently only supported in 2D physics. * * @name physics.create_joint * @param joint_type [type:number] the joint type * @param collisionobject_a [type:string|hash|url] first collision object * @param joint_id [type:string|hash] id of the joint * @
| 693 | * |
| 694 | */ |
| 695 | static int Physics_CreateJoint(lua_State* L) |
| 696 | { |
| 697 | DM_LUA_STACK_CHECK(L, 0); |
| 698 | |
| 699 | dmPhysics::JointType type = (dmPhysics::JointType)luaL_checkinteger(L, 1); |
| 700 | if (type >= dmPhysics::JOINT_TYPE_COUNT) |
| 701 | { |
| 702 | return DM_LUA_ERROR("unknown joint type: %d", type); |
| 703 | } |
| 704 | |
| 705 | dmhash_t joint_id = dmScript::CheckHashOrString(L, 3); |
| 706 | dmVMath::Point3 pos_a = dmVMath::Point3(*dmScript::CheckVector3(L, 4)); |
| 707 | dmVMath::Point3 pos_b = dmVMath::Point3(*dmScript::CheckVector3(L, 6)); |
| 708 | |
| 709 | dmGameObject::HCollection collection = dmGameObject::GetCollection(CheckGoInstance(L)); |
| 710 | |
| 711 | CollisionComponent* comp_a = 0x0; |
| 712 | CollisionWorld* comp_world_a = 0x0; |
| 713 | GetCollisionObject(L, 2, collection, &comp_a, &comp_world_a); |
| 714 | CollisionComponent* comp_b = 0x0; |
| 715 | CollisionWorld* comp_world_b = 0x0; |
| 716 | GetCollisionObject(L, 5, collection, &comp_b, &comp_world_b); |
| 717 | |
| 718 | if (comp_world_a != comp_world_b) { |
| 719 | return DM_LUA_ERROR("joints can only be connected to collision objects within the same physics world"); |
| 720 | } |
| 721 | |
| 722 | dmPhysics::ConnectJointParams params(type); |
| 723 | UnpackConnectJointParams(L, type, 7, params); |
| 724 | dmPhysics::JointResult r = dmGameSystem::CreateJoint(comp_world_a, comp_a, joint_id, pos_a, comp_b, pos_b, type, params); |
| 725 | if (r != dmPhysics::RESULT_OK) { |
| 726 | return DM_LUA_ERROR("could not create joint: %s (%d)", PhysicsResultString[r], r); |
| 727 | } |
| 728 | |
| 729 | return 0; |
| 730 | |
| 731 | } |
| 732 | |
| 733 | /*# destroy a physics joint |
| 734 | * |
nothing calls this directly
no test coverage detected