コード例 #1
0
ファイル: Sprite3d.cs プロジェクト: thyawan/storybrew
        public override void GenerateStates(double time, CameraState cameraState, Object3dState object3dState)
        {
            var wvp            = object3dState.WorldTransform * cameraState.ViewProjection;
            var screenPosition = cameraState.ToScreen(wvp, Vector3.Zero);

            var angle = 0.0;

            switch (RotationMode)
            {
            case RotationMode.UnitX:
            {
                var unitXPosition = cameraState.ToScreen(wvp, Vector3.UnitX);
                var delta         = unitXPosition - screenPosition;
                angle += (float)Math.Atan2(delta.Y, delta.X);
            }
            break;

            case RotationMode.UnitY:
            {
                var unitYPosition = cameraState.ToScreen(wvp, Vector3.UnitY);
                var delta         = unitYPosition - screenPosition;
                angle += (float)Math.Atan2(delta.Y, delta.X) - Math.PI * 0.5;
            }
            break;
            }

            var previousState = Generator.EndState;
            var rotation      = InterpolatingFunctions.DoubleAngle(previousState?.Rotation ?? 0 - SpriteRotation.ValueAt(previousState?.Time ?? time), angle, 1) + SpriteRotation.ValueAt(time);

            var scale = SpriteScale.ValueAt(time)
                        * object3dState.WorldTransform.ExtractScale().Xy
                        *(float)(cameraState.FocusDistance / screenPosition.W)
                        * (float)cameraState.ResolutionScale;

            var opacity = screenPosition.W < 0 ? 0 : object3dState.Opacity;

            if (UseDistanceFade)
            {
                opacity *= cameraState.OpacityAt(screenPosition.W);
            }

            Generator.Add(new CommandGenerator.State()
            {
                Time     = time,
                Position = screenPosition.Xy,
                Scale    = scale,
                Rotation = rotation,
                Color    = object3dState.Color,
                Opacity  = opacity,
                Additive = Additive,
            });
        }
コード例 #2
0
        public void GenerateTreeStates(double time, CameraState cameraState, Object3dState parent3dState = null)
        {
            parent3dState = parent3dState ?? Object3dState.InitialState;

            var object3dState = new Object3dState(
                WorldTransformAt(time) * parent3dState.WorldTransform,
                Coloring.ValueAt(time) * (InheritsColor ? parent3dState.Color : CommandColor.White),
                Opacity.ValueAt(time) * (InheritsOpacity ? parent3dState.Opacity : 1));

            GenerateStates(time, cameraState, object3dState);
            foreach (var child in children)
            {
                child.GenerateTreeStates(time, cameraState, object3dState);
            }
        }
コード例 #3
0
 public void GenerateTreeStates(double time, Camera camera, Object3dState parent3dState = null)
 => GenerateTreeStates(time, camera.StateAt(time), parent3dState);
コード例 #4
0
 public virtual void GenerateStates(double time, CameraState cameraState, Object3dState object3dState)
 {
 }
