Exemplo n.º 1
0
        protected override void  InitializeService()
        {
            SpawnPosition = new Vector3(0.0f, 2.0f, 0.0f);

            //  "alpha" is used as player ship
            {
                float sq3 = (float)Math.Sqrt(3.0f);

                Geometry gLow = new CustomTetrahedron(1.0f, sq3 / 2.0f, 2.0f);
                gLow.BuildEdges();
                Geometry g = new SubdivideGeometryOperation(gLow).Destination;


                //g.Transform(Matrix4.CreateScale(1.6f));
                //g = new CatmullClarkGeometryOperation(g).Destination;
                //g = new CatmullClarkGeometryOperation(g).Destination;
                var gm = new GeometryMesh(
                    g,
                    NormalStyle.PolygonNormals
                    );
                var m = gm.GetMesh;
                alpha = new UnitType(
                    "Alpha",
                    materialManager["magenta"],
                    m,
                    MakeShape(gLow),
                    g.ComputeBoundingSphere(),
                    10.0f,  // max health
                    1.0f,   // density
                    null,
                    //typeof(PhysicsFrameController)
                    typeof(LookAtPhysicsFrameController)
                    );
            }

            {
                Geometry g = new Cuboctahedron(1.0f);
                helium = new UnitType(
                    "Helium",
                    materialManager["red"],
                    new GeometryMesh(g, NormalStyle.PolygonNormals).GetMesh,
                    MakeShape(g),
                    g.ComputeBoundingSphere(),
                    5.0f,
                    1.0f,
                    seeker as IAI,
                    typeof(LookAtPhysicsFrameController)
                    );
            }
        }
Exemplo n.º 2
0
        public void AddFloor(float size)
        {
            Geometry g = new Cube(size, 1.0, size);

            g = new SubdivideGeometryOperation(g).Destination;
            g = new SubdivideGeometryOperation(g).Destination;
            g = new SubdivideGeometryOperation(g).Destination;
            GeometryMesh floorMesh = new GeometryMesh(g, NormalStyle.PolygonNormals);

            var floorModel = new Model(
                "Cube (floor)",
                floorMesh,
                materialManager.GridMaterial,
                0.0f, -0.5f, 0.0f
                );

            AddModel(floorModel);
        }
Exemplo n.º 3
0
        public void Subdivide(Model model)
        {
            if (model == null)
            {
                return;
            }
            GeometryMesh mesh = model.Batch.MeshSource as GeometryMesh;

            if (mesh == null)
            {
                return;
            }
            Geometry newGeometry = new SubdivideGeometryOperation(mesh.Geometry).Destination;

            newGeometry.ComputePolygonCentroids();
            newGeometry.ComputePolygonNormals();
            //newGeometry.ComputeCornerNormals(0.0f);
            newGeometry.SmoothNormalize("corner_normals", "polygon_normals", (0.0f * (float)Math.PI));
            newGeometry.BuildEdges();

            MeshModified op = new MeshModified(
                model,
                new MeshModified.State(
                    model.Name,
                    model.Batch
                    ),
                new MeshModified.State(
                    "Subdivide(" + model.Name + ")",
                    new Batch(
                        new GeometryMesh(newGeometry, NormalStyle.PolygonNormals),
                        model.Batch.Material
                        )
                    )
                );

            operationStack.Do(op);

            //model.MeshSource = new GeometryMesh(newGeometry);
            //model.Name = "Subdivide(" + model.Name + ")";
        }
        public void AddFloor(float size, int subdivisions, float y)
        {
#if false
            Message("SceneManager: AddFloor Geometry...");
            Geometry g = new Cube(size, 1.0, size);
            for (int i = 0; i < subdivisions; ++i)
            {
                Message("SceneManager: AddFloor Subdivide " + i + "/" + subdivisions + "...");
                g = new SubdivideGeometryOperation(g).Destination;
            }
            Message("SceneManager: AddFloor GeometryMesh...");
#endif
            GeometryMesh floorMesh;
            Shape        shape;
            if (RuntimeConfiguration.gameTest)
            {
                //HeightField.Evaluate evaluate = testNoise;
                int div = 40;
                float[,] heights = new float[div, div];
                float scaleX = size / heights.GetLength(0);
                float scaleZ = size / heights.GetLength(1);
                for (int x = 0; x < div; x++)
                {
                    float relX = (float)x / (float)div;
                    for (int z = 0; z < div; z++)
                    {
                        float relZ = (float)z / (float)div;
                        float xP   = relX * size;
                        float zP   = relZ * size;
                        float rx   = 6.0f * (relX - 0.5f);
                        float rz   = 6.0f * (relZ - 0.5f);
                        float d2   = rx * rx + rz * rz;
                        if (d2 > 1.0f)
                        {
                            d2 = 1.0f;
                        }
                        float yP = 1.0f + d2 * 0.5f * (0.5f + 0.5f * testNoise(xP, zP));
                        heights[x, z] = yP;
                    }
                }
                Geometry g = new HeightField(
                    heights,
                    scaleX,
                    scaleZ
                    );
                floorMesh  = new GeometryMesh(g, NormalStyle.PointNormals);
                shape      = new TerrainShape(heights, scaleX, scaleZ);
                floorModel = new Model(
                    "Cube (floor)",
                    floorMesh,
                    //materialManager["Schlick"],
                    materialManager["Grid"],
                    -size / 2.0f, y, -size / 2.0f
                    );
            }
            else
            {
                Geometry g = new Cube(
                    new Vector3(size, 1.0f, size),
                    new IVector3(4 * subdivisions, 1, 4 * subdivisions)
                    );
                floorMesh  = new GeometryMesh(g, NormalStyle.PolygonNormals);
                shape      = new BoxShape(size, 1.0f, size);
                floorModel = new Model(
                    "Cube (floor)",
                    floorMesh,
                    //materialManager["Schlick"],
                    materialManager["Grid"],
                    0.0f, y, 0.0f
                    );
            }
            floorSize = size;

            floorModel.PhysicsShape = shape;
            floorModel.Static       = true;

            AddModel(floorModel);
        }
