コード例 #1
0
ファイル: AnimationUtility.cs プロジェクト: weimingtom/Sakura
 public static float EaseInCircInterpolator(float from, float to, float ratio)
 {
     ratio = FMath.Clamp(ratio, 0f, 1f);
     return((float)((double)(-(double)(to - from)) * (Math.Sqrt((double)(1f - ratio * ratio)) - 1.0) + (double)from));
 }
コード例 #2
0
ファイル: Composition.cs プロジェクト: furaga/Magic2D_rev3
        public Operation OnMouseUp(MouseButtons button, Point point, OperationType op, CompositionCanvasControl canvas)
        {
            if (button == MouseButtons.Right)
            {
                if (!prevPoint.IsEmpty)
                {
                    Pan(point.X - prevPoint.X, point.Y - prevPoint.Y);
                }
                prevPoint = point;
                //           return null;
            }

            SegmentMeshInfo transform;

            switch (op)
            {
            case OperationType.Skeleton:
                if (editingJoint != null)
                {
                    editingJoint.position = canvas.PointToWorld(new Point((int)point.X, (int)point.Y));
                }
                editingJoint = null;
                if (editingJoint == null && nearestJoint == null)
                {
                    if (button == MouseButtons.Left)
                    {
                        prevPoint = point;
                    }
                }
                break;

            case OperationType.Segment:
                if (button == MouseButtons.Left)
                {
                    prevPoint = point;
                }
                break;

            case OperationType.ControlPoint:
                if (button != MouseButtons.Left)
                {
                    break;
                }
                if (FMath.SqDistance(prevPoint, point) <= 1)
                {
                    transform = GetMeshInfo(editingSegment);
                    if (transform == null || transform.arap == null)
                    {
                        break;
                    }
                    // 既存の制御点をクリックしたら消す
                    if (editingControlPoint == null || !editingControlPoint.HasValue)
                    {
                        break;
                    }
                    transform.arap.RemoveControlPoint(editingControlPoint.Value);
                    transform.arap.EndDeformation();
                    transform.arap.BeginDeformation();
                }
                editingControlPoint = null;
                break;
            }

            return(null);
        }
コード例 #3
0
 public void Update(Vector2 centrePos, Vector2 rotation)
 {
     sprite.Position = centrePos;
     sprite.Angle    = -(float)FMath.Atan2(rotation.X, rotation.Y);
 }
コード例 #4
0
ファイル: PlanetCute.cs プロジェクト: weimingtom/Sakura
        // Recreated the test scene there:
        // http://www.lostgarden.com/2007/05/dancs-miraculously-flexible-game.html

        public void CreateRPGTestScene()
        {
            // layer y=0

            SetBlock(new Vector3i(0, 0, 0), DirtBlock);
            SetBlock(new Vector3i(1, 0, 0), DirtBlock);
            SetBlock(new Vector3i(2, 0, 0), DirtBlock);
            SetBlock(new Vector3i(3, 0, 0), DirtBlock);
            SetBlock(new Vector3i(4, 0, 0), DirtBlock);
            SetBlock(new Vector3i(5, 0, 0), DirtBlock);
            SetBlock(new Vector3i(6, 0, 0), DirtBlock);

            SetBlock(new Vector3i(0, 0, 1), GrassBlock);
            SetBlock(new Vector3i(1, 0, 1), GrassBlock);
            SetBlock(new Vector3i(2, 0, 1), GrassBlock);
            SetBlock(new Vector3i(3, 0, 1), StoneBlock);
            SetBlock(new Vector3i(4, 0, 1), StoneBlock);
            SetBlock(new Vector3i(5, 0, 1), DirtBlock);
            SetBlock(new Vector3i(6, 0, 1), DirtBlock);

            SetBlock(new Vector3i(0, 0, 2), GrassBlock);
            SetBlock(new Vector3i(1, 0, 2), WaterBlock);
            SetBlock(new Vector3i(2, 0, 2), WaterBlock);
            SetBlock(new Vector3i(3, 0, 2), GrassBlock);

            // layer y=1

            SetBlock(new Vector3i(4, 1, 1), StoneBlock);
            SetBlock(new Vector3i(5, 1, 1), DirtBlock);
            SetBlock(new Vector3i(6, 1, 1), DirtBlock);

            SetBlock(new Vector3i(0, 1, 2), GrassBlock);
            SetBlock(new Vector3i(1, 1, 2), WaterBlock);
            SetBlock(new Vector3i(2, 1, 2), WaterBlock);
            SetBlock(new Vector3i(3, 1, 2), GrassBlock);

            // layer y=2

            SetBlock(new Vector3i(0, 2, 2), StoneBlock);
            SetBlock(new Vector3i(1, 2, 2), WaterBlock);
            SetBlock(new Vector3i(2, 2, 2), WaterBlock);
            SetBlock(new Vector3i(3, 2, 2), StoneBlock);
            SetBlock(new Vector3i(4, 2, 2), StoneBlock);
            SetBlock(new Vector3i(5, 2, 2), StoneBlock);
            SetBlock(new Vector3i(6, 2, 2), RampSouth);

            // layer y=3

            SetBlock(new Vector3i(0, 3, 3), RampWest);
            SetBlock(new Vector3i(1, 3, 3), StoneBlock);
            SetBlock(new Vector3i(2, 3, 3), StoneBlock);
            SetBlock(new Vector3i(3, 3, 3), StoneBlock);
            SetBlock(new Vector3i(4, 3, 3), RampEast);
            SetBlock(new Vector3i(5, 3, 2), StoneBlock);
            SetBlock(new Vector3i(6, 3, 2), StoneBlock);

            // layer y=4

            SetBlock(new Vector3i(0, 4, 2), StoneBlock);
            SetBlock(new Vector3i(1, 4, 2), WaterBlock);
            SetBlock(new Vector3i(2, 4, 2), WaterBlock);
            SetBlock(new Vector3i(3, 4, 2), PlainBlock);
            SetBlock(new Vector3i(4, 4, 3), WallBlock);
            SetBlock(new Vector3i(4, 4, 4), WallBlock);
            SetBlock(new Vector3i(4, 4, 5), WallBlock);
            SetBlock(new Vector3i(5, 4, 2), StoneBlock);
            SetBlock(new Vector3i(5, 4, 3), DoorTallClosed);
            SetBlock(new Vector3i(6, 4, 3), WallBlock);
            SetBlock(new Vector3i(6, 4, 4), WallBlock);
            SetBlock(new Vector3i(6, 4, 5), WallBlock);

            // try put as many sprites in SpriteList for performance

            SpriteList sprite_list = new SpriteList(ObjectsMap);

            sprite_list.AddChild(NewCharater(CharacterBoy, new Vector3(3, 1.5f, 3)));
            sprite_list.AddChild(NewCharater(CharacterHornGirl, new Vector3(5, 2.6f, 3)));
            sprite_list.AddChild(NewCharater(CharacterPrincessGirl, new Vector3(6, 1, 2)));

            sprite_list.AddChild(NewObject(Rock, new Vector3(3, 0, 3)));
            sprite_list.AddChild(NewObject(Rock, new Vector3(6, 0, 2)));
            sprite_list.AddChild(NewObject(Key, new Vector3(5, 0, 2)));

            sprite_list.AddChild(NewTree(TreeShort, new Vector3(0.5f, 1, 3)));

            AddChild(sprite_list);

            {
                var bug = NewObject(EnemyBug, new Vector3(2, 3, 4));

                bug.Schedule((dt) => {
                    float p = 1.0f;

                    bug.Position = this.GetCellPos(Math.Lerp(new Vector3(1, 3, 4), new Vector3(3, 3, 4)
                                                             , (1.0f + FMath.Sin((float)Director.Instance.DirectorTime * p)) * 0.5f));

                    // we just care about the sign of the derivative
                    bug.FlipU = (FMath.Cos((float)Director.Instance.DirectorTime * p) < 0.0f);
                });

                AddChild(bug);
            }
        }
