Пример #1
0
        public Quaternion Multiply(Quaternion other)
        {
            Float3 vA = ToFloat3();
            Float3 vB = other.ToFloat3();

            Float4 result = new Float4(vA.Cross(vB) + vA * other.W + vB * W, W * other.W - vA.Dot(vB));

            return(new Quaternion(result));
        }
Пример #2
0
        public Float4 RotateVector(Float4 vector)
        {
            Float3 u      = ToFloat3();
            Float3 v      = new Float3(vector);
            Float3 result = 2.0f * u.Dot(v) * u;

            result += (W * W - u.Dot(u)) * v;
            result += 2.0f * W * u.Cross(v);
            return(new Float4(result));
        }
Пример #3
0
        public static void DrawAnchor(Float3 origin, Float3 up, Float3 forward)
        {
            up      = up.Normalized;
            forward = forward.Normalized;
            Float3 right = up.Cross(forward);

            Gizmos.color = Color.red;
            DrawArrow(origin, origin + right);

            Gizmos.color = Color.green;
            DrawArrow(origin, origin + up);

            Gizmos.color = Color.blue;
            DrawArrow(origin, origin + forward);
        }
        public void SetViewParameters(Float3 eyePosition, Float3 lookPosition, Float3 up)
        {
            this.position  = eyePosition;
            this.direction = (lookPosition - eyePosition).Normalize();
            Float3 zAxis   = -this.direction;
            Float3 xAxis   = Float3.Cross(up, zAxis).Normalize();
            Float3 yAxis   = Float3.Cross(zAxis, xAxis);
            float  xOffset = -Float3.Dot(xAxis, this.position);
            float  yOffset = -Float3.Dot(yAxis, this.position);
            float  zOffset = -Float3.Dot(zAxis, this.position);

            this.view = new Float4X4(
                xAxis.X, xAxis.Y, xAxis.Z, xOffset,
                yAxis.X, yAxis.Y, yAxis.Z, yOffset,
                zAxis.X, zAxis.Y, zAxis.Z, zOffset,
                0.0f, 0.0f, 0.0f, 1.0f
                );
        }
Пример #5
0
        public static void DrawArrow(Float3 origin, Float3 end, float length)
        {
            Gizmos.DrawLine(origin, end);

            var rotation = Quaternion.FromToRotation(Float3.up, origin - end);

            DrawPiece(Float3.right);
            DrawPiece(Float3.forward);
            DrawPiece(Float3.left);
            DrawPiece(Float3.backward);

            void DrawPiece(Float3 perpendicular)
            {
                const float Angle = 30f;

                var localRotation = Quaternion.AngleAxis(Angle, Float3.Cross(Float3.up, perpendicular));

                Gizmos.DrawLine(end, (Vector3)end + rotation * localRotation * Float3.up * length);
            }
        }
Пример #6
0
        /// <summary>
        /// Downloads the raw vertex buffer that contains mesh vertices data. To download data from GPU set <paramref name="forceGpu"/> to true and call this method from the thread other than main thread (see <see cref="Platform.IsInMainThread"/>).
        /// </summary>
        /// <param name="forceGpu">If set to <c>true</c> the data will be downloaded from the GPU, otherwise it can be loaded from the drive (source asset file) or from memory (if cached). Downloading mesh from GPU requires this call to be made from the other thread than main thread. Virtual assets are always downloaded from GPU memory due to lack of dedicated storage container for the asset data.</param>
        /// <returns>The gathered data.</returns>
        public Vertex[] DownloadVertexBuffer(bool forceGpu = false)
        {
            // TODO: perform data conversion on C++ side to make it faster

            var vb0 = DownloadVertexBuffer0(forceGpu);

            var vertices = VertexCount;
            var result   = new Vertex[vertices];

            for (int i = 0; i < vertices; i++)
            {
                ref var v0            = ref vb0[i];
                float   bitangentSign = v0.Tangent.A > Mathf.Epsilon ? -1.0f : +1.0f;

                result[i].Position     = v0.Position;
                result[i].TexCoord     = (Float2)v0.TexCoord;
                result[i].Normal       = v0.Normal.ToFloat3() * 2.0f - 1.0f;
                result[i].Tangent      = v0.Tangent.ToFloat3() * 2.0f - 1.0f;
                result[i].Bitangent    = Float3.Cross(result[i].Normal, result[i].Tangent) * bitangentSign;
                result[i].BlendIndices = new Int4(v0.BlendIndices.R, v0.BlendIndices.G, v0.BlendIndices.B, v0.BlendIndices.A);
                result[i].BlendWeights = (Float4)v0.BlendWeights;
            }
Пример #7
0
        public sealed override void UpdateMapping(RyneCamera camera, EditAxis axis)
        {
            Float3 xAxis, yAxis;

            if (axis == EditAxis.All)
            {
                // Set axes from plane tangents relative to camera
                Float3 planeNormal = (camera.Focus - new Float3(camera.GetPosition())).Normalize();
                xAxis = planeNormal.Cross(camera.Up).Normalize() * -1.0f;
                yAxis = xAxis.Cross(planeNormal).Normalize();
            }
            else
            {
                xAxis = AxisToFloat3(axis);
                yAxis = xAxis;
            }

            MouseAxisInputs[0] = new MouseAxisInput {
                Axis = new Float2(1, 0), Action = new InputMovementAction(xAxis, Speed, false)
            };
            MouseAxisInputs[1] = new MouseAxisInput {
                Axis = new Float2(0, 1), Action = new InputMovementAction(yAxis, Speed, false)
            };
        }