<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpGL
{
    // ReSharper disable InconsistentNaming
    public static partial class glm
    {
        /// <summary>
        /// Creates a frustrum projection matrix.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <param name="bottom">The bottom.</param>
        /// <param name="top">The top.</param>
        /// <param name="nearVal">The near val.</param>
        /// <param name="farVal">The far val.</param>
        /// <returns></returns>
        public static mat4 frustum(float left, float right, float bottom, float top, float nearVal, float farVal)
        {
            var result = mat4.identity();

            result[0, 0] = (2.0f * nearVal) / (right - left);
            result[1, 1] = (2.0f * nearVal) / (top - bottom);
            result[2, 0] = (right + left) / (right - left);
            result[2, 1] = (top + bottom) / (top - bottom);
            result[2, 2] = -(farVal + nearVal) / (farVal - nearVal);
            result[2, 3] = -1.0f;
            result[3, 2] = -(2.0f * farVal * nearVal) / (farVal - nearVal);
            result[3, 3] = 0.0f;

            return result;
        }

        /// <summary>
        /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite.
        /// </summary>
        /// <param name="fovy">The fovy.</param>
        /// <param name="aspect">The aspect.</param>
        /// <param name="zNear">The z near.</param>
        /// <returns></returns>
        public static mat4 infinitePerspective(float fovy, float aspect, float zNear)
        {

            float range = tan(fovy / (2f)) * zNear;

            float left = -range * aspect;
            float right = range * aspect;
            float bottom = -range;
            float top = range;

            var result = new mat4(0);
            result[0, 0] = ((2f) * zNear) / (right - left);
            result[1, 1] = ((2f) * zNear) / (top - bottom);
            result[2, 2] = -(1f);
            result[2, 3] = -(1f);
            result[3, 2] = -(2f) * zNear;
            return result;
        }

        /// <summary>
        /// Build a look at view matrix.
        /// transform object's coordinate from world's space to camera's space.
        /// </summary>
        /// <param name="eye">The eye.</param>
        /// <param name="center">The center.</param>
        /// <param name="up">Up.</param>
        /// <returns></returns>
        public static mat4 lookAt(vec3 eye, vec3 center, vec3 up)
        {
            vec3 forward = (center - eye).normalize();
            vec3 right = forward.cross(up).normalize();
            vec3 standardUp = right.cross(forward);

            mat4 Result = new mat4(1);
            // Left (X) Axis
            Result[0, 0] = right.x;
            Result[0, 1] = standardUp.x;
            Result[0, 2] = -forward.x;
            // Up (Y) Axis
            Result[1, 0] = right.y;
            Result[1, 1] = standardUp.y;
            Result[1, 2] = -forward.y;
            // Forward (Z) Axis
            Result[2, 0] = right.z;
            Result[2, 1] = standardUp.z;
            Result[2, 2] = -forward.z;
            // Translation
            Result[3, 0] = -right.dot(eye);// dot(s, eye);
            Result[3, 1] = -standardUp.dot(eye);// dot(u, eye);
            Result[3, 2] = forward.dot(eye);// dot(f, eye);
            return Result;
        }
<commit_msg>glm.lookAt() using bacok, right, up<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpGL
{
    // ReSharper disable InconsistentNaming
    public static partial class glm
    {
        /// <summary>
        /// Creates a frustrum projection matrix.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <param name="bottom">The bottom.</param>
        /// <param name="top">The top.</param>
        /// <param name="nearVal">The near val.</param>
        /// <param name="farVal">The far val.</param>
        /// <returns></returns>
        public static mat4 frustum(float left, float right, float bottom, float top, float nearVal, float farVal)
        {
            var result = mat4.identity();

            result[0, 0] = (2.0f * nearVal) / (right - left);
            result[1, 1] = (2.0f * nearVal) / (top - bottom);
            result[2, 0] = (right + left) / (right - left);
            result[2, 1] = (top + bottom) / (top - bottom);
            result[2, 2] = -(farVal + nearVal) / (farVal - nearVal);
            result[2, 3] = -1.0f;
            result[3, 2] = -(2.0f * farVal * nearVal) / (farVal - nearVal);
            result[3, 3] = 0.0f;

            return result;
        }

        /// <summary>
        /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite.
        /// </summary>
        /// <param name="fovy">The fovy.</param>
        /// <param name="aspect">The aspect.</param>
        /// <param name="zNear">The z near.</param>
        /// <returns></returns>
        public static mat4 infinitePerspective(float fovy, float aspect, float zNear)
        {

            float range = tan(fovy / (2f)) * zNear;

            float left = -range * aspect;
            float right = range * aspect;
            float bottom = -range;
            float top = range;

            var result = new mat4(0);
            result[0, 0] = ((2f) * zNear) / (right - left);
            result[1, 1] = ((2f) * zNear) / (top - bottom);
            result[2, 2] = -(1f);
            result[2, 3] = -(1f);
            result[3, 2] = -(2f) * zNear;
            return result;
        }

        /// <summary>
        /// Build a look at view matrix.
        /// transform object's coordinate from world's space to camera's space.
        /// </summary>
        /// <param name="eye">The eye.</param>
        /// <param name="center">The center.</param>
        /// <param name="up">Up.</param>
        /// <returns></returns>
        public static mat4 lookAt(vec3 eye, vec3 center, vec3 up)
        {
            vec3 back = (eye - center).normalize();
            vec3 right = up.cross(back).normalize();
            vec3 standardUp = back.cross(right);

            mat4 Result = new mat4(1);
            // Left (X) Axis
            Result[0, 0] = right.x;
            Result[0, 1] = standardUp.x;
            Result[0, 2] = back.x;
            // Up (Y) Axis
            Result[1, 0] = right.y;
            Result[1, 1] = standardUp.y;
            Result[1, 2] = back.y;
            // Forward (Z) Axis
            Result[2, 0] = right.z;
            Result[2, 1] = standardUp.z;
            Result[2, 2] = back.z;
            // Translation
            Result[3, 0] = -right.dot(eye);// dot(s, eye);
            Result[3, 1] = -standardUp.dot(eye);// dot(u, eye);
            Result[3, 2] = -back.dot(eye);// dot(f, eye);
            return Result;
        }

{'fraction_non_alphanumeric': 0.1617709065354884, 'fraction_numerical': 0.022768798313422347, 'mean_word_length': 1.5541995692749462, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 75, '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': '1048454', 'n_tokens_mistral': 2277, 'n_tokens_neox': 2156, 'n_words': 592}