-moved C stdlib function definitions to ecs_utils.utils -added function to calculate mix(linear interpolation) and rsqrt(fast inverse sqrt) -added some math to vec2 (length, normalize...) -improved renderer with possibility to use multiple materials (one per block, not perfect solution for parallel compute, but works with some requirements) -added blending support for material (opaque, additive, mixed) -added Android support -added gprahical representation for mouse tools (tool_circle.d) -added initial support for editing template components variables -better Component and Templates listing -added possibility to add/removes components using mouse -move CLocation to game_core.basic and reuse in every test -moved tools code from demos to App (now code is fully separated from demos!) -some improvement and fixes in Snake demo, with additional systems to handle adding and removing entities -added new demo: Particles. By now demo has several particles to spawn and support for attractors and vortexes (calculation is made as every attractor with every entity) -fixed bug with window hover and tools -improved tool behaviour -added new material -now window is always opened as maximized windowed mode -some minor fixes and improvements
206 lines
No EOL
3.9 KiB
D
206 lines
No EOL
3.9 KiB
D
module ecs_utils.math.vector;
|
|
|
|
import ecs_utils.utils;
|
|
|
|
struct vec2
|
|
{
|
|
this(float v) @nogc nothrow
|
|
{
|
|
x = v;
|
|
y = v;
|
|
}
|
|
|
|
this(float x, float y) @nogc nothrow
|
|
{
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
|
|
union
|
|
{
|
|
struct
|
|
{
|
|
float x;
|
|
float y;
|
|
}
|
|
float[2] data;
|
|
}
|
|
|
|
vec2 opBinary(string op)(vec2 v)
|
|
{
|
|
static if (op == "+") return vec2(x + v.x, y + v.y);
|
|
else static if (op == "-") return vec2(x - v.x, y - v.y);
|
|
else static if (op == "*") return vec2(x * v.x, y * v.y);
|
|
else static if (op == "/") return vec2(x / v.x, y / v.y);
|
|
else static assert(0, "Operator "~op~" not implemented");
|
|
}
|
|
|
|
vec2 opBinary(string op)(float v)
|
|
{
|
|
static if (op == "+") return vec2(x + v, y + v);
|
|
else static if (op == "-") return vec2(x - v, y - v);
|
|
else static if (op == "*") return vec2(x * v, y * v);
|
|
else static if (op == "/") return vec2(x / v, y / v);
|
|
else static assert(0, "Operator "~op~" not implemented");
|
|
}
|
|
|
|
ivec2 opCast()
|
|
{
|
|
return ivec2(cast(int)x,cast(int)y);
|
|
}
|
|
|
|
void opOpAssign(string op)(vec2 v)
|
|
{
|
|
static if (op == "+")
|
|
{
|
|
x += v.x;
|
|
y += v.y;
|
|
}
|
|
else static if (op == "-")
|
|
{
|
|
x -= v.x;
|
|
y -= v.y;
|
|
}
|
|
else static if (op == "*")
|
|
{
|
|
x *= v.x;
|
|
y *= v.y;
|
|
}
|
|
else static if (op == "/")
|
|
{
|
|
x /= v.x;
|
|
y /= v.y;
|
|
}
|
|
else static assert(0, "Operator "~op~" not implemented");
|
|
}
|
|
|
|
float length2()
|
|
{
|
|
return x*x + y*y;
|
|
}
|
|
|
|
float length()
|
|
{
|
|
return sqrtf(length2);
|
|
}
|
|
|
|
float fastSqrLength()
|
|
{
|
|
return rsqrt(length2);
|
|
}
|
|
|
|
vec2 normalize()
|
|
{
|
|
return this * fastSqrLength();
|
|
}
|
|
}
|
|
|
|
struct vec4
|
|
{
|
|
union
|
|
{
|
|
struct
|
|
{
|
|
float x;
|
|
float y;
|
|
float z;
|
|
float w;
|
|
}
|
|
float[4] data;
|
|
}
|
|
|
|
this(float v) @nogc nothrow
|
|
{
|
|
x = v;
|
|
y = v;
|
|
z = v;
|
|
w = v;
|
|
}
|
|
|
|
this(float x, float y, float z, float w) @nogc nothrow
|
|
{
|
|
this.x = x;
|
|
this.y = y;
|
|
this.z = z;
|
|
this.w = w;
|
|
}
|
|
|
|
vec4 opBinary(string op)(float v)
|
|
{
|
|
static if (op == "+") return vec4(x + v, y + v, z + v, w + v);
|
|
else static if (op == "-") return vec4(x - v, y - v, z - v, w - v);
|
|
else static if (op == "*") return vec4(x * v, y * v, z * v, w * v);
|
|
else static if (op == "/") return vec4(x / v, y / v, z / v, w / v);
|
|
else static assert(0, "Operator "~op~" not implemented");
|
|
}
|
|
}
|
|
|
|
struct ivec2
|
|
{
|
|
union
|
|
{
|
|
struct
|
|
{
|
|
int x;
|
|
int y;
|
|
}
|
|
int[2] data;
|
|
}
|
|
|
|
this(int v) @nogc nothrow
|
|
{
|
|
x = v;
|
|
y = v;
|
|
}
|
|
|
|
this(int x, int y) @nogc nothrow
|
|
{
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
|
|
ivec2 opBinary(string op, T)(T v)
|
|
{
|
|
static if (op == "+") return ivec2(x + v, y + v);
|
|
else static if (op == "-") return ivec2(x - v, y - v);
|
|
else static if (op == "*") return ivec2(x * v, y * v);
|
|
else static if (op == "/") return ivec2(x / v, y / v);
|
|
else static assert(0, "Operator "~op~" not implemented");
|
|
}
|
|
|
|
vec2 opCast()
|
|
{
|
|
return vec2(x,y);
|
|
}
|
|
}
|
|
|
|
struct ivec4
|
|
{
|
|
union
|
|
{
|
|
struct
|
|
{
|
|
int x;
|
|
int y;
|
|
int z;
|
|
int w;
|
|
}
|
|
int[4] data;
|
|
}
|
|
|
|
this(int v) @nogc nothrow
|
|
{
|
|
x = v;
|
|
y = v;
|
|
z = v;
|
|
w = v;
|
|
}
|
|
|
|
this(int x, int y, int z, int w) @nogc nothrow
|
|
{
|
|
this.x = x;
|
|
this.y = y;
|
|
this.z = z;
|
|
this.w = w;
|
|
}
|
|
} |