Created
April 2, 2021 17:10
-
-
Save codingminecraft/b25b9bf5f8e968756655c70a503d3c98 to your computer and use it in GitHub Desktop.
C++ Episode 7 Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Vector3.h" | |
#include <stdio.h> | |
namespace Math | |
{ | |
float Dot(Vector3 a, Vector3 b) | |
{ | |
return a.x * b.x + a.y * b.y + a.z * b.z; | |
} | |
Vector3 Scale(Vector3 vector, float scaleFactor) | |
{ | |
return Vector3 { | |
vector.x * scaleFactor, | |
vector.y * scaleFactor, | |
vector.z * scaleFactor | |
}; | |
} | |
Vector3 Add(Vector3 a, Vector3 b) | |
{ | |
return Vector3 { | |
a.x + b.x, | |
a.y + b.y, | |
a.z + b.z | |
}; | |
} | |
void Print(Vector3 vector) | |
{ | |
printf("X: %2.3f, Y: %2.3f, Z: %2.3f\n", vector.x, vector.y, vector.z); | |
} | |
float Dot(Vector2 a, Vector2 b) | |
{ | |
return a.x * b.x + a.y * b.y; | |
} | |
Vector2 Scale(Vector2 vector, float scaleFactor) | |
{ | |
return Vector2 { | |
vector.x * scaleFactor, | |
vector.y * scaleFactor | |
}; | |
} | |
Vector2 Add(Vector2 a, Vector2 b) | |
{ | |
return Vector2 { | |
a.x + b.x, | |
a.y + b.y | |
}; | |
} | |
void Print(Vector2 vector) | |
{ | |
printf("X: %2.3f, Y: %2.3f\n", vector.x, vector.y); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
struct Vector3 | |
{ | |
float x; | |
float y; | |
float z; | |
}; | |
struct Vector2 | |
{ | |
float x; | |
float y; | |
}; | |
namespace Math | |
{ | |
// Dot Product: a.x * b.x + a.y * b.y + a.z * b.z + .. | |
float Dot(Vector3 a, Vector3 b); | |
Vector3 Scale(Vector3 vector, float scaleFactor); | |
Vector3 Add(Vector3 a, Vector3 b); | |
void Print(Vector3 vector); | |
float Dot(Vector2 a, Vector2 b); | |
Vector2 Scale(Vector2 vector, float scaleFactor); | |
Vector2 Add(Vector2 a, Vector2 b); | |
void Print(Vector2 vector); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment