From 44e573da16b92c1791c6e8b62c9c8aa40544fdec Mon Sep 17 00:00:00 2001 From: = Date: Tue, 19 Jan 2016 17:41:23 -0700 Subject: [PATCH] Setup Vec2, Vec3, Vec4 and their initialization functions --- .gitignore | 1 + HandmadeMath.h | 212 +++++++++++++++++++++++++++++++++++++++++++++++++ build.bat | 13 +++ main.c | 8 ++ main.cpp | 8 ++ 5 files changed, 242 insertions(+) create mode 100644 .gitignore create mode 100644 HandmadeMath.h create mode 100644 build.bat create mode 100644 main.c create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d163863 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/HandmadeMath.h b/HandmadeMath.h new file mode 100644 index 0000000..f9a1104 --- /dev/null +++ b/HandmadeMath.h @@ -0,0 +1,212 @@ +/* + Author: Zak Strange + +*/ + +#ifndef HANDMADE_MATH_H +#define HANDMADE_MATH_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef HANDMADEMATH_STATIC +#define HMMDEF static +#else +#define HMMDEF extern +#endif + +#if _MSC_VER && !__INTEL_COMPILER +#define HINLINE __inline +#else +#define HINLLINE inline +#endif + +typedef union vec2 +{ + struct + { + float x, y; + }; + struct + { + float u, v; + }; + struct + { + float left, right; + } + + float E[2]; +} vec2; + +typedef union vec3 +{ + struct + { + float x, y, z; + }; + struct + { + float u, v, w; + }; + struct + { + float r, g, b; + }; + struct + { + vec2 xy; + float Ignored0_; + }; + struct + { + float Ignored1_; + vec2 yz; + }; + struct + { + vec2 uv; + float Ignored2_; + }; + struct + { + float Ignored3_; + vec2 vw; + }; + + float E[3]; +} vec3; + +typedef union vec4 +{ + struct + { + union + { + vec3 xyz; + struct + { + float x, y, z; + }; + }; + + float w; + }; + struct + { + union + { + vec3 rgb; + struct + { + float r, g, b; + }; + }; + + float a; + }; + struct + { + vec2 xy; + float Ignored0_; + float Ignored1_; + }; + struct + { + float Ignored2_; + vec2 yz; + float Ignored3_; + }; + struct + { + float Ignored4_; + float Ignored5_; + vec2 zw; + }; + + float E[4]; +} vec4; + + +HMMDEF HINLINE vec2 V2i(int X, int Y); +HMMDEF HINLINE vec2 V2(float X, float Y); + +#ifdef __cplusplus +} +#endif + +#endif /* HANDMADE_MATH_H */ + +#ifdef HANDMADE_MATH_IMPLEMENTATION + +HINLINE vec2 V2i(int X, int Y) +{ + vec2 Result = {0}; + + Result.x = (float)X; + Result.y = (float)Y; + + return(Result); +} + +HINLINE vec2 V2(float X, float Y) +{ + vec2 Result = {0}; + + Result.x = X; + Result.y = Y; + + return(Result); +} + + +HINLINE vec3 V3i(int X, int Y, int Z) +{ + vec3 Result = {0}; + + Result.x = (float)X; + Result.y = (float)Y; + Result.z = (float)Z; + + return(Result); +} + +HINLINE vec3 V3(float X, float Y, float Z) +{ + vec3 Result = {0}; + + Result.x = X; + Result.y = Y; + Result.z = Z; + + return(Result); +} + +HINLINE vec4 V4i(int X, int Y, int Z, int W) +{ + vec4 Result = {0}; + + Result.x = (float)X; + Result.y = (float)Y; + Result.z = (float)Z; + Result.w = (float)W; + + return(Result); +} + +HINLINE vec4 V4(float X, float Y, float Z, float W) +{ + vec4 Result = {0}; + + Result.x = X; + Result.y = Y; + Result.z = Z; + Result.w = W; + + return(Result); +} + +#endif + + diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..0971308 --- /dev/null +++ b/build.bat @@ -0,0 +1,13 @@ +@echo off + +IF NOT EXIST build mkdir build + +pushd build + +REM C Build +cl -nologo -Zi ../main.c + +REM C++ Build +REM cl -nologo -Zi ../main.cpp + +popd diff --git a/main.c b/main.c new file mode 100644 index 0000000..e7c2d4f --- /dev/null +++ b/main.c @@ -0,0 +1,8 @@ +#define HANDMADEMATH_DEFINE +#include "HandmadeMath.h" + +int +main(int ArgC, char **ArgV) +{ + +} diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..3f1e293 --- /dev/null +++ b/main.cpp @@ -0,0 +1,8 @@ +#define HANDMADE_MATH_IMPLEMENTATION +#include "HandmadeMath.h" + +int +main(int ArgC, char **ArgV) +{ + +}