Example #1
0
        private static M2 Transform(M2Model model, IEnumerable <int> indicies, MapDoodadDefinition mddf)
        {
            var currentM2 = new M2();

            currentM2.Vertices.Clear();
            currentM2.Indices.Clear();

            var posX   = (mddf.Position.X - TerrainConstants.CenterPoint) * -1;
            var posY   = (mddf.Position.Y - TerrainConstants.CenterPoint) * -1;
            var origin = new Vector3(posX, posY, mddf.Position.Z);

            // Create the scale matrix used in the following loop.
            Matrix scaleMatrix;

            Matrix.CreateScale(mddf.Scale, out scaleMatrix);

            // Creation the rotations
            var rotateZ = Matrix.CreateRotationZ(MathHelper.ToRadians(mddf.OrientationB + 180));
            var rotateY = Matrix.CreateRotationY(MathHelper.ToRadians(mddf.OrientationA));
            var rotateX = Matrix.CreateRotationX(MathHelper.ToRadians(mddf.OrientationC));

            var worldMatrix = Matrix.Multiply(scaleMatrix, rotateZ);

            worldMatrix = Matrix.Multiply(worldMatrix, rotateX);
            worldMatrix = Matrix.Multiply(worldMatrix, rotateY);

            for (var i = 0; i < model.BoundingVertices.Length; i++)
            {
                var position = model.BoundingVertices[i];
                var normal   = model.BoundingNormals[i];

                // Scale and Rotate
                Vector3 rotatedPosition;
                Vector3.Transform(ref position, ref worldMatrix, out rotatedPosition);

                Vector3 rotatedNormal;
                Vector3.Transform(ref normal, ref worldMatrix, out rotatedNormal);
                rotatedNormal.Normalize();

                // Translate
                Vector3 finalVector;
                Vector3.Add(ref rotatedPosition, ref origin, out finalVector);

                currentM2.Vertices.Add(finalVector);
            }

            currentM2.Indices.AddRange(indicies);
            return(currentM2);
        }
Example #2
0
        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="SkyObjectNode" /> class.
        /// </summary>
        public SkyObjectNode()
        {
            AngularDiameter = new Vector2F(MathHelper.ToRadians(5));
            Alpha           = 1;
            SunDirection    = new Vector3F(1, 1, 1);
            SunLight        = new Vector3F(1, 1, 1);
            AmbientLight    = new Vector3F(0, 0, 0);
            LightWrap       = 0.1f;
            LightSmoothness = 1;

            GlowColor0          = new Vector3F(0.1f);
            GlowExponent0       = 200;
            GlowColor1          = new Vector3F(0, 0, 0);
            GlowExponent0       = 4000;
            GlowCutoffThreshold = 0.001f;
        }
Example #3
0
        protected override void Initialize()
        {
            basicEffect = new BasicEffect(GraphicsDevice);
            basicEffect.TextureEnabled     = true;
            basicEffect.VertexColorEnabled = true;
            basicEffect.View = XNAMatrix.CreateLookAt(
                orgCameraPosition,
                XNAVector3.Zero,
                XNAVector3.Up
                );
            basicEffect.Projection = XNAMatrix.CreatePerspectiveFieldOfView(
                XNAMathHelper.ToRadians(45.0f),
                (float)GraphicsDevice.Viewport.Width / GraphicsDevice.Viewport.Height,
                1.0f,
                10000.0f
                );
            basicEffect.Texture = null;

            dummyTexture = XNATexture.Load(GraphicsDevice, "./dummyTexture.png");
        }
Example #4
0
        /// <summary>
        /// Edits the specified object's value using the editor style indicated by the <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle"/> method.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that can be used to gain additional context information.</param>
        /// <param name="provider">An <see cref="T:System.IServiceProvider"/> that this editor can use to obtain services.</param>
        /// <param name="value">The object to edit.</param>
        /// <returns>
        /// The new value of the object. If the value of the object has not changed, this should return the same object it was passed.
        /// </returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (value.GetType() != typeof(float))
            {
                return(value);
            }

            var editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            if (editorService != null)
            {
                float angleDegrees = MathHelper.ToDegrees((float)value);

                AngleControl control = new AngleControl(angleDegrees);

                editorService.DropDownControl(control);

                float angleRadians = MathHelper.ToRadians(control.Angle);

                return(angleRadians);
            }

            return(value);
        }
