void Vehicle::InitWheel(const String& name, const Vector3& offset, WeakPtr<Node>& wheelNode, unsigned& wheelNodeID) { ResourceCache* cache = GetSubsystem<ResourceCache>(); // Note: do not parent the wheel to the hull scene node. Instead create it on the root level and let the physics // constraint keep it together wheelNode = GetScene()->CreateChild(name); wheelNode->SetPosition(node_->LocalToWorld(offset)); wheelNode->SetRotation(node_->GetRotation() * (offset.x_ >= 0.0 ? Quaternion(0.0f, 0.0f, -90.0f) : Quaternion(0.0f, 0.0f, 90.0f))); wheelNode->SetScale(Vector3(0.8f, 0.5f, 0.8f)); // Remember the ID for serialization wheelNodeID = wheelNode->GetID(); StaticModel* wheelObject = wheelNode->CreateComponent<StaticModel>(); RigidBody* wheelBody = wheelNode->CreateComponent<RigidBody>(); CollisionShape* wheelShape = wheelNode->CreateComponent<CollisionShape>(); Constraint* wheelConstraint = wheelNode->CreateComponent<Constraint>(); wheelObject->SetModel(cache->GetResource<Model>("Models/Cylinder.mdl")); wheelObject->SetMaterial(cache->GetResource<Material>("Materials/Stone.xml")); wheelObject->SetCastShadows(true); wheelShape->SetSphere(1.0f); wheelBody->SetFriction(1.0f); wheelBody->SetMass(1.0f); wheelBody->SetLinearDamping(0.2f); // Some air resistance wheelBody->SetAngularDamping(0.75f); // Could also use rolling friction wheelBody->SetCollisionLayer(1); wheelConstraint->SetConstraintType(CONSTRAINT_HINGE); wheelConstraint->SetOtherBody(GetComponent<RigidBody>()); // Connect to the hull body wheelConstraint->SetWorldPosition(wheelNode->GetPosition()); // Set constraint's both ends at wheel's location wheelConstraint->SetAxis(Vector3::UP); // Wheel rotates around its local Y-axis wheelConstraint->SetOtherAxis(offset.x_ >= 0.0 ? Vector3::RIGHT : Vector3::LEFT); // Wheel's hull axis points either left or right wheelConstraint->SetLowLimit(Vector2(-180.0f, 0.0f)); // Let the wheel rotate freely around the axis wheelConstraint->SetHighLimit(Vector2(180.0f, 0.0f)); wheelConstraint->SetDisableCollision(true); // Let the wheel intersect the vehicle hull }
void Tile::HandleUpdate(StringHash eventType, VariantMap &eventData) { double elapsedTime = masterControl_->world.scene->GetElapsedTime(); double offsetY = 0.0; //Alien Chaos - Disorder = time*1.0525f //Talpa - Unusual Chair = time*1.444 wave_ = 6.0*pow(masterControl_->Sine(Abs(float(centerDistExp_ - elapsedTime) * 0.666f)), 4.0f); uint nHexAffectors = tileMaster_->hexAffectors_.Size(); if (nHexAffectors) { for (uint i = 0; i < nHexAffectors; i++) { WeakPtr<Node> hexAffector = tileMaster_->hexAffectors_.Keys()[i]; double hexAffectorMass = tileMaster_->hexAffectors_[hexAffector]->GetMass(); if (hexAffector->IsEnabled()) { double offsetYPart = sqrt(hexAffectorMass) - (0.1* Vector3::Distance(referencePosition_, hexAffector->GetPosition())); if (offsetYPart > 0.0) { offsetYPart = pow(offsetYPart, 4); offsetY += offsetYPart; } } } offsetY = sqrt(offsetY); } offsetY += 0.023f * wave_; Vector3 lastPos = rootNode_->GetPosition(); Vector3 newPos = Vector3(lastPos.x_, referencePosition_.y_ - offsetY, lastPos.z_); rootNode_->SetPosition(newPos); double color = Clamp((0.25f * offsetY) +0.3f, 0.0f, 1.0f); model_->GetMaterial(0)->SetShaderParameter("MatDiffColor", Color(color, color, color, color + (0.023 * wave_))); }