コード例 #5
0
 private static GLShader FragmentShader()
 {
     return(GLShader.Create(ShaderType.FragmentShader, () =>
                            from f in Shader.Inputs <TerrainFragment> ()
                            from u in Shader.Uniforms <Terrain> ()
                            from l in Shader.Uniforms <LightingUniforms> ()
                            from c in Shader.Uniforms <CascadedShadowUniforms> ()
                            let rockColor = FragmentShaders.TextureColor(!u.rockSampler, f.fragTexturePos)
                                            let grassColor = FragmentShaders.TextureColor(!u.grassSampler, f.fragTexturePos)
                                                             let sandColor = FragmentShaders.TextureColor(!u.sandSampler, f.fragTexturePos)
                                                                             let sandBlend = FMath.SmoothStep(2f, 4f, f.height)
                                                                                             let flatColor = grassColor.Mix(sandColor, sandBlend)
                                                                                                             let rockBlend = FMath.SmoothStep(0.8f, 0.9f, f.slope)
                                                                                                                             let terrainColor = rockColor.Mix(flatColor, rockBlend)
                                                                                                                                                let diffuseLight = LightingShaders.LightDiffuseIntensity(
                                (!l.directionalLight).direction,
                                (!l.directionalLight).intensity,
                                f.vertexNormal)
                                                                                                                                                                   let ambient = (!l.globalLighting).ambientLightIntensity
                                                                                                                                                                                 //let shadow = ShadowShaders.PcfShadowMapFactor (f.fragPositionLightSpace, 0.0015f)
                                                                                                                                                                                 //let shadow = ShadowShaders.VarianceShadowMapFactor (new Vec4 (f.vertexPos, 1f))
                                                                                                                                                                                 let shadow = ShadowShaders.CascadedShadowMapFactor(new Vec4(f.vertexPos, 1f), 0.0015f)
                                                                                                                                                                                              let litColor = LightingShaders.GlobalLightIntensity(!l.globalLighting, ambient,
                                                                                                                                                                                                                                                  diffuseLight * shadow, new Vec3(0f), terrainColor, new Vec3(0f))
                                                                                                                                                                                                             select new
     {
         outputColor = litColor.Mix(!u.skyColor, f.visibility)
     }));
 }
コード例 #6
0
        public static void Initialize()
        {
            //Set up director and UISystem.
            Director.Initialize();
            UISystem.Initialize(Director.Instance.GL.Context);

            //Set game scene
            gameScene = new Sce.PlayStation.HighLevel.GameEngine2D.Scene();
            gameScene.Camera.SetViewFromViewport();

            //Set the ui scene.
            uiScene = new Sce.PlayStation.HighLevel.UI.Scene();
            Panel panel = new Panel();

            panel.Width  = Director.Instance.GL.Context.GetViewport().Width;
            panel.Height = Director.Instance.GL.Context.GetViewport().Height;
            uiScene.RootWidget.AddChildLast(panel);

            //Set the highscores scene.
            highscoresManager = new HighScoreManager(gameScene);
            highscoresScene   = new Sce.PlayStation.HighLevel.UI.Scene();
            Panel highscoresPanel = new Panel();

            highscoresPanel.Width  = Director.Instance.GL.Context.GetViewport().Width;
            highscoresPanel.Height = Director.Instance.GL.Context.GetViewport().Height;
            highscoresScene.RootWidget.AddChildLast(highscoresPanel);

            // Setup highscores label
            highscoresLabel        = new Sce.PlayStation.HighLevel.UI.Label();
            highscoresLabel.Height = 200.0f;
            highscoresLabel.Text   = "Retrieving Data";
            highscoresPanel.AddChildLast(highscoresLabel);
            highscoresScene.RootWidget.AddChildLast(highscoresPanel);

            // Setup ui scene labels
            scoreLabel = new Sce.PlayStation.HighLevel.UI.Label();
            scoreLabel.SetPosition(10, 8);
            int roundedScore = (int)FMath.Floor(score / 100) * 100;

            scoreLabel.Text = "Score: " + roundedScore.ToString("N0");
            panel.AddChildLast(scoreLabel);

            gameSpeedLabel = new Sce.PlayStation.HighLevel.UI.Label();
            gameSpeedLabel.SetPosition(770, 8);
            float speed = FMath.Round(moveSpeed * 10) / 10;             // round to 1dp

            gameSpeedLabel.Text = "Game Speed: " + moveSpeed.ToString("N1");
            panel.AddChildLast(gameSpeedLabel);

            soundManager = new SoundManager();

            //Create Sprite
            rTextureInfo     = new TextureInfo("/Application/textures/reset.png");
            rSprite          = new SpriteUV();
            rSprite          = new SpriteUV(rTextureInfo);
            rSprite.Quad.S   = rTextureInfo.TextureSizef;
            rSprite.Scale    = new Vector2(1.0f, 1.0f);
            rSprite.Position = new Vector2(0.0f, 0.0f);
            rSprite.CenterSprite();

            //Run the scene.
            Director.Instance.RunWithScene(gameScene, true);
            screenManager = new ScreenManager(gameScene);
        }
コード例 #7
0
 public static Signal <T, float> Mask <T> (this Signal <T, float> signal, Signal <T, float> other,
                                           Signal <T, float> mask)
 {
     return(signal.Combine(other, mask, (x, y, m) => FMath.Mix(x, y, m)));
 }
コード例 #8
0
ファイル: FeatureCatalog.cs プロジェクト: weimingtom/Sakura
    public static Scene MakeTestActionsScene()
    {
        TextureInfo Characters = new TextureInfo(new Texture2D("/Application/Sample/GameEngine2D/FeatureCatalog/data/PlanetCute/Objects.png", false), new Vector2i(7, 3));

        float world_scale = 0.036f;

        var sprite = new SpriteTile();

        sprite.TextureInfo = Characters;
        sprite.TileIndex1D = 2;
        sprite.Quad.S      = sprite.CalcSizeInPixels() * world_scale;
        sprite.CenterSprite();
        sprite.Color     = new Vector4(1.0f, 1.0f, 1.0f, 0.75f);
        sprite.BlendMode = BlendMode.Normal;

        var scene = new Scene()
        {
            Name = "Action tests"
        };

        scene.AddChild(sprite);

        var pos = new Vector2(0.0f, 0.0f);

        int writing_color_tag    = 333;
        int writing_position_tag = 65406;

        AddButton(scene, "MoveTo (0,0)", ref pos, () => { sprite.RunAction(new MoveTo(new Vector2(0.0f, 0.0f), 0.1f)); });
        AddButton(scene, "MoveBy (3,0)", ref pos, () => { sprite.RunAction(new MoveBy(new Vector2(3.0f, 0.0f), 0.1f)); });
        AddButton(scene, "ScaleBy (2,2)", ref pos, () => { sprite.RunAction(new ScaleBy(new Vector2(2.0f, 2.0f), 0.1f)); });
        AddButton(scene, "ScaleBy (0.5,0.5)", ref pos, () => { sprite.RunAction(new ScaleBy(new Vector2(0.5f, 0.5f), 0.1f)); });

        AddButton(scene, "TintTo White", ref pos, () =>
        {
            // prevent from running an other action that writes the color
            if (sprite.GetActionByTag(writing_color_tag) != null)
            {
                sprite.StopActionByTag(writing_color_tag);
            }

            sprite.RunAction(new TintTo(Math.SetAlpha(Colors.White, 0.75f), 2.0f)
            {
                Tag = writing_color_tag
            });
        }
                  );

        AddButton(scene, "TintTo Blue", ref pos, () =>
        {
            // prevent from running an other action that writes the color
            if (sprite.GetActionByTag(writing_color_tag) != null)
            {
                sprite.StopActionByTag(writing_color_tag);
            }

            sprite.RunAction(new TintTo(Math.SetAlpha(Colors.Blue, 0.75f), 2.0f)
            {
                Tag = writing_color_tag
            });
        }
                  );

        AddButton(scene, "Pingpong colors", ref pos, () =>

        {
            // prevent from running an other action that writes the color
            if (sprite.GetActionByTag(writing_color_tag) != null)
            {
                sprite.StopActionByTag(writing_color_tag);
            }

            var action12 = new TintTo(Colors.Green, 0.5f)
            {
                Tween = (t) => FMath.Sin(t * Math.Pi * 0.5f),
            };

            var action13 = new TintTo(Colors.Magenta, 0.5f)
            {
                Tween = (t) => FMath.Sin(t * Math.Pi * 0.5f),
            };

            var seq = new Sequence();
            seq.Add(action12);
            seq.Add(action13);
            var repeat0 = new RepeatForever()
            {
                InnerAction = seq, Tag = writing_color_tag
            };
            sprite.RunAction(repeat0);
        }
                  );

        AddButton(scene, "Pingpong position", ref pos, () =>

        {
            // prevent from running the same action twice
            // (we could also just hold an Action object somewhere and re-run, so that this check wouldn't be needed)
            if (sprite.GetActionByTag(writing_position_tag) != null)
            {
                sprite.StopActionByTag(writing_position_tag);
            }

            var action12 = new MoveTo(new Vector2(-5, 0), 0.5f)
            {
                Tween = (t) => FMath.Sin(t * Math.Pi * 0.5f),
            };

            var action13 = new MoveTo(new Vector2(5, 0), 0.5f)
            {
                Tween = (t) => FMath.Sin(t * Math.Pi * 0.5f),
            };

            var seq = new Sequence();
            seq.Add(action12);
            seq.Add(action13);
            var repeat0 = new RepeatForever()
            {
                InnerAction = seq, Tag = writing_position_tag
            };

            sprite.RunAction(repeat0);
        }
                  );

        AddButton(scene, "StopAllActions", ref pos, () => sprite.StopAllActions());

        scene.RegisterDisposeOnExit((System.IDisposable)Characters);

        return(scene);
    }