Example #5
0
        protected override void OnLoad()
        {
            _inputService    = _services.GetInstance <IInputService>();
            _graphicsService = _services.GetInstance <IGraphicsService>();
            _scene           = _services.GetInstance <IScene>();
            var content = _services.GetInstance <ContentManager>();

            var gameObjectService = _services.GetInstance <IGameObjectService>();

            _cameraObject = (CameraObject)gameObjectService.Objects["Camera"];

            // This scene node is used as the parent of all other scene nodes created here.
            _groupNode = new SceneNode
            {
                Name     = "ScatteringSkyGroup",
                Children = new SceneNodeCollection()
            };
            _scene.Children.Add(_groupNode);

            // Add a skybox with milky way cube map.
            _milkyWayNode = new SkyboxNode(content.Load <TextureCube>("Sky/MilkyWay"))
            {
                Color = new Vector3F(MilkyWayLightScale),
            };
            _groupNode.Children.Add(_milkyWayNode);

            // Add a starfield with all visible stars from a star catalog.
            InitializeStarfield();
            _groupNode.Children.Add(_starfieldNode);

            // Add a node which draws a sun disk.
            _sunNode = new SkyObjectNode
            {
                GlowExponent0 = 4000,
            };
            _groupNode.Children.Add(_sunNode);

            // Add a node which draws a moon texture including moon phase.
            _moonNode = new SkyObjectNode
            {
                Texture         = new PackedTexture(content.Load <Texture2D>("Sky/Moon")),
                LightWrap       = 0.1f,
                LightSmoothness = 1,
                AngularDiameter = new Vector2F(MathHelper.ToRadians(5)),

                // Disable glow.
                GlowColor0 = new Vector3F(0),
                GlowColor1 = new Vector3F(0),
            };
            _groupNode.Children.Add(_moonNode);

            // Add a ScatteringSky which renders the sky colors using a physically-based model.
            _scatteringSkyNode = new ScatteringSkyNode
            {
                SunIntensity = 1,

                // Set a base color to get a dark blue instead of a pitch black night.
                BaseHorizonColor = new Vector3F(0.043f, 0.090f, 0.149f) * 0.01f,
                BaseZenithColor  = new Vector3F(0.024f, 0.051f, 0.102f) * 0.01f,
                BaseColorShift   = 0.5f
            };
            _groupNode.Children.Add(_scatteringSkyNode);

            if (_enableCloudLayer)
            {
                // Add a CloudLayerNode which renders dynamic clouds.
                // This layer represents dense, lit clouds at low altitude.
                _cloudMap0 = new LayeredCloudMap
                {
                    Density  = 15,
                    Coverage = 0.5f,
                    Size     = 2048,
                };
                _cloudLayerNode0 = new CloudLayerNode(_cloudMap0)
                {
                    SkyCurvature           = 0.9f,
                    TextureMatrix          = CreateScale(0.5f),
                    ForwardScatterExponent = 10,
                    ForwardScatterScale    = 10f,
                    ForwardScatterOffset   = 0.3f,
                    NumberOfSamples        = 16,
                    HorizonFade            = 0.03f,
                };
                // Define the layers which are combined to a single CloudMap.Texture in the CloudMapRenderer.
                var   scale          = CreateScale(0.2f);
                float animationScale = 0.01f;
                animationScale       = 0; // Uncomment to enable formation and dissolution of clouds.
                _cloudMap0.Layers[0] = new CloudMapLayer(null, scale * CreateScale(1), -0.5f, 1, 1 * animationScale);
                _cloudMap0.Layers[1] = new CloudMapLayer(null, scale * CreateScale(1.7f), -0.5f, 1f / 2f, 5 * animationScale);
                _cloudMap0.Layers[2] = new CloudMapLayer(null, scale * CreateScale(3.97f), -0.5f, 1f / 4f, 13 * animationScale);
                _cloudMap0.Layers[3] = new CloudMapLayer(null, scale * CreateScale(8.1f), -0.5f, 1f / 8f, 27 * animationScale);
                _cloudMap0.Layers[4] = new CloudMapLayer(null, scale * CreateScale(16, 17), -0.5f, 1f / 16f, 43 * animationScale);
                _cloudMap0.Layers[5] = new CloudMapLayer(null, scale * CreateScale(32, 31), -0.5f, 1f / 32f, 77 * animationScale);
                _cloudMap0.Layers[6] = new CloudMapLayer(null, scale * CreateScale(64, 67), -0.5f, 1f / 64f,
                                                         127 * animationScale);
                _cloudMap0.Layers[7] = new CloudMapLayer(null, scale * CreateScale(128, 127), -0.5f, 1f / 64f,
                                                         200 * animationScale);
                _groupNode.Children.Add(_cloudLayerNode0);

                // Add a second CloudLayerNode which renders dynamic clouds.
                // This layer represents light clouds at high altitude.
                _cloudMap1 = new LayeredCloudMap
                {
                    Density  = 2,
                    Coverage = 0.4f,
                    Size     = 1024,
                    Seed     = 77777,
                };
                _cloudLayerNode1 = new CloudLayerNode(_cloudMap1)
                {
                    SkyCurvature           = 0.9f,
                    TextureMatrix          = CreateScale(0.5f),
                    ForwardScatterExponent = 10,
                    ForwardScatterScale    = 10f,
                    ForwardScatterOffset   = 0f,
                    NumberOfSamples        = 0, // No samples to disable lighting calculations.
                    HorizonFade            = 0.03f,
                    Alpha = 0.5f,               // Make these clouds more transparent.
                };
                scale = CreateScale(0.25f);
                _cloudMap1.Layers[0] = new CloudMapLayer(null, scale * CreateScale(1), -0.5f, 1, 0);
                _cloudMap1.Layers[1] = new CloudMapLayer(null, scale * CreateScale(1.7f), -0.5f, 1f / 2f, 0);
                _cloudMap1.Layers[2] = new CloudMapLayer(null, scale * CreateScale(3.97f), -0.5f, 1f / 4f, 0);
                _cloudMap1.Layers[3] = new CloudMapLayer(null, scale * CreateScale(8.1f), -0.5f, 1f / 8f, 0);
                _cloudMap1.Layers[4] = new CloudMapLayer(null, scale * CreateScale(16, 17), -0.5f, 1f / 16f, 0);
                _cloudMap1.Layers[5] = new CloudMapLayer(null, scale * CreateScale(32, 31), -0.5f, 1f / 32f, 0);
                _cloudMap1.Layers[6] = new CloudMapLayer(null, scale * CreateScale(64, 67), -0.5f, 1f / 64f, 0);
                _cloudMap1.Layers[7] = new CloudMapLayer(null, scale * CreateScale(128, 127), -0.5f, 1f / 128f, 0);
                _groupNode.Children.Add(_cloudLayerNode1);
            }

            // The following scene nodes inherit from SkyNode and are rendered by a SkyRenderer
            // in the DeferredLightingScreen. We have to set the DrawOrder to render them from
            // back to front.
            _milkyWayNode.DrawOrder      = 0;
            _starfieldNode.DrawOrder     = 1;
            _sunNode.DrawOrder           = 2;
            _moonNode.DrawOrder          = 3;
            _scatteringSkyNode.DrawOrder = 4;
            if (_enableCloudLayer)
            {
                _cloudLayerNode1.DrawOrder = 5;
                _cloudLayerNode0.DrawOrder = 6;
            }

            // Add an ambient light.
            var ambientLight = new AmbientLight
            {
                HemisphericAttenuation = 1,
            };

            _ambientLightNode = new LightNode(ambientLight)
            {
                Name = "Ambient",
            };
            _groupNode.Children.Add(_ambientLightNode);

            // Add a directional light for the sun.
            _sunlightNode = new LightNode(new DirectionalLight())
            {
                Name     = "Sunlight",
                Priority = 10, // This is the most important light.

                // This light uses Cascaded Shadow Mapping.
                Shadow = new CascadedShadow
                {
                    PreferredSize     = 1024,
                    DepthBiasScale    = new Vector4F(0.99f),
                    DepthBiasOffset   = new Vector4F(0),
                    FadeOutDistance   = 20,
                    MaxDistance       = 30,
                    MinLightDistance  = 100,
                    ShadowFog         = 0.5f,
                    JitterResolution  = 3000,
                    SplitDistribution = 0.7f
                }
            };
            _groupNode.Children.Add(_sunlightNode);

            // Add a directional light for the moonlight.
            _moonlightNode = new LightNode(new DirectionalLight())
            {
                Name     = "Moonlight",
                Priority = 5,
            };
            _groupNode.Children.Add(_moonlightNode);

            // The Ephemeris class computes the positions of the sun and the moon as seen
            // from any place on the earth.
            _ephemeris = new Ephemeris();

            // Seattle, Washington
            _ephemeris.Latitude  = 47;
            _ephemeris.Longitude = 122;
            _ephemeris.Altitude  = 100;

#if XBOX
            _time = DateTime.Now;
#else
            _time = DateTimeOffset.Now;
#endif

            // Update the positions of sky objects and the lights.
            UpdateSky();
        }