コード例 #5
0
ファイル: Line3dEx.cs プロジェクト: starrodkirby86/storybrew
        public override void GenerateStates(double time, CameraState cameraState, Object3dState object3dState)
        {
            var wvp         = object3dState.WorldTransform * cameraState.ViewProjection;
            var startVector = cameraState.ToScreen(wvp, StartPosition.ValueAt(time));
            var endVector   = cameraState.ToScreen(wvp, EndPosition.ValueAt(time));

            var delta  = endVector.Xy - startVector.Xy;
            var length = delta.Length;

            if (length == 0)
            {
                return;
            }

            var angle    = Math.Atan2(delta.Y, delta.X);
            var rotation = InterpolatingFunctions.DoubleAngle(GeneratorBody.EndState?.Rotation ?? 0, angle, 1);

            var thickness   = Thickness.ValueAt(time);
            var scaleFactor = object3dState.WorldTransform.ExtractScale().Y *(float)cameraState.ResolutionScale;
            var startScale  = scaleFactor * (float)(cameraState.FocusDistance / startVector.W) * thickness * StartThickness.ValueAt(time);
            var endScale    = scaleFactor * (float)(cameraState.FocusDistance / endVector.W) * thickness * EndThickness.ValueAt(time);

            var totalHeight = Math.Max(startScale, endScale);
            var bodyHeight  = Math.Min(startScale, endScale);
            var edgeHeight  = (totalHeight - bodyHeight) * 0.5f;
            var flip        = startScale < endScale;

            var ignoreEdges = edgeHeight < EdgeOverlap;

            if (ignoreEdges)
            {
                bodyHeight += edgeHeight * 2;
            }

            var opacity = startVector.W < 0 && endVector.W < 0 ? 0 : object3dState.Opacity;

            if (UseDistanceFade)
            {
                opacity *= Math.Max(cameraState.OpacityAt(startVector.W), cameraState.OpacityAt(endVector.W));
            }

            // Body

            var bitmapBody = StoryboardObjectGenerator.Current.GetMapsetBitmap(spriteBody.GetTexturePathAt(time));
            var bodyScale  = new Vector2(length / bitmapBody.Width, bodyHeight / bitmapBody.Height);

            var positionBody = startVector.Xy + delta * 0.5f;
            var bodyOpacity  = opacity;

            GeneratorBody.Add(new CommandGenerator.State()
            {
                Time     = time,
                Position = positionBody,
                Scale    = bodyScale,
                Rotation = rotation,
                Color    = object3dState.Color,
                Opacity  = bodyOpacity,
                Additive = Additive,
            });

            // Edges

            if (SpritePathEdge != null)
            {
                var bitmapEdge = StoryboardObjectGenerator.Current.GetMapsetBitmap(spriteTopEdge.GetTexturePathAt(time));
                var edgeScale  = new Vector2(length / bitmapEdge.Width, edgeHeight / bitmapEdge.Height);

                var edgeOffset     = new Vector2((float)Math.Cos(angle - Math.PI * 0.5), (float)Math.Sin(angle - Math.PI * 0.5)) * (bodyHeight * 0.5f - EdgeOverlap);
                var positionTop    = positionBody + edgeOffset;
                var positionBottom = positionBody - edgeOffset;

                var edgeOpacity = ignoreEdges ? 0 : opacity;

                GeneratorTopEdge.Add(new CommandGenerator.State()
                {
                    Time     = time,
                    Position = positionTop,
                    Scale    = edgeScale,
                    Rotation = rotation,
                    Color    = object3dState.Color,
                    Opacity  = edgeOpacity,
                    FlipH    = flip,
                    Additive = Additive,
                });
                GeneratorBottomEdge.Add(new CommandGenerator.State()
                {
                    Time     = time,
                    Position = positionBottom,
                    Scale    = edgeScale,
                    Rotation = rotation,
                    Color    = object3dState.Color,
                    Opacity  = edgeOpacity,
                    Additive = Additive,
                    FlipH    = flip,
                    FlipV    = true,
                });
            }

            // Caps

            if (SpritePathCap != null)
            {
                var bitmapCap     = StoryboardObjectGenerator.Current.GetMapsetBitmap(spriteStartCap.GetTexturePathAt(time));
                var startCapScale = new Vector2(startScale / bitmapCap.Width, startScale / bitmapCap.Height);
                var endCapScale   = new Vector2(endScale / bitmapCap.Width, endScale / bitmapCap.Height);

                var capOffset = OrientedCaps ? new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * CapOverlap : Vector2.Zero;

                if (OrientedCaps)
                {
                    startCapScale.X *= 0.5f;
                    endCapScale.X   *= 0.5f;
                }

                var startCapOpacity = startScale > 0.5f ? opacity : 0;
                var endCapOpacity   = endScale > 0.5f ? opacity : 0;

                GeneratorStartCap.Add(new CommandGenerator.State()
                {
                    Time     = time,
                    Position = startVector.Xy + capOffset,
                    Scale    = startCapScale,
                    Rotation = OrientedCaps ? rotation + Math.PI : 0,
                    Color    = object3dState.Color,
                    Opacity  = startCapOpacity,
                    Additive = Additive,
                });
                GeneratorEndCap.Add(new CommandGenerator.State()
                {
                    Time     = time,
                    Position = endVector.Xy - capOffset,
                    Scale    = endCapScale,
                    Rotation = OrientedCaps ? rotation + Math.PI : 0,
                    Color    = object3dState.Color,
                    Opacity  = endCapOpacity,
                    Additive = Additive,
                    FlipH    = OrientedCaps,
                });
            }
        }
コード例 #6
0
ファイル: Line3d.cs プロジェクト: starrodkirby86/storybrew
        public override void GenerateStates(double time, CameraState cameraState, Object3dState object3dState)
        {
            var wvp         = object3dState.WorldTransform * cameraState.ViewProjection;
            var startVector = cameraState.ToScreen(wvp, StartPosition.ValueAt(time));
            var endVector   = cameraState.ToScreen(wvp, EndPosition.ValueAt(time));

            var delta  = endVector.Xy - startVector.Xy;
            var length = delta.Length;

            if (length == 0)
            {
                return;
            }

            var angle    = Math.Atan2(delta.Y, delta.X);
            var rotation = InterpolatingFunctions.DoubleAngle(Generator.EndState?.Rotation ?? 0, angle, 1);

            var bitmap = StoryboardObjectGenerator.Current.GetMapsetBitmap(sprite.GetTexturePathAt(time));
            var scale  = new Vector2(length / bitmap.Width, Thickness.ValueAt(time));

            var opacity = startVector.W < 0 && endVector.W < 0 ? 0 : object3dState.Opacity;

            if (UseDistanceFade)
            {
                opacity *= Math.Max(cameraState.OpacityAt(startVector.W), cameraState.OpacityAt(endVector.W));
            }

            Vector2 position;

            switch (sprite.Origin)
            {
            default:
            case OsbOrigin.TopLeft:
            case OsbOrigin.CentreLeft:
            case OsbOrigin.BottomLeft:
                position = startVector.Xy;
                break;

            case OsbOrigin.TopCentre:
            case OsbOrigin.Centre:
            case OsbOrigin.BottomCentre:
                position = startVector.Xy + delta * 0.5f;
                break;

            case OsbOrigin.TopRight:
            case OsbOrigin.CentreRight:
            case OsbOrigin.BottomRight:
                position = endVector.Xy;
                break;
            }

            Generator.Add(new CommandGenerator.State()
            {
                Time     = time,
                Position = position,
                Scale    = scale,
                Rotation = rotation,
                Color    = object3dState.Color,
                Opacity  = opacity,
                Additive = Additive,
            });
        }