コード例 #9
0
ファイル: FeatureCatalog.cs プロジェクト: weimingtom/Sakura
    public static Scene MakeForestScene()
    {
//		System.Console.WriteLine( "MakeForestScene" );

        var scene = new Scene()
        {
            Name = "Forest"
        };

        TextureInfo ObjectsMap = new TextureInfo(new Texture2D("/Application/Sample/GameEngine2D/FeatureCatalog/data/PlanetCute/Objects.png", false), new Vector2i(7, 3));

        Vector2i[] tree_indexes = new Vector2i[3];
        tree_indexes[0] = PlanetCute.TreeShort;
        tree_indexes[1] = PlanetCute.TreeTall;
        tree_indexes[2] = PlanetCute.TreeUgly;

        Math.RandGenerator rgen = new Math.RandGenerator();

        Bounds2  bounds   = scene.Camera2D.CalcBounds();
        Vector2i numcells = new Vector2i(7, 4);
        Vector2  cellsize = bounds.Size / numcells.Vector2();

        System.Random rnd1 = new System.Random();

        SpriteList sprite_list = new SpriteList(ObjectsMap);

        // we are going to put a tree at a random location inside each cell of a regular grid
        for (int x = 0; x < numcells.X; ++x)
        {
            // generate rows of tree top to bottom, for draw order
            for (int y = numcells.Y - 1; y >= 0; --y)
            {
                Vector2 cellindexf = new Vector2((float)x, (float)y);
                var     sprite     = new SpriteTile();
//				sprite.TextureInfo = tree_tex[rnd1.Next(3)];
                sprite.TextureInfo = ObjectsMap;
                sprite.TileIndex2D = tree_indexes[rnd1.Next(3)];

                // bounds for one cell
                Bounds2 gen_bounds = new Bounds2(bounds.Min + cellindexf * cellsize,
                                                 bounds.Min + cellindexf * cellsize + cellsize);

                // scale gen_bounds to countrols irregularity
                gen_bounds = gen_bounds.Scale(new Vector2(0.6f), gen_bounds.Center);

                // pick up a random point in that cell
                sprite.Position = gen_bounds.Min + gen_bounds.Size * rgen.NextVector2(Math._00, Math._11);

                // make the size of the tree match the size of cells, preserve texture ratio
                Vector2 aspect = sprite.CalcSizeInPixels() / sprite.CalcSizeInPixels().X;
                sprite.Quad.S = cellsize.X * aspect;

                // make the sprite bottom center point be the new pivot (for Skew)
                sprite.Quad.Centering(TRS.Local.BottomCenter);

                // make the trees move in the wind
                sprite.Schedule((dt) => {
                    int hc             = sprite.GetHashCode();
                    System.Random rnd2 = new System.Random(hc);

                    sprite.Skew = new Vector2(Math.Deg2Rad(1.0f) * FMath.Sin((float)Director.Instance.DirectorTime * 1.0f * rnd2.Next(4096) / 4096.0f),
                                              Math.Deg2Rad(2.0f) * FMath.Sin((float)Director.Instance.DirectorTime * 3.0f * rnd2.Next(4096) / 4096.0f));
                });

                sprite_list.AddChild(sprite);
            }
        }

        scene.Camera2D.Center += new Vector2(0.0f, 2.0f);

        scene.AddChild(sprite_list);

        scene.RegisterDisposeOnExit((System.IDisposable)ObjectsMap);

        return(scene);
    }
コード例 #10
0
        public override void Tick(float dt)
        {
            base.Tick(dt);

            if (Input2.GamePad0.Left.Press)
            {
                if (levelSelection > 0)
                {
                    levelSelection -= 1;

                    adjustPositions();
                }
            }

            if (Input2.GamePad0.Right.Press)
            {
                if (levelSelection + 1 < MapManager.Instance.predefinedMaps.Count)
                {
                    levelSelection += 1;
                    adjustPositions();
                }
            }

            if (Input2.GamePad0.Circle.Press)
            {
                SceneManager.Instance.changeSceneTo(MainMenu.Instance);
            }

            if (Input2.GamePad0.Cross.Press)
            {
                MapManager.Instance.currentMap = MapManager.Instance.predefinedMaps [levelSelection];

                SceneManager.Instance.changeSceneTo(Game.Instance);
            }

            if (Input2.Touch00.Down)
            {
                if (Input2.Touch00.Press)
                {
                    originalTouch = GetTouchPos();
                }


                for (int i = 0; i < MapManager.Instance.predefinedMaps.Count; i++)
                {
                    float newX = 960.0f / 2.0f + i * (thumbnailSize + thumbnailSpacing) - levelSelection * (thumbnailSize + thumbnailSpacing) - (originalTouch.X - GetTouchPos().X) * 2.0f;

                    MapManager.Instance.predefinedMaps [i].thumbnailSprite.RunAction(
                        new MoveTo(
                            new Vector2(
                                newX,
                                MapManager.Instance.predefinedMaps [i].thumbnailSprite.Position.Y),
                            transitionDuration));

                    float scaleFactor = FMath.Clamp(thumbnailSize - FMath.Abs((960.0f / 2.0f) - newX) / 4.0f, 0.0f, thumbnailSize);

                    MapManager.Instance.predefinedMaps [i].thumbnailSprite.RunAction(
                        new ScaleTo(new Vector2(scaleFactor, scaleFactor), 0.5f));


                    //adjust labels

                    float labelScaleFactor = FMath.Clamp(1.0f - FMath.Abs((960.0f / 2.0f) - newX) / 1000.0f, 0.0f, 1.0f);
                    labels [i].RunAction(
                        new MoveTo(
                            new Vector2(
                                newX,
                                MapManager.Instance.predefinedMaps [i].thumbnailSprite.Position.Y - thumbnailSize * 0.65f * labelScaleFactor), transitionDuration));
                    labels [i].RunAction(new ScaleTo(new Vector2(labelScaleFactor, labelScaleFactor), 0.5f));
                }
            }


            if (Input2.Touch00.Release)
            {
                levelSelection += (int)((originalTouch.X - GetTouchPos().X) * 2.0f / (thumbnailSize * 0.75f));

                levelSelection = (int)FMath.Clamp(levelSelection, 0, MapManager.Instance.predefinedMaps.Count - 1);
                adjustPositions();
            }
        }
コード例 #11
0
ファイル: FeatureCatalog.cs プロジェクト: weimingtom/Sakura
    public static Scene MakeTestPivotScene()
    {
        var scene = new Scene()
        {
            Name = "Pivot test"
        };

        scene.Camera2D.SetViewFromHeightAndCenter(8.0f, new Vector2(3, 3));

        var texture_info = Director.Instance.GL.WhiteTextureInfo;

        var sprite = new SpriteUV()
        {
            TextureInfo = texture_info
        };

        sprite.Position = new Vector2(2, 3);

        sprite.Scale = new Vector2(2, 2);
        sprite.Pivot = new Vector2(0.5f, 0.5f);

        sprite.Color     = new Vector4(0.0f, 0.0f, 1.0f, 0.5f);
        sprite.BlendMode = BlendMode.Normal;

        //FIXME:added
//		sprite.Name = "sprite001";
//		sprite.__isdebug = true;

        sprite.Schedule((dt) =>

        {
            float period_in_seconds = 3.0f;
            float wave = ((1.0f + FMath.Sin((float)Director.Instance.CurrentScene.SceneTime * Math.Pi / period_in_seconds)) * 0.5f);

            sprite.Rotation = Vector2.Rotation(Math.Pi * 2.0f * wave);
            sprite.Scale    = new Vector2(1.0f + 2.0f * wave);
        }
                        );

        //FIXME:added
//		sprite.__allowAdHocDraw = true;
//		sprite.AdHocDraw += () =>
//
//			{
//				// debug draw the emission rectangle in pink
//
//				if (false)
//				{
//					Director.Instance.GL.SetBlendMode( BlendMode.Additive );
//					Director.Instance.DrawHelpers.SetColor( Colors.Pink * 0.3f );
//					Director.Instance.DrawHelpers.DrawBounds2( Bounds2.QuadMinus1_1.Scale( sprite.Position, Math._00 ) );
//				}
//				else
//				{
//					Director.Instance.GL.SetBlendMode( BlendMode.Additive );
//					Director.Instance.DrawHelpers.SetColor( Colors.Pink * 0.3f );
//					Director.Instance.DrawHelpers.DrawDisk( new Vector2(1, 1), 1f, 16 );
////					Director.Instance.DrawHelpers.DrawBounds2( new Bounds2(new Vector2(1, 1), new Vector2(2, 2)) );
//				}
//			};


//		System.Console.WriteLine( Director.Instance.GL.GetViewportf().Aspect );
        Vector2 bpos = new Vector2(0.0f, 0.0f);

        AddButton(scene, "Pivot at 0,0", ref bpos, () => { sprite.Pivot = new Vector2(0.0f, 0.0f); });
        AddButton(scene, "Pivot at 0.5,0.5", ref bpos, () => { sprite.Pivot = new Vector2(0.5f, 0.5f); });

        scene.AdHocDraw += () =>

        {
            Director.Instance.GL.ModelMatrix.Push();
            Director.Instance.GL.ModelMatrix.SetIdentity();             // go in world space

            Director.Instance.GL.SetBlendMode(BlendMode.None);
            Director.Instance.DrawHelpers.SetColor(Colors.Yellow);
            Director.Instance.DrawHelpers.DrawDisk(sprite.LocalToWorld(sprite.Pivot), 0.05f, 16);

            Director.Instance.GL.SetBlendMode(BlendMode.Normal);
            Director.Instance.SpriteRenderer.DefaultFontShader.SetColor(ref Colors.Yellow);
            Director.Instance.SpriteRenderer.DrawTextDebug(".Pivot=" + sprite.Pivot.ToString(), sprite.LocalToWorld(sprite.Pivot) + new Vector2(0.05f, 0.05f)
                                                           , scene.Camera2D.GetPixelSize() * EmbeddedDebugFontData.CharSizei.Y);

            Director.Instance.GL.ModelMatrix.Pop();
        };

        scene.AddChild(sprite, -1);

        return(scene);
    }
