示例#1
0
        private Mesh GetAtomMesh()
        {
            if (_atom != null)
                return _atom;

            Console.Write("Generating atom mesh... ");

            //adapted from sandy_bence's 2005 post over at:
            //http://www.gamedev.net/topic/350823-rendering-a-sphere-using-triangle-strips/

            List<Vector3> vertices = new List<Vector3>();
            for (uint stack = 0; stack <= ATOM_STACKS; stack++)
            {
                for (uint slice = 0; slice < ATOM_SLICES; slice++)
                {
                    float theta = stack * PI / ATOM_STACKS;
                    float phi   = slice * 2 * PI / ATOM_SLICES;

                    float sinTheta = (float)Math.Sin(theta);
                    float cosTheta = (float)Math.Cos(theta);

                    float sinPhi = (float)Math.Sin(phi);
                    float cosPhi = (float)Math.Cos(phi);

                    vertices.Add(new Vector3(
                        cosPhi * sinTheta,
                        sinPhi * sinTheta,
                        cosTheta
                    ));
                }
            }

            List<int> indices = new List<int>();
            for (uint stack = 0; stack < ATOM_STACKS; stack++)
            {
                for (uint slice = 0; slice <= ATOM_SLICES; slice++)
                {
                    var sliceMod = slice % ATOM_SLICES;
                    indices.Add((int)((stack       * ATOM_SLICES) + sliceMod));
                    indices.Add((int)(((stack + 1) * ATOM_SLICES) + sliceMod));
                }
            }

            var vBuffer = new VertexBuffer(vertices);
            var iBuffer = new IndexBuffer(indices, BeginMode.TriangleStrip);
            _atom = new Mesh(vBuffer, iBuffer, BeginMode.TriangleStrip);

            Console.WriteLine("done. Cached the result.");
            return _atom;
        }
示例#2
0
        private Mesh GetBondMesh()
        {
            if (_bond != null)
                return _bond;

            Console.Write("Generating bond mesh... ");

            // http://in.answers.yahoo.com/question/index?qid=20060907224537AA8MBBH
            const float sqrt3over2 = 0.86602540378f;
            const float sqrt3over4 = sqrt3over2 / 2;
            List<Vector3> vertices = new List<Vector3>(){
                new Vector3(0,            0, 0),
                new Vector3(1,            0, 0),
                new Vector3(0.5F, sqrt3over2, 0),
                new Vector3(0,            0, 1),
                new Vector3(1,            0, 1),
                new Vector3(0.5F, sqrt3over2, 1)
            };

            List<int> indices = new List<int>(){
                2, 5, 4, 1,
                3, 5, 2, 0,
                1, 4, 3, 0,
                0, 2, 1, 0/*, //this and next line are the end caps
                3, 4, 5, 3*/
            };

            Vector3 OFFSET = new Vector3(0.25F, sqrt3over4, 0);
            //Vector3 vertex;
            //std.Transformation(vertices[0], vertices[vertices.Count-1], vertices[0], out vertex);
            //vertex -= OFFSET;
            /*
               std::transform(vertices.begin(), vertices.end(), vertices.begin(),
                    [&](const glm::vec3& vertex)
                    {
                        return vertex - OFFSET;
                    }
                );
            */

            var vBuffer = new VertexBuffer(vertices);
            var iBuffer = new IndexBuffer(indices, BeginMode.TriangleStrip); // quads
            _bond = new Mesh(vBuffer, iBuffer, BeginMode.TriangleStrip); // quads

            Console.WriteLine("done. Cached the result.");
            return _bond;
        }
 public InstancedModel(Mesh mesh, List<Matrix> modelMatricies, List<OptionalDataBuffer> optionalDBs)
     : this(mesh)
 {
     _modelMatricies = modelMatricies;
     _optionalDBs = optionalDBs;
 }
 public InstancedModel(Mesh mesh, Matrix modelMatrix, List<OptionalDataBuffer> optionalDBs)
     : this(mesh, modelMatrix)
 {
     _optionalDBs = optionalDBs;
 }
 public InstancedModel(Mesh mesh, List<OptionalDataBuffer> optionalDBs)
     : this(mesh)
 {
     _optionalDBs = optionalDBs;
 }
 public InstancedModel(Mesh mesh, Matrix modelMatrix)
     : this(mesh)
 {
     _modelMatricies.Add(modelMatrix);
 }
 public InstancedModel(Mesh mesh)
 {
     _mesh = mesh;
     _cachedHandle = 0;
     _isVisible = true;
 }