CSharpGL.Quaternion.Parse C# (CSharp) Method

Parse() public method

public Parse ( float &angleDegree, vec3 &axis ) : void
angleDegree float
axis vec3
return void
        public void Parse(out float angleDegree, out vec3 axis)
        {
            angleDegree = (float)(Math.Acos(w) * 2 * 180.0 / Math.PI);
            axis = (new vec3(x, y, z)).normalize();
        }

Usage Example

Example #1
0
        ///// <summary>
        ///// Get model matrix.
        ///// </summary>
        ///// <param name="model"></param>
        ///// <returns></returns>
        //public static mat4 GetModelMatrix(this IWorldSpace model)
        //{
        //    mat4 matrix = glm.translate(mat4.identity(), model.WorldPosition);
        //    matrix = glm.scale(matrix, model.Scale);
        //    matrix = glm.rotate(matrix, model.RotationAngle, model.RotationAxis);

        //    var node = model as RendererBase;
        //    if (node != null)
        //    {
        //        var parent = node.Parent as RendererBase;
        //        if (parent != null)
        //        {
        //            matrix = parent.modelMat * matrix;
        //        }

        //        node.modelMat = matrix;
        //    }

        //    return matrix;
        //}

        /// <summary>
        /// Rotate this model based on all previous rotation actions.
        /// Thus all rotations will take part in model's rotation result.
        /// <para>在目前的旋转状态下继续旋转一次,即所有的旋转操作都会(按照发生顺序)生效。</para>
        /// </summary>
        /// <param name="model"></param>
        /// <param name="angleDegree">Angle in Degree.</param>
        /// <param name="axis"></param>
        public static void Rotate(this IWorldSpace model, float angleDegree, vec3 axis)
        {
            mat4       currentRotationMatrix = glm.rotate(model.RotationAngle, model.RotationAxis);
            mat4       newRotationMatrix     = glm.rotate(angleDegree, axis);
            mat4       latestRotationMatrix  = newRotationMatrix * currentRotationMatrix;
            Quaternion quaternion            = latestRotationMatrix.ToQuaternion();
            float      latestAngle;
            vec3       latestAxis;

            quaternion.Parse(out latestAngle, out latestAxis);
            model.RotationAngle = latestAngle;
            model.RotationAxis  = latestAxis;
        }
All Usage Examples Of CSharpGL.Quaternion::Parse