コード例 #12
0
ファイル: AnimationUtility.cs プロジェクト: weimingtom/Sakura
 internal static AnimationInterpolator GetSpringInterpolator(int strength)
 {
     if (strength > 0)
     {
         strength = Math.Min(100, strength);
         float startupTime                  = 0.4f / (float)strength;
         float cycleTime                    = (1f - startupTime) / (float)strength;
         float angularFrequency             = 6.28318548f / cycleTime;
         Func <float, float> ratioConverter = delegate(float t)
         {
             if (t >= startupTime)
             {
                 return(0.7f + 0.3f * FMath.Exp(-(t - startupTime) / cycleTime) * FMath.Cos(angularFrequency * (t - startupTime)));
             }
             return(FMath.Sin(t * 3.14159274f / 2f / startupTime));
         };
         return(AnimationUtility.GetAnimationInterpolator(ratioConverter));
     }
     return(new AnimationInterpolator(AnimationUtility.LinearInterpolator));
 }
コード例 #13
0
ファイル: AnimationUtility.cs プロジェクト: weimingtom/Sakura
        private static float GetFunctionInterpolateRatio(int strength)
        {
            float num = (float)(-(float)strength) / 100f;

            return(Math.Abs(FMath.Max(-1f, FMath.Min(1f, num))));
        }
コード例 #14
0
ファイル: AnimationUtility.cs プロジェクト: weimingtom/Sakura
 public static float EaseOutCircInterpolator(float from, float to, float ratio)
 {
     ratio = FMath.Clamp(ratio, 0f, 1f);
     return((float)((double)(to - from) * Math.Sqrt((double)(1f - (ratio -= 1f) * ratio)) + (double)from));
 }
コード例 #15
0
        //
        // Expand()
        //

        /// <summary>
        /// smesh1, smesh2の輪郭をずらして重ねる。輪郭に制御点をおいてARAPする
        /// </summary>
        static void Expand(PatchSkeletalMesh smesh1, PatchSkeletalMesh smesh2, PatchSkeleton skl, PatchSection section1, PatchSection section2, PatchSkeletonBone bone)
        {
            List <PatchVertex> rawPath1 = GetPath(smesh1);
            List <PatchVertex> rawPath2 = GetPath(smesh2);
            List <PointF>      path1    = rawPath1.Select(v => v.position).ToList();
            List <PointF>      path2    = rawPath2.Select(v => v.position).ToList();

            //
            // 輪郭を変形できるように制御点を作り直す
            //

            // smesh1
            smesh1.mesh.ClearControlPoints();
            foreach (var v in rawPath1)
            {
                smesh1.mesh.AddControlPoint(v.position, v.orgPosition);
            }
            smesh1.mesh.BeginDeformation();

            // smesh2
            smesh2.mesh.ClearControlPoints();
            foreach (var v in rawPath2)
            {
                smesh2.mesh.AddControlPoint(v.position, v.orgPosition);
            }
            smesh2.mesh.BeginDeformation();


            //
            // 切り口に隣接する2曲線を各切り口について取得し、これらが重なるように輪郭をずらす
            //

            // 切り口に隣接する2曲線をそれぞれ取得
            var rawCurves1 = SectionToAdjuscentCurves(path1, section1, 5, 30);
            var rawCurves2 = SectionToAdjuscentCurves(path2, section2, 5, 30);

            if (rawCurves1 == null || rawCurves2 == null)
            {
                return;
            }

            PatchSkeletonBone refBone = null;

            foreach (var b in skl.bones)
            {
                if (bone == b)
                {
                    refBone = b;
                    break;
                }
            }

            // curves1, curves2の第一要素、第二要素がそれぞれ向かい合う(ボーンにとって同じ側の)切り口となるように並び替える
            var curves1 = GetSortedCurves(path1, rawCurves1, refBone);
            var curves2 = GetSortedCurves(path2, rawCurves2, refBone);

            if (curves1.Count != 2 || curves2.Count != 2)
            {
                return;
            }

            // curves1, curves2の移動履歴を記録
            List <Tuple <PointF, PointF> > move1 = new List <Tuple <PointF, PointF> >();
            List <Tuple <PointF, PointF> > move2 = new List <Tuple <PointF, PointF> >();

            // 対応する曲線間で2点がかぶる(同じ座標になる)ように変形。
            for (int i = 0; i < 2; i++)
            {
                var p1 = curves1[i].First();
                var v1 = new PointF(p1.X - curves1[i].Last().X, p1.Y - curves1[i].Last().Y);
                var p2 = curves2[i].First();
                var v2 = new PointF(curves2[i].Last().X - p2.X, curves2[i].Last().Y - p2.Y);

                // 2点かぶらせる
                int cnt = curves1[i].Count + curves2[i].Count - 2;
                if (cnt <= 1)
                {
                    continue;
                }

                for (int j = 0; j < curves1[i].Count; j++)
                {
                    PointF to = FMath.HelmitteInterporate(p1, v1, p2, v2, (float)j / (cnt - 1));
                    if (j == curves1[i].Count - 1)
                    {
                        move1.Add(new Tuple <PointF, PointF>(curves1[i][j], to));
                    }
                    smesh1.mesh.TranslateControlPoint(curves1[i][j], to, false);
                }
                for (int j = 0; j < curves2[i].Count; j++)
                {
                    PointF to = FMath.HelmitteInterporate(p1, v1, p2, v2, (float)(-j + cnt - 1) / (cnt - 1));
                    if (j == curves2[i].Count - 1)
                    {
                        move2.Add(new Tuple <PointF, PointF>(curves2[i][j], to));
                    }
                    smesh2.mesh.TranslateControlPoint(curves2[i][j], to, false);
                }
            }

            //
            // 各曲線の動きに合わせて切り口を動かす
            //
            List <PointF> sections1 = new List <PointF>();

            for (int i = section1.First + 1; i < section1.First + section1.Length - 1; i++)
            {
                sections1.Add(path1[FMath.Rem(i, path1.Count)]);
            }
            List <PointF> newSection1 = ARAPDeformation.ARAPDeformation.Deform(sections1, move1);

            if (newSection1.Count == sections1.Count)
            {
                for (int i = 0; i < newSection1.Count; i++)
                {
                    smesh1.mesh.TranslateControlPoint(sections1[i], newSection1[i], false);
                }
            }

            List <PointF> sections2 = new List <PointF>();

            for (int i = section2.First + 1; i < section2.First + section2.Length - 1; i++)
            {
                sections2.Add(path2[FMath.Rem(i, path2.Count)]);
            }
            List <PointF> newSection2 = ARAPDeformation.ARAPDeformation.Deform(sections2, move2);

            if (newSection2.Count == sections2.Count)
            {
                for (int i = 0; i < newSection2.Count; i++)
                {
                    smesh2.mesh.TranslateControlPoint(sections2[i], newSection2[i], false);
                }
            }

            //
            // 変形
            //
            smesh1.mesh.FlushDefomation();
            smesh2.mesh.FlushDefomation();

            //
            // 変形終了
            //
            smesh1.mesh.EndDeformation();
            smesh2.mesh.EndDeformation();
        }
