/// <summary>
        /// Builds the standard scene.
        /// </summary>
        /// <param name="newScene">The scenegraph to be updated.</param>
        /// <param name="newCamera">The camera to be updated.</param>
        public static void BuildStandardFloor(SceneManipulator manipulator, string sceneLayer)
        {
            SceneLayer bgLayer = manipulator.AddLayer("BACKGROUND");

            manipulator.SetLayerOrderID(bgLayer, 0);
            manipulator.SetLayerOrderID(Scene.DEFAULT_LAYER_NAME, 1);
            ResourceLink sourceBackgroundTexture = new AssemblyResourceLink(
                typeof(SeeingSharpSampleResources),
                "Textures.Background.dds");
            ResourceLink sourceTileTexture = new AssemblyResourceLink(
                typeof(SeeingSharpSampleResources),
                "Textures.Floor.dds");

            var resBackgroundTexture = manipulator.AddTexture(sourceBackgroundTexture);

            manipulator.Add(new FullscreenTextureObject(resBackgroundTexture), bgLayer.Name);

            // Define textures and materials
            var resTileTexture  = manipulator.AddResource(() => new StandardTextureResource(sourceTileTexture));
            var resTileMaterial = manipulator.AddResource(() => new SimpleColoredMaterialResource(resTileTexture));

            // Define floor geometry
            FloorType floorType = new FloorType(new Vector2(4f, 4f), 0f);

            floorType.BottomMaterial       = resTileMaterial;
            floorType.DefaultFloorMaterial = resTileMaterial;
            floorType.SideMaterial         = resTileMaterial;
            floorType.SetTilemap(25, 25);

            // Add floor to scene
            var resFloorGeometry = manipulator.AddResource((() => new GeometryResource(floorType)));
            var floorObject      = manipulator.AddGeneric(resFloorGeometry, sceneLayer);
        }
        /// <summary>
        /// Builds the demo scene.
        /// </summary>
        /// <param name="manipulator">Current scene manipulator object.</param>
        /// <param name="sideLength">The side length of the pallet cube.</param>
        /// <param name="camera">The camera to be manipulated too.</param>
        private static void BuildPalletCubes(SceneManipulator manipulator, NamedOrGenericKey[] resPalletGeometrys, int sideLength)
        {
            // Build the scene
            Vector3 startPosition = new Vector3(-sideLength * SPACE_X / 2f, 0f, -sideLength * SPACE_Z / 2f);
            Random  randomizer    = new Random(Environment.TickCount);

            for (int loopX = 0; loopX < sideLength; loopX++)
            {
                for (int loopY = 0; loopY < sideLength; loopY++)
                {
                    for (int loopZ = 0; loopZ < sideLength; loopZ++)
                    {
                        GenericObject palletObject = new GenericObject(
                            resPalletGeometrys[randomizer.Next(0, resPalletGeometrys.Length)],
                            new Vector3(loopX * SPACE_X, loopY * SPACE_Y, loopZ * SPACE_Z) + startPosition);
                        palletObject.Color = POSSIBLE_COLORS[randomizer.Next(0, POSSIBLE_COLORS.Length)];
                        palletObject.EnableShaderGeneratedBorder();
                        manipulator.Add(palletObject);

                        // Define animation
                        palletObject.BuildAnimationSequence()
                        .Delay(randomizer.Next(100, 1000))
                        .Apply();
                        palletObject.BuildAnimationSequence()
                        .Scale3DTo(0.5f, TimeSpan.FromSeconds(2.0))
                        .WaitFinished()
                        .Scale3DTo(1f, TimeSpan.FromSeconds(2.0))
                        .ApplyAndRewind();
                    }
                }
            }
        }
        /// <summary>
        /// Attaches this component to a scene.
        /// Be careful, this method gets called from a background thread of seeing#!
        /// It may also be called from multiple scenes in parallel or simply withoud previous Detach call.
        /// </summary>
        /// <param name="manipulator">The manipulator of the scene we attach to.</param>
        /// <param name="correspondingView">The view which attached this component.</param>
        protected override PerSceneContext Attach(SceneManipulator manipulator, ViewInformation correspondingView)
        {
            PerSceneContext context = new PerSceneContext();

            switch (m_gradientDirection)
            {
            case GradientDirection.LeftToRight:
                context.BrushResource = new LinearGradientBrushResource(
                    new System.Numerics.Vector2(0f, 0f),
                    new System.Numerics.Vector2(m_textureWidth, 0f),
                    new GradientStop[]
                {
                    new GradientStop(m_colorStart, 0f),
                    new GradientStop(m_colorEnd, 1f)
                });
                break;

            case GradientDirection.TopToBottom:
                context.BrushResource = new LinearGradientBrushResource(
                    new System.Numerics.Vector2(0f, 0f),
                    new System.Numerics.Vector2(0f, m_textureHeight),
                    new GradientStop[]
                {
                    new GradientStop(m_colorStart, 0f),
                    new GradientStop(m_colorEnd, 1f)
                });
                break;

            case GradientDirection.Directional:
                context.BrushResource = new LinearGradientBrushResource(
                    new System.Numerics.Vector2(0f, 0f),
                    new System.Numerics.Vector2(m_textureWidth, m_textureHeight),
                    new GradientStop[]
                {
                    new GradientStop(m_colorStart, 0f),
                    new GradientStop(m_colorEnd, 1f)
                });
                break;
            }

            // Create the background layer if not available already
            base.CreateLayerIfNotAvailable(manipulator);

            // Create and add the background
            context.BackgroundTextureKey = manipulator.AddResource(
                () => new Direct2DSingleRenderTextureResource(context.BrushResource, m_textureWidth, m_textureHeight));
            context.BackgroundPainter         = new FullscreenTextureObject(context.BackgroundTextureKey);
            context.BackgroundPainter.Scaling = 1.1f;
            manipulator.Add(context.BackgroundPainter, DEFAULT_LAYER);

            return(context);
        }
