コード例 #1
0
ファイル: PointsRender.cs プロジェクト: xj361685640/opengems
        public override void Initialize( )
        {
            if (pointBuffer != null)
            {
                pointBuffer.Dispose();
            }

            //Create the vertex buffer
            pointBuffer = new AutoVertexBuffer(d3d, typeof(CustomVertex.PositionNormalColored), positions.Count,
                                               Usage.Dynamic, CustomVertex.PositionNormalColored.Format, Pool.Default);

            CustomVertex.PositionNormalColored[] verts = new CustomVertex.PositionNormalColored[positions.Count];

            int index = 0;

            foreach (CustomVertex.PositionColored vertex in positions)
            {
                verts[index].Position = vertex.Position;
                verts[index].Color    = vertex.Color;
                verts[index].Normal   = new Vector3(0, 0, 1);

                index++;
            }

            pointBuffer.VB.SetData(verts, 0, LockFlags.None);
        }
コード例 #2
0
ファイル: GridRender.cs プロジェクト: xj361685640/opengems
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void PerformDispose( )
        {
            enviroment.GridOptionChanged -= new GEMSEnvironment.GridOptionChangedEventHandler(OnGridOptionChanged);
            camera.ViewChanged           -= new Camera.ViewChangedEventHandler(OnViewChanged);
            camera.ProjectionChanged     -= new Camera.ProjectionChangedEventHandler(OnProjectionChanged);

            gridVertexBuffer.Dispose( );
            gridVertexBuffer = null;
        }
コード例 #3
0
        public override void Initialize( )
        {
            if (pointBuffer != null)
            {
                pointBuffer.Dispose();
            }

            model = source as PointModel;

            //Create the vertex buffer
            pointBuffer = new AutoVertexBuffer(d3d, typeof(CustomVertex.PositionNormal), 1,
                                               Usage.Dynamic, CustomVertex.PositionNormal.Format, Pool.Default);

            CustomVertex.PositionNormal[] verts = new CustomVertex.PositionNormal[1];

            verts[0].Position = model.Position;
            verts[0].Normal   = Direct3dRender.DefaultVertexNormal;

            pointBuffer.VB.SetData(verts, 0, LockFlags.None);
        }
コード例 #4
0
ファイル: GridRender.cs プロジェクト: xj361685640/opengems
        /// <summary>
        /// Generate the grid along the YZ plane
        /// </summary>
        private void GenerateYZGrid( )
        {
            Vector3 leftTop;
            Vector3 leftBottom;
            Vector3 rightTop;
            Vector3 rightBottom;

            camera.ComputeGridRange(new Plane(1, 0, 0, gridOffset)
                                    , out leftTop, out leftBottom, out rightTop, out rightBottom);

            float maxZ = leftTop.Z;

            maxZ = maxZ > leftBottom.Z ? maxZ : leftBottom.Z;
            maxZ = maxZ > rightTop.Z ? maxZ : rightTop.Z;
            maxZ = maxZ > rightBottom.Z ? maxZ : rightBottom.Z;

            float minZ = leftTop.Z;

            minZ = minZ < leftBottom.Z ? minZ : leftBottom.Z;
            minZ = minZ < rightTop.Z ? minZ : rightTop.Z;
            minZ = minZ < rightBottom.Z ? minZ : rightBottom.Z;

            float maxY = leftTop.Y;

            maxY = maxY > leftBottom.Y ? maxY : leftBottom.Y;
            maxY = maxY > rightTop.Y ? maxY : rightTop.Y;
            maxY = maxY > rightBottom.Y ? maxY : rightBottom.Y;

            float minY = leftTop.Y;

            minY = minY < leftBottom.Y ? minY : leftBottom.Y;
            minY = minY < rightTop.Y ? minY : rightTop.Y;
            minY = minY < rightBottom.Y ? minY : rightBottom.Y;

            //Swap the four value to the interger multiple of gridSize
            maxY = gridSize * ((int)(maxY / gridSize) + 2);
            minY = gridSize * ((int)(minY / gridSize) - 2);
            maxZ = gridSize * ((int)(maxZ / gridSize) + 2);
            minZ = gridSize * ((int)(minZ / gridSize) - 2);

            float width  = maxY - minY;
            float height = maxZ - minZ;

            if (width > 1e-6 && height > 1e-6)
            {
                //Compute the count of vertex
                int widthCount  = (int)(width / gridSize) + 2;
                int heightCount = (int)(height / gridSize) + 2;
                vertexCount = widthCount * 2 + heightCount * 2;

                if (vertexCount < maxVertexCount)
                {
                    //Create the vertex buffer
                    gridVertexBuffer = new AutoVertexBuffer(d3d, typeof(CustomVertex.PositionOnly), vertexCount,
                                                            Usage.Dynamic, CustomVertex.PositionOnly.Format, Pool.Default);
                    verts = new CustomVertex.PositionOnly[vertexCount];

                    //Fill the data
                    int widthIndex = 0;
                    int index      = 0;
                    for (index = 0; index < widthCount * 2; index++)
                    {
                        verts[index].Position   = new Vector3(gridOffset, maxY - widthIndex * gridSize, maxZ);
                        verts[++index].Position = new Vector3(gridOffset, maxY - widthIndex * gridSize, minZ);

                        widthIndex++;
                    }

                    int heightIndex = 0;
                    for ( ; index < vertexCount; index++)
                    {
                        verts[index].Position   = new Vector3(gridOffset, maxY, maxZ - heightIndex * gridSize);
                        verts[++index].Position = new Vector3(gridOffset, minY, maxZ - heightIndex * gridSize);

                        heightIndex++;
                    }

                    gridVertexBuffer.VB.SetData(verts, 0, LockFlags.None);
                }
            }
        }