コード例 #16
0
ファイル: FeatureCatalog.cs プロジェクト: weimingtom/Sakura
        public ChainedLabel(ChainedLabel target, Scene scene, Plane3D parent, float alpha, int order)
            : base()
        {
            if (alpha != 0.0f)
            {
                alpha = Math.Lerp(0.2f, 1.0f, alpha);
            }

            FontMap     = LargeFontMap;
            HeightScale = scene.Camera.GetPixelSize();
            Color       = Math.Lerp(Colors.White, Colors.Grey60, alpha);

            VertexZ = 1.0f;

            Text = "Label.VertexZ=" + VertexZ;

            Shadow = new Label()
            {
                FontMap = LargeFontMap, Color = Colors.Grey05
            };
            Shadow.HeightScale = HeightScale;
            Shadow.Text        = Text;

            Target = target;

            Schedule((dt) =>

            {
                if (Target == null)
                {
                    // head node

                    this.Position = m_center + m_radius * new Vector2(FMath.Cos((float)Director.Instance.DirectorTime * 0.5f * 2.033f),
                                                                      FMath.Cos((float)Director.Instance.DirectorTime * 0.5f * 0.98033f + 0.5f));

                    Vector2 touch_pos = Director.Instance.CurrentScene.Camera.GetTouchPos();

                    // you can drag the Label

                    if (Input2.Touch00.Down)
                    {
                        if (Input2.Touch00.Press
                            // not that since we set VertexZ and have used a perspective in this particular test scene,
                            // the picking here won't be very precise
                            && this.IsWorldPointInsideContentLocalBounds(touch_pos))
                        {
                            m_dragged           = true;
                            m_drag_start        = touch_pos;
                            m_center            = this.Position;                          // this is our new position, we zero the cosine offset too
                            m_radius            = 0.0f;
                            m_drag_start_center = m_center;
                        }

                        if (m_dragged)
                        {
                            m_center = m_drag_start_center + (touch_pos - m_drag_start);
                            m_radius = 0.0f;
                        }
                    }
                    else
                    {
                        m_dragged = false;
                        m_radius += (m_radius_target - m_radius) * 0.001f;
                    }
                }
                else
                {
                    // follower node

                    this.Position += 0.08f * (Target.Position - this.Position);
                }

                this.Shadow.Position = this.Position;
            }
                     );

            parent.AddChild(Shadow, -1);
            parent.AddChild(this, order);
        }
コード例 #17
0
        // 切り口に隣接する部分パス(2つ)を返す
        // この部分を引き伸ばしてメッシュを繋げる
        static Tuple <CharacterRange, CharacterRange> SectionToAdjuscentCurves(List <PointF> path, PatchSection section, int maxPtNum, float maxAngle)
        {
            if (section.Length <= 0 || path == null || path.Count < 5 || maxPtNum < 3)
            {
                return(null);
            }

            float cos = (float)Math.Cos(maxAngle);

            // 1つ目の部分パス

            int start1 = section.First;

            while (start1 < 0)
            {
                start1 += path.Count;
            }
            start1 = start1 % path.Count;

            int end1 = start1 - 2;

            for (int i = 0; i < maxPtNum - 2; i++)
            {
                int idx   = (start1 - 2 - i + path.Count) % path.Count;
                var curve = new List <PointF>();
                for (int j = idx; j < idx + 3; j++)
                {
                    curve.Add(path[FMath.Rem(j, path.Count)]);
                }
                if (FMath.GetAngleCos(curve) < cos)
                {
                    break;
                }
                end1 = idx;
            }

            CharacterRange r1 = new CharacterRange();

            if (start1 > end1)
            {
                r1 = new CharacterRange(end1, start1 - end1 + 1);
            }
            if (start1 < end1)
            {
                // 始点と終点をまたがっている場合
                r1 = new CharacterRange(end1, start1 + path.Count - end1 + 1);
            }

            if (r1.Length <= 0)
            {
                return(null);
            }

            // 2つ目の部分パス

            int start2 = section.First + section.Length - 1;

            while (start2 < 0)
            {
                start2 += path.Count;
            }
            start2 = start2 % path.Count;

            int end2 = start2 + 2;

            for (int i = 0; i < maxPtNum - 2; i++)
            {
                int idx   = (start2 + i) % path.Count;
                var curve = path.Skip(idx).Take(3).ToList();
                if (FMath.GetAngleCos(curve) < cos)
                {
                    break;
                }
                end2 = start2 + i + 2;
            }

            CharacterRange r2 = new CharacterRange();

            if (start2 < end2)
            {
                r2 = new CharacterRange(start2, end2 - start2 + 1);
            }
            if (start2 > end2)
            {
                r2 = new CharacterRange(start2, end2 + path.Count - start2 + 1);
            }

            if (r2.Length <= 0)
            {
                return(null);
            }

            return(new Tuple <CharacterRange, CharacterRange>(r1, r2));
        }
コード例 #18
0
ファイル: Quaternion.cs プロジェクト: zimengyang/ModelViewer
        public static Quatf Slerp(Quatf q0, Quatf q1, float t)
        {
            Quatf q2;
            float dot = q0 % q1;

            if (dot < 0.00f)
            {
                dot = -dot; q2 = q1 * -1.0f;
            }
            else
            {
                q2 = q1;
            }

            if (dot < 0.95f)
            {
                float ang = FMath.Acos(dot);
                return((q0 * FMath.Sin(ang * (1.0f - t)) + q2 * FMath.Sin(ang * t)) / FMath.Sin(ang));
            }
            else
            {
                return(Lerp(q0, q2, t));
            }
        }
コード例 #19
0
        public override void Tick(float dt)
        {
            //base.Tick(dt);
            if (Player.Instance == null)
            {
            }
            else
            {
                setCameraPosition();
            }

            //check bullet delay
            if (Bullet.bulletDelay > 0)
            {
                Bullet.bulletDelay--;
            }

            //check buttons
            if (Input2.GamePad0.Cross.Down || Input2.GamePad0.R.Down)
            {
                if (Bullet.bulletDelay == 0 && Player.Instance.ammo > 0)
                {
                    SoundSystem.Instance.Play("shot.wav");
                    Bullet bullet = new Bullet();
                    bulletList.Add(bullet);
                    World.AddChild(bullet);
                    Bullet.bulletDelay = 2;
                    Player.Instance.ammo--;

                    //update player's sprite
                    Player.Instance.playerBodySprite.TileIndex1D = Player.Instance.animationFrame;
                    Player.Instance.animationFrame = (Player.Instance.animationFrame + 1) % Player.Instance.playerBodySprite.TextureInfo.NumTiles.X;
                }
            }

            //check buttons
            if (Input2.GamePad0.Cross.Release || Input2.GamePad0.R.Release)
            {
                //update player's sprite
                Player.Instance.playerBodySprite.TileIndex1D = 0;
            }


            //check start button(for pause menu)
            if (Input2.GamePad0.Start.Press)
            {
                this.paused = true;
                SceneManager.Instance.pushScene(PauseScene.Instance);
            }

            // pinch-to-zoom
            //only check for multitouch points if device supports more than one touch point
            if (Input2.Touch.MaxTouch > 1)
            {
                //only proceed if the user is actually touching both points
                if (Input2.Touch.GetData(0)[0].Down && Input2.Touch.GetData(0)[1].Down)
                {
                    //first touch point
                    Vector2 touch1 = Director.Instance.CurrentScene.GetTouchPos(0);

                    //second touch point
                    Vector2 touch2 = Director.Instance.CurrentScene.GetTouchPos(1);

                    //reset the distance measure if the screen has just been touched
                    if (Input2.Touch.GetData(0)[0].Press || Input2.Touch.GetData(0)[1].Press)
                    {
                        multitouchDistance = touch1.Distance(touch2);
                    }
                    else
                    {
                        var newDistance = touch1.Distance(touch2);

                        cameraHeight += (multitouchDistance - newDistance);
                        this.Camera2D.SetViewFromHeightAndCenter(cameraHeight, Player.Instance.Position);
                    }
                }
            }


            //check if the player has collected any ammo packs
            AmmoItem ammoItemToRemove;

            if (Collisions.checkAmmoPackCollisions(Player.Instance, ammoList, out ammoItemToRemove))
            {
                Game.Instance.EffectsLayer.AddChild(new ammoMarker(ammoItemToRemove.Position));
                SoundSystem.Instance.Play("ammoclip.wav");
                World.RemoveChild(ammoItemToRemove, true);
                ammoList.Remove(ammoItemToRemove);

                Player.Instance.ammo = (int)FMath.Clamp((Player.Instance.ammo + 50), 100, 100);

                ammoItemToRemove.Die();
            }



            if (Player.Instance.Health <= 0)
            {
                Background.RemoveAllChildren(true);
                Foreground.RemoveAllChildren(true);
                EffectsLayer.RemoveAllChildren(true);
                World.RemoveAllChildren(true);
                Interface.RemoveAllChildren(true);



                SceneManager.Instance.changeSceneTo(GameOverScene.Instance);
                //Sce.PlayStation.HighLevel.GameEngine2D.Scheduler.Instance.Unschedule(Scene, gameTick);
                //Sce.PlayStation.HighLevel.GameEngine2D.Scheduler.Instance.Schedule(Scene, gameoverTick, 0.0f, false);
            }
        }