Esempio n. 4
0
        /// <summary>
        /// Builds the demo scene.
        /// </summary>
        /// <param name="manipulator">Current scene manipulator object.</param>
        /// <param name="sideLength">The side length of the pallet cube.</param>
        /// <param name="camera">The camera to be manipulated too.</param>
        private static void BuildPalletCubes(SceneManipulator manipulator, NamedOrGenericKey[] resPalletGeometrys, int sideLength)
        {
            // Build the scene
            Vector3 startPosition = new Vector3(-sideLength * SPACE_X / 2f, 0f, -sideLength * SPACE_Z / 2f);
            Random  randomizer    = new Random(Environment.TickCount);

            for (int loopX = 0; loopX < sideLength; loopX++)
            {
                for (int loopY = 0; loopY < sideLength; loopY++)
                {
                    for (int loopZ = 0; loopZ < sideLength; loopZ++)
                    {
                        GenericObject palletObject = new GenericObject(
                            resPalletGeometrys[randomizer.Next(0, resPalletGeometrys.Length)],
                            new Vector3(loopX * SPACE_X, loopY * SPACE_Y, loopZ * SPACE_Z) + startPosition);
                        palletObject.Color = POSSIBLE_COLORS[randomizer.Next(0, POSSIBLE_COLORS.Length)];
                        palletObject.EnableShaderGeneratedBorder();
                        palletObject.IsStatic = true;
                        manipulator.Add(palletObject);
                    }
                }
            }
        }
        /// <summary>
        /// This method is called after the scene was created.
        /// Be carefull: This method run's in 3D-Engines update thread.
        /// </summary>
        /// <param name="manipulator">The manipulator.</param>
        private void OnBodyScene_Initialize(SceneManipulator manipulator)
        {
            SceneLayer bgLayer = manipulator.AddLayer("BACKGROUND");
            manipulator.SetLayerOrderID(bgLayer, 0);
            manipulator.SetLayerOrderID(Scene.DEFAULT_LAYER_NAME, 1);

            ResourceLink sourceWallTexture = new Uri(
                "/SeeingSharp.ModelViewer;component/Resources/Textures/Background.png",
                UriKind.Relative);
            var resBackgroundTexture = manipulator.AddTexture(sourceWallTexture);
            manipulator.Add(new TexturePainter(resBackgroundTexture), bgLayer.Name);

            FloorType floorType = new FloorType(new Vector2(3f, 3f), 0.1f);
            floorType.SetTilemap(40, 40);
            floorType.DefaultFloorMaterial = manipulator.AddSimpleColoredMaterial(new Uri(
                "/SeeingSharp.ModelViewer;component/Resources/Textures/Floor.png",
                UriKind.Relative));
            var resGeometry = manipulator.AddResource<GeometryResource>(() => new GeometryResource(floorType));
            GenericObject floorObject = manipulator.AddGeneric(resGeometry);
            floorObject.IsPickingTestVisible = false;
        }
        /// <summary>
        /// Builds up the given screen on the given SceneManipulator.
        /// </summary>
        /// <param name="manipulator">The manipulator.</param>
        /// <param name="currentScreen">The screen to be build.</param>
        private void BuildScreen(SceneManipulator manipulator, ScreenData currentScreen)
        {
            int tilesX = m_currentLevel.Tilemap.TilesX;
            int tilesY = m_currentLevel.Tilemap.TilesY;
            float tileDistX = Constants.TILE_DISTANCE_X;
            float tileDistY = -Constants.TILE_DISTANCE_Y;
            Vector3 midPoint = new Vector3((tilesX - 1) * tileDistX / 2f, 0f, ((tilesY - 1) * tileDistY / 2f));

            foreach (CardPairData actPairData in currentScreen.MemoryPairs)
            {
                CardPairLogic actCardPair = new CardPairLogic(actPairData);

                // Define all resources needed for a card for this pair
                var resTitleMaterial = manipulator.AddSimpleColoredMaterial(actPairData.TitleFile);
                var resGeometry1 = manipulator.AddGeometry(new CardObjectType()
                {
                    FrontMaterial = resTitleMaterial,
                    BackMaterial = m_resBackgroundMaterial1
                });
                var resGeometry2 = manipulator.AddGeometry(new CardObjectType()
                {
                    FrontMaterial = resTitleMaterial,
                    BackMaterial = m_resBackgroundMaterial2
                });

                // Create both cards for this pair
                Card cardA = new Card(resGeometry1, actCardPair);
                Card cardB = new Card(resGeometry2, actCardPair);
                Tuple<int, int> slotA = SearchFreeCardSlot(m_currentLevel, m_cardMapOnScreen);
                m_cardMapOnScreen[slotA.Item1, slotA.Item2] = cardA;
                Tuple<int, int> slotB = SearchFreeCardSlot(m_currentLevel, m_cardMapOnScreen);
                m_cardMapOnScreen[slotB.Item1, slotB.Item2] = cardB;

                // Add both cards to the scene
                cardA.Position = new Vector3(slotA.Item1 * tileDistX, 0f, slotA.Item2 * tileDistY) - midPoint;
                cardA.AccentuationFactor = 1f;
                cardB.Position = new Vector3(slotB.Item1 * tileDistX, 0f, slotB.Item2 * tileDistY) - midPoint;
                cardB.AccentuationFactor = 1f;
                manipulator.Add(cardA);
                manipulator.Add(cardB);

                // Assigns the cards to the pair object
                actCardPair.Cards = new Card[] { cardA, cardB };
                manipulator.Add(actCardPair);

                m_cardPairsOnScreen.Add(actCardPair);
            }
        }