<commit_before>/**
 * @file breaches.cpp
 *
 * @brief Controls the breaches.
 *
 * @section LICENSE
 *
 * Copyright (c) 2011 <NAME>
 *
 * This file is part of Breach.
 *
 * Licensed under the Simplified BSD License,
 * for details please see LICENSE file or the website
 * http://www.opensource.org/licenses/BSD-2-Clause
 */

#include "breaches.hpp"

using namespace std;



std::vector<Breach> breaches;

IRenderable* breachesRenderer;



const float Breach::DEFAULT_BREACH_WIDTH = 0.8;
const float Breach::DEFAULT_BREACH_HEIGHT = 0.8;

Matrix<float,2,1> Breach::getAdjustedShotPoint(const Wall& wall, const Matrix<float,2,1> shotPoint)
{
    float x = shotPoint[0];
    float y = shotPoint[1];
    float aNorm = wall.getAxisA().norm();
    float bNorm = wall.getAxisB().norm();
    if (x - DEFAULT_BREACH_WIDTH /2/aNorm < 0) x =     DEFAULT_BREACH_WIDTH /2/aNorm;
    if (x + DEFAULT_BREACH_WIDTH /2/aNorm > 1) x = 1 - DEFAULT_BREACH_WIDTH /2/aNorm;
    if (y - DEFAULT_BREACH_HEIGHT/2/bNorm < 0) y =     DEFAULT_BREACH_HEIGHT/2/bNorm;
    if (y + DEFAULT_BREACH_HEIGHT/2/bNorm > 1) y = 1 - DEFAULT_BREACH_HEIGHT/2/bNorm;
    if (x < 0 || y < 0) return shotPoint;
    return Matrix<float,2,1>((float[]){x, y});
}

Matrix<float,4,4> Breach::getTransformationFromWall(const Wall& wall, const Matrix<float,2,1> shotPoint)
{
    Matrix<float,4,1> a = wall.getAxisA();
    Matrix<float,4,1> b = wall.getAxisB();
    Matrix<float,4,1> c = wall.getCorner();
    Matrix<float,4,1> z = a * b;
    z = z / z.norm();
    Matrix<float,4,1> t = c + a*shotPoint[0] + b*shotPoint[1];
    a = a * (DEFAULT_BREACH_WIDTH /2 / a.norm());
    b = b * (DEFAULT_BREACH_HEIGHT/2 / b.norm());
    Matrix<float,4,4> rtn ((float[]){a[0],a[1],a[2],0, b[0],b[1],b[2],0, z[0],z[1],z[2],0, t[0],t[1],t[2],1});
    return rtn;
}

Breach::Breach(bool opened, const Wall& wall, Matrix<float,2,1> shotPoint)
: opened(opened)
, wall(&wall)
, transformation(getTransformationFromWall(wall, getAdjustedShotPoint(wall, shotPoint)))
{
}

Breach::Breach(bool opened, const Wall& wall, Matrix<float,4,4> transformation)
: opened(opened)
, wall(&wall)
, transformation(transformation)
{
}

Breach::~Breach()
{<commit_msg>Take inclination into account when shooting breaches.<commit_after>/**
 * @file breaches.cpp
 *
 * @brief Controls the breaches.
 *
 * @section LICENSE
 *
 * Copyright (c) 2011 <NAME>
 *
 * This file is part of Breach.
 *
 * Licensed under the Simplified BSD License,
 * for details please see LICENSE file or the website
 * http://www.opensource.org/licenses/BSD-2-Clause
 */

#include "breaches.hpp"

using namespace std;



// From main.cpp
// TODO: Create a separate header for the player
extern Matrix<float,4,1> playerInclinaison;



std::vector<Breach> breaches;

IRenderable* breachesRenderer;



const float Breach::DEFAULT_BREACH_WIDTH = 0.8;
const float Breach::DEFAULT_BREACH_HEIGHT = 0.8;

Matrix<float,2,1> Breach::getAdjustedShotPoint(const Wall& wall, const Matrix<float,2,1> shotPoint)
{
    float x = shotPoint[0];
    float y = shotPoint[1];
    float aNorm = wall.getAxisA().norm();
    float bNorm = wall.getAxisB().norm();
    if (x - DEFAULT_BREACH_WIDTH /2/aNorm < 0) x =     DEFAULT_BREACH_WIDTH /2/aNorm;
    if (x + DEFAULT_BREACH_WIDTH /2/aNorm > 1) x = 1 - DEFAULT_BREACH_WIDTH /2/aNorm;
    if (y - DEFAULT_BREACH_HEIGHT/2/bNorm < 0) y =     DEFAULT_BREACH_HEIGHT/2/bNorm;
    if (y + DEFAULT_BREACH_HEIGHT/2/bNorm > 1) y = 1 - DEFAULT_BREACH_HEIGHT/2/bNorm;
    if (x < 0 || y < 0) return shotPoint;
    return Matrix<float,2,1>((float[]){x, y});
}

Matrix<float,4,4> Breach::getTransformationFromWall(const Wall& wall, const Matrix<float,2,1> shotPoint)
{
    Matrix<float,4,1> a = wall.getAxisA();
    Matrix<float,4,1> b = wall.getAxisB();
    Matrix<float,4,1> c = wall.getCorner();
    Matrix<float,4,1> z = a * b;
    z = z / z.norm();
    Matrix<float,4,1> t = c + a*shotPoint[0] + b*shotPoint[1];
    a = a / a.norm();
    b = b / b.norm();
    Matrix<float,1,4> upT (playerInclinaison.values);
    upT = upT / upT.norm();
    a(3,0) = b(3,0) = upT(0,3) = 0; // merely for the following vector product
    float upA = (upT * a)[0];
    float upB = (upT * b)[0];
    a = a * (DEFAULT_BREACH_WIDTH /2);
    b = b * (DEFAULT_BREACH_HEIGHT/2);
    Matrix<float,4,4> rtn ((float[]){a[0],a[1],a[2],0, b[0],b[1],b[2],0, z[0],z[1],z[2],0, t[0],t[1],t[2],1});
    float upAngle = -atan2(upA,upB);
    rtn = rtn * MatrixHelper::rotation(upAngle, MatrixHelper::unitAxisVector<float>(2));
    return rtn;
}

Breach::Breach(bool opened, const Wall& wall, Matrix<float,2,1> shotPoint)
: opened(opened)
, wall(&wall)
, transformation(getTransformationFromWall(wall, getAdjustedShotPoint(wall, shotPoint)))
{
}

Breach::Breach(bool opened, const Wall& wall, Matrix<float,4,4> transformation)
: opened(opened)
, wall(&wall)
, transformation(transformation)
{
}

Breach::~Breach()
{
{'fraction_non_alphanumeric': 0.16646191646191646, 'fraction_numerical': 0.03296478296478297, 'mean_word_length': 4.147523709167545, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2832633', 'n_tokens_mistral': 1947, 'n_tokens_neox': 1868, 'n_words': 412}