Exemplo n.º 5
0
        public void DemoInit()
        {
            InitializeRenderers();
            windowViewport           = new RenderStack.Viewport(this.Width, this.Height);
            Renderer.CurrentViewport = windowViewport;

            blinnPhong = Material.Create(Renderer.Programs.BlinnPhong);
            blinnPhong.Parameters.Add <Floats>("surface_color").Value     = new Floats(0.5f, 0.5f, 0.5f);
            blinnPhong.Parameters.Add <Floats>("surface_rim_color").Value = new Floats(0.1f, 0.2f, 0.5f);
            blinnPhong.Parameters.Add <Floats>("surface_diffuse_reflectance_color").Value     = new Floats(0.24f, 0.24f, 0.24f);
            blinnPhong.Parameters.Add <Floats>("surface_specular_reflectance_color").Value    = new Floats(0.8f, 0.8f, 0.8f);
            blinnPhong.Parameters.Add <Floats>("surface_specular_reflectance_exponent").Value = new Floats(200.0f);

            gridMaterial = Material.Create(Renderer.Programs.Grid);

#if false
            var mesh = PolyMesh.CreateGreatRhombicosidodecahedron(1.0);
#else
            var mesh   = PolyMesh.CreateTruncatedIcosahedron(1.0);
            var dodeca = PolyMesh.CreateDodecahedron(1.0);
            Attach(mesh, dodeca, 5);
#endif

            var subd1 = new SubdivideGeometryOperation(mesh.Geometry).Destination;
            var subd2 = new SubdivideGeometryOperation(subd1).Destination;
            var cc1   = new CatmullClarkGeometryOperation(subd2).Destination;
            var cc2   = new CatmullClarkGeometryOperation(cc1).Destination;
            cc2.ComputePolygonCentroids();
            cc2.ComputePolygonNormals();
            cc2.ComputeCornerNormals(2.0f * (float)Math.PI);
            //cc2.BuildEdges();

            mesh  = new GeometryMesh(cc2);
            model = Model.Create("model", mesh, blinnPhong);
            //model                   = Model.Create("model", mesh, gridMaterial);

            camera                   = Camera.Create();
            camera.FovXRadians       = OpenTK.MathHelper.DegreesToRadians(90.0f);
            camera.FovYRadians       = OpenTK.MathHelper.DegreesToRadians(90.0f);
            camera.ProjectionType    = ProjectionType.PerspectiveVertical;
            camera.Frame.Parent      = model.Frame;
            cameraPath               = new OrbitPath(camera.Frame);
            cameraPath.Points[0.0f]  = new OrbitPoint(0.0f, 0.0f, 20.0f);
            cameraPath.Points[2.0f]  = new OrbitPoint(0.0f, 0.0f, 12.0f);
            cameraPath.Points[3.0f]  = new OrbitPoint(0.5f, 0.2f, 15.0f);
            cameraPath.Points[4.0f]  = new OrbitPoint(1.0f, 0.5f, 12.0f);
            cameraPath.Points[5.0f]  = new OrbitPoint(1.4f, 1.0f, 16.0f);
            cameraPath.Points[7.0f]  = new OrbitPoint(2.0f, 1.5f, 13.0f);
            cameraPath.Points[10.0f] = new OrbitPoint(1.6f, 0.0f, 20.0f);

            exposure = new Signal();
            exposure.Values[0.0f]  = 0.0f;
            exposure.Values[1.0f]  = 1.0f;
            exposure.Values[2.0f]  = 2.0f;
            exposure.Values[3.0f]  = 1.0f;
            exposure.Values[4.0f]  = 5.0f;
            exposure.Values[8.0f]  = 1.0f;
            exposure.Values[10.0f] = 0.0f;

            InitializeRendererParameters();
            DemoStart();
        }