Addition, Subtraction, Multiplication, and division for Vectors

This commit is contained in:
=
2016-01-22 20:05:47 -07:00
parent c4a8f1a2b1
commit 8ee6f8a20d
3 changed files with 154 additions and 3 deletions

View File

@@ -218,6 +218,139 @@ HINLINE vec4 V4(float X, float Y, float Z, float W)
return(Result);
}
HINLINE vec2 AddV2(vec2 Left, vec2 Right)
{
vec2 Result;
Result.x = Left.x + Right.x;
Result.y = Left.y + Right.y;
return(Result);
}
HINLINE vec3 AddV3(vec3 Left, vec3 Right)
{
vec3 Result;
Result.x = Left.x + Right.x;
Result.y = Left.y + Right.y;
Result.z = Left.z + Right.z;
return(Result);
}
HINLINE vec4 AddV4(vec4 Left, vec4 Right)
{
vec4 Result;
Result.x = Left.x + Right.x;
Result.y = Left.y + Right.y;
Result.z = Left.z + Right.z;
Result.w = Left.w + Right.w;
return(Result);
}
HINLINE vec2 SubtractV2(vec2 Left, vec2 Right)
{
vec2 Result;
Result.x = Left.x - Right.x;
Result.y = Left.y - Right.y;
return(Result);
}
HINLINE vec3 SubtractV3(vec3 Left, vec3 Right)
{
vec3 Result;
Result.x = Left.x - Right.x;
Result.y = Left.y - Right.y;
Result.z = Left.z - Right.z;
return(Result);
}
HINLINE vec4 SubtractV4(vec4 Left, vec4 Right)
{
vec4 Result;
Result.x = Left.x - Right.x;
Result.y = Left.y - Right.y;
Result.z = Left.z - Right.z;
Result.w = Left.w - Right.w;
return(Result);
}
HINLINE vec2 MultiplyV2(vec2 Left, vec2 Right)
{
vec2 Result;
Result.x = Left.x * Right.x;
Result.y = Left.y * Right.y;
return(Result);
}
HINLINE vec3 MultiplyV3(vec3 Left, vec3 Right)
{
vec3 Result;
Result.x = Left.x * Right.x;
Result.y = Left.y * Right.y;
Result.z = Left.z * Right.z;
return(Result);
}
HINLINE vec4 MultiplyV4(vec4 Left, vec4 Right)
{
vec4 Result;
Result.x = Left.x * Right.x;
Result.y = Left.y * Right.y;
Result.z = Left.z * Right.z;
Result.w = Left.w * Right.w;
return(Result);
}
HINLINE vec2 DivideV2(vec2 Left, vec2 Right)
{
vec2 Result;
Result.x = Left.x / Right.x;
Result.y = Left.y / Right.y;
return(Result);
}
HINLINE vec3 DivideV3(vec3 Left, vec3 Right)
{
vec3 Result;
Result.x = Left.x / Right.x;
Result.y = Left.y / Right.y;
Result.z = Left.z / Right.z;
return(Result);
}
HINLINE vec4 DivideV4(vec4 Left, vec4 Right)
{
vec4 Result;
Result.x = Left.x / Right.x;
Result.y = Left.y / Right.y;
Result.z = Left.z / Right.z;
Result.w = Left.w / Right.w;
return(Result);
}
#endif

View File

@@ -5,7 +5,7 @@ IF NOT EXIST build mkdir build
pushd build
REM C Build
cl -nologo -Zi ../main.c
cl -FC -nologo -Z7 -Tc ../main.c
REM C++ Build
REM cl -nologo -Zi ../main.cpp

22
main.c
View File

@@ -1,8 +1,26 @@
#define HANDMADEMATH_DEFINE
/*
HANDMADE_MATH_IMPLEMENTATION:
This is for the implementation you want this.
HANDMADE_MATH_CPP_MODE:
This will give the function overloaded and operator overloaded version of the functions
*/
#include <conio.h>
#define HANDMADE_MATH_IMPLEMENTATION
#define HANDMADE_MATH_CPP_MODE
#include "HandmadeMath.h"
int
main(int ArgC, char **ArgV)
{
vec2 VectorOne = V2(6.0f, 8.0f);
vec2 VectorTwo = V2(3.0f, 2.0f);
vec2 Result = DivideV2(VectorOne, VectorTwo);
_getch();
return(0);
}