Exemplo n.º 1
0
 private void tileClicked(FlipTile tileData)
 {
     m_isFlipped = !m_isFlipped;
     if (m_isFlipped)
     {
         m_backMaterial.Brush = tileData.FrontBrush;
     }
 }
Exemplo n.º 2
0
        private void setup3D()
        {
            PerspectiveCamera camera = new PerspectiveCamera(
                new Point3D(0, 0, 3.73), //position
                new Vector3D(0, 0, -1),  //lookDirection
                new Vector3D(0, 1, 0),   //upDirection
                30                       //FOV
                );

            WrappedElement.Camera = camera;

            Model3DGroup everything = new Model3DGroup();

            Model3DGroup     lights     = new Model3DGroup();
            DirectionalLight whiteLight = new DirectionalLight(Colors.White, new Vector3D(0, 0, -1));

            lights.Children.Add(whiteLight);

            everything.Children.Add(lights);

            ModelVisual3D model = new ModelVisual3D();

            double tileSizeX = 2.0 / c_xCount;
            double startX    = -((double)c_xCount) / 2 * tileSizeX + tileSizeX / 2;
            double startY    = -((double)c_yCount) / 2 * tileSizeX + tileSizeX / 2;

            int index;

            Size tileTextureSize = new Size(1.0 / c_xCount, 1.0 / c_yCount);

            //so, tiles are numbers, left-to-right (ascending x), bottom-to-top (ascending y)
            for (int y = 0; y < c_yCount; y++)
            {
                for (int x = 0; x < c_xCount; x++)
                {
                    index = y * c_xCount + x;

                    Rect backTextureCoordinates = new Rect(
                        x * tileTextureSize.Width,

                        // this will give you a headache. Exists since we are going
                        // from bottom bottomLeft of 3D space (negative Y is down),
                        // but texture coor are negative Y is up
                        1 - y * tileTextureSize.Height - tileTextureSize.Height,

                        tileTextureSize.Width, tileTextureSize.Height);

                    m_tiles[index] = new FlipTile(
                        getMaterial(index),
                        new Size(tileSizeX, tileSizeX),
                        new Point(startX + x * tileSizeX, startY + y * tileSizeX),
                        m_backMaterial,
                        backTextureCoordinates);

                    m_tiles[index].Click += (sender, args) => tileClicked((FlipTile)sender);

                    WrappedElement.Children.Add(m_tiles[index]);
                }
            }

            model.Content = everything;

            WrappedElement.Children.Add(model);

            //start the per-frame tick for the physics
            m_listener.StartListening();
        }