// ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- void ChSingleIdler::AddVisualizationAssets(VisualizationType vis) { ChIdler::AddVisualizationAssets(vis); if (vis != VisualizationType::PRIMITIVES) return; double radius = GetWheelRadius(); double width = GetWheelWidth(); auto cyl = std::make_shared<ChCylinderShape>(); cyl->GetCylinderGeometry().p1 = ChVector<>(0, width / 2, 0); cyl->GetCylinderGeometry().p2 = ChVector<>(0, -width / 2, 0); cyl->GetCylinderGeometry().rad = radius; m_wheel->AddAsset(cyl); auto tex = std::make_shared<ChTexture>(); tex->SetTextureFilename(chrono::GetChronoDataFile("bluwhite.png")); m_wheel->AddAsset(tex); }
// ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- void ChSingleIdler::Initialize(std::shared_ptr<ChBodyAuxRef> chassis, const ChVector<>& location) { // Invoke the base class method ChIdler::Initialize(chassis, location); // Add contact geometry. double radius = GetWheelRadius(); double width = GetWheelWidth(); m_wheel->SetCollide(true); m_wheel->GetCollisionModel()->ClearModel(); m_wheel->GetCollisionModel()->SetFamily(TrackedCollisionFamily::IDLERS); m_wheel->GetCollisionModel()->SetFamilyMaskNoCollisionWithFamily(TrackedCollisionFamily::WHEELS); m_wheel->GetCollisionModel()->AddCylinder(radius, radius, width / 2); m_wheel->GetCollisionModel()->BuildModel(); }
VariantVector RaycastVehicle::GetWheelDataAttr() const { VariantVector ret; ret.Reserve(GetNumWheels() * 22 + 1); ret.Push(GetNumWheels()); for (int i = 0; i < GetNumWheels(); i++) { Node* wNode = GetWheelNode(i); int node_id = wNode->GetID(); URHO3D_LOGDEBUG("RaycastVehicle: Saving node id = " + String(node_id)); ret.Push(node_id); ret.Push(GetWheelDirection(i)); ret.Push(GetWheelAxle(i)); ret.Push(GetWheelRestLength(i)); ret.Push(GetWheelRadius(i)); ret.Push(IsFrontWheel(i)); ret.Push(GetSteeringValue(i)); ret.Push(GetWheelConnectionPoint(i)); ret.Push(origRotation_[i]); ret.Push(GetWheelSkidInfoCumulative(i)); ret.Push(GetWheelSideSlipSpeed(i)); ret.Push(WheelIsGrounded(i)); ret.Push(GetContactPosition(i)); ret.Push(GetContactNormal(i)); // 14 ret.Push(GetWheelSuspensionStiffness(i)); ret.Push(GetWheelDampingRelaxation(i)); ret.Push(GetWheelDampingCompression(i)); ret.Push(GetWheelFrictionSlip(i)); ret.Push(GetWheelRollInfluence(i)); ret.Push(GetEngineForce(i)); ret.Push(GetBrake(i)); ret.Push(GetWheelSkidInfo(i)); } URHO3D_LOGDEBUG("RaycastVehicle: saved items: " + String(ret.Size())); URHO3D_LOGDEBUG("maxSideSlipSpeed_ value save: " + String(maxSideSlipSpeed_)); return ret; }
void RaycastVehicle::FixedPostUpdate(float timeStep) { btRaycastVehicle* vehicle = vehicleData_->Get(); Vector3 velocity = hullBody_->GetLinearVelocity(); for (int i = 0; i < GetNumWheels(); i++) { btWheelInfo& whInfo = vehicle->getWheelInfo(i); if (!WheelIsGrounded(i) && GetEngineForce(i) != 0.0f) { float delta; if (inAirRPM_ != 0.0f) { delta = inAirRPM_ * timeStep / 60.0f; } else { delta = 8.0f * GetEngineForce(i) * timeStep / (hullBody_->GetMass() * GetWheelRadius(i)); } if (Abs(whInfo.m_deltaRotation) < Abs(delta)) { whInfo.m_rotation += delta - whInfo.m_deltaRotation; whInfo.m_deltaRotation = delta; } if (skidInfoCumulative_[i] > 0.05f) { skidInfoCumulative_[i] -= 0.002; } } else { skidInfoCumulative_[i] = GetWheelSkidInfo(i); } wheelSideSlipSpeed_[i] = Abs(ToVector3(whInfo.m_raycastInfo.m_wheelAxleWS).DotProduct(velocity)); if (wheelSideSlipSpeed_[i] > maxSideSlipSpeed_) { skidInfoCumulative_[i] = Clamp(skidInfoCumulative_[i], 0.0f, 0.89f); } } }