Ejemplo n.º 1
0
        public Carrier() : base()
        {
            Color carrierColor = Color.Red;

            this.AddComponent(new CarrierController());

            ProceduralShape body = new ProceduralCuboid(1f, 2f, 0.5f);

            body.SetColor(carrierColor);
            RenderGeometryComponent renderGeom = new RenderGeometryComponent(body);
            EffectRenderComponent   effectComp = new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded"));
            ShadowCasterComponent   shadowComp = new ShadowCasterComponent();

            AddComponent(new PhysicsComponent(true, true, PhysicsMeshType.box));
            AddComponent(renderGeom);
            AddComponent(effectComp);
            AddComponent(shadowComp);



            var conTower = new ProceduralCuboid(0.25f, 0.25f, 0.35f);

            conTower.SetColor(carrierColor);
            GameObject conT = GameObjectFactory.CreateRenderableGameObjectFromShape(conTower, EffectLoader.LoadSM5Effect("flatshaded"));

            conT.Transform.RelativeTransform.Translation = new Vector3(0.8f, 0.8f, 0);
            conT.AddComponent(new ShadowCasterComponent());
            SystemCore.GameObjectManager.AddAndInitialiseGameObject(conT);
            AddChild(conT);
        }
Ejemplo n.º 2
0
        public Chopper() : base("chopper")
        {
            Color chopperColor = Color.Red;

            this.AddComponent(new ChopperController());

            ProceduralShape body = new ProceduralCuboid(0.15f, 0.3f, 0.15f);

            body.SetColor(chopperColor);
            RenderGeometryComponent renderGeom = new RenderGeometryComponent(body);
            EffectRenderComponent   effectComp = new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded"));
            ShadowCasterComponent   shadowComp = new ShadowCasterComponent();

            AddComponent(new PhysicsComponent(true, true, PhysicsMeshType.box));


            AddComponent(renderGeom);
            AddComponent(effectComp);
            AddComponent(shadowComp);

            var rotorCuboid = new ProceduralCuboid(0.03f, 0.6f, 0.03f);

            rotorCuboid.SetColor(chopperColor);
            GameObject rotor = GameObjectFactory.CreateRenderableGameObjectFromShape(rotorCuboid, EffectLoader.LoadSM5Effect("flatshaded"));

            rotor.Transform.RelativeTransform.Translation = new Vector3(0, 0.2f, 0);
            rotor.AddComponent(new RotatorComponent(Vector3.Up, 0.1f));
            rotor.AddComponent(new ShadowCasterComponent());
            SystemCore.GameObjectManager.AddAndInitialiseGameObject(rotor);
            AddChild(rotor);
        }
Ejemplo n.º 3
0
        public static void ApplyMaterialComponent(GameObject go, string materialName)
        {
            var    mat    = matDictionary[materialName];
            Effect effect = EffectLoader.LoadSM5Effect(mat.ShaderName).Clone();
            EffectRenderComponent effectComponent = new EffectRenderComponent(effect);

            go.AddComponent(mat);
            go.AddComponent(effectComponent);
        }
Ejemplo n.º 4
0
        public Atmosphere(float radius, float planetRadius, float scale = 1)
        {
            m_fInnerRadius = planetRadius;
            m_fOuterRadius = radius;

            m_Kr4PI  = m_Kr * 4.0f * MathHelper.Pi;
            m_Km4PI  = m_Km * 4.0f * MathHelper.Pi;
            m_fScale = scale / (m_fOuterRadius - m_fInnerRadius);

            m_fWavelength.X  = 0.650f;          // 650 nm for red
            m_fWavelength.Y  = 0.570f;          // 570 nm for green
            m_fWavelength.Z  = 0.475f;          // 475 nm for blue
            m_fWavelength4.X = (float)Math.Pow(m_fWavelength.X, 4.0f);
            m_fWavelength4.Y = (float)Math.Pow(m_fWavelength.Y, 4.0f);
            m_fWavelength4.Z = (float)Math.Pow(m_fWavelength.Z, 4.0f);

            atmosphereEffect = EffectLoader.LoadSM5Effect("AtmosphericScatteringSky").Clone();
            EffectRenderComponent effectRenderComponent = new EffectRenderComponent(atmosphereEffect);

            AddComponent(effectRenderComponent);

            ProceduralSphere sphere = new ProceduralSphere(100, 100);

            sphere.Scale(m_fOuterRadius);
            sphere.InsideOut();

            AddComponent(new RenderGeometryComponent(sphere));


            atmosphereEffect.Parameters["v3InvWavelength"].SetValue(new Vector3(1 / m_fWavelength4.X,
                                                                                1 / m_fWavelength4.Y, 1 / m_fWavelength4.Z));

            atmosphereEffect.Parameters["fInnerRadius"].SetValue(m_fInnerRadius);
            atmosphereEffect.Parameters["fInnerRadius2"].SetValue(m_fInnerRadius * m_fInnerRadius);
            atmosphereEffect.Parameters["fOuterRadius"].SetValue(m_fOuterRadius);
            atmosphereEffect.Parameters["fOuterRadius2"].SetValue(m_fOuterRadius * m_fOuterRadius);

            atmosphereEffect.Parameters["fKrESun"].SetValue(m_Kr * m_ESun);
            atmosphereEffect.Parameters["fKmESun"].SetValue(m_Km * m_ESun);
            atmosphereEffect.Parameters["fKr4PI"].SetValue(m_Kr4PI);
            atmosphereEffect.Parameters["fKm4PI"].SetValue(m_Km4PI);

            atmosphereEffect.Parameters["g"].SetValue(m_g);
            atmosphereEffect.Parameters["g2"].SetValue(m_g * m_g);

            atmosphereEffect.Parameters["fScale"].SetValue(m_fScale);
            atmosphereEffect.Parameters["fScaleDepth"].SetValue(m_fRayleighScaleDepth);
            atmosphereEffect.Parameters["fScaleOverScaleDepth"].SetValue(1 /
                                                                         (m_fOuterRadius -
                                                                          m_fInnerRadius) /
                                                                         m_fRayleighScaleDepth);
        }
