<commit_before>﻿using System;

namespace CSharpGL
{
    /// <summary>
    /// Transform model's position from model space to world space,
    /// including translation, scale and rotation.
    /// </summary>
    public partial class TransformComponent : Component
    {
        /// <summary>
        /// translate this object.
        /// </summary>
        public vec3 Position { get; set; }
        /// <summary>
        /// rotate this object.
        /// </summary>
        public vec3 Rotation { get; set; }
        /// <summary>
        /// scale this object.
        /// </summary>
        public vec3 Scale { get; set; }

        /// <summary>
        /// Transform model's position from model space to world space,
        /// including translation, scale and rotation.
        /// </summary>
        /// <param name="bindingObject"></param>
        public TransformComponent(SceneObject bindingObject = null)
            : base(bindingObject)
        {
            this.Scale = new vec3(1, 1, 1);
        }

        static readonly vec3 xAxis = new vec3(1, 0, 0);
        static readonly vec3 yAxis = new vec3(0, 1, 0);
        static readonly vec3 zAxis = new vec3(0, 0, 1);

        mat4 selfMatrix = mat4.identity();

        /// <summary>
        /// Get model matrix that transform model's position from model space to world space,
        /// Make sure the scene object list is traversed in pre-order.
        /// </summary>
        /// <returns></returns>
        public mat4 GetModelMatrix()
        {
            SceneObject obj = this.BindingObject;
            if (obj != null)
            {
                mat4 matrix = mat4.identity();
                matrix = glm.translate(matrix, this.Position);
                matrix = glm.scale(matrix, this.Scale);
                matrix = glm.rotate(matrix, (float)(this.Rotation.x * Math.PI / 180.0), xAxis);
                matrix = glm.rotate(matrix, (float)(this.Rotation.y * Math.PI / 180.0), yAxis);
                matrix = glm.rotate(matrix, (float)(this.Rotation.z * Math.PI / 180.0), zAxis);

                this.selfMatrix = matrix;
            }

            return this.selfMatrix;
        }
    }
}<commit_msg>matrix equals to (translate * scale * rotation) as below<commit_after>﻿using System;

namespace CSharpGL
{
    /// <summary>
    /// Transform model's position from model space to world space,
    /// including translation, scale and rotation.
    /// </summary>
    public partial class TransformComponent : Component
    {
        /// <summary>
        /// translate this object.
        /// </summary>
        public vec3 Position { get; set; }
        /// <summary>
        /// rotate this object.
        /// </summary>
        public vec3 Rotation { get; set; }
        /// <summary>
        /// scale this object.
        /// </summary>
        public vec3 Scale { get; set; }

        /// <summary>
        /// Transform model's position from model space to world space,
        /// including translation, scale and rotation.
        /// </summary>
        /// <param name="bindingObject"></param>
        public TransformComponent(SceneObject bindingObject = null)
            : base(bindingObject)
        {
            this.Scale = new vec3(1, 1, 1);
        }

        static readonly vec3 xAxis = new vec3(1, 0, 0);
        static readonly vec3 yAxis = new vec3(0, 1, 0);
        static readonly vec3 zAxis = new vec3(0, 0, 1);

        mat4 selfMatrix = mat4.identity();

        /// <summary>
        /// Get model matrix that transform model's position from model space to world space,
        /// Make sure the scene object list is traversed in pre-order.
        /// </summary>
        /// <returns></returns>
        public mat4 GetModelMatrix()
        {
            SceneObject obj = this.BindingObject;
            if (obj != null)
            {
                mat4 matrix = mat4.identity();
                matrix = glm.translate(matrix, this.Position);
                matrix = glm.scale(matrix, this.Scale);
                matrix = glm.rotate(matrix, (float)(this.Rotation.x * Math.PI / 180.0), xAxis);
                matrix = glm.rotate(matrix, (float)(this.Rotation.y * Math.PI / 180.0), yAxis);
                matrix = glm.rotate(matrix, (float)(this.Rotation.z * Math.PI / 180.0), zAxis);

                // matrix equals to (translate * scale * rotation) as below:
                //mat4 translate = glm.translate(mat4.identity(), this.Position);
                //mat4 scale = glm.scale(mat4.identity(), this.Scale);
                //mat4 rotation = glm.rotate(mat4.identity(), (float)(this.Rotation.x * Math.PI / 180.0), xAxis);
                //rotation = glm.rotate(rotation, (float)(this.Rotation.y * Math.PI / 180.0), yAxis);
                //rotation = glm.rotate(rotation, (float)(this.Rotation.z * Math.PI / 180.0), zAxis);

                this.selfMatrix = matrix;
            }

            return this.selfMatrix;
        }
    }
}
{'fraction_non_alphanumeric': 0.12972646822204345, 'fraction_numerical': 0.019308125502815767, 'mean_word_length': 1.6664879356568365, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3099887', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1315, 'n_words': 394}