///// <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;
}