Example #1
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            simpleEffect = new SimpleEffect(GraphicsDevice)
            {
                Texture = UVTexture
            };

            primitives = new List <GeometricPrimitive>();

            // Creates all primitives
            primitives = new List <GeometricPrimitive>
            {
                GeometricPrimitive.Plane.New(GraphicsDevice),
                GeometricPrimitive.Cube.New(GraphicsDevice),
                GeometricPrimitive.Sphere.New(GraphicsDevice),
                GeometricPrimitive.GeoSphere.New(GraphicsDevice),
                GeometricPrimitive.Cylinder.New(GraphicsDevice),
                GeometricPrimitive.Torus.New(GraphicsDevice),
                GeometricPrimitive.Teapot.New(GraphicsDevice)
            };


            view = Matrix.LookAtRH(new Vector3(0, 0, 5), new Vector3(0, 0, 0), Vector3.UnitY);

            Window.AllowUserResizing = true;
        }
Example #2
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var view       = Matrix.LookAtRH(new Vector3(2, 2, 2), new Vector3(0, 0, 0), Vector3.UnitY);
            var projection = Matrix.PerspectiveFovRH((float)Math.PI / 4.0f, (float)GraphicsDevice.BackBuffer.ViewWidth / GraphicsDevice.BackBuffer.ViewHeight, 0.1f, 100.0f);

            worldViewProjection = Matrix.Multiply(view, projection);

            geometry     = GeometricPrimitive.Cube.New(GraphicsDevice);
            simpleEffect = new SimpleEffect(GraphicsDevice)
            {
                Texture = UVTexture
            };

            // TODO DisposeBy is not working with device reset
            offlineTarget0 = Texture.New2D(GraphicsDevice, 512, 512, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this);

            offlineTarget1 = Texture.New2D(GraphicsDevice, 512, 512, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this);
            offlineTarget2 = Texture.New2D(GraphicsDevice, 512, 512, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget).DisposeBy(this);

            depthBuffer = Texture.New2D(GraphicsDevice, 512, 512, PixelFormat.D16_UNorm, TextureFlags.DepthStencil).DisposeBy(this);

            width  = GraphicsDevice.BackBuffer.ViewWidth;
            height = GraphicsDevice.BackBuffer.ViewHeight;
        }
Example #3
0
        internal ModelMesh(Mesh sourceMesh, Device device, VertexBuffer vertexBuffer, int numVertices,
                           IndexBuffer indexBuffer, int primitiveCount,
                           Matrix3D world, Material material)
        {
            SourceMesh      = sourceMesh;
            _device         = device;
            _vertexBuffer   = vertexBuffer;
            _numVertices    = numVertices;
            _indexBuffer    = indexBuffer;
            _primitiveCount = primitiveCount;

            _effect = new SimpleEffect(device)
            {
                World             = world,
                AmbientLightColor = new ColorRgbF(0.1f, 0.1f, 0.1f),
                DiffuseColor      = material.DiffuseColor,
                SpecularColor     = material.SpecularColor,
                SpecularPower     = material.Shininess,
                Alpha             = material.Transparency
            };
            if (!string.IsNullOrEmpty(material.DiffuseTextureName))
            {
                _effect.DiffuseTexture = Texture.FromFile(device, material.DiffuseTextureName, Usage.None, Pool.Default);
            }
            _effect.CurrentTechnique = "RenderScene";
            Opaque = (material.Transparency == 1.0f);
        }
 public SteamParticlesSystem(int particlesPerSecond, SimpleEffect effect, Texture texture, Camera camera)
 {
     ParticlesPerSecond = particlesPerSecond;
     this.effect        = effect;
     this.texture       = texture;
     Camera             = camera;
 }
Example #5
0
 public SkyBox(Model skybox, Texture texture, SimpleEffect effect)
 {
     _skyBox  = skybox;
     _texture = texture;
     _effect  = effect;
     //Scale = new Vector3(30);
 }
