srp
software rendering pipeline
Loading...
Searching...
No Matches
vec.h
Go to the documentation of this file.
1// Software Rendering Pipeline (SRP) library
2// Licensed under GNU GPLv3
3
8#pragma once
9
10#include <stdint.h>
11
15#pragma pack(push, 1)
16
18typedef union vec2 {
19 struct { float x, y; };
20 float v[2];
22
24typedef union vec3 {
25 struct { float x, y, z; };
26 struct { vec2 xy; float _z; };
27 struct { float _x; vec2 yz; };
28 float v[3];
30
32typedef union vec4 {
33 struct { float x, y, z, w; };
34 struct { vec2 xy; float _z, _w; };
35 struct { float _x; vec2 yz; float __w; };
36 struct { float __x, _y; vec2 zw; };
37 struct { vec3 xyz; float ___w; };
38 struct { float ___x; vec3 yzw; };
39 float v[4];
41
43#define VEC2(x, y) ((vec2) {{x, y}})
44#define VEC3(x, y, z) ((vec3) {{x, y, z}})
45#define VEC4(x, y, z, w) ((vec4) {{x, y, z, w}})
46#define VEC4_FROM_VEC3(v, a) ((vec4) {.xyz = (v), .___w = (a)})
47
49#define SWZ2(v, a, b) ((vec2) {{(v).a, (v).b}})
50#define SWZ3(v, a, b, c) ((vec3) {{(v).a, (v).b, (v).c}})
51#define SWZ4(v, a, b, c, d) ((vec4) {{(v).a, (v).b, (v).c, (v).d}})
52
53#pragma pack(pop)
54
56vec2 vec2Add(vec2 a, vec2 b);
60float vec2DotProduct(vec2 a, vec2 b);
62vec2 vec2MultiplyScalar(vec2 a, float b);
71
73vec3 vec3Add(vec3 a, vec3 b);
77float vec3DotProduct(vec3 a, vec3 b);
79vec3 vec3MultiplyScalar(vec3 a, float b);
88
90vec4 vec4Add(vec4 a, vec4 b);
94float vec4DotProduct(vec4 a, vec4 b);
96vec4 vec4MultiplyScalar(vec4 a, float b);
105
// ingroup Math
vec2 vec2Add(vec2 a, vec2 b)
Definition vec.c:16
Definition vec.h:18
Definition vec.h:24
Definition vec.h:32
vec4 vec4MultiplyVec4(vec4 a, vec4 b)
Definition vec.c:166
vec4 vec4MultiplyScalar(vec4 a, float b)
Definition vec.c:151
vec3 vec3Negate(vec3 v)
Definition vec.c:120
vec4 vec4Negate(vec4 v)
Definition vec.c:161
vec2 vec2MultiplyVec2(vec2 a, vec2 b)
Definition vec.c:41
vec4 vec4Subtract(vec4 a, vec4 b)
Definition vec.c:136
vec2 vec2Reflect(vec2 i, vec2 n)
Definition vec.c:57
vec2 vec2MultiplyScalar(vec2 a, float b)
Definition vec.c:31
vec2 vec2Negate(vec2 v)
Definition vec.c:36
vec4 vec4Add(vec4 a, vec4 b)
Definition vec.c:126
float vec2DotProduct(vec2 a, vec2 b)
Definition vec.c:26
vec3 vec3Normalize(vec3 v)
Definition vec.c:97
vec3 vec3Reflect(vec3 i, vec3 n)
Definition vec.c:108
vec3 vec3Add(vec3 a, vec3 b)
Definition vec.c:65
vec2 vec2Subtract(vec2 a, vec2 b)
Definition vec.c:21
vec3 vec3MultiplyVec3(vec3 a, vec3 b)
Definition vec.c:115
float vec3DotProduct(vec3 a, vec3 b)
Definition vec.c:83
vec2 vec2Normalize(vec2 v)
Definition vec.c:46
float vec4DotProduct(vec4 a, vec4 b)
Definition vec.c:146
vec3 vec3MultiplyScalar(vec3 a, float b)
Definition vec.c:88
vec3 vec3Subtract(vec3 a, vec3 b)
Definition vec.c:74
vec4 vec4Normalize(vec4 v)
Definition vec.c:171
vec4 vec4Reflect(vec4 i, vec4 n)
Definition vec.c:182