public Camera( CubeGame game ) : base(game) { #region Init Projection mFov = new AnimatedVariable<float>( Utils.Tween ); mAspectRatio = new AnimatedVariable<float>( Utils.Tween ); mNearPlaneDist = new AnimatedVariable<float>( Utils.Tween ); mFarPlaneDist = new AnimatedVariable<float>( Utils.Tween ); mFov.ValueChanged += OnProjectionValueChanged; mAspectRatio.ValueChanged += OnProjectionValueChanged; mNearPlaneDist.ValueChanged += OnProjectionValueChanged; mFarPlaneDist.ValueChanged += OnProjectionValueChanged; #endregion #region Init View mPosition = new AnimatedVariable<Vector3>( (v0, v1, d) => Vector3.Distance( v0, v1 ) > d / 10 ? v0.Slerp( v1, d ) : v1 ); mTarget = new AnimatedVariable<Vector3>( (v0, v1, d) => Vector3.Distance( v0, v1 ) > d ? v0.Slerp( v1, d ) : v1 ); mUpVector = new AnimatedVariable<Vector3>( Vector3.Up, (v0, v1, d) => Vector3.Distance( v0, v1 ) > d ? v0.Slerp( v1, d * 10 ) : v1 ); mPosition.ValueChanged += OnViewValueChanged; mTarget.ValueChanged += OnViewValueChanged; mUpVector.ValueChanged += OnViewValueChanged; mPosition.ValueChanged += FixNaN; mTarget.ValueChanged += FixNaN; mUpVector.ValueChanged += FixNaN; #endregion }
public Player( PlayScreen screen, PlayableCube cube, Vector3 worldPos, float rotation ) : base(cube.Game, screen, cube, worldPos, (Direction) rotation) { this.Visible = true; this.DrawOrder = 1; mModelRotation = new AnimatedVariable<float>( rotation, (f0, f1, step) => { var diff = MathHelper.WrapAngle( f1 - f0 ); return f0.Tween( f0 + diff, step ); } ); mHeadbob = new AnimatedVariable<float>( //Utils.Lerp ); (f0, f1, step) => { return f0.Tween( f1, step ); } ); }
public Enemy( PlayScreen screen, PlayableCube cube, Vector3 worldPos, float rotation ) : base(cube.Game, screen, cube, worldPos, (Direction) rotation) { this.Visible = true; this.DrawOrder = 1; mModelRotation = new AnimatedVariable<float>( rotation, (f0, f1, step) => { var diff = MathHelper.WrapAngle( f1 - f0 ); return f0.Tween( f0 + diff, step ); } ); mMovementDirection = (Direction) rotation; sRand = new Random(); if (sRand.Next() % 2 == 0) { mMovementDirection++; } else { mMovementDirection--; } }
private void OnViewValueChanged( AnimatedVariable<Vector3> sender, Vector3 value ) { if ( !sender.IsAnimating ) mViewMatrix = default( Matrix ); }
private void OnProjectionValueChanged( AnimatedVariable<float> sender, float value ) { if ( !sender.IsAnimating ) mProjectionMatrix = default( Matrix ); }
private void FixNaN( AnimatedVariable<Vector3> sender, Vector3 value ) { if ( float.IsNaN( value.X ) || float.IsNaN( value.Y ) || float.IsNaN( value.Z ) ) sender.EndAnimation(); }