コード例 #7
0
        public override void GenerateStates(double time, CameraState cameraState, Object3dState object3dState)
        {
            var wvp = object3dState.WorldTransform * cameraState.ViewProjection;

            if (FixedEdge >= 0)
            {
                edgeIndex = FixedEdge;
            }

            Vector4 vector0, vector1, vector2;

            switch (edgeIndex)
            {
            case 0:
                vector0 = cameraState.ToScreen(wvp, Position0.ValueAt(time));
                vector1 = cameraState.ToScreen(wvp, Position1.ValueAt(time));
                vector2 = cameraState.ToScreen(wvp, Position2.ValueAt(time));
                break;

            case 1:
                vector2 = cameraState.ToScreen(wvp, Position0.ValueAt(time));
                vector0 = cameraState.ToScreen(wvp, Position1.ValueAt(time));
                vector1 = cameraState.ToScreen(wvp, Position2.ValueAt(time));
                break;

            case 2:
                vector1 = cameraState.ToScreen(wvp, Position0.ValueAt(time));
                vector2 = cameraState.ToScreen(wvp, Position1.ValueAt(time));
                vector0 = cameraState.ToScreen(wvp, Position2.ValueAt(time));
                break;

            default: throw new InvalidOperationException();
            }

            var cross = (vector2.X - vector0.X) * (vector1.Y - vector0.Y)
                        - (vector2.Y - vector0.Y) * (vector1.X - vector0.X);

            if (cross > 0)
            {
                if (Generator0.EndState != null)
                {
                    Generator0.EndState.Opacity = 0;
                }
                if (Generator1.EndState != null)
                {
                    Generator1.EndState.Opacity = 0;
                }
                return;
            }

            var bitmap = StoryboardObjectGenerator.Current.GetMapsetBitmap(sprite0.GetTexturePathAt(time));

            var switchedEdge = false;

            for (var i = 0; i < 3; i++)
            {
                var delta           = vector2.Xy - vector0.Xy;
                var deltaLength     = delta.Length;
                var normalizedDelta = delta / deltaLength;

                var delta2 = vector1.Xy - vector0.Xy;
                var dot    = Vector2.Dot(normalizedDelta, delta2);
                if (dot <= 0 || dot > deltaLength)
                {
                    if (FixedEdge >= 0)
                    {
                        if (Generator0.EndState != null)
                        {
                            Generator0.EndState.Opacity = 0;
                        }
                        if (Generator1.EndState != null)
                        {
                            Generator1.EndState.Opacity = 0;
                        }
                        break;
                    }

                    var temp = vector0;
                    vector0      = vector1;
                    vector1      = vector2;
                    vector2      = temp;
                    edgeIndex    = (edgeIndex + 1) % 3;
                    switchedEdge = true;
                    continue;
                }

                var position = project(vector0.Xy, vector2.Xy, vector1.Xy);
                var scale0   = new Vector2((vector2.Xy - position).Length / bitmap.Width, (vector1.Xy - position).Length / bitmap.Height);
                var scale1   = new Vector2((vector0.Xy - position).Length / bitmap.Width, scale0.Y);

                var angle    = Math.Atan2(delta.Y, delta.X);
                var rotation = InterpolatingFunctions.DoubleAngle(Generator0.EndState?.Rotation ?? 0, angle, 1);

                var opacity = vector0.W < 0 && vector1.W < 0 && vector2.W < 0 ? 0 : object3dState.Opacity;
                if (UseDistanceFade)
                {
                    opacity *= (cameraState.OpacityAt(vector0.W) + cameraState.OpacityAt(vector1.W) + cameraState.OpacityAt(vector2.W)) / 3;
                }

                if (switchedEdge)
                {
                    if (Generator0.EndState != null)
                    {
                        Generator0.EndState.Opacity = 0;
                    }
                    if (Generator1.EndState != null)
                    {
                        Generator1.EndState.Opacity = 0;
                    }
                }

                Generator0.Add(new CommandGenerator.State()
                {
                    Time     = time,
                    Position = position,
                    Scale    = scale0,
                    Rotation = rotation,
                    Color    = object3dState.Color,
                    Opacity  = switchedEdge ? 0 : opacity,
                    Additive = Additive,
                });
                Generator1.Add(new CommandGenerator.State()
                {
                    Time     = time,
                    Position = position,
                    Scale    = scale1,
                    Rotation = rotation,
                    Color    = object3dState.Color,
                    Opacity  = switchedEdge ? 0 : opacity,
                    Additive = Additive,
                    FlipH    = true,
                });
                break;
            }
        }