public void Update(Time deltaTime, bool useMouse = true) { if (Dice.Count <= 0) { return; } switch (State) { case RollState.Preparing: if (_cupShakeCooldown > 0) { _cupShakeCooldown -= deltaTime.DeltaF; return; } var shakeSpeed = _shakeRotSpeed + (_shaking ? (_lastShakeMomentum.Length + 1) : 0); foreach (var r in Rolling) { r.Transform.Orientation = r.Transform.Orientation.Rotated(shakeSpeed * deltaTime.DeltaF, _shakeRotAxis * vec3.UnitY); } _shakeRotAxis = _shakeRotAxis.Rotated(shakeSpeed / 3 * deltaTime.DeltaF, vec3.UnitZ); if (!_shaking) { return; } var v2 = (Program.InputManager.MousePosition - _shakeCenter) / _maxShakeDist; var signs = new vec2(Math.Sign(v2.x), Math.Sign(v2.y)); v2 = signs * v2; v2 = _maxShakeMove * new vec2(signs.x * _shakeCurve[v2.x <= 1 ? v2.x : 1], signs.y * _shakeCurve[v2.y <= 1 ? v2.y : 1]); _currentCupPos = CupPos + new vec3(v2.x, 0, v2.y); v2 = new vec2(Program.InputManager.MousePosition - _lastShakePos) * _shakeScale; _lastShakeMomentum = new vec3(v2.x, 0, v2.y) / deltaTime.DeltaF; _lastShakePos = Program.InputManager.MousePosition; foreach (var d in Rolling) { d.Transform.Translation = _currentCupPos + _cupOffset[d]; } break; case RollState.Rolling: if (!Rolling.Exists(d => !d.RigidBody.Sleeping)) { MoveDiceToCamera(); State = RollState.Scoring; if (Rolling.Count == Dice.Count || RerollsLeft <= 0) { Rolling.Clear(); UpdateOutliners(); } OnRolled?.Invoke(Rolled); } break; case RollState.Scoring: if (useMouse) { UpdateOutliners(); } break; } }
public void Rotate(float angle, vec3 axis) => Orientation = Orientation.Rotated(angle, axis);