Example #6
0
        public Cylinder(GraphicsDeviceManager graphics, SimpleEffect effect, Color c, float raius, float height, int n) : base(effect)
        {
            Vector3[] pos     = new Vector3[2 * (n + 1)];
            Vector3[] normals = new Vector3[pos.Length];
            height    /= 2;
            pos[0]     = Vector3.Up * height;
            normals[0] = Vector3.Up;

            pos[pos.Length - 1]     = Vector3.Down * height;
            normals[pos.Length - 1] = Vector3.Down;

            float _pi  = (float)Math.PI;
            float _2pi = _pi * 2f;

            for (int i = 0; i < n; i++)
            {
                Vector3 norm = new Vector3();
                float   a2   = _2pi * (float)(i + 1) / n;
                float   z    = (float)Math.Sin(a2);
                float   x    = (float)Math.Cos(a2);
                norm.X = x;
                norm.Z = z;
                norm.Normalize();
                pos[i + 1]     = new Vector3(x * raius, height, z * raius);
                pos[i + 1 + n] = new Vector3(x * raius, -height, z * raius);
                normals[i + 1] = normals[i + 1 + n] = norm;
            }

            var vertexes = new List <VertexPositionColorNormal>();

            for (int i = 0; i < n; i++)
            {
                //top
                vertexes.Add(new VertexPositionColorNormal(pos[0], c, Vector3.Up));
                vertexes.Add(new VertexPositionColorNormal(pos[(i + 1)], c, Vector3.Up));
                vertexes.Add(new VertexPositionColorNormal(pos[(i + 1) % n + 1], c, Vector3.Up));
                //bottom
                vertexes.Add(new VertexPositionColorNormal(pos[pos.Length - 1], c, Vector3.Down));
                vertexes.Add(new VertexPositionColorNormal(pos[(i + 1) % n + 1 + n], c, Vector3.Down));
                vertexes.Add(new VertexPositionColorNormal(pos[i + 1 + n], c, Vector3.Down));

                //
                int i1  = i + 1,
                    n1  = n + 1,
                    i1n = i + 1 + n,
                    imn = (i + 1) % n;

                vertexes.Add(new VertexPositionColorNormal(pos[i1], c, normals[i1]));
                vertexes.Add(new VertexPositionColorNormal(pos[i1n], c, normals[i1n]));
                vertexes.Add(new VertexPositionColorNormal(pos[imn + n1], c, normals[imn + n1]));

                vertexes.Add(new VertexPositionColorNormal(pos[i1], c, normals[i1]));
                vertexes.Add(new VertexPositionColorNormal(pos[imn + n1], c, normals[imn + n1]));
                vertexes.Add(new VertexPositionColorNormal(pos[imn + 1], c, normals[imn + 1]));
            }
            Vertices = vertexes.ToArray();
        }
Example #7
0
 protected override EffectPass SetEffectVariableGetPass(SimpleEffect effect)
 {
     effect.Texture          = Texture;
     effect.TextureLoaded    = Texture == null ? 0 : 1;
     effect.CurrentTechnique = effect.Techniques["Bilboard"];
     //wasLightEnabled = effect.LightsEnabled;
     //effect.LightsEnabled = false;
     return(effect.CurrentTechnique.Passes["Pass1"]);
 }
Example #8
0
        public BilboardModel(SimpleEffect effect, Texture texture) : base(effect)
        {
            Vertices = new BilboardVertex[6];

            Vector3 position = new Vector3(0.5f, 0, 0);

            Vertices[0] = new BilboardVertex(position, new Vector2(0));
            Vertices[1] = new BilboardVertex(position, new Vector2(1, 0));
            Vertices[2] = new BilboardVertex(position, new Vector2(1));

            Vertices[3] = new BilboardVertex(position, new Vector2(0));
            Vertices[4] = new BilboardVertex(position, new Vector2(1));
            Vertices[5] = new BilboardVertex(position, new Vector2(0, 1));
            Texture     = texture;
        }
Example #9
0
        public static Contract Build()
        {
            var main = MagicBag.Bag.main;

            var price         = 100 * main.Difficulty;
            var triggerTime   = 5 * main.Difficulty;
            var triggerAmount = 1000 * main.Difficulty;
            var comboAmount   = 1.5m * main.Difficulty;
            var penaltyAmount = triggerAmount * 10 * main.Difficulty;

            var cashTrigger = new CashTrigger(CashTriggerKey.Contracts, triggerTime, TimeUnit.Minute, triggerAmount, "");
            var bonus       = new SimpleEffect(comboAmount, (customer, amount) => amount + (main.PositiveCombo * comboAmount));
            var penalty     = new SimpleEffect(penaltyAmount, (customer, amount) => amount + penaltyAmount);

            return(new Contract(price, cashTrigger, bonus, penalty));
        }
Example #10
0
        private void AddPlanetoids(List <IComponet> gameObjects, SimpleEffect effect)
        {
            Random r = new Random();

            for (int i = 0; i < 200; i++)
            {
                Vector3 pos = new Vector3((float)(r.NextDouble() * 2 - 1), (float)(r.NextDouble() * 2 - 1), (float)(r.NextDouble() * 2 - 1));
                pos.Normalize();
                pos = pos * (r.Next() % 10 + 35);
                Vector3 scale = new Vector3((float)(r.NextDouble() + 1));
                gameObjects.Add(new BilboardModel(effect, Content.Load <Texture2D>($"inne/stones/stone{r.Next() % 4 + 1}"))
                {
                    Position = pos,
                    Scale    = scale
                });
            }
        }
