{"size": 4527, "ext": "js", "max_stars_repo_path": "src/mathematics/transform.js", "max_stars_repo_name": "ucesana/qd3d", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/mathematics/transform.js", "max_issues_repo_name": "ucesana/qd3d", "max_issues_repo_issues_event_min_datetime": "2020-09-12T07:07:02.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T06:49:06.000Z", "max_forks_repo_path": "src/mathematics/transform.js", "max_forks_repo_name": "ucesana/qd3d", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 12, "max_forks_count": null, "avg_line_length": 25.15, "max_line_length": 41, "alphanum_fraction": 0.4413518887}
import { Mat44 } from "./mat44";

export const Transform = {
    translate: function (t, out) {
        let transform = null;
        if (!out) {
            transform = Mat44.identity();
        } else {
            transform = out;
        }

        transform[0][0] = 1;
        transform[0][1] = 0;
        transform[0][2] = 0;
        transform[0][3] = 0;
        transform[1][0] = 0;
        transform[1][1] = 1;
        transform[1][2] = 0;
        transform[1][3] = 0;
        transform[2][0] = 0;
        transform[2][1] = 0;
        transform[2][2] = 1;
        transform[2][3] = 0;
        transform[3][0] = t[0];
        transform[3][1] = t[1];
        transform[3][2] = t[2];
        transform[3][3] = 1;
        return out;
    },

    scale: function (s, out) {
        let transform = null;
        if (!out) {
            transform = Mat44.identity();
        } else {
            transform = out;
        }

        transform[0][0] = s[0];
        transform[0][1] = 0;
        transform[0][2] = 0;
        transform[0][3] = 0;
        transform[1][0] = 0;
        transform[1][1] = s[1];
        transform[1][2] = 0;
        transform[1][3] = 0;
        transform[2][0] = 0;
        transform[2][1] = 0;
        transform[2][2] = s[2];
        transform[2][3] = 0;
        transform[3][0] = 0;
        transform[3][1] = 0;
        transform[3][2] = 0;
        transform[3][3] = 1;

        return transform;
    },

    shear: function (k, out) {
        let transform = null;
        if (!out) {
            transform = Mat44.identity();
        } else {
            transform = out;
        }

        transform[0][0] = 1;
        transform[0][1] = 0;
        transform[0][2] = 0;
        transform[0][3] = 0;
        transform[1][0] = 0;
        transform[1][1] = 1;
        transform[1][2] = 0;
        transform[1][3] = 0;
        transform[2][0] = 0;
        transform[2][1] = 0;
        transform[2][2] = 1;
        transform[2][3] = 0;
        transform[3][0] = 0;
        transform[3][1] = 0;
        transform[3][2] = 0;
        transform[3][3] = 1;
        // TODO:
        return transform;
    },

    rotateX: function (theta, out) {
        let transform = null;
        if (!out) {
            transform = Mat44.identity();
        } else {
            transform = out;
        }

        const cosTheta = Math.cos(theta);
        const sinTheta = Math.sin(theta);

        transform[0][0] = 1;
        transform[0][1] = 0;
        transform[0][2] = 0;
        transform[0][3] = 0;
        transform[1][0] = 0;
        transform[1][1] = cosTheta;
        transform[1][2] = sinTheta;
        transform[1][3] = 0;
        transform[2][0] = 0;
        transform[2][1] = -sinTheta;
        transform[2][2] = cosTheta;
        transform[2][3] = 0;
        transform[3][0] = 0;
        transform[3][1] = 0;
        transform[3][2] = 0;
        transform[3][3] = 1;

        return transform;
    },

    rotateY: function (theta, out) {
        let transform = null;
        if (!out) {
            transform = Mat44.identity();
        } else {
            transform = out;
        }

        const cosTheta = Math.cos(theta);
        const sinTheta = Math.sin(theta);

        transform[0][0] = cosTheta;
        transform[0][1] = 0;
        transform[0][2] = -sinTheta;
        transform[0][3] = 0;
        transform[1][0] = 0;
        transform[1][1] = 1;
        transform[1][2] = 0;
        transform[1][3] = 0;
        transform[2][0] = sinTheta;
        transform[2][1] = 0;
        transform[2][2] = cosTheta;
        transform[2][3] = 0;
        transform[3][0] = 0;
        transform[3][1] = 0;
        transform[3][2] = 0;
        transform[3][3] = 1;

        return transform;
    },

    rotateZ: function (theta, out) {
        let transform = null;
        if (!out) {
            transform = Mat44.identity();
        } else {
            transform = out;
        }

        const cosTheta = Math.cos(theta);
        const sinTheta = Math.sin(theta);

        transform[0][0] = cosTheta;
        transform[0][1] = sinTheta;
        transform[0][2] = 0;
        transform[0][3] = 0;
        transform[1][0] = -sinTheta;
        transform[1][1] = cosTheta;
        transform[1][2] = 0;
        transform[1][3] = 0;
        transform[2][0] = 0;
        transform[2][1] = 0;
        transform[2][2] = 1;
        transform[2][3] = 0;
        transform[3][0] = 0;
        transform[3][1] = 0;
        transform[3][2] = 0;
        transform[3][3] = 1;

        return transform;
    }
};
