Example #1
0
        protected override void InitializeInternal()
        {
            base.InitializeInternal();
            var device = D3DApp11.I.D3DDevice;

            using (var r = CubeMapSRV.Resource) {
                r.DebugName = "sky cubemap";
            }

            var sphere   = GeometryGenerator.CreateSphere(_skySphereRadius, 30, 30);
            var vertices = sphere.Vertices.Select(v => v.Position).ToArray();
            var vbd      = new BufferDescription(
                VertPos.Stride * vertices.Length,
                ResourceUsage.Immutable,
                BindFlags.VertexBuffer,
                CpuAccessFlags.None,
                ResourceOptionFlags.None,
                0
                );

            _vb = new Buffer(device, DataStream.Create(vertices, false, false), vbd);

            _indexCount = sphere.Indices.Count;
            var ibd = new BufferDescription(
                _indexCount * sizeof(int),
                ResourceUsage.Immutable,
                BindFlags.IndexBuffer,
                CpuAccessFlags.None,
                ResourceOptionFlags.None,
                0
                );

            _ib = new Buffer(device, DataStream.Create(sphere.Indices.ToArray(), false, false), ibd);
        }
Example #2
0
        protected override void CreateSphereInternal(Device device, float radius, int slices, int stacks)
        {
            var sphere = GeometryGenerator.CreateSphere(radius, slices, stacks);

            InitFromMeshData(device, sphere);
            _meshCount = 1;
        }
Example #3
0
        public static SkyObject Create(float radius)
        {
            var mesh = GeometryGenerator.CreateSphere(radius, 30, 30);

            return(new SkyObject(mesh.Vertices.Select(x => new InputLayouts.VerticeP(x.Position)).ToArray(),
                                 mesh.Indices.Select(x => (ushort)x).ToArray()));
        }