Example #11
0
        internal ModelMesh(Mesh sourceMesh, Device device, VertexBuffer vertexBuffer, int numVertices,
                           IndexBuffer indexBuffer, int primitiveCount,
                           Matrix3D world, Material material)
        {
            SourceMesh      = sourceMesh;
            _device         = device;
            _vertexBuffer   = vertexBuffer;
            _numVertices    = numVertices;
            _indexBuffer    = indexBuffer;
            _primitiveCount = primitiveCount;

            _effect = new SimpleEffect(device)
            {
                World             = world,
                AmbientLightColor = new ColorRgbF(0.1f, 0.1f, 0.1f),
                DiffuseColor      = material.DiffuseColor,
                SpecularColor     = material.SpecularColor,
                SpecularPower     = material.Shininess,
                Alpha             = material.Transparency
            };
            _effect.CurrentTechnique = "RenderScene";
            Opaque = (material.Transparency == 1.0f);
        }
Example #12
0
 public CustomModel(SimpleEffect effect)
 {
     Effect = effect;
     Initialize();
 }
Example #13
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            basicFont   = Content.Load <SpriteFont>("FontDesc");
            // GUI
            sampler      = graphics.GraphicsDevice.SamplerStates[0].CopySampler();
            sampler.Name = "custom sampler";

            GuiMenu menu = new GuiMenu(spriteBatch, basicFont, this);

            menu.MultiSamplingChange.Checked    = graphics.PreferMultiSampling;
            menu.MultiSampleAntiAliasingChange += (s, e) =>
            {
                graphics.PreferMultiSampling = e;
                graphics.ApplyChanges();
            };

            menu.Select.OnSelectionChanged += (s, e) =>
            {
                graphics.PreferredBackBufferHeight = e.Height;
                graphics.PreferredBackBufferWidth  = e.Width;
                graphics.IsFullScreen = e.IsFullScreen;

                graphics.ApplyChanges();
            };

            Func <TextureFilter> getFilter = () =>
            {
                if (menu.LinearMipFilterCheckBox.Checked)
                {
                    if (menu.LinearMagFilterCheckBox.Checked)
                    {
                        return(TextureFilter.Linear);
                    }
                    return(TextureFilter.PointMipLinear);
                }
                else
                {
                    if (menu.LinearMagFilterCheckBox.Checked)
                    {
                        return(TextureFilter.LinearMipPoint);
                    }
                    return(TextureFilter.Point);
                }
            };

            sampler.Filter = getFilter();
            menu.LinearMipFilterCheckBox.OnCheckChanged += (s, e) =>
            {
                sampler.Dispose();
                sampler        = sampler.CopySampler();
                sampler.Filter = getFilter();
            };
            menu.LinearMagFilterCheckBox.OnCheckChanged += (s, e) =>
            {
                sampler.Dispose();
                sampler        = sampler.CopySampler();
                sampler.Filter = getFilter();
            };



            menu.MinMapLevelOfDetailsBiasPicker.OnValueChange += (s, e) =>
            {
                if (e >= 16)
                {
                    return;
                }
                sampler.Dispose();
                sampler = sampler.CopySampler();
                sampler.MipMapLevelOfDetailBias = e;
            };
            menu.DrawOrder = 100;
            Components.Add(menu);
            //
            effect = new SimpleEffect(graphics, Content.Load <Effect>("Shaders/Simple"));
            var light = new Light
            {
                Color     = new Color(255, 255, 255, 255),
                Type      = GK3D.Components.SceneObjects.LightType.Directional,
                Direction = new Vector3(-1, -1, 0),
                KDiffuse  = 0.8f,
                Power     = 1f,
                KSpecular = 0.5f
            };

            effect.AddLight(light);
            var shipTexture = Content.Load <Texture2D>("Rocket_Ship_v1_L3.123c485c9e1d-6d02-47cf-b751-9606e55c8fa1/10475_Rocket_Ship_v1_Diffuse");
            var spaceship1  = Content.LoadXnaModel("Rocket_Ship_v1_L3.123c485c9e1d-6d02-47cf-b751-9606e55c8fa1/10475_Rocket_Ship_v1_L3", effect);
            var spaceship2  = Content.LoadXnaModel("Rocket_Ship_v1_L3.123c485c9e1d-6d02-47cf-b751-9606e55c8fa1/10475_Rocket_Ship_v1_L3", effect);
            var satelite2   = Content.LoadXnaModel("Satellite", effect);
            var satelite3   = Content.LoadXnaModel("Satellite", effect);
            var mars        = Content.LoadXnaModel("mars/Mars 2K", effect);

            mars.Texture       = Content.Load <Texture2D>("mars/Textures/Diffuse_2K");
            mars.Scale         = new Vector3(5.55f);
            spaceship1.Texture = shipTexture;
            spaceship2.Texture = shipTexture;

            var sph1 = Content.LoadXnaModel("mars/Mars 2K", effect);

            sph1.Textures.Add(Content.Load <Texture2D>("inne/BaseTexture"));
            sph1.Textures.Add(Content.Load <Texture2D>("inne/mesh"));
            sph1.Textures.Add(Content.Load <Texture2D>("inne/Alfa-Romeo-logo-1982-1920x1080"));
            sph1.AddComponent(new SwapBaseTextureComponent(sph1,
                                                           Content.Load <Texture2D>("inne/BaseTexture2"),
                                                           Content.Load <Texture2D>("inne/BaseTexture3"), Content.Load <Texture2D>("inne/BaseTexture")));

            var sph2 = Content.LoadXnaModel("mars/Mars 2K", effect);

            sph2.Texture = Content.Load <Texture2D>("inne/BaseTexture");
            sph2.Textures.Add(Content.Load <Texture2D>("inne/mesh"));

            sph1.Position = new Vector3(5, 19, 0);
            sph2.Position = new Vector3(-5, 19, 0);

            var  planet = new Sphere(graphics, effect, new Color(26, 86, 216, 255), 20, 40, 40);
            Cube cube1  = new Cube(graphics, effect, 3, Color.DeepPink);

            cube1.Position = new Vector3(0, 0, planet.Radius);
            cube1.Scale    = new Vector3(0.5f);
            cube1.Rotation = new Vector3(30f);

            Cylinder cylinder1 = new Cylinder(graphics, effect, new Color(75, 198, 13, 255), 1.5f, 4, 6);

            cylinder1.Rotation = new Vector3(90, 0, 30);
            var pos = new Vector3(60, 15, -15);

            pos.Normalize();
            pos *= planet.Radius;
            cylinder1.Position = pos;

            spaceship1.Effect   = effect;
            spaceship1.Scale    = new Vector3(0.02f);
            spaceship1.Position = new Vector3(6, -(planet.Radius + 10), -8);

            spaceship2.Effect   = effect;
            spaceship2.Scale    = new Vector3(0.02f);
            spaceship2.Position = new Vector3(-(planet.Radius + 6), planet.Radius, 10);

            satelite2.Effect   = effect;
            satelite2.Scale    = new Vector3(5, 5, 5);
            satelite2.Position = new Vector3(planet.Radius + 6, planet.Radius, 0);

            satelite3.Effect   = effect;
            satelite3.Scale    = new Vector3(5, 5, 5);
            satelite3.Position = new Vector3(10, -6, planet.Radius + 10);

            var connector = new Cylinder(graphics, effect, Color.Red, 1, 6, 14)
            {
                Position = new Vector3(0, 20, 0),
                Rotation = new Vector3(0, 0, 1.6f)
            };

            var dir = (connector.Position - satelite2.Position);

            dir.Normalize();
            Light lightSat2 = new Light()
            {
                Color     = new Color(0, 100, 190, 255),
                Type      = GK3D.Components.SceneObjects.LightType.Spot,
                Position  = satelite2.Position,
                Direction = dir,
                KDiffuse  = 0.8f,
                Power     = 1f,
                KSpecular = 0.5f
            };

            var dir2 = (cube1.Position - satelite3.Position);

            dir2.Normalize();
            Light lightSat3 = new Light()
            {
                Color     = new Color(175, 216, 26, 255),
                Type      = GK3D.Components.SceneObjects.LightType.Spot,
                Position  = satelite3.Position,
                Direction = dir2,
                KDiffuse  = 0.8f,
                Power     = 1f,
                KSpecular = 0.5f
            };


            effect.AddLight(lightSat2);
            effect.AddLight(lightSat3);
            Camera camera = new Camera()
            {
                Position = new Vector3(0, 0, 60),
            };

            monitorCamera = new Camera()
            {
                Position = new Vector3(6, 20, 16)
            };
            //skybox
            var    cube      = Content.Load <TextureCube>("SunInSpace/skybox");
            Model  cubemodel = Content.Load <Model>("SunInSpace/cube2");
            SkyBox skybox    = new SkyBox(cubemodel, cube, effect)
            {
                Camera = camera
            };

            lightSat2.AddComponent(new LightAnimatorCommponent(lightSat2, effect));

            EkranModel tb = new EkranModel(effect);

            tb.Position = cube1.Position + new Vector3(0, 0, cube1.a);
            tb.Scale    = new Vector3(3);
            tb.AddComponent(new TelebimTextureControllerComponent(tb));

            EnvMappingModel envmodel = Content.LoadEnvMappingModel("Rocket_Ship_v1_L3.123c485c9e1d-6d02-47cf-b751-9606e55c8fa1/10475_Rocket_Ship_v1_L3", effect);

            envmodel.Texture  = cube;
            envmodel.Scale    = new Vector3(0.02f);
            envmodel.Position = new Vector3(30, 30, -10);
            SteamParticlesSystem ps = new SteamParticlesSystem(50, effect, Content.Load <Texture2D>("inne/para2"), camera);

            ps.Position = connector.Position;
            var mainState = new ProjectSceneState
            {
                Effect     = effect,
                Camera     = camera,
                Components = new System.Collections.Generic.List <IComponet>
                {
                    light,
                    skybox,
                    envmodel,
                    cube1,
                    mars,
                    cylinder1,
                    lightSat2,
                    //planet, //planet
                    sph1,
                    connector,
                    satelite3,
                    satelite2,
                    sph2,
                    spaceship1,
                    spaceship2,
                    tb,
                    ps,
                },
                Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, graphics.GraphicsDevice.Viewport.AspectRatio, 1, 500)
            };

            //AddPlanetoids(mainState.Components, effect);
            manager.StateManager.SetState(States.Main, mainState);
            renderTarget = new RenderTarget2D(
                GraphicsDevice,
                GraphicsDevice.PresentationParameters.BackBufferWidth,
                GraphicsDevice.PresentationParameters.BackBufferHeight,
                true,
                GraphicsDevice.PresentationParameters.BackBufferFormat,
                DepthFormat.Depth24Stencil8);
            tb.Texture = renderTarget;

            graphics.DeviceReset += (s, e) =>
            {
                mainState.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, graphics.GraphicsDevice.Viewport.AspectRatio, 1, 500);
            };
            manager.StateManager.SetCurrentState(States.Main);
            Components.Add(manager);
        }
        }//EnvMappingModel

        public static EnvMappingModel LoadEnvMappingModel(this ContentManager manager, string assetName, SimpleEffect effect)
        {
            Model asset = manager.Load <Model>(assetName);

            if (asset == null)
            {
                return(null);
            }
            return(new EnvMappingModel(asset, effect));
        }//EnvMappingModel
