void KX_NearSensor::SynchronizeTransform() { // The near and radar sensors are using a different physical object which is // not linked to the parent object, must synchronize it. if (m_physCtrl) { PHY_IMotionState* motionState = m_physCtrl->GetMotionState(); KX_GameObject* parent = ((KX_GameObject*)GetParent()); const MT_Vector3& pos = parent->NodeGetWorldPosition(); float ori[12]; parent->NodeGetWorldOrientation().getValue(ori); motionState->SetWorldPosition(pos[0], pos[1], pos[2]); motionState->SetWorldOrientation(ori); m_physCtrl->WriteMotionStateToDynamics(true); } }
void SyncWheels() { int numWheels = GetNumWheels(); int i; for (i=0;i<numWheels;i++) { WheelInfo& info = m_vehicle->GetWheelInfo(i); PHY_IMotionState* motionState = (PHY_IMotionState*)info.m_clientInfo ; m_vehicle->UpdateWheelTransform(i); SimdTransform trans = m_vehicle->GetWheelTransformWS(i); SimdQuaternion orn = trans.getRotation(); const SimdVector3& pos = trans.getOrigin(); motionState->setWorldOrientation(orn.x(),orn.y(),orn.z(),orn[3]); motionState->setWorldPosition(pos.x(),pos.y(),pos.z()); } }
/** * Transforms the collision object. A cone is not correctly centered * for usage. */ void KX_RadarSensor::SynchronizeTransform() { // Getting the parent location was commented out. Why? MT_Transform trans; trans.setOrigin(((KX_GameObject*)GetParent())->NodeGetWorldPosition()); trans.setBasis(((KX_GameObject*)GetParent())->NodeGetWorldOrientation()); // What is the default orientation? pointing in the -y direction? // is the geometry correctly converted? // a collision cone is oriented // center the cone correctly // depends on the radar 'axis' switch (m_axis) { case SENS_RADAR_X_AXIS: // +X Axis { MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(90)); trans.rotate(rotquatje); trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0)); break; }; case SENS_RADAR_Y_AXIS: // +Y Axis { MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-180)); trans.rotate(rotquatje); trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0)); break; }; case SENS_RADAR_Z_AXIS: // +Z Axis { MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-90)); trans.rotate(rotquatje); trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0)); break; }; case SENS_RADAR_NEG_X_AXIS: // -X Axis { MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(-90)); trans.rotate(rotquatje); trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0)); break; }; case SENS_RADAR_NEG_Y_AXIS: // -Y Axis { //MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-180)); //trans.rotate(rotquatje); trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0)); break; }; case SENS_RADAR_NEG_Z_AXIS: // -Z Axis { MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(90)); trans.rotate(rotquatje); trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0)); break; }; default: { } } //Using a temp variable to translate MT_Point3 to float[3]. //float[3] works better for the Python interface. MT_Point3 temp = trans.getOrigin(); m_cone_origin[0] = temp[0]; m_cone_origin[1] = temp[1]; m_cone_origin[2] = temp[2]; temp = trans(MT_Point3(0, -m_coneheight/2.0 ,0)); m_cone_target[0] = temp[0]; m_cone_target[1] = temp[1]; m_cone_target[2] = temp[2]; if (m_physCtrl) { PHY_IMotionState* motionState = m_physCtrl->GetMotionState(); const MT_Point3& pos = trans.getOrigin(); float ori[12]; trans.getBasis().getValue(ori); motionState->setWorldPosition(pos[0], pos[1], pos[2]); motionState->setWorldOrientation(ori); m_physCtrl->WriteMotionStateToDynamics(true); } }