Example #4
0
        private void BuildShapeGeometryBuffers()
        {
            var box      = GeometryGenerator.CreateBox(1, 1, 1);
            var grid     = GeometryGenerator.CreateGrid(20, 30, 60, 40);
            var sphere   = GeometryGenerator.CreateSphere(0.5f, 20, 20);
            var cylinder = GeometryGenerator.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20);

            _boxVertexOffset      = 0;
            _gridVertexOffset     = box.Vertices.Count;
            _sphereVertexOffset   = _gridVertexOffset + grid.Vertices.Count;
            _cylinderVertexOffset = _sphereVertexOffset + sphere.Vertices.Count;

            _boxIndexCount      = box.Indices.Count;
            _gridIndexCount     = grid.Indices.Count;
            _sphereIndexCount   = sphere.Indices.Count;
            _cylinderIndexCount = cylinder.Indices.Count;

            _boxIndexOffset      = 0;
            _gridIndexOffset     = _boxIndexCount;
            _sphereIndexOffset   = _gridIndexOffset + _gridIndexCount;
            _cylinderIndexOffset = _sphereIndexOffset + _sphereIndexCount;

            var totalVertexCount = box.Vertices.Count + grid.Vertices.Count + sphere.Vertices.Count + cylinder.Vertices.Count;
            var totalIndexCount  = _boxIndexCount + _gridIndexCount + _sphereIndexCount + _cylinderIndexCount;

            var vertices = box.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC)).ToList();

            vertices.AddRange(grid.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC)));
            vertices.AddRange(sphere.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC)));
            vertices.AddRange(cylinder.Vertices.Select(v => new Basic32(v.Position, v.Normal, v.TexC)));

            var vbd = new BufferDescription(Basic32.Stride * totalVertexCount, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _shapesVB = new Buffer(Device, new DataStream(vertices.ToArray(), false, false), vbd);

            var indices = new List <int>();

            indices.AddRange(box.Indices);
            indices.AddRange(grid.Indices);
            indices.AddRange(sphere.Indices);
            indices.AddRange(cylinder.Indices);

            var ibd = new BufferDescription(sizeof(int) * totalIndexCount, ResourceUsage.Immutable, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _shapesIB = new Buffer(Device, new DataStream(indices.ToArray(), false, false), ibd);
        }
Example #5
0
        private void BuildBallGeometryBuffers()
        {
            var mesh = GeometryGenerator.CreateSphere(10, 30, 30);

            var vertices = new List <VertexPN>();

            foreach (var vertex in mesh.Vertices)
            {
                var pos = vertex.Position;
                vertices.Add(new VertexPN(pos, vertex.Normal, vertex.TexC));
            }
            var vbd = new D3D11.BufferDescription(VertexPN.Stride * vertices.Count, D3D11.ResourceUsage.Immutable, D3D11.BindFlags.VertexBuffer, D3D11.CpuAccessFlags.None, D3D11.ResourceOptionFlags.None, 0);

            _ballVB = new D3D11.Buffer(Device, DataStream.Create <VertexPN>(vertices.ToArray(), false, false), vbd);

            var ibd = new D3D11.BufferDescription(sizeof(int) * mesh.Indices.Count, D3D11.ResourceUsage.Immutable, D3D11.BindFlags.IndexBuffer, D3D11.CpuAccessFlags.None, D3D11.ResourceOptionFlags.None, 0);

            _ballIB         = new D3D11.Buffer(Device, DataStream.Create <Int32>(mesh.Indices.ToArray(), false, false), ibd);
            _ballIndexCount = mesh.Indices.Count;
        }
Example #6
0
        public void DrawSuspensionDebugStuff(DeviceContextHolder holder, ICamera camera)
        {
            if (_suspensionLines == null)
            {
                _suspensionLines = new DebugLinesObject(Matrix.Identity, GetDebugSuspensionVertices(SuspensionsPack));
            }

            _suspensionLines.ParentMatrix = RootObject.Matrix;
            _suspensionLines.Draw(holder, camera, SpecialRenderMode.Simple);

            if (_wheelLfCon != default(Vector3))
            {
                if (_debugNode == null)
                {
                    _debugNode = new DebugObject(Matrix.Translation(_wheelLfCon), GeometryGenerator.CreateSphere(0.02f, 6, 6));
                }

                _debugNode.Transform    = Matrix.Translation(_wheelLfCon);
                _debugNode.ParentMatrix = RootObject.Matrix;

                holder.DeviceContext.OutputMerger.DepthStencilState = holder.States.DisabledDepthState;
                _debugNode.Draw(holder, camera, SpecialRenderMode.Simple);
            }
        }
Example #7
0
        private void BuildGeometryBuffers()
        {
            var box      = GeometryGenerator.CreateBox(1.0f, 1.0f, 1.0f);
            var grid     = GeometryGenerator.CreateGrid(20.0f, 30.0f, 60, 40);
            var sphere   = GeometryGenerator.CreateSphere(0.5f, 20, 20);
            var cylinder = GeometryGenerator.CreateCylinder(0.5f, 0.3f, 3.0f, 20, 20);

            _boxVertexOffset      = 0;
            _gridVertexOffset     = box.Vertices.Count;
            _sphereVertexOffset   = _gridVertexOffset + grid.Vertices.Count;
            _cylinderVertexOffset = _sphereVertexOffset + sphere.Vertices.Count;

            _boxIndexCount      = box.Indices.Count;
            _gridIndexCount     = grid.Indices.Count;
            _sphereIndexCount   = sphere.Indices.Count;
            _cylinderIndexCount = cylinder.Indices.Count;

            _boxIndexOffset      = 0;
            _gridIndexOffset     = _boxIndexCount;
            _sphereIndexOffset   = _gridIndexOffset + _gridIndexCount;
            _cylinderIndexOffset = _sphereIndexOffset + _sphereIndexCount;

            var totalVertexCount = box.Vertices.Count + grid.Vertices.Count + sphere.Vertices.Count + cylinder.Vertices.Count;
            var totalIndexCount  = _boxIndexCount + _gridIndexCount + _sphereIndexCount + _cylinderIndexCount;

            var vs = new List <VertexPC>();

            foreach (var vertex in box.Vertices)
            {
                vs.Add(new VertexPC(vertex.Position, Color.Red));
            }
            foreach (var v in grid.Vertices)
            {
                vs.Add(new VertexPC(v.Position, Color.Green));
            }
            foreach (var v in sphere.Vertices)
            {
                vs.Add(new VertexPC(v.Position, Color.Blue));
            }
            foreach (var v in cylinder.Vertices)
            {
                vs.Add(new VertexPC(v.Position, Color.Yellow));
            }
            var vbd = new BufferDescription(VertexPC.Stride * totalVertexCount,
                                            ResourceUsage.Immutable, BindFlags.VertexBuffer,
                                            CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _vb = new Buffer(Device, new DataStream(vs.ToArray(), false, false), vbd);

            var indices = new List <int>();

            indices.AddRange(box.Indices);
            indices.AddRange(grid.Indices);
            indices.AddRange(sphere.Indices);
            indices.AddRange(cylinder.Indices);

            var ibd = new BufferDescription(sizeof(int) * totalIndexCount, ResourceUsage.Immutable,
                                            BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            _ib = new Buffer(Device, new DataStream(indices.ToArray(), false, false), ibd);
        }
Example #8
0
        public override void CreateSphere(Device device, float radius, int slices, int stacks)
        {
            var sphere = GeometryGenerator.CreateSphere(radius, slices, stacks);

            InitFromMeshData(device, sphere);
        }