Example #15
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            var vertices = new Vertex[4];

            vertices[0] = new Vertex {
                Position = new Vector3(-1, -1, 0.5f), TexCoords = new Vector2(0, 0)
            };
            vertices[1] = new Vertex {
                Position = new Vector3(-1, 1, 0.5f), TexCoords = new Vector2(3, 0)
            };
            vertices[2] = new Vertex {
                Position = new Vector3(1, 1, 0.5f), TexCoords = new Vector2(3, 3)
            };
            vertices[3] = new Vertex {
                Position = new Vector3(1, -1, 0.5f), TexCoords = new Vector2(0, 3)
            };

            var indices = new short[] { 0, 1, 2, 0, 2, 3 };

            var vertexBuffer = Buffer.Vertex.New(GraphicsDevice, vertices, GraphicsResourceUsage.Default);
            var indexBuffer  = Buffer.Index.New(GraphicsDevice, indices, GraphicsResourceUsage.Default);
            var meshDraw     = new MeshDraw
            {
                DrawCount     = 4,
                PrimitiveType = PrimitiveType.TriangleList,
                VertexBuffers = new[]
                {
                    new VertexBufferBinding(vertexBuffer,
                                            new VertexDeclaration(VertexElement.Position <Vector3>(),
                                                                  VertexElement.TextureCoordinate <Vector2>()),
                                            4)
                },
                IndexBuffer = new IndexBufferBinding(indexBuffer, false, indices.Length),
            };

            var mesh = new Mesh
            {
                Draw       = meshDraw,
                Parameters = new ParameterCollection()
            };

            simpleEffect         = new SimpleEffect(GraphicsDevice);
            simpleEffect.Texture = UVTexture;

            vao = VertexArrayObject.New(GraphicsDevice, mesh.Draw.IndexBuffer, mesh.Draw.VertexBuffers);

            myDraws    = new DrawOptions[3];
            myDraws[0] = new DrawOptions {
                Sampler = GraphicsDevice.SamplerStates.LinearClamp, Transform = Matrix.Multiply(Matrix.Scaling(0.4f), Matrix.Translation(-0.5f, 0.5f, 0f))
            };
            myDraws[1] = new DrawOptions {
                Sampler = GraphicsDevice.SamplerStates.LinearWrap, Transform = Matrix.Multiply(Matrix.Scaling(0.4f), Matrix.Translation(0.5f, 0.5f, 0f))
            };
            myDraws[2] = new DrawOptions {
                Sampler = SamplerState.New(GraphicsDevice, new SamplerStateDescription(TextureFilter.Linear, TextureAddressMode.Mirror)), Transform = Matrix.Multiply(Matrix.Scaling(0.4f), Matrix.Translation(0.5f, -0.5f, 0f))
            };
            //var borderDescription = new SamplerStateDescription(TextureFilter.Linear, TextureAddressMode.Border) { BorderColor = Color.Purple };
            //var border = SamplerState.New(GraphicsDevice, borderDescription);
            //myDraws[3] = new DrawOptions { Sampler = border, Transform = Matrix.Multiply(Matrix.Scaling(0.3f), Matrix.Translation(-0.5f, -0.5f, 0f)) };
        }