コード例 #20
0
ファイル: Quaternion.cs プロジェクト: zimengyang/ModelViewer
        public static Quatf Slerp_NoInvert(Quatf q0, Quatf q1, float t)
        {
            float dot = q0 % q1;

            if (dot > -0.95f && dot < 0.95f)
            {
                float ang = FMath.Acos(dot);
                return((q0 * FMath.Sin(ang * (1.0f - t)) + q1 * FMath.Sin(ang * t)) / FMath.Sin(ang));
            }
            else
            {
                return(Lerp(q0, q1, t));
            }
        }
コード例 #21
0
ファイル: SpriteBuffer.cs プロジェクト: hatano0x06/Coroppoxus
        public void Copy2Buffer(SpriteB spriteB, int index)
        {
            if (spriteB.Rotation == 0.0f)
            {
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE]     = spriteB.Position.X - spriteB.Width * spriteB.Center.X;            //0.0f;	// x0
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 1] = spriteB.Position.Y - spriteB.Height * spriteB.Center.Y;           //0.0f;	// y0
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 2] = spriteB.Position.Z;                                               // z0

                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 3] = spriteB.Position.X - spriteB.Width * spriteB.Center.X;            //0.0f;	// x1
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 4] = spriteB.Position.Y + spriteB.Height * (1.0f - spriteB.Center.Y);  //1.0f;	// y1
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 5] = spriteB.Position.Z;                                               // z1

                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 6] = spriteB.Position.X + spriteB.Width * (1.0f - spriteB.Center.X);   //1.0f;	// x2
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 7] = spriteB.Position.Y - spriteB.Height * spriteB.Center.Y;           //0.0f;	// y2
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 8] = spriteB.Position.Z;                                               // z2

                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 9]  = spriteB.Position.X + spriteB.Width * (1.0f - spriteB.Center.X);  //1.0f;	// x3
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 10] = spriteB.Position.Y + spriteB.Height * (1.0f - spriteB.Center.Y); //1.0f;	// y3
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 11] = spriteB.Position.Z;                                              // z3
            }
            else
            {
                float x, y, rc, rs;

                rc = FMath.Cos(spriteB.Rotation);
                rs = FMath.Sin(spriteB.Rotation);

                x = -spriteB.Width * spriteB.Center.X;
                y = -spriteB.Height * spriteB.Center.Y;
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE]     = spriteB.Position.X + (float)(x * rc - y * rs); // x0
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 1] = spriteB.Position.Y + (float)(x * rs + y * rc); // y0
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 2] = spriteB.Position.Z;                            // z0

                x = -spriteB.Width * spriteB.Center.X;
                y = spriteB.Height * (1.0f - spriteB.Center.Y);
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 3] = spriteB.Position.X + (float)(x * rc - y * rs); // x1
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 4] = spriteB.Position.Y + (float)(x * rs + y * rc); // y1
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 5] = spriteB.Position.Z;                            // z1

                x = spriteB.Width * (1.0f - spriteB.Center.X);
                y = -spriteB.Height * spriteB.Center.Y;
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 6] = spriteB.Position.X + (float)(x * rc - y * rs); // x2
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 7] = spriteB.Position.Y + (float)(x * rs + y * rc); // y2
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 8] = spriteB.Position.Z;                            // z2

                x = spriteB.Width * (1.0f - spriteB.Center.X);
                y = spriteB.Height * (1.0f - spriteB.Center.Y);
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 9]  = spriteB.Position.X + (float)(x * rc - y * rs); // x3
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 10] = spriteB.Position.Y + (float)(x * rs + y * rc); // y3
                bufferVerties[index * VERTEX_SIZE_PER_SPRITE + 11] = spriteB.Position.Z;                            // z3
            }

#if false
            bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE]     = texcoords[0];       // left top u
            bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE + 1] = texcoords[1];       // left top v
            bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE + 2] = texcoords[2];       // left bottom u
            bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE + 3] = texcoords[3];       // left bottom v
            bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE + 4] = texcoords[4];       // right top u
            bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE + 5] = texcoords[5];       // right top v
            bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE + 6] = texcoords[6];       // right bottom u
            bufferTexcoords[index * TEXCOORD_SIZE_PER_SPRITE + 7] = texcoords[7];       // right bottom v
#else
            Buffer.BlockCopy(spriteB.Texcoords, 0, bufferTexcoords, index * TEXCOORD_SIZE_PER_SPRITE * sizeof(float), 8 * sizeof(float));
#endif

            // color

#if false
            bufferColors[index * COLOR_SIZE_PER_SPRITE]     = colors[0];
            bufferColors[index * COLOR_SIZE_PER_SPRITE + 1] = colors[1];
            bufferColors[index * COLOR_SIZE_PER_SPRITE + 2] = colors[2];
            bufferColors[index * COLOR_SIZE_PER_SPRITE + 3] = colors[3];

            bufferColors[index * COLOR_SIZE_PER_SPRITE + 4] = colors[4];
            bufferColors[index * COLOR_SIZE_PER_SPRITE + 5] = colors[5];
            bufferColors[index * COLOR_SIZE_PER_SPRITE + 6] = colors[6];
            bufferColors[index * COLOR_SIZE_PER_SPRITE + 7] = colors[7];

            bufferColors[index * COLOR_SIZE_PER_SPRITE + 8]  = colors[8];
            bufferColors[index * COLOR_SIZE_PER_SPRITE + 9]  = colors[9];
            bufferColors[index * COLOR_SIZE_PER_SPRITE + 10] = colors[10];
            bufferColors[index * COLOR_SIZE_PER_SPRITE + 11] = colors[11];

            bufferColors[index * COLOR_SIZE_PER_SPRITE + 12] = colors[12];
            bufferColors[index * COLOR_SIZE_PER_SPRITE + 13] = colors[13];
            bufferColors[index * COLOR_SIZE_PER_SPRITE + 14] = colors[14];
            bufferColors[index * COLOR_SIZE_PER_SPRITE + 15] = colors[15];
#else
            Buffer.BlockCopy(spriteB.Colors, 0, bufferColors, index * COLOR_SIZE_PER_SPRITE * sizeof(float), 16 * sizeof(float));
#endif

            bufferIndices[index * INDEX_SIZE_PER_SPRITE]     = (ushort)(index * VERTEX_NUM_PER_SPRITE);
            bufferIndices[index * INDEX_SIZE_PER_SPRITE + 1] = (ushort)(index * VERTEX_NUM_PER_SPRITE + 1);
            bufferIndices[index * INDEX_SIZE_PER_SPRITE + 2] = (ushort)(index * VERTEX_NUM_PER_SPRITE + 2);
            bufferIndices[index * INDEX_SIZE_PER_SPRITE + 3] = (ushort)(index * VERTEX_NUM_PER_SPRITE + 1);
            bufferIndices[index * INDEX_SIZE_PER_SPRITE + 4] = (ushort)(index * VERTEX_NUM_PER_SPRITE + 2);
            bufferIndices[index * INDEX_SIZE_PER_SPRITE + 5] = (ushort)(index * VERTEX_NUM_PER_SPRITE + 3);
        }
コード例 #22
0
ファイル: Quaternion.cs プロジェクト: zimengyang/ModelViewer
 public static Quatf AxisAngleToQuatf(Vec3f axis, float angle)
 {
     return(new Quatf(FMath.Cos(angle), axis * FMath.Sin(angle)));
 }
