void RigidBody::OnMarkedDirty(Node* node) { // If node transform changes, apply it back to the physics transform. However, do not do this when a SmoothedTransform // is in use, because in that case the node transform will be constantly updated into smoothed, possibly non-physical // states; rather follow the SmoothedTransform target transform directly // Also, for kinematic objects Bullet asks the position from us, so we do not need to apply ourselves if (!kinematic_ && (!physicsWorld_ || !physicsWorld_->IsApplyingTransforms()) && !smoothedTransform_) { // Physics operations are not safe from worker threads Scene* scene = GetScene(); if (scene && scene->IsThreadedUpdate()) { scene->DelayedMarkedDirty(this); return; } // Check if transform has changed from the last one set in ApplyWorldTransform() Vector3 newPosition = node_->GetWorldPosition(); Quaternion newRotation = node_->GetWorldRotation(); if (!newRotation.Equals(lastRotation_)) { lastRotation_ = newRotation; SetRotation(newRotation); } if (!newPosition.Equals(lastPosition_)) { lastPosition_ = newPosition; SetPosition(newPosition); } } }
void ScriptInstance::OnMarkedDirty(Node* node) { // Script functions are not safe from worker threads Scene* scene = GetScene(); if (scene && scene->IsThreadedUpdate()) { scene->DelayedMarkedDirty(this); return; } if (scriptObject_ && methods_[METHOD_TRANSFORMCHANGED]) scriptFile_->Execute(scriptObject_, methods_[METHOD_TRANSFORMCHANGED]); }
void LuaScriptInstance::OnMarkedDirty(Node* node) { // Script functions are not safe from worker threads Scene* scene = GetScene(); if (scene && scene->IsThreadedUpdate()) { scene->DelayedMarkedDirty(this); return; } WeakPtr<LuaFunction> function = scriptObjectMethods_[LSOM_TRANSFORMCHANGED]; if (function && function->BeginCall(this)) { function->EndCall(); } }
void Zone::OnMarkedDirty(Node* node) { // Due to the octree query and weak pointer manipulation, is not safe from worker threads Scene* scene = GetScene(); if (scene && scene->IsThreadedUpdate()) { scene->DelayedMarkedDirty(this); return; } Drawable::OnMarkedDirty(node); // Clear zone reference from all drawables inside the bounding box, and mark gradient dirty in neighbor zones ClearDrawablesZone(); inverseWorldDirty_ = true; }
void CollisionShape::OnMarkedDirty(Node* node) { Vector3 newWorldScale = node_->GetWorldScale(); if (HasWorldScaleChanged(cachedWorldScale_, newWorldScale) && shape_) { // Physics operations are not safe from worker threads Scene* scene = GetScene(); if (scene && scene->IsThreadedUpdate()) { scene->DelayedMarkedDirty(this); return; } switch (shapeType_) { case SHAPE_BOX: case SHAPE_SPHERE: case SHAPE_CYLINDER: case SHAPE_CAPSULE: case SHAPE_CONE: shape_->setLocalScaling(ToBtVector3(newWorldScale)); break; case SHAPE_TRIANGLEMESH: case SHAPE_CONVEXHULL: shape_->setLocalScaling(ToBtVector3(newWorldScale * size_)); break; case SHAPE_TERRAIN: { HeightfieldData* heightfield = static_cast<HeightfieldData*>(geometry_.Get()); shape_->setLocalScaling(ToBtVector3(Vector3(heightfield->spacing_.x_, 1.0f, heightfield->spacing_.z_) * newWorldScale * size_)); } break; default: break; } NotifyRigidBody(); cachedWorldScale_ = newWorldScale; } }
void Zone::OnMarkedDirty(Node* node) { // Due to the octree query and weak pointer manipulation, is not safe from worker threads Scene* scene = GetScene(); if (scene && scene->IsThreadedUpdate()) { scene->DelayedMarkedDirty(this); return; } Drawable::OnMarkedDirty(node); // When marked dirty, clear the cached zone from all drawables inside the zone bounding box, // and mark gradient dirty in all neighbor zones if (octant_ && lastWorldBoundingBox_.defined_) { PODVector<Drawable*> result; BoxOctreeQuery query(result, lastWorldBoundingBox_, DRAWABLE_GEOMETRY | DRAWABLE_ZONE); octant_->GetRoot()->GetDrawables(query); for (PODVector<Drawable*>::Iterator i = result.Begin(); i != result.End(); ++i) { Drawable* drawable = *i; unsigned drawableFlags = drawable->GetDrawableFlags(); if (drawableFlags & DRAWABLE_GEOMETRY) { if (drawable->GetZone() == this) drawable->SetZone(0); } else if (drawableFlags & DRAWABLE_ZONE) { Zone* zone = static_cast<Zone*>(drawable); zone->lastAmbientStartZone_.Reset(); zone->lastAmbientEndZone_.Reset(); } } } lastWorldBoundingBox_ = GetWorldBoundingBox(); lastAmbientStartZone_.Reset(); lastAmbientEndZone_.Reset(); inverseWorldDirty_ = true; }
void CollisionShape2D::OnMarkedDirty(Node* node) { Vector3 newWorldScale = node_->GetWorldScale(); Vector3 delta = newWorldScale - cachedWorldScale_; if (delta.DotProduct(delta) < 0.01f) return; // Physics operations are not safe from worker threads Scene* scene = GetScene(); if (scene && scene->IsThreadedUpdate()) { scene->DelayedMarkedDirty(this); return; } cachedWorldScale_ = newWorldScale; if (fixture_) ApplyNodeWorldScale(); }
void RigidBody2D::OnMarkedDirty(Node* node) { if (physicsWorld_ && physicsWorld_->IsApplyingTransforms()) return; // Physics operations are not safe from worker threads Scene* scene = GetScene(); if (scene && scene->IsThreadedUpdate()) { scene->DelayedMarkedDirty(this); return; } // Check if transform has changed from the last one set in ApplyWorldTransform() b2Vec2 newPosition = ToB2Vec2(node_->GetWorldPosition()); float newAngle = node_->GetWorldRotation().RollAngle() * M_DEGTORAD; if (newPosition != bodyDef_.position || newAngle != bodyDef_.angle) { bodyDef_.position = newPosition; bodyDef_.angle = newAngle; if (body_) body_->SetTransform(newPosition, newAngle); } }