Example #16
0
        public Cube(GraphicsDeviceManager graphics, SimpleEffect effect, float size, Color color) : base(effect)
        {
            a        = size;
            Vertices = new VertexPositionColorNormal[36];
            var Size = new Vector3(size);

            Vector3 topLeftFront  = new Vector3(-1.0f, 1.0f, -1.0f) * Size;
            Vector3 topLeftBack   = new Vector3(-1.0f, 1.0f, 1.0f) * Size;
            Vector3 topRightFront = new Vector3(1.0f, 1.0f, -1.0f) * Size;
            Vector3 topRightBack  = new Vector3(1.0f, 1.0f, 1.0f) * Size;

            // Calculate the position of the vertices on the bottom face.
            Vector3 btmLeftFront  = new Vector3(-1.0f, -1.0f, -1.0f) * Size;
            Vector3 btmLeftBack   = new Vector3(-1.0f, -1.0f, 1.0f) * Size;
            Vector3 btmRightFront = new Vector3(1.0f, -1.0f, -1.0f) * Size;
            Vector3 btmRightBack  = new Vector3(1.0f, -1.0f, 1.0f) * Size;

            // Normal vectors for each face (needed for lighting / display)
            Vector3 normalFront  = new Vector3(0.0f, 0.0f, 1.0f);
            Vector3 normalBack   = new Vector3(0.0f, 0.0f, -1.0f);
            Vector3 normalTop    = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 normalBottom = new Vector3(0.0f, -1.0f, 0.0f);
            Vector3 normalLeft   = new Vector3(-1.0f, 0.0f, 0.0f);
            Vector3 normalRight  = new Vector3(1.0f, 0.0f, 0.0f);

            // UV texture coordinates
            Vector2 textureTopLeft     = new Vector2(1.0f * Size.X, 0.0f * Size.Y);
            Vector2 textureTopRight    = new Vector2(0.0f * Size.X, 0.0f * Size.Y);
            Vector2 textureBottomLeft  = new Vector2(1.0f * Size.X, 1.0f * Size.Y);
            Vector2 textureBottomRight = new Vector2(0.0f * Size.X, 1.0f * Size.Y);

            // Add the vertices for the FRONT face.
            Vertices[0] = new VertexPositionColorNormal(topLeftFront, color, normalFront);
            Vertices[1] = new VertexPositionColorNormal(btmLeftFront, color, normalFront);
            Vertices[2] = new VertexPositionColorNormal(topRightFront, color, normalFront);
            Vertices[3] = new VertexPositionColorNormal(btmLeftFront, color, normalFront);
            Vertices[4] = new VertexPositionColorNormal(btmRightFront, color, normalFront);
            Vertices[5] = new VertexPositionColorNormal(topRightFront, color, normalFront);

            // Add the vertices for the BACK face.
            Vertices[6]  = new VertexPositionColorNormal(topLeftBack, color, normalBack);
            Vertices[7]  = new VertexPositionColorNormal(topRightBack, color, normalBack);
            Vertices[8]  = new VertexPositionColorNormal(btmLeftBack, color, normalBack);
            Vertices[9]  = new VertexPositionColorNormal(btmLeftBack, color, normalBack);
            Vertices[10] = new VertexPositionColorNormal(topRightBack, color, normalBack);
            Vertices[11] = new VertexPositionColorNormal(btmRightBack, color, normalBack);

            // Add the vertices for the TOP face.
            Vertices[12] = new VertexPositionColorNormal(topLeftFront, color, normalTop);
            Vertices[13] = new VertexPositionColorNormal(topRightBack, color, normalTop);
            Vertices[14] = new VertexPositionColorNormal(topLeftBack, color, normalTop);
            Vertices[15] = new VertexPositionColorNormal(topLeftFront, color, normalTop);
            Vertices[16] = new VertexPositionColorNormal(topRightFront, color, normalTop);
            Vertices[17] = new VertexPositionColorNormal(topRightBack, color, normalTop);

            // Add the vertices for the BOTTOM face.
            Vertices[18] = new VertexPositionColorNormal(btmLeftFront, color, normalTop);
            Vertices[19] = new VertexPositionColorNormal(btmLeftBack, color, normalTop);
            Vertices[20] = new VertexPositionColorNormal(btmRightBack, color, normalTop);
            Vertices[21] = new VertexPositionColorNormal(btmLeftFront, color, normalTop);
            Vertices[22] = new VertexPositionColorNormal(btmRightBack, color, normalTop);
            Vertices[23] = new VertexPositionColorNormal(btmRightFront, color, normalBottom);

            // Add the vertices for the LEFT face.
            Vertices[24] = new VertexPositionColorNormal(topLeftFront, color, normalLeft);
            Vertices[25] = new VertexPositionColorNormal(btmLeftBack, color, normalLeft);
            Vertices[26] = new VertexPositionColorNormal(btmLeftFront, color, normalLeft);
            Vertices[27] = new VertexPositionColorNormal(topLeftBack, color, normalLeft);
            Vertices[28] = new VertexPositionColorNormal(btmLeftBack, color, normalLeft);
            Vertices[29] = new VertexPositionColorNormal(topLeftFront, color, normalLeft);

            // Add the vertices for the RIGHT face.
            Vertices[30] = new VertexPositionColorNormal(topRightFront, color, normalRight);
            Vertices[31] = new VertexPositionColorNormal(btmRightFront, color, normalRight);
            Vertices[32] = new VertexPositionColorNormal(btmRightBack, color, normalRight);
            Vertices[33] = new VertexPositionColorNormal(topRightBack, color, normalRight);
            Vertices[34] = new VertexPositionColorNormal(topRightFront, color, normalRight);
            Vertices[35] = new VertexPositionColorNormal(btmRightBack, color, normalRight);

            //// Add the vertices for the FRONT face.
            //Vertexes[0] = new VertexPositionNormalTexture(topLeftFront, normalFront, textureTopLeft);
            //Vertexes[1] = new VertexPositionNormalTexture(btmLeftFront, normalFront, textureBottomLeft);
            //Vertexes[2] = new VertexPositionNormalTexture(topRightFront, normalFront, textureTopRight);
            //Vertexes[3] = new VertexPositionNormalTexture(btmLeftFront, normalFront, textureBottomLeft);
            //Vertexes[4] = new VertexPositionNormalTexture(btmRightFront, normalFront, textureBottomRight);
            //Vertexes[5] = new VertexPositionNormalTexture(topRightFront, normalFront, textureTopRight);

            //// Add the vertices for the BACK face.
            //Vertexes[6] = new VertexPositionNormalTexture(topLeftBack, normalBack, textureTopRight);
            //Vertexes[7] = new VertexPositionNormalTexture(topRightBack, normalBack, textureTopLeft);
            //Vertexes[8] = new VertexPositionNormalTexture(btmLeftBack, normalBack, textureBottomRight);
            //Vertexes[9] = new VertexPositionNormalTexture(btmLeftBack, normalBack, textureBottomRight);
            //Vertexes[10] = new VertexPositionNormalTexture(topRightBack, normalBack, textureTopLeft);
            //Vertexes[11] = new VertexPositionNormalTexture(btmRightBack, normalBack, textureBottomLeft);

            //// Add the vertices for the TOP face.
            //Vertexes[12] = new VertexPositionNormalTexture(topLeftFront, normalTop, textureBottomLeft);
            //Vertexes[13] = new VertexPositionNormalTexture(topRightBack, normalTop, textureTopRight);
            //Vertexes[14] = new VertexPositionNormalTexture(topLeftBack, normalTop, textureTopLeft);
            //Vertexes[15] = new VertexPositionNormalTexture(topLeftFront, normalTop, textureBottomLeft);
            //Vertexes[16] = new VertexPositionNormalTexture(topRightFront, normalTop, textureBottomRight);
            //Vertexes[17] = new VertexPositionNormalTexture(topRightBack, normalTop, textureTopRight);

            //// Add the vertices for the BOTTOM face.
            //Vertexes[18] = new VertexPositionNormalTexture(btmLeftFront, normalBottom, textureTopLeft);
            //Vertexes[19] = new VertexPositionNormalTexture(btmLeftBack, normalBottom, textureBottomLeft);
            //Vertexes[20] = new VertexPositionNormalTexture(btmRightBack, normalBottom, textureBottomRight);
            //Vertexes[21] = new VertexPositionNormalTexture(btmLeftFront, normalBottom, textureTopLeft);
            //Vertexes[22] = new VertexPositionNormalTexture(btmRightBack, normalBottom, textureBottomRight);
            //Vertexes[23] = new VertexPositionNormalTexture(btmRightFront, normalBottom, textureTopRight);

            //// Add the vertices for the LEFT face.
            //Vertexes[24] = new VertexPositionNormalTexture(topLeftFront, normalLeft, textureTopRight);
            //Vertexes[25] = new VertexPositionNormalTexture(btmLeftBack, normalLeft, textureBottomLeft);
            //Vertexes[26] = new VertexPositionNormalTexture(btmLeftFront, normalLeft, textureBottomRight);
            //Vertexes[27] = new VertexPositionNormalTexture(topLeftBack, normalLeft, textureTopLeft);
            //Vertexes[28] = new VertexPositionNormalTexture(btmLeftBack, normalLeft, textureBottomLeft);
            //Vertexes[29] = new VertexPositionNormalTexture(topLeftFront, normalLeft, textureTopRight);

            //// Add the vertices for the RIGHT face.
            //Vertexes[30] = new VertexPositionNormalTexture(topRightFront, normalRight, textureTopLeft);
            //Vertexes[31] = new VertexPositionNormalTexture(btmRightFront, normalRight, textureBottomLeft);
            //Vertexes[32] = new VertexPositionNormalTexture(btmRightBack, normalRight, textureBottomRight);
            //Vertexes[33] = new VertexPositionNormalTexture(topRightBack, normalRight, textureTopRight);
            //Vertexes[34] = new VertexPositionNormalTexture(topRightFront, normalRight, textureTopLeft);
            //Vertexes[35] = new VertexPositionNormalTexture(btmRightBack, normalRight, textureBottomRight);
        }