コード例 #23
0
        private Matrix4 CalcSpriteMatrix(Vector3 cameraPosition, Vector3 myPosition)
        {
//		myPosition.Z += 5.0f;
            myPosition.Y += texCenter.Y * scale;
            var transMatrix = Matrix4.Translation(myPosition);
            var subPosition = cameraPosition - myPosition;
            var scaleMatrix = Matrix4.Scale(new Vector3(scale, scale, scale));

//		myRotation.Y = FMath.Atan(subPosition.X/subPosition.Z);
//      var rotMatrix = Matrix4.RotationXyz(new Vector3(0.0f,FMath.Atan(subPosition.X/subPosition.Z),0.0f));
            Common.VectorUtil.Set(ref BodyPos, myPosition.X, myPosition.Y, myPosition.Z);

            Matrix4 rotMatrix;

            rotMatrix = Matrix4.RotationZ(FMath.PI);
            if (cameraPosition.Z < myPosition.Z)
            {
                rotMatrix *= Matrix4.RotationY(-FMath.Atan(subPosition.X / subPosition.Z) + FMath.PI);
            }
            else
            {
                rotMatrix *= Matrix4.RotationY(-FMath.Atan(subPosition.X / subPosition.Z));
            }

            Matrix4 rotMatrixZ;

            if (deadflag == true || changeFlag == true || farFlag == true)
            {
                if (appearCount < (int)Data.SetupValue.AppearAndLeaveTime)
                {
                    appearCount++;
                }
                else
                {
                    if (deadflag == true)
                    {
                        deadflag    = false;
                        glowFinish  = false;
                        glowNumber  = 0;
                        glowCounter = 0;
                        startforChange((int)Data.Tex2dResId.MakingWall1);
                    }
                    appearCount = (int)Data.SetupValue.AppearAndLeaveTime;
                }
            }
            else
            {
                if (appearCount > 0)
                {
                    appearCount--;
                }
                else
                {
                    appearCount = 0;
                }
            }

            Matrix4 centerMatrix;

            if (appearCount != 0)
            {
                centerMatrix = Matrix4.Translation(new Vector3(-texCenter.X, texCenter.Y, 0.0f));
                rotMatrixZ   = Matrix4.RotationX(FMath.PI / 2 * -appearCount / (int)Data.SetupValue.AppearAndLeaveTime);
                rotMatrixZ  *= Matrix4.Translation(new Vector3(0.0f, -texCenter.Y * 2, 0.0f));
                return(transMatrix * rotMatrix * scaleMatrix * centerMatrix * rotMatrixZ);
            }
            else
            {
                centerMatrix = Matrix4.Translation(new Vector3(-texCenter.X, -texCenter.Y, 0.0f));
                return(transMatrix * rotMatrix * scaleMatrix * centerMatrix);
            }
        }
コード例 #24
0
 public static VInt3 Max(VInt3 a, VInt3 b)
 {
     return(new VInt3(FMath.Max(a.x, b.x), FMath.Max(a.y, b.y), FMath.Max(a.z, b.z)));
 }
コード例 #25
0
        override public void Update(float speed)
        {
            springSprite.Position    = new Vector2(springSprite.Position.X - speed, springSprite.Position.Y);
            springSprite2.Position   = new Vector2(springSprite2.Position.X - speed, springSprite2.Position.Y);
            springTopSprite.Position = new Vector2(springTopSprite.Position.X - speed, springTopSprite.Position.Y);

            trap.Update(speed);
            pit.Update(speed);

            if (springReleased)
            {
                // Spring can move too fast for collisions, split it up
                int   iterations    = (int)FMath.Ceiling(speed / 3.0f);
                float speedPerCycle = speed / iterations;

                for (int i = 0; i < iterations; i++)
                {
                    // Update collision box
                    _min.X   = springTopSprite.Position.X;
                    _min.Y   = springTopSprite.Position.Y;
                    _max.X   = springTopSprite.Position.X + springTopTextureInfo.TextureSizef.X;
                    _max.Y   = springTopSprite.Position.Y + springTopTextureInfo.TextureSizef.Y;
                    _box.Min = _min;
                    _box.Max = _max;

                    // Check for collision with player
                    if (AppMain.GetPlayer().GetBottomBox().Overlaps(_box))
                    {
                        missedSpring = false;
                        AppMain.GetPlayer().DoJump();
                    }

                    // Update spring height
                    if (springCurrentHeight < springOriginalHeight)
                    {
                        springTopSprite.Position = new Vector2(springTopSprite.Position.X, springTopSprite.Position.Y + (speedPerCycle * 5));
                        springCurrentHeight     += (speedPerCycle * 5);
                        springSprite.Scale       = new Vector2(springSprite.Scale.X, springCurrentHeight / springOriginalHeight);
                        springSprite2.Scale      = new Vector2(springSprite2.Scale.X, springCurrentHeight / springOriginalHeight);
                    }

                    if (springCurrentHeight <= 55)
                    {
                        AppMain.GetSoundManager().PlayJump();
                    }

                    else
                    {
                        springReleased = false;
                    }
                }
            }
            else if (beingPushed)
            {
                WindSpring(speed);
            }

            Vector2 touchPos = AppMain.GetTouchPosition();

            if ((touchPos.X - 100 < springSprite.Position.X) &&
                (touchPos.X + 125 > springSprite2.Position.X + springWidth) &&
                (touchPos.Y - (springTopHeight / 5) > springTopSprite.Position.Y))        // Touching spring
            {
                PushSpring();
            }

            if (Touch.GetData(0).ToArray().Length <= 0)
            {
                ReleaseSpring(true);
            }

            if (magmaTrap && missedSpring && AppMain.GetPlayer().GetPos().X > springSprite2.Position.X + springTopWidth * 1.5)
            {
                AppMain.GetPlayer().KillByFire();
            }


            if (!magmaTrap && missedSpring && AppMain.GetPlayer().GetPos().X > springSprite2.Position.X + springTopWidth * 1.5)
            {
                AppMain.GetPlayer().KillByFire();
            }
        }
コード例 #26
0
        public void Render()
        {
            // =============== BEGINNING OF NEW STUFF =======================
            float x, y;
            float cosRot = FMath.Cos(Rotation);
            float sinRot = FMath.Sin(Rotation);

            // Point 1 - top left
            x           = -Width * Center.X;
            y           = -Height * Center.Y;
            vertices[0] = Position.X + (float)(x * cosRot - y * sinRot);        // x0
            vertices[1] = Position.Y + (float)(x * sinRot + y * cosRot);        // y0
            vertices[2] = Position.Z;                                           // z0

            // Point 2 - bottom left
            x           = -Width * Center.X;
            y           = Height * (1.0f - Center.Y);
            vertices[3] = Position.X + (float)(x * cosRot - y * sinRot);      // x1
            vertices[4] = Position.Y + (float)(x * sinRot + y * cosRot);      // y1
            vertices[5] = Position.Z;                                         // z1

            // Point 3 - top right
            x           = Width * (1.0f - Center.X);
            y           = -Height * Center.Y;
            vertices[6] = Position.X + (float)(x * cosRot - y * sinRot);        // x2
            vertices[7] = Position.Y + (float)(x * sinRot + y * cosRot);        // y2
            vertices[8] = Position.Z;                                           // z2

            // Point 4 - bottom right
            x            = Width * (1.0f - Center.X);
            y            = Height * (1.0f - Center.Y);
            vertices[9]  = Position.X + (float)(x * cosRot - y * sinRot);      // x3
            vertices[10] = Position.Y + (float)(x * sinRot + y * cosRot);      // y3
            vertices[11] = Position.Z;                                         // z3

            graphics.Enable(EnableMode.Blend);
            // "Original"
            if (!isBlended)
            {
                graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.SrcAlpha, BlendFuncFactor.OneMinusSrcAlpha);
            }

            // Something Cool
            //graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.SrcAlpha, BlendFuncFactor.DstAlpha);

            // Additive blending
            else
            {
                graphics.SetBlendFunc(BlendFuncMode.Add, BlendFuncFactor.SrcAlpha, BlendFuncFactor.One);
            }

            // ===============  END OF NEW STUFF ================================

            graphics.SetShaderProgram(shaderProgram);

            vertexBuffer.SetVertices(0, vertices);
            vertexBuffer.SetVertices(1, texcoords);
            vertexBuffer.SetVertices(2, colors);

            vertexBuffer.SetIndices(indices);
            graphics.SetVertexBuffer(0, vertexBuffer);
            graphics.SetTexture(0, texture);


            Matrix4 screenMatrix = new Matrix4(
                2.0f / graphics.Screen.Rectangle.Width, 0.0f, 0.0f, 0.0f,
                0.0f, -2.0f / graphics.Screen.Rectangle.Height, 0.0f, 0.0f,
                0.0f, 0.0f, 1.0f, 0.0f,
                -1.0f, 1.0f, 0.0f, 1.0f
                );

            shaderProgram.SetUniformValue(0, ref screenMatrix);

            graphics.DrawArrays(DrawMode.TriangleStrip, 0, indexSize);
            graphics.Disable(EnableMode.Blend);
        }