Ejemplo n.º 5
0
        public GameObject.GameObject CreateTranslatedRenderableHeightMap(Color color, Effect effect, Vector3 translation)
        {
            var vertexArray = GenerateVertexArray(translation.X, translation.Y, translation.Z);
            var indexArray  = GenerateIndices();

            GameObject.GameObject heightMapObject = new GameObject.GameObject();
            ProceduralShape       shape           = new ProceduralShape(vertexArray, indexArray);

            shape.SetColor(color);
            RenderGeometryComponent renderGeom      = new RenderGeometryComponent(shape);
            EffectRenderComponent   renderComponent = new EffectRenderComponent(effect);

            heightMapObject.AddComponent(renderGeom);
            heightMapObject.AddComponent(renderComponent);
            heightMapObject.AddComponent(new StaticMeshColliderComponent(heightMapObject, GetVertices(), GetIndices().ToArray(), Vector3.Zero));
            return(heightMapObject);
        }
Ejemplo n.º 6
0
        public void BuildGeometry()
        {
            var vertices = new VertexPositionColorTextureNormal[(heightMapSize * heightMapSize)];

            int vertIndex = 0;



            List <int> topEdges    = new List <int>();
            List <int> bottomEdges = new List <int>();
            List <int> leftEdges   = new List <int>();
            List <int> rightEdges  = new List <int>();

            for (float i = 0; i < heightMapSize; i++)
            {
                for (float j = 0; j < heightMapSize; j++)
                {
                    var vert = new VertexPositionColorTextureNormal();

                    vert.Position       = CalculateVertexPosition(i, j);
                    vert.Texture        = new Vector2(i * 2f / heightMapSize, j * 2f / heightMapSize);
                    vert.Normal         = normal;
                    vert.Color          = NodeColor;
                    vertices[vertIndex] = vert;


                    if (i == 0)
                    {
                        rightEdges.Add(vertIndex);
                    }
                    if (i == heightMapSize - 1)
                    {
                        leftEdges.Add(vertIndex);
                    }
                    if (j == 0)
                    {
                        bottomEdges.Add(vertIndex);
                    }
                    if (j == heightMapSize - 1)
                    {
                        topEdges.Add(vertIndex);
                    }



                    vertIndex++;
                }
            }

            var indices = GenerateIndices();

            if (normal == Vector3.Up || normal == Vector3.Forward || normal == Vector3.Left)
            {
                indices = indices.Reverse().ToArray();
            }



            List <NeighbourTracker.Connection> connections = this.Planet.GetNeighbours(this);

            if (connections != null && SystemWarGlobalSettings.RepairSeams)
            {
                var northConn = connections.Find(x => x.direction == NeighbourTracker.ConnectionDirection.north);
                var southConn = connections.Find(x => x.direction == NeighbourTracker.ConnectionDirection.south);
                var westConn  = connections.Find(x => x.direction == NeighbourTracker.ConnectionDirection.west);
                var eastConn  = connections.Find(x => x.direction == NeighbourTracker.ConnectionDirection.east);

                Sphereify(sphereSize, ref vertices);

                if (northConn != null)
                {
                    CalculateEdgeAdjustment(northConn, ref vertices, topEdges, NeighbourTracker.ConnectionDirection.north);
                }
                if (southConn != null)
                {
                    CalculateEdgeAdjustment(southConn, ref vertices, bottomEdges, NeighbourTracker.ConnectionDirection.south);
                }
                if (westConn != null)
                {
                    CalculateEdgeAdjustment(westConn, ref vertices, leftEdges, NeighbourTracker.ConnectionDirection.west);
                }
                if (eastConn != null)
                {
                    CalculateEdgeAdjustment(eastConn, ref vertices, rightEdges, NeighbourTracker.ConnectionDirection.east);
                }
            }
            else
            {
                Sphereify(sphereSize, ref vertices);
            }



            GenerateNormals(ref vertices, ref indices);


            var p = vertices.Select(x => x.Position).ToList();

            boundingSphere = BoundingSphere.CreateFromPoints(p);

            ProceduralShape spherePatch = new ProceduralShape(vertices, indices);



            this.AddComponent(new RenderGeometryComponent(spherePatch));

            meshCollider = new MobileMeshColliderComponent(this, spherePatch.GetVertices(), spherePatch.GetIndicesAsInt().ToArray());
            AddComponent(meshCollider);

            renderComponent           = new EffectRenderComponent(effect);
            renderComponent.DrawOrder = Planet.DrawOrder;
            this.AddComponent(renderComponent);



            SetHighPrecisionPosition(this);

            built = true;
        }