# data[].attributes.body
glm::vec3 v(2, -1, 1);
glm::vec3 u(1, 1, 2);
float d = glm::dot(v, u);
float a = glm::length(v);
float b = glm::length(u);
float res;

a = glm::sqrt(a);
b = glm::sqrt(b);
d / (a * b);
glm::acos(d);
res = d;
res = res * 180 / glm::pi<float>();
std::cout << res << std::endl;
return 0;

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtc/constants.hpp>

const double DEGREES_TO_RADIANS = glm::pi<float>() / 180.0;
const double RADIANS_TO_DEGREES = 180.0 / glm::pi<float>();

int main() {
glm::vec3 v(2, -1, 1);
glm::vec3 u(1, 1, 2);
float F = glm::acos((glm::dot(u, v) / (glm::length(u) * glm::length(v)))) * RADIANS_TO_DEGREES;
std::cout << F << std::endl;
return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtc/constants.hpp>

const double DEGREE_TO_RADIAN = glm::pi<float>() / 180.0;
const double RADIAN_TO_DEGREE = 180.0 / glm::pi<float>();

void cours3() {
glm::vec3 v1(2, -1, 1);
glm::vec3 v2(1, 1, 2);

float f = glm::dot(v1, v2);
float g = f / (glm::length(v1), glm::length(v2));
float h = glm::acos(g) * RADIAN_TO_DEGREE;

std::cout << h << std::endl;
}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include "glm/vec2.hpp"

#include "glm/vec3.hpp"

#include "glm/gtx/string_cast.hpp"

#include "glm/gtc/constants.hpp"

#include <iostream>

int main()

{

const double DEGREES_TO_RADIANS = glm::pi<float>() / 180.0;

const double RADIANS_TO_DEGREES = 180.0 / glm::pi<float>();

glm::vec3 v(2, -1, 1);

glm::vec3 u(1, 1, 2);

float deg = glm::acos(glm::dot(v, u) / (glm::length(u) * glm::length(v))) * RADIANS_TO_DEGREES;

std::cout << deg << std::endl;

}

# data[].attributes.body
const double DEGREES_TO_RADIANS = glm::pi<float>() / 180.0;
const double RADIANS_TO_DEGREES = 180.0 / glm::pi<float>();

glm::vec3 v(2, -1, 1);
glm::vec3 u(1, 1, 2);

float c = glm::dot(v, u) / (glm::length(u) * glm::length(v));
std::cout << glm::acos(c)*RADIANS_TO_DEGREES << std::endl;

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>
#include <glm/vec2.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtx/string_cast.hpp>

int main() {
const float DEGREES_TO_RADIANS = glm::pi<float>() / 180.0;
const float RADIANS_TO_DEGREES = 180.0 / glm::pi<float>();

glm::vec3 a(2, -1, 1);
glm::vec3 b(1, 1, 2);

float d = glm::dot(a, b);
float c = d / (glm::length(a) * glm::length(b));
float deg = glm::acos(c) * RADIANS_TO_DEGREES;
std::cout << deg << std::endl;
return 0;
}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

#include <glm/gtc/constants.hpp>

const double DEGREES_TO_RADIANS = glm::pi<float>() / 180.0;

const double RADIANS_TO_DEGREES = 180.0 / glm::pi<float>();

int main()

{

glm::vec3 v(2, -1, 1);

glm::vec2 u(1, 1, 2);

float rad = glm::acos(glm::dot(v, u) / (glm::length(u) * glm::length(v)));

float deg = rad * RADIANS_TO_DEGREES;

std::cout << deg << std::endl;

return 0;

}

# data[].attributes.body
#include "pch.h"
#include <iostream>
#include <glm/vec2.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtx/string_cast.hpp>

int main() {
#define GLM_ENABLE_EXPERIMENTAL

const float DEGREES_TO_RADIANS = glm::pi<float>() / 180.0;
const float RADIANS_TO_DEGREES = 180.0 / glm::pi<float>();

glm::vec3 v(2, -1, 1);
glm::vec3 u(1, 1, 2);

float d = glm::dot(v, u);
float c = d / (glm::length(u) * glm::length(v));
float deg = glm::acos(c) * RADIANS_TO_DEGREES;
std::cout << c << std::endl;
}

# data[].attributes.body
#include "pch.h"
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>

int main()
{

#define GLM_ENABLE_EXPERIMENTAL
glm::vec3 p(1,4,-5);
glm::vec3 p2(4,-3,9);
glm::vec3 v = p + p2;
std::cout << glm::to_string(v) << std::endl;

glm::vec3 v1(1,0,0);
glm::vec3 v2(0,1,0);
glm::vec3 v3 = v1 + v2;
std::cout << glm::to_string(v3) << std::endl;

v1 = v2 * 5.0f;
std::cout << glm::to_string(v1) << std::endl;

glm::vec3 p3(8,2,5);
glm::vec3 p4(1,-1,4);
v = p4 - p3;
std::cout << glm::to_string(v) << std::endl;

glm::vec3 v4(1, 3, 4);
glm::vec3 v_norm = glm::normalize(v3);
std::cout << glm::to_string(v_norm) << std::endl;
}

# data[].attributes.body
#include <iostream>

#define GLM_ENABLE_EXPERIMENTAL

#include <glm/vec3.hpp>
#include <glm/gtx/string_cast.hpp>

void step1() {
glm::vec3 v1(1, 4, -5);
glm::vec3 v2(5, 1, 4);

std::cout << glm::to_string(v1 + v2) << std::endl;
}

void step2(){
glm::vec3 v1(1, 0, 3);
glm::vec3 v2(0, 1, 0);

std::cout << glm::to_string(v1 + v2) << std::endl;
}

void step3() {
glm::vec3 v1(1, 4, -5);
std::cout << glm::to_string(v1 * 5.0f) << std::endl;
}

void step4() {
std::cout << glm::to_string(glm::vec3(1,-1,4) - glm::vec3(8, 2, 5)) << std::endl;
}

void step5() {
glm::vec3 v(1, 3, 4);
std::cout << glm::to_string(glm::normalize(v)) << std::endl;
}

int main() {
step1();
step2();
step3();
step4();
step5();
}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>

int main() {
//Step 1
glm::vec3 p(1, 4, -5);
glm::vec3 v(5, 1, 4);
p = p + v;
std::cout << glm::to_string(p) << std::endl;

//Step 2
glm::vec3 v1(1, 0, 0);
glm::vec3 v2(0, 1, 0);
glm::vec3 v3 = v1 + v2;
std::cout << glm::to_string(v3) << std::endl;

//Step 3
v1 = glm::vec3(0, 1, 0);
v1 = v1 * 5.0f;
std::cout << glm::to_string(v1) << std::endl;

//Step 4
v = glm::vec3(8, 2, 5);
glm::vec3 v4(1, -1, 4);
v = v4 - v;
std::cout << glm::to_string(v) << std::endl;

//Step 5
v = glm::vec3(1, 3, 4);
v = glm::normalize(v);
std::cout << glm::to_string(v) << std::endl;
return 0;
}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>

#include <glm/glm.hpp>

#include <glm/gtx/string_cast.hpp>

int main()

{

// Move point p(1, 4, -5) to vector v(5, 1, 4)

{

glm::vec3 p(1, 4, -5);

glm::vec3 v(5, 1, 4);

glm::vec3 moved = p + v;

}

// Add vector v1(1, 0, 0) and vector v2(0, 1, 0)

{

glm::vec3 v1(1, 0, 0);

glm::vec3 v2(0, 1, 0);

glm::vec3 a = v1 + v2;

}

// Multiply v1(0, 1, 0) with scalar 5

{

glm::vec3 b = v1 * 5f;

}

// Get a vector v starting at (8, 2, 5) and ending at (1, -1, 4)

{

glm::vec3 v_prime = glm::vec3(1, -1, 4) - glm::vec3(8, 2, 5);

}

// Normalize vector v(1, 3, 4)

{

glm::normalize(glm::vec3(1, 3, 4));

}

return 0;

}

# data[].attributes.body
// first
glm::vec3 p(1, 4, -5);
glm::vec3 v(5, 1, 4);

glm::vec3 result1 = p + v;

// second
glm::vec3 v1(1, 0, 0);
glm::vec3 v2(0, 1, 0);

glm::vec3 result2 = v1 + v2;

//third
glm::vec3 v1bis(0, 1, 0);

glm::vec3 result3 = v1bis * 5.0f;

//forth
glm::vec3 start(8, 2, 5);
glm::vec3 end(1, -1, 4);

glm::vec3 result4 = end - start;

//fifth
v = glm::vec3(1, 3, 4);

glm::vec3 result5 = glm::normalize(v);

return 0;

// SECOND EXERCICE

const double DEGREES_TO_RADIANS = glm::pi<float>() / 180.0;
const double RADIANS_TO_DEGREES = 180.0 / glm::pi<float>();

glm::vec3 v(2, -1, 1);
glm::vec3 u(1, 1, 2);

double result = RADIANS_TO_DEGREES * glm::acos(glm::dot(v, u) / (glm::length(v) * glm::length(u)));

std::cout << result << std::endl;

return 0;

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>

int main()
{
//ex1
glm::vec3 p(1, 4, -5);
glm::vec3 v(5, 1, 4);
glm::vec3 r = p + v;
std::cout << glm::to_string(r) << std::endl;

/ex2
glm::vec3 v1(1, 0, 0);
glm::vec3 v2(0, 1, 0);
glm::vec3 v3 = v1 + v2;
std::cout << glm::to_string(v3) << std::endl;
//ex3
glm::vec3 scalar(0, 1 * 5, 0);
//ex4
glm::vec3 vv(1 - 8, -1 - 2, 4 - 5);
std::cout << glm::to_string(v) << std::endl;
//ex5
glm::vec3 nv(1, 3, 4);
glm::vec3 nvv = glm::normalize(nv);
std::cout << glm::to_string(nvv) << std::endl;
return 0;
}

# data[].attributes.body
#include <glm/glm.h>
#include <glm/gtc/constants.hpp>
#include <iostream>
int main()
{
//Ex 1
{
glm::vec3 p(1, 4, -5);
glm::vec3 v(5, 1, 4);
p += v;
}
//Ex 2
{
glm::vec3 v1(1, 4, -5);
glm::vec3 v2(5, 1, 4);
glm::vec3 res = v1 + v2;
}
//Ex 3
{
glm::vec3 v1(1, 4, -5);
v1 *= 5.0f;
}
//Ex 4
{
glm::vec3 v = glm::vec3(1,-1,4) - glm::vec3(8, 2, 5);
}
//Ex 5
{
glm::vec3 v(1, 3, 4);
v = glm::normalize(v);
}
// Angle
{
const double RADIANS_TO_DEGREES = 180.0 / glm::pi<float>();

glm::vec3 v(2, -1, 1);
glm::vec3 u(1, 1, 2);

float cross = glm::dot(glm::normalize(u), glm::normalize(v));
std::cout << glm::acos(cross) * RADIANS_TO_DEGREES << std::endl;
}
}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include "glm/vec2.hpp"

#include "glm/vec3.hpp"

#include "glm/gtx/string_cast.hpp"

#include <iostream>

void movePoint()

{

glm::vec3 v1(1, 4, -5);

glm::vec3 v2(5, 1, 4);

glm::vec3 v3 = v1 + v2;

std::cout << glm::to_string(v3) << std::endl;

}

void addVector()

{

glm::vec3 v1(1, 0, 0);

glm::vec3 v2(0, 1, 0);

glm::vec3 v3 = v1 + v2;

std::cout << glm::to_string(v3) << std::endl;

}

void multiplyVector()

{

glm::vec3 v1(0, 1, 0);

glm::vec3 v2 = v1 * 5.0f;

std::cout << glm::to_string(v2) << std::endl;

}

void normalizeVector()

{

glm::vec3 v1(1, 3, 4);

glm::vec3 v2 = glm::normalize(v1);

std::cout << glm::to_string(v2) << std::endl;

}

void getVector()

{

glm::vec3 v1(8, 2, 5);

glm::vec3 v2(1, -1, 4);

glm::vec3 v3 = v2 - v1;

std::cout << glm::to_string(v3) << std::endl;

}

int main()

{

addVector();

multiplyVector();

normalizeVector();

movePoint();

getVector();

return 0;

}

# data[].attributes.body
glm::vec3 p(1, 4, -5);
glm::vec3 v(5, 1, 4);
p = v;

glm::vec3 v1(1, 0, 0);
glm::vec3 v2(0, 1, 0);
glm::vec3 v3 = v1 + v2;

glm::vec3 v1(0, 1, 0);
v1 = v1 * 5.0f;

glm::vec3 vb(8, 2, 5);
glm::vec3 ve(1, -1, 4);
glm::vec3 v();
v = ve - vb;

glm::vec3 v(1, 3, 4);
v = glm::normalize(v);

# data[].attributes.body
glm::vec3 movePointToVector(glm::vec3 a, glm::vec3 b)
{
glm::vec3 res = a + b;
return res;
}

glm::vec3 AddVectors(glm::vec3 a, glm::vec3 b)
{
glm::vec3 res = a + b;
return res;
}

glm::vec3 MultiplyVector(glm::vec3 a, float b)
{
glm::vec3 res = a * b;
return res;
}

glm::vec3 NormalizeVector(glm::vec3 a)
{
glm::vec3 res = glm::normalize(a);
return res;
}

glm::vec3 CreateVector(glm::vec3 a, glm::vec3 b)
{
glm::vec3 res;
res = b - a;

return res;
}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>
#include <glm/vec3.hpp>
#include <glm/gtx/string_cast.hpp>

int main()
{
glm::vec3 const p{ 1.0f, 4.0f, -5.0f };
glm::vec3 v{ 5.0f, 1.0f, 4.0f };

std::cout << "p + v = " << glm::to_string(p + v) << std::endl;

glm::vec3 v1{ 1.0f, 0.0f, 0.0f };
glm::vec3 const v2{ 0.0f, 1.0f, 0.0f };

std::cout << "v1 + v2 = " << glm::to_string(v1 + v2) << std::endl;

v1 = glm::vec3{ 0.0f, 1.0f, 0.0f };

std::cout << "v1 * 5 = " << glm::to_string(v1 * 5.0f) << std::endl;

v = glm::vec3{ 1.0f, -1.0f, 4.0f } - glm::vec3{ 8.0f, 2.0f, 5.0f };

std::cout << "v = " << glm::to_string(v) << std::endl;

std::cout << "norm(v) = " << glm::to_string(glm::normalize(v)) << std::endl;

return 0;
}

////////// ANGLE //////////

#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>

int main()
{
auto const deg2Rad{ glm::pi<float>() / 180.0f };
auto const rad2Deg{ 180.0f / glm::pi<float>() };

glm::vec3 const v{ 2.0f, -1.0f, 1.0f };
glm::vec3 const u{ 1.0f, 1.0f, 2.0f };

auto const dot{ glm::dot(v, u) };
auto const len{ glm::length(v) * glm::length(u) };

auto const angle{ glm::acos(dot / len) };

std::cout << "Angle =" << std::endl;
std::cout << "\tRad = " << angle << std::endl;
std::cout << "\tDeg = " << angle * rad2Deg << std::endl;

return 0;
}

# data[].attributes.body
/*
** EX 1 (GLM simple exercises)
*/
#include <glm/glm.hpp>

int main()
{
glm::vec3 p(1, 4, -5);
glm::vec3 v(5, 1, 4);
p += v;  // 1.

glm::vec3 v1(1, 0, 0);
glm::vec3 v2(0, 1, 0);
v1 += v2;  // 2.

v1 = glm::vec3(0, 1, 0);
v1 *= 5.0f;  // 3.

v = glm::vec3(1, -1, 4) - glm::vec3(8, 2, 5);  // 4.

v = glm::vec3(1, 3, 4);
v = glm::normalize(v);  // 5.

return 0;
}

/*
** EX 2 (calculate angle)
*/

#include <glm/gtc/constants.hpp>
#include <glm/glm.hpp>
#include <iostream>

constexpr double DEGREES_TO_RADIANS = glm::pi<float>() / 180.0;
constexpr double RADIANS_TO_DEGREES = 180.0 / glm::pi<float>();

float calculate_angle(glm::vec3 a, glm::vec3 b)
{

float c = glm::dot(a, b);
float d = c / (glm::length(a) * glm::length(b));
float deg = glm::acos(d) * RADIANS_TO_DEGREES;

return deg;
}

int main()
{
glm::vec3 a(2, -1, 1);
glm::vec3 b(1, 1, 2);

std::cout << calculate_angle(a, b) << std::endl;
}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>
#include <glm/vec2.hpp>
#include <glm/gtx/string_cast.hpp>

void printPracticeResult(int practiceNumber, glm::vec3 result) {
std::cout << "Result for practice " << practiceNumber << " : " << glm::to_string(result) << std::endl;
}

void practice1() {
glm::vec3 p(1, 4, -5);
glm::vec3 v(5, 1, 4);

glm::vec3 res = p + v;
printPracticeResult(1, res);
}

void practice2() {
glm::vec3 v1(1, 0, 0);
glm::vec3 v2(0, 1, 0);

glm::vec3 res = v1 + v2;
printPracticeResult(2, res);
}

void practice3() {
glm::vec3 v1(0, 1, 0);

glm::vec3 res = v1 * 5.0f;
printPracticeResult(3, res);
}

void practice4() {
glm::vec3 start(8, 2, 5);
glm::vec3 end(1, -1, 4);

glm::vec3 res = end - start;
printPracticeResult(4, res);
}

void practice5() {
glm::vec3 v(1, 3, 4);

glm::vec3 res = glm::normalize(v);
printPracticeResult(5, res);
}

int main() {
practice1();
practice2();
practice3();
practice4();
practice5();
return 0;
}

# data[].attributes.body
#include <iostream>

#define GLM_ENABLE_EXPERIMENTAL

#include <glm/vec3.hpp>
#include <glm/gtx/string_cast.hpp>

int main(int, char **) {
    glm::vec3 p{1, 4, -5};
    glm::vec3 v{5, 1, 4};

    std::cout << "p + v = " << glm::to_string(p + v) << std::endl;

    glm::vec3 v1{1, 0, 0};
    glm::vec3 v2{0, 1, 0};

    std::cout << "v1 + v2 = " << glm::to_string(v1 + v2) << std::endl;

    glm::vec3 v3{0, 1, 0};

    std::cout << "v3 * 5 = " << glm::to_string(v3 * 5.0f) << std::endl;

    glm::vec3 p1{8, 2, 5};
    glm::vec3 p2{1, -1, 4};

    std::cout << "v4 = " << glm::to_string(p2 - p1) << std::endl;

    glm::vec3 v5{1, 3, 4};

    std::cout << "normalized v5 = " << glm::to_string(glm::normalize(v5)) << std::endl;

    return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>

void exo1() {
glm::vec3 p(1, 4, -5);
glm::vec3 v(5, 1, 4);

glm::vec3 u = p + v;
std::cout << "Result of exo1 : " + glm::to_string(u) << std::endl;
}

void exo2() {
glm::vec3 v1(1, 0, 0);
glm::vec3 v2(0, 1, 0);

glm::vec3 v3 = v1 + v2;
std::cout << "Result of exo2 : " + glm::to_string(v3) << std::endl;
}

void exo3() {
glm::vec3 v1(0, 1, 0);

glm::vec3 v2 = v1 * 5.0f;
std::cout << "Result of exo3 : " + glm::to_string(v2) << std::endl;
}

void exo4() {
glm::vec3 v1(8, 2, 5);
glm::vec3 v2(1, -1, 4);

glm::vec3 v3 = v2 - v1;
std::cout << "Result of exo4 : " + glm::to_string(v3) << std::endl;
}

void exo5() {
glm::vec3 v1(1, 3, 4);

glm::vec3 v2 = glm::normalize(v1);
std::cout << "Result of exo5 : " + glm::to_string(v2) << std::endl;
}

int main() {
exo1();
exo2();
exo3();
exo4();
exo5();
}

# data[].attributes.body
#define GLM_ENABLE_EXPIREMENTAL

#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtc/constants.hpp>

const double DEGREES_TO_RADIANS = glm::pi<float>() / 180;
const double RADIANS_TO_DEGREES = 180.0 / glm::pi<float>();

int main()
{

glm::vec3 a{2, -1, 1};
glm::vec3 b{1, 1, 2};

float dotValue = glm::dot(a, b);

float theta = glm::acos(dotValue / (glm::length(a) * glm::length(b)));

float thetaDeg = RADIANS_TO_DEGREES * theta;

std::cout << thetaDeg << std::endl;

return 0;
}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>
#include <iostream>

int main()
{
// 1
glm::vec3 p(1, 4, -5);
glm::vec3 v(5, 1, 4);
p += v;
std::cout << glm::to_string(p) << std::endl;

// 2
glm::vec3 v1(1, 0, 0);
glm::vec3 v2(0, 1, 0);
v1 += v2;
std::cout << glm::to_string(v1) << std::endl;

// 3
v1 = glm::vec3(0, 1, 0);
v1 *= 5;
std::cout << glm::to_string(v1) << std::endl;

// 4
v = glm::vec3(1, -1, 4) - glm::vec3(8, 2, 5);
std::cout << glm::to_string(v) << std::endl;

// 5
v = glm::vec3(1, 3, 4);
v = glm::normalize(v);
std::cout << glm::to_string(v) << std::endl;

return 0;
}

# data[].attributes.body
#define GLM_ENABLE_EXPIREMENTAL

#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>

int main()
{

// Task01

glm::vec3 p(1, 4, -5);
glm::vec3 v(5, 1, 4);

p = p + v;

std::cout << p.x << " " << p.y << " " << p.z << "\n";

// Task02

glm::vec3 v1(1, 0, 0);
glm::vec3 v2(0, 1, 0);

glm::vec3 v3 = v1 + v2;

std::cout << v3.x << " " << v3.y << " " << v3.z << "\n";

// task03

v1 = v2 * 5.0f;

std::cout << v1.x << " " << v1.y << " " << v1.z << "\n";

// task04

v = (glm::vec3(1, -1, 4) - glm::vec3(8, 2, 5));

std::cout << v.x << " " << v.y << " " << v.z << "\n";

// task05

v = glm::normalize(v);

std::cout << v.x << " " << v.y << " " << v.z << "\n";

return 0;
}