Example #17
0
 public EnvMappingModel(Model model, SimpleEffect effect)
 {
     Effect     = effect;
     this.model = model;
 }
Example #18
0
 protected override void SetEffectPrevValues(SimpleEffect effect)
 {
     base.SetEffectPrevValues(effect);
     //effect.LightsEnabled = wasLightEnabled;
 }
Example #19
0
 protected virtual EffectPass SetEffectVariableGetPass(SimpleEffect effect)
 {
     effect.CurrentTechnique = Effect.Techniques["TechColor"];
     return(effect.CurrentTechnique.Passes["Color"]);
 }
Example #20
0
        public Sphere(GraphicsDeviceManager graphics, SimpleEffect effect, Color c, float radius, int nbLat, int nbLong) : base(effect)
        {
            Vertices = new VertexPositionColorNormal[(nbLong + 1) * nbLat + 2];
            Vector3[] vertices = new Vector3[(nbLong + 1) * nbLat + 2];
            float     _pi      = (float)Math.PI;
            float     _2pi     = _pi * 2f;

            Radius      = radius;
            vertices[0] = Vector3.Up * radius;
            for (int lat = 0; lat < nbLat; lat++)
            {
                float a1   = _pi * (float)(lat + 1) / (nbLat + 1);
                float sin1 = (float)Math.Sin(a1);
                float cos1 = (float)Math.Cos(a1);

                for (int lon = 0; lon <= nbLong; lon++)
                {
                    float a2   = _2pi * (float)(lon == nbLong ? 0 : lon) / nbLong;
                    float sin2 = (float)Math.Sin(a2);
                    float cos2 = (float)Math.Cos(a2);

                    vertices[lon + lat * (nbLong + 1) + 1] = new Vector3(sin1 * cos2, cos1, sin1 * sin2) * radius;
                }
            }
            vertices[vertices.Length - 1] = Vector3.Up * -radius;

            Vector3[] normales = new Vector3[vertices.Length];
            for (int n = 0; n < vertices.Length; n++)
            {
                normales[n] = vertices[n];
                normales[n].Normalize();
            }



            //#region UVs
            //Vector2[] uvs = new Vector2[vertices.Length];
            //uvs[0] = Vector2.up;
            //uvs[uvs.Length - 1] = Vector2.zero;
            //for (int lat = 0; lat < nbLat; lat++)
            //    for (int lon = 0; lon <= nbLong; lon++)
            //        uvs[lon + lat * (nbLong + 1) + 1] = new Vector2((float)lon / nbLong, 1f - (float)(lat + 1) / (nbLat + 1));
            //#endregion


            #region Triangles
            var vertexes = new List <VertexPositionColorNormal>();

            //Top Cap
            int i = 0;
            for (int lon = 0; lon < nbLong; lon++)
            {
                vertexes.Add(new VertexPositionColorNormal(vertices[0], c, normales[0]));
                vertexes.Add(new VertexPositionColorNormal(vertices[lon + 1], c, normales[lon + 1]));
                vertexes.Add(new VertexPositionColorNormal(vertices[lon + 2], c, normales[lon + 2]));
            }

            //Middle
            for (int lat = 0; lat < nbLat - 1; lat++)
            {
                for (int lon = 0; lon < nbLong; lon++)
                {
                    int current = lon + lat * (nbLong + 1) + 1;
                    int next    = current + nbLong + 1;

                    vertexes.Add(new VertexPositionColorNormal(vertices[next + 1], c, normales[next + 1]));
                    vertexes.Add(new VertexPositionColorNormal(vertices[current + 1], c, normales[current + 1]));
                    vertexes.Add(new VertexPositionColorNormal(vertices[current], c, normales[current]));

                    vertexes.Add(new VertexPositionColorNormal(vertices[next], c, normales[next]));
                    vertexes.Add(new VertexPositionColorNormal(vertices[next + 1], c, normales[next + 1]));
                    vertexes.Add(new VertexPositionColorNormal(vertices[current], c, normales[current]));
                }
            }

            //Bottom Cap
            for (int lon = 0; lon < nbLong; lon++)
            {
                vertexes.Add(new VertexPositionColorNormal(vertices[vertices.Length - (lon + 1) - 1], c, normales[vertices.Length - (lon + 1) - 1]));
                vertexes.Add(new VertexPositionColorNormal(vertices[vertices.Length - (lon + 2) - 1], c, normales[vertices.Length - (lon + 2) - 1]));
                vertexes.Add(new VertexPositionColorNormal(vertices[vertices.Length - 1], c, normales[vertices.Length - 1]));
            }
            #endregion

            Vertices = vertexes.ToArray();
        }
Example #21
0
 protected virtual void SetEffectPrevValues(SimpleEffect effect)
 {
 }
 public LightAnimatorCommponent(Light l, SimpleEffect e)
 {
     effect = e;
     light  = l;
     dirR   = dirG = dirB = 1;
 }