Пример #1
0
        private void BufferData(Camera camera)
        {
            var    coneHeight = 0.25f;
            Conic_ arrow      = new Conic_(coneHeight, coneHeight / Maths.Phi);

            var rightArrowCoordinates   = TransformCoordinates(ref arrow, this.right);
            var forwardArrowCoordinates = TransformCoordinates(ref arrow, this.forward);
            var upArrowCoordinates      = TransformCoordinates(ref arrow, this.up);

            var vertexCount = arrow.VertexCoordinates.Count;

            var magic       = 1 - Maths.PhiConjugate;
            var coordinates = new Vector3[] {
                origin + right * magic,
                origin + forward * magic,
                origin + up * magic,
                origin + right,
                origin + forward,
                origin + up
            }
            .Concat(rightArrowCoordinates)
            .Concat(forwardArrowCoordinates)
            .Concat(upArrowCoordinates).ToArray( );

            var indices           = new ushort[] { 0, 3, 1, 4, 2, 5 };
            var offset            = indices.Length;
            var rightArrowIndices = arrow.Indices.Select(x => x == ushort.MaxValue ? x : (ushort)(x + offset)).ToArray( );

            offset += vertexCount;
            var forwardArrowIndices = arrow.Indices.Select(x => x == ushort.MaxValue ? x : (ushort)(x + offset)).ToArray( );

            offset += vertexCount;
            var upArrowIndices = arrow.Indices.Select(x => x == ushort.MaxValue ? x : (ushort)(x + offset)).ToArray( );

            indices = indices.Concat(rightArrowIndices).Concat(new[] { ushort.MaxValue })
                      .Concat(forwardArrowIndices).Concat(new[] { ushort.MaxValue })
                      .Concat(upArrowIndices).ToArray( );

            this.elementCount = indices.Length;

            BufferData(coordinates, indices);
        }
Пример #2
0
        private IEnumerable <Vector3> TransformCoordinates(ref Conic_ arrow, Vector3 targetAxis)
        {
            var normal = targetAxis;

            normal.Normalize( );
            normal.Normalize( );// idk.
            var dot = Vector3.Dot(Vector3.UnitZ, normal);

            var axis       = Vector3.Cross(Vector3.UnitZ, normal);
            var projection = axis.Length;
            var angle      = (float)Math.Acos(dot);


            var translationMatrix = Matrix4.CreateTranslation(origin + targetAxis);
            var rotationMatrix    = dot == 1 || dot == -1 ? Matrix4.Identity : Matrix4.CreateFromAxisAngle(axis, angle);
            var scaleMatrix       = Matrix4.CreateScale(this.scale == 0 ? 1 : scale);

            var matrix = scaleMatrix * rotationMatrix * translationMatrix;

            var rightArrowCoordinates = arrow.VertexCoordinates.Select(x => Vector3.Transform(x, matrix)).ToArray( );

            return(rightArrowCoordinates);
        }
Пример #3
0
        private IEnumerable<Vector3> TransformCoordinates(ref Conic_ arrow, Vector3 targetAxis)
        {
            var normal = targetAxis;
            normal.Normalize();
            normal.Normalize();// idk.
            var dot = Vector3.Dot(Vector3.UnitZ, normal);

            var axis = Vector3.Cross(Vector3.UnitZ, normal);
            var projection = axis.Length;
            var angle = (float)Math.Acos(dot);


            var translationMatrix = Matrix4.CreateTranslation(origin + targetAxis);
            var rotationMatrix = dot == 1 || dot == -1 ? Matrix4.Identity : Matrix4.CreateFromAxisAngle(axis, angle);
            var scaleMatrix = Matrix4.CreateScale(this.scale == 0 ? 1 : scale);

            var matrix = scaleMatrix * rotationMatrix * translationMatrix;

            var rightArrowCoordinates = arrow.VertexCoordinates.Select(x => Vector3.Transform(x, matrix)).ToArray();

            return rightArrowCoordinates;
        }
Пример #4
0
        private void BufferData(Camera camera)
        {
            var coneHeight = 0.25f;
            Conic_ arrow = new Conic_(coneHeight, coneHeight / Maths.Phi);

            var rightArrowCoordinates = TransformCoordinates(ref arrow, this.right);
            var forwardArrowCoordinates = TransformCoordinates(ref arrow, this.forward);
            var upArrowCoordinates = TransformCoordinates(ref arrow, this.up);

            var vertexCount = arrow.VertexCoordinates.Count;

            var magic = 1 - Maths.PhiConjugate;
            var coordinates = new Vector3[] { 
                origin + right * magic, 
                origin + forward * magic, 
                origin + up * magic,
                origin + right, 
                origin + forward, 
                origin + up }
                .Concat(rightArrowCoordinates)
            .Concat(forwardArrowCoordinates)
            .Concat(upArrowCoordinates).ToArray();

            var indices = new ushort[] { 0, 3, 1, 4, 2, 5 };
            var offset = indices.Length;
            var rightArrowIndices = arrow.Indices.Select(x => x == ushort.MaxValue ? x : (ushort)(x + offset)).ToArray();
            offset += vertexCount;
            var forwardArrowIndices = arrow.Indices.Select(x => x == ushort.MaxValue ? x : (ushort)(x + offset)).ToArray();
            offset += vertexCount;
            var upArrowIndices = arrow.Indices.Select(x => x == ushort.MaxValue ? x : (ushort)(x + offset)).ToArray();
            indices = indices.Concat(rightArrowIndices).Concat(new[] { ushort.MaxValue })
                .Concat(forwardArrowIndices).Concat(new[] { ushort.MaxValue })
                .Concat(upArrowIndices).ToArray();

            this.elementCount = indices.Length;

            BufferData(coordinates, indices);
        }