コード例 #27
0
        public override void Tick(float dt)
        {
            base.Tick(dt);

            GamePadData data = GamePad.GetData(0);

            float analogX = 0.0f;
            float analogY = 0.0f;


            //d-pad movement,emulating analog movement of the sticks
            if (Input2.GamePad0.Right.Down)
            {
                analogX = 1.0f;
            }
            else if (Input2.GamePad0.Left.Down)
            {
                analogX = -1.0f;
            }
            if (Input2.GamePad0.Up.Down)
            {
                analogY = -1.0f;
            }
            else if (Input2.GamePad0.Down.Down)
            {
                analogY = 1.0f;
            }


            //if the left stick is moving,then use values read from the stick
            if (data.AnalogLeftX > 0.2f || data.AnalogLeftX < -0.2f || data.AnalogLeftY > 0.2f || data.AnalogLeftY < -0.2f)
            {
                analogX = data.AnalogLeftX;
                analogY = data.AnalogLeftY;
            }


            //calculate the position


            /*if(analogX>0)
             * {
             *      Position = new Vector2 (Position.X + 0.1f, Position.Y);
             * }else if(analogX<0)
             * {
             *      Position = new Vector2 (Position.X - 0.1f, Position.Y);
             * }
             *
             * if(analogY>0)
             * {
             *      Position = new Vector2 (Position.X + Position.Y- 0.1f);
             * }else if(analogY<0)
             * {
             *      Position = new Vector2 (Position.X, Position.Y + 0.1f);
             * }*/
            Vector2 proposedChange;

            if (analogX != 0.0f)
            {
                proposedChange = new Vector2(analogX / 10f, 0.0f);
                if (!Collisions.checkWallsCollisions(this, MapManager.Instance.currentMap, ref proposedChange))
                {
                    Position += proposedChange;
                }
            }
            if (analogY != 0.0f)
            {
                proposedChange = new Vector2(0.0f, -analogY / 10f);
                if (!Collisions.checkWallsCollisions(this, MapManager.Instance.currentMap, ref proposedChange))
                {
                    Position += proposedChange;
                }
            }



            //rotate according to the right analog stick, or if it's not moving, then according the the left stick
            // so basically if you are not pointing the player in any direction with the right stick he is going to point in the walking direction
            //or if both sticks are not moving,then use the analogX and analogY values(d-pad movement)
            // OR do autoaim if enabled
            if (data.AnalogRightX > 0.2f || data.AnalogRightX < -0.2f || data.AnalogRightY > 0.2f || data.AnalogRightY < -0.2f)
            {
                var angleInRadians = FMath.Atan2(-data.AnalogRightX, -data.AnalogRightY);
                playerBodySprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians));
            }
            else if (!Game.autoAim && (data.AnalogLeftX > 0.2f || data.AnalogLeftX < -0.2f || data.AnalogLeftY > 0.2f || data.AnalogLeftY < -0.2f))
            {
                var angleInRadians = FMath.Atan2(-data.AnalogLeftX, -data.AnalogLeftY);
                playerBodySprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians));
            }
            else if (!Game.autoAim && (analogX != 0.0f || analogY != 0.0f))
            {
                var angleInRadians = FMath.Atan2(-analogX, -analogY);
                playerBodySprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians));
            }
            else if (Game.autoAim)
            {
                GameEntity e;
                if (Collisions.findNearestEnemy(Player.Instance, 8.0f, out e))
                {
                    Vector2 distance       = (Player.Instance.Position - e.Position).Normalize();
                    var     angleInRadians = FMath.Atan2(distance.X, -distance.Y);
                    playerBodySprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians));
                }
                else
                {
                    var angleInRadians = FMath.Atan2(-analogX, -analogY);
                    playerBodySprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians));
                }
            }
        }
コード例 #28
0
        private static List <int> CombinePath(List <int> path1, List <int> path2,
                                              List <PatchVertex> vertices1,
                                              List <PatchVertex> vertices2,
                                              PatchSection section1, PatchSection section2,
                                              Dictionary <PointF, int> p2i)
        {
            List <int> path = new List <int>();

            HashSet <int> sectionIndices1 = new HashSet <int>();

            for (int i = section1.First; i < section1.First + section1.Length; i++)
            {
                sectionIndices1.Add(i);
            }

            HashSet <int> sectionIndices2 = new HashSet <int>();

            for (int i = section2.First; i < section2.First + section2.Length; i++)
            {
                sectionIndices2.Add(i);
            }

            HashSet <PointF> pathPoints = new HashSet <PointF>();

            // 切り口の端からパスを登録していく.  切り口の両端は必ずpathに含まれている。と思う
            for (int _i = section1.First + section1.Length; _i != section1.First + 1; _i = FMath.Rem(_i + 1, path1.Count))
            {
                int i = path1[_i];
                if (sectionIndices1.Contains(i))
                {
                    continue;
                }
                path.Add(p2i[vertices1[i].position]);
                pathPoints.Add(vertices1[i].position);
            }

            PointF path1_preendPt = vertices1[path1[FMath.Rem(section1.First - 1, path1.Count)]].position;
            PointF path1_endPt    = vertices1[path1[FMath.Rem(section1.First, path1.Count)]].position;

            int path2_start = -1;

            for (int i = 0; i < path2.Count; i++)
            {
                if (vertices2[path2[i]].position == path1_endPt)
                {
                    path2_start = i;
                    break;
                }
            }

            if (path2_start < 0)
            {
                return(new List <int>());
            }

            int    path2_poststart   = FMath.Rem(path2_start + 1, path2.Count);
            PointF path2_poststartPt = vertices2[path2[path2_poststart]].position;
            int    dir = 1;

            if (path2_poststartPt == path1_preendPt)
            {
                dir = -1;
            }

            for (int i = path2_start + dir; ; i += dir)
            {
                PointF pt = vertices2[path2[FMath.Rem(i, path2.Count)]].position;
                if (path.Contains(p2i[pt]))
                {
                    break;
                }
                path.Add(p2i[pt]);
            }

            return(path);
        }
コード例 #29
0
ファイル: BasicMeshFactory.cs プロジェクト: weimingtom/Sakura
        static private bool createSphereVertex(
            MeshData mesh,
            float radius,
            int div
            )
        {
            if (div <= 0 || radius <= 0)
            {
                return(false);
            }

            int   i_stacks = div;
            int   i_slices = div;
            float i_radius = radius;

            float a_st_now     = 0;
            float a_stack_step = (float)(FMath.PI / (i_stacks - 1));

            int idx = 0;

            for (int i = 0; i < i_stacks; i++)
            {
                float a_s = (float)FMath.Sin(a_st_now);
                float ny  = (float)FMath.Cos(a_st_now);
                float py  = i_radius * ny;

                float a_sl_now     = 0;
                float a_slice_step = (float)((FMath.PI * 2) / (i_slices - 1));

                for (int j = 0; j < i_slices; j++)
                {
                    float nx = (float)FMath.Cos(FMath.PI * 2 - a_sl_now) * a_s;
                    float nz = (float)FMath.Sin(FMath.PI * 2 - a_sl_now) * a_s;

                    float px = i_radius * nx;
                    float pz = i_radius * nz;

                    mesh.Positions[(idx * 3) + 0] = px;
                    mesh.Positions[(idx * 3) + 1] = py;
                    mesh.Positions[(idx * 3) + 2] = pz;

                    // Normals
                    mesh.Normals[(idx * 3) + 0] = nx;
                    mesh.Normals[(idx * 3) + 1] = ny;
                    mesh.Normals[(idx * 3) + 2] = nz;

                    // Tangents
                    float len = (float)FMath.Sqrt(nx * nx + nz * nz);
                    mesh.Tangents[(idx * 3) + 0] = nz / len;
                    mesh.Tangents[(idx * 3) + 1] = 0;
                    mesh.Tangents[(idx * 3) + 2] = -nx / len;

                    // Singularities
                    if (nz == 0.0f && nx == 0.0f)
                    {
                        mesh.Tangents[(idx * 3) + 0] = (float)FMath.Cos(a_sl_now);
                        mesh.Tangents[(idx * 3) + 1] = 0;
                        mesh.Tangents[(idx * 3) + 2] = (float)FMath.Sin(a_sl_now);
                    }

                    float u = 1.0f / (i_slices - 1) * j;
                    float v = 1.0f / (i_stacks - 1) * i;

                    mesh.TexCoords[(idx * 2) + 0] = u;
                    mesh.TexCoords[(idx * 2) + 1] = v;

                    a_sl_now += a_slice_step;
                    idx++;
                }
                a_st_now += a_stack_step;
            }
            return(true);
        }
コード例 #30
0
ファイル: AnimationUtility.cs プロジェクト: weimingtom/Sakura
 public static float EaseInOutSineInterpolator(float from, float to, float ratio)
 {
     ratio = FMath.Clamp(ratio, 0f, 1f);
     return((float)((double)(-(double)(to - from) / 2f) * (Math.Cos(3.1415926535897931 * (double)ratio) - 1.0) + (double)from));
 }