Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
| Context not available. | |||||
| } | } | ||||
| #endif | #endif | ||||
sybren: `if(!constraintId) return;` would also work here, and unindent a big chunk of code. It also… | |||||
| } | } | ||||
Not Done Inline ActionsThere is a lot of code duplication in these if-bodies. Possibly by re-ordering some code and pushing the ifs down, this can be avoided. sybren: There is a lot of code duplication in these `if`-bodies. Possibly by re-ordering some code and… | |||||
| void CcdPhysicsEnvironment::SetupObjectConstraints(KX_GameObject *obj_src, KX_GameObject *obj_dest, | |||||
| bRigidBodyJointConstraint *dat) | |||||
| { | |||||
| PHY_IPhysicsController *phy_src = obj_src->GetPhysicsController(); | |||||
| PHY_IPhysicsController *phy_dest = obj_dest->GetPhysicsController(); | |||||
| PHY_IPhysicsEnvironment *phys_env = obj_src->GetScene()->GetPhysicsEnvironment(); | |||||
Not Done Inline Actions"disabled limit" seems a strange concept to me, as in this case there is no limit to disable in the first place. "no limit" makes more sense to me. The same condition is also described differently in different comments. Also see my note about code de-duplication. sybren: "disabled limit" seems a strange concept to me, as in this case there is no limit to disable in… | |||||
| /* We need to pass a full constraint frame, not just axis. */ | |||||
| MT_Matrix3x3 localCFrame(MT_Vector3(dat->axX,dat->axY,dat->axZ)); | |||||
| MT_Vector3 axis0 = localCFrame.getColumn(0); | |||||
| MT_Vector3 axis1 = localCFrame.getColumn(1); | |||||
| MT_Vector3 axis2 = localCFrame.getColumn(2); | |||||
| MT_Vector3 scale = obj_src->NodeGetWorldScaling(); | |||||
| /* Apply not only the pivot and axis values, but also take scale into count | |||||
| * this is not working well, if only one or two axis are scaled, but works ok on | |||||
| * homogeneous scaling. */ | |||||
| int constraintId = phys_env->CreateConstraint( | |||||
| phy_src, phy_dest, (PHY_ConstraintType)dat->type, | |||||
| (float)(dat->pivX * scale.x()), (float)(dat->pivY * scale.y()), (float)(dat->pivZ * scale.z()), | |||||
| (float)(axis0.x() * scale.x()), (float)(axis0.y() * scale.y()), (float)(axis0.z() * scale.z()), | |||||
| (float)(axis1.x() * scale.x()), (float)(axis1.y() * scale.y()), (float)(axis1.z() * scale.z()), | |||||
| (float)(axis2.x() * scale.x()), (float)(axis2.y() * scale.y()), (float)(axis2.z() * scale.z()), | |||||
| dat->flag); | |||||
| /* PHY_POINT2POINT_CONSTRAINT = 1, | |||||
| * PHY_LINEHINGE_CONSTRAINT = 2, | |||||
| * PHY_ANGULAR_CONSTRAINT = 3, | |||||
| * PHY_CONE_TWIST_CONSTRAINT = 4, | |||||
| * PHY_VEHICLE_CONSTRAINT = 11, | |||||
| * PHY_GENERIC_6DOF_CONSTRAINT = 12 */ | |||||
Not Done Inline ActionsWouldn't a switch statement be better here? sybren: Wouldn't a `switch` statement be better here? | |||||
| if (!constraintId) | |||||
| return; | |||||
| int dof = 0; | |||||
| int dof_max = 0; | |||||
| int dofbit = 0; | |||||
| switch (dat->type) { | |||||
| /* Set all the limits for generic 6DOF constraint. */ | |||||
| case PHY_GENERIC_6DOF_CONSTRAINT: | |||||
| dof_max = 6; | |||||
| dofbit = 1; | |||||
| break; | |||||
| /* Set XYZ angular limits for cone twist constraint. */ | |||||
| case PHY_CONE_TWIST_CONSTRAINT: | |||||
| dof = 3; | |||||
| dof_max = 6; | |||||
| dofbit = 1 << 3; | |||||
| break; | |||||
| /* Set only X angular limits for line hinge and angular constraint. */ | |||||
| case PHY_LINEHINGE_CONSTRAINT: | |||||
| case PHY_ANGULAR_CONSTRAINT: | |||||
| dof = 3; | |||||
| dof_max = 4; | |||||
| dofbit = 1 << 3; | |||||
| break; | |||||
| default: | |||||
| break; | |||||
| } | |||||
| for (dof; dof < dof_max; dof++) { | |||||
| if (dat->flag & dofbit) { | |||||
| phys_env->SetConstraintParam(constraintId, dof, dat->minLimit[dof], dat->maxLimit[dof]); | |||||
| } | |||||
| else { | |||||
| /* minLimit > maxLimit means free (no limit) for this degree of freedom. */ | |||||
| phys_env->SetConstraintParam(constraintId, dof, 1.0f, -1.0f); | |||||
| } | |||||
| dofbit <<= 1; | |||||
| } | |||||
| } | |||||
| Context not available. | |||||
if(!constraintId) return; would also work here, and unindent a big chunk of code. It also fits the semantics of the method; when there is no constraint, the process of setting it up is done.