mirror of
https://github.com/HandmadeMath/HandmadeMath.git
synced 2025-09-07 10:48:17 +00:00
Setup Vec2, Vec3, Vec4 and their initialization functions
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
build/
|
212
HandmadeMath.h
Normal file
212
HandmadeMath.h
Normal file
@@ -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
|
||||
|
||||
|
13
build.bat
Normal file
13
build.bat
Normal file
@@ -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
|
8
main.c
Normal file
8
main.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#define HANDMADEMATH_DEFINE
|
||||
#include "HandmadeMath.h"
|
||||
|
||||
int
|
||||
main(int ArgC, char **ArgV)
|
||||
{
|
||||
|
||||
}
|
Reference in New Issue
Block a user