示例#1
0
文件: Mesh.cs 项目: yandol/VORS2012
        public Mesh(Scene _scene)
        {
            this.scene = _scene;
            this.graphicsDevice = _scene.GraphicsDevice;
            this.mySilverlightEffect = _scene.ContentManager.Load<SilverlightEffect>("CustomEffect");

            //init map for mesh
            mapWidth = 128;
            mapHeight = 128;

            //cache effect parameters
            worldViewProjectionParameter = mySilverlightEffect.Parameters["WorldViewProjection"];
            worldParameter = mySilverlightEffect.Parameters["World"];
            lightPositionParameter = mySilverlightEffect.Parameters["LightPosition"];
            this.LightPosition = new Vector3(0, 10, 0);

            //init vertices/indices
            vertices = new VertexPositionNormalTexture[mapWidth * mapHeight];
            indices = new ushort[(mapWidth - 1) * (mapHeight - 1) * 6];
            Canvas _canvas = new Canvas();
            _canvas.Width = _canvas.Height = 128;
            _canvas.Background = new SolidColorBrush(Colors.Blue);
            WriteableBitmap _map = new WriteableBitmap(_canvas, null);
            heightData = LoadHeightDataFromMap(_map);
            texture = new Texture2D(graphicsDevice, _map.PixelWidth, _map.PixelHeight);
            texture.SetData(_map.Pixels);

            //
            SetupVertices();
            SetupIndices();
            CalculateNormals();
        }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // Check if GPU is on
            if (GraphicsDeviceManager.Current.RenderMode != RenderMode.Hardware)
            {
                MessageBox.Show("Please activate enableGPUAcceleration=true on your Silverlight plugin page.", "Warning", MessageBoxButton.OK);
            }

            // Create the scene
            scene = new Scene(myDrawingSurface);
        }
示例#3
0
文件: Cube.cs 项目: yandol/VORS2012
        public Cube(Scene scene, float size)
        {
            this.scene = scene;
            this.graphicsDevice = scene.GraphicsDevice;
            this.mySilverlightEffect = scene.ContentManager.Load<SilverlightEffect>("CustomEffect");

            // Cache effect parameters
            worldViewProjectionParameter = mySilverlightEffect.Parameters["WorldViewProjection"];
            worldParameter = mySilverlightEffect.Parameters["World"];
            lightPositionParameter = mySilverlightEffect.Parameters["LightPosition"];

            // Init static parameters
            this.LightPosition = new Vector3(1, 1, -10);

            // Temporary lists
            List<VertexPositionNormalTexture> vertices = new List<VertexPositionNormalTexture>();
            List<ushort> indices = new List<ushort>();

            vertices.Add(new VertexPositionNormalTexture(new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector2(0, 0)));
            vertices.Add(new VertexPositionNormalTexture(new Vector3(5, 5, 0), new Vector3(1, 0, 0), new Vector2(1.0f, 1.0f)));
            vertices.Add(new VertexPositionNormalTexture(new Vector3(5, 0, 0), new Vector3(1, 0, 0), new Vector2(1, 0)));

            indices.Add((ushort)0);
            indices.Add((ushort)1);
            indices.Add((ushort)2);

            // Create a vertex buffer, and copy our vertex data into it.
            vertexBuffer = new VertexBuffer(graphicsDevice, VertexPositionColorNormal.VertexDeclaration, vertices.Count, BufferUsage.None);

            vertexBuffer.SetData(0, vertices.ToArray(), 0, vertices.Count, VertexPositionColorNormal.Stride);

            // Create an index buffer, and copy our index data into it.
            indexBuffer = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, indices.Count, BufferUsage.None);

            indexBuffer.SetData(0, indices.ToArray(), 0, indices.Count);

            // Statistics
            VerticesCount = vertices.Count;
            FaceCount = indices.Count / 3;
        }
