Пример #1
0
        public Cylinder(float[] Begin, float[] End, float radius1, float radius2, int slices, int stacks, Device dev)
        {
            float_coordinates    = new float[2][];
            float_coordinates[0] = Begin;
            float_coordinates[1] = End;
            device = dev;
            if ((Begin.Length != Basis.Length) || (End.Length != Basis.Length))
            {
                throw new Exception("Размерность базиса не совпадает с размерностью вектора позиции.");
            }
            Vector3 begin = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 end   = new Vector3(0.0f, 0.0f, 0.0f);

            for (int i = 0; i < Basis.Length; i++)
            {
                begin += Begin[i] * Basis[i];
                end   += End[i] * Basis[i];
            }

            MovingMatrix = Matrix.Translation(new Vector3(0, 0, (begin - end).Length() / 2));
            Vector3 be     = end - begin;
            Vector3 curpos = new Vector3(0, 0, (begin - end).Length());
            float   angle  = (float)Math.Acos(VectorActions.scalmul(be, curpos) / (be.Length() * curpos.Length()));
            Vector3 axis   = VectorActions.vectmul(be, curpos);

            MovingMatrix *= Matrix.RotationAxis(axis, -angle);
            MovingMatrix *= Matrix.Translation(begin);

            meshes    = new Mesh[1];
            meshes[0] = Mesh.Cylinder(device, radius1, radius2, (begin - end).Length(), slices, stacks);
            meshes[0].ComputeNormals();
            material = new Material();
        }
Пример #2
0
        public static void RotateVertical(float angle)
        {
            Vector3 direction = lookat - position;
            Vector3 normal    = VectorActions.vectmul(vertical, direction);

            direction.TransformCoordinate(Matrix.RotationAxis(normal, -angle));
            lookat = direction + position;
            Initialize(position, lookat, vertical);
        }
Пример #3
0
        public Triangle(float[] FirstPoint, float[] SecondPoint, float[] ThirdPoint, Device dev)
        {
            device = dev;

            if ((Basis.Length != FirstPoint.Length) || (Basis.Length != SecondPoint.Length) ||
                (Basis.Length != ThirdPoint.Length))
            {
                throw new Exception("Размерность базиса не совпадает с размерностью вектора позиции или нормали.");
            }

            float_coordinates    = new float[3][];
            float_coordinates[0] = FirstPoint;
            float_coordinates[1] = SecondPoint;
            float_coordinates[2] = ThirdPoint;

            Vector3 first  = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 second = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 third  = new Vector3(0.0f, 0.0f, 0.0f);

            for (int i = 0; i < Basis.Length; i++)
            {
                first  += FirstPoint[i] * Basis[i];
                second += SecondPoint[i] * Basis[i];
                third  += ThirdPoint[i] * Basis[i];
            }

            verts             = new CustomVertex.PositionNormalColored[3];
            position          = new Vector3[3];
            position[0]       = first;
            position[1]       = second;
            position[2]       = third;
            verts[0].Position = first;
            verts[1].Position = second;
            verts[2].Position = third;
            normal            = VectorActions.vectmul(first - second, first - third);
            normal.Normalize();
            verts[0].Normal = verts[1].Normal = verts[2].Normal = normal;
        }