/// <summary> /// Attaches the Root transform of this entity to another. An entity can only attach to one other. /// TODO: Since Renderer2DObjects are also entities, how is it possible for Renderer2DObjects to use this? /// </summary> /// <param name="entity">The entity to attach to</param> public virtual void Attach(Object3 entity, string mesh) { position = entity.MountPosition(mesh); attachedTo = entity; mountMeshName = mesh; following = false; attached = true; orbiting = false; }
/// <summary> /// Attaches the Root transform of this entity to another. An entity can only attach to one other. /// TODO: Since Renderer2DObjects are also entities, how is it possible for Renderer2DObjects to use this? /// </summary> /// <param name="entity">The entity to attach to</param> public virtual void Attach(Object3 entity, string mesh) { position = entity.MountPosition(mesh); attachedTo = entity; mountMeshName = mesh; following = false; attached = true; orbiting = false; }
/// <summary> /// Rotates, scales, then translates the entity. /// </summary> public virtual void Update(Boolean updateToggle) { if (HasUpdated != updateToggle && updatable) { rotation = Matrix.CreateFromYawPitchRoll(yRot, xRot, zRot); if (following) { if (targetEntity.HasUpdated != updateToggle) { targetEntity.Update(updateToggle); } Vector3 wantedPosition = targetEntity.Position + followingVector; translation = wantedPosition - position; targetPosition = targetEntity.Position; } if (mimicPosition) { if (targetEntity.HasUpdated != updateToggle) { targetEntity.Update(updateToggle); } position = targetEntity.Position + targetOffset; } if (mimicRotation) { if (targetEntity.HasUpdated != updateToggle) { targetEntity.Update(updateToggle); } rotation = targetEntity.rotation; } if (attached) { if (attachedTo.HasUpdated != updateToggle) { attachedTo.Update(updateToggle); } position = attachedTo.MountPosition(mountMeshName); } if (tracking) { if (trackingEntity) { if (targetEntity.HasUpdated != updateToggle) { targetEntity.Update(updateToggle); } targetPosition = targetEntity.Position; } else if (trackingCursor) { Plane p = new Plane(Vector3.UnitZ, -Position.Z); Ray r = WorldMouse.WorldRay; float denominator = Vector3.Dot(p.Normal, r.Direction); float numerator = Vector3.Dot(p.Normal, r.Position) + p.D; float t = -(numerator / denominator); targetPosition = r.Position + r.Direction * t; if (t < 0) { targetPosition = position + (position - targetPosition); } } Aim(targetPosition, 1); } if (orbiting) { UpdateOrbit(); } Commit(); HasUpdated = updateToggle; } }