示例#4
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            //Check if GPU is on
            if (GraphicsDeviceManager.Current.RenderMode != RenderMode.Hardware) MessageBox.Show("Please activate enableGPUAcceleration=true on your Silverlight plugin page.", "Warning", MessageBoxButton.OK);

            //initialise UI
            InitialiseUI();

            //Create scene
            scene = new Scene(myDrawingSurface);

            //load rte data
            rteData = new XMLDataParse("Data/RTEdata.xml");
            rteData.ParseRTEData(); //-> rteData.AllRTEData
            rteMap = new DataImage(512, 512);
            //rteMap.GenerateHisFaces(rteData.AllRTEData);//-> rteMap.TextureImage
            rteMap.GenerateHisCircles(rteData.RTEAllRTEData);

            //update scene mesh
            scene.Update(rteMap.DepthImage, rteMap.TextureImage, state);

            //load research oei data
            oeiData = new XMLDataParse("Data/researchOEIdata.xml");
            oeiData.ParseOEIData(); //-> oeiData.AllOEIData
            oeiMap = new DataImage(512, 512);

            //load publication data
            pubData = new XMLDataParse("Data/pubsdata.xml");
            pubData.ParsePubData();
            pubMap = new DataImage(512, 512);

            //load school stuff data
            schStuffData = new XMLDataParse("Data/schStuffData.xml");
            schStuffData.ParseSchStuffData();
            schStuffMap = new DataImage(512, 512);

            //debug info
            //foreach (var ps in pubData.PubSchoolPubs){Debug.WriteLine("/schName:{0}\n\\pubcount:{1}",ps.schName, ps.schPubCount);}

            //debug
            //DebugShow(rteMap.TextureImage);
        }
示例#5
0
        public Cube(Scene scene, float size)
        {
            this.scene = scene;
            this.graphicsDevice = scene.GraphicsDevice;
            this.mySilverlightEffect = scene.ContentManager.Load<SilverlightEffect>("CustomEffect");

            // Cache effect parameters
            worldViewProjectionParameter = mySilverlightEffect.Parameters["WorldViewProjection"];
            worldParameter = mySilverlightEffect.Parameters["World"];
            lightPositionParameter = mySilverlightEffect.Parameters["LightPosition"];

            // Init static parameters
            this.LightPosition = new Vector3(1, 1, -10);

            // Temporary lists
            List<VertexPositionColorNormal> vertices = new List<VertexPositionColorNormal>();
            List<ushort> indices = new List<ushort>();

            // A cube has six faces, each one pointing in a different direction.
            Vector3[] normals =
            {
                new Vector3(0, 0, 1),
                new Vector3(0, 0, -1),
                new Vector3(1, 0, 0),
                new Vector3(-1, 0, 0),
                new Vector3(0, 1, 0),
                new Vector3(0, -1, 0)
            };

            // Create each face in turn.
            foreach (Vector3 normal in normals)
            {
                // Get two vectors perpendicular to the face normal and to each other.
                Vector3 side1 = new Vector3(normal.Y, normal.Z, normal.X);
                Vector3 side2 = Vector3.Cross(normal, side1);

                // Six indices (two triangles) per face.
                indices.Add((ushort)vertices.Count);
                indices.Add((ushort)(vertices.Count + 1));
                indices.Add((ushort)(vertices.Count + 2));

                indices.Add((ushort)vertices.Count);
                indices.Add((ushort)(vertices.Count + 2));
                indices.Add((ushort)(vertices.Count + 3));

                // Four vertices per face.
                Vector4 color = new Vector4(0, 1, 0, 1);
                vertices.Add(new VertexPositionColorNormal((normal - side1 - side2) * size / 2, normal, color));
                vertices.Add(new VertexPositionColorNormal((normal - side1 + side2) * size / 2, normal, color));
                vertices.Add(new VertexPositionColorNormal((normal + side1 + side2) * size / 2, normal, color));
                vertices.Add(new VertexPositionColorNormal((normal + side1 - side2) * size / 2, normal, color));
            }

            // Create a vertex buffer, and copy our vertex data into it.
            vertexBuffer = new VertexBuffer(graphicsDevice, VertexPositionColorNormal.VertexDeclaration, vertices.Count, BufferUsage.None);

            vertexBuffer.SetData(0, vertices.ToArray(), 0, vertices.Count, VertexPositionColorNormal.Stride);

            // Create an index buffer, and copy our index data into it.
            indexBuffer = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, indices.Count, BufferUsage.None);

            indexBuffer.SetData(0, indices.ToArray(), 0, indices.Count);

            // Statistics
            VerticesCount = vertices.Count;
            FaceCount = indices.Count / 3;
        }