dav1dde / gl3n Goto Github PK
View Code? Open in Web Editor NEWOpenGL Maths for D (not glm for D).
Home Page: http://dav1dde.github.com/gl3n/
License: Other
OpenGL Maths for D (not glm for D).
Home Page: http://dav1dde.github.com/gl3n/
License: Other
Yup, it does.
Add/Create a DUB Package
Any plan for these?
I had to look into the code in order to get the documentation. For some reason it's missing from the docs.
Hello again!
When you create a 1 by 1 matrix the invert() function complains...
Matrix!(float, 1, 1) M;
Note: I'm not actually explicitly creating a 1 by 1 matrix since that would be silly, but it comes up as the result of multiplying multiple matrices together.
It would be nice to have rotate, translate and scale in 2d aswell
Every time I want to compile something with gl3n as dependency now it spams the console with
dub\packages\gl3n-1.1.0\gl3n\linalg.d(425): Warning: int /= real is performing truncating conversion
and then stops compilation.
Tested on windows (gl3n 1.0.1 and 1.1.0) and on linux (1.0.1)
(I will provide a PR as soon as i get to it)
../../../../../.dub/packages/dlib-0.7.1/dlib/filesystem/stdfs.d(34,8): Deprecation: module std.c.stdio is deprecated - Import core.stdc.stdio instead
dlib.container.aarray is deprecated, use dlib.container.dict instead
../../../../../.dub/packages/dlib-0.7.1/dlib/geometry/ray.d(46,5): Deprecation: constructor dlib.geometry.ray.Ray.this all parameters have default arguments, but structs cannot have default constructors.
../../../../../.dub/packages/dlib-0.7.1/dlib/filesystem/posix/file.d(53,17): Deprecation: package core.sys is not accessible here
../../../../../.dub/packages/dlib-0.7.1/dlib/filesystem/posix/file.d(53,21): Deprecation: package core.sys.posix is not accessible here
../../../../../.dub/packages/dlib-0.7.1/dlib/filesystem/posix/file.d(53,27): Deprecation: module core.sys.posix.unistd is not accessible here, perhaps add 'static import core.sys.posix.unistd;'
../../../../../.dub/packages/dlib-0.7.1/dlib/filesystem/posix/file.d(88,36): Deprecation: package core.sys is not accessible here
../../../../../.dub/packages/dlib-0.7.1/dlib/filesystem/posix/file.d(88,40): Deprecation: package core.sys.posix is not accessible here
../../../../../.dub/packages/dlib-0.7.1/dlib/filesystem/posix/file.d(88,46): Deprecation: module core.sys.posix.unistd is not accessible here, perhaps add 'static import core.sys.posix.unistd;'
../../../../../.dub/packages/dlib-0.7.1/dlib/filesystem/posix/file.d(101,20): Deprecation: package core.sys is not accessible here
../../../../../.dub/packages/dlib-0.7.1/dlib/filesystem/posix/file.d(101,24): Deprecation: package core.sys.posix is not accessible here
../../../../../.dub/packages/dlib-0.7.1/dlib/filesystem/posix/file.d(101,30): Deprecation: module core.sys.posix.unistd is not accessible here, perhaps add 'static import core.sys.posix.unistd;'
gl3n 1.2.0: building configuration "library"...
../../../../../.dub/packages/gl3n-1.2.0/gl3n/util.d(14,12): Error: module std.typecons import 'TypeTuple' not found, did you mean template 'isTypeTuple(T...)'?
dmd failed with exit code 1.
Joels-MacBook-Pro:Joel joelcnz$
Please could you make an initial release, "v0.1.0" perhaps, to fit in with dub's deprecation of git branch support (e.g. "~master").
Cheers.
Fails with GDC 2.064.2. Other compilers untested.
private import gl3n.linalg;
int main(string[] args) {
vec3 pos = vec3(1, 1, 1);
vec3 size = vec3(1, 1, 1);
vec3 of = vec3(1, 1, 1);
//vec3 fails = pos + size * of;
vec3 inter = size * of;
vec3 works = pos + inter;
return 0;
}
t.d:9: error: incompatible types for ((pos) + (size.opBinary(of))): 'Vector!(float, 3)' and 'float'
is it supported or possible to implement without a great hassle? it is the layout that bgfx uses natively right now: bkaradzic/bgfx#517
Thought I'd just make a few optimization reports when I find them. Here's the one from Bitbucket:
static auto look_at(Vector!(mt, 3) eye, Vector!(mt, 3) target, Vector!(mt, 3) up) {
auto look_dir = (target - eye).normalized;
auto right_dir = cross(look_dir, up).normalized;
auto perp_up_dir = cross(right_dir, look_dir);
auto ret = Matrix.identity;
// rotate
ret.matrix[0][0..3] = right_dir.vector;
ret.matrix[1][0..3] = perp_up_dir.vector;
ret.matrix[2][0..3] = (-look_dir).vector;
// translate
ret.matrix[0][3] = eye.dot(-perp_up_dir.vector);
ret.matrix[1][3] = eye.dot(-right_dir.vector);
ret.matrix[2][3] = eye.dot(look_dir.vector);
return ret;
}
I strongly believe that "static Matrix perspective(mt width, mt height, mt fov = 60.0, mt near = 1.0, mt far = 100.0)" should be removed.
I don't see the reason for its existence (it seems like a testing function to me, so should be hidden from the api) and because of the default parameters it can cause massive confusion if one believes that the functionality is similar to that of glm's perceptive function.
i.e. I called perspective(fov, ratio, near, far) and it silently worked, but did completely the wrong thing.
I'll submit a patch to this affect later if it help, and thanks for the great work.
The github hosted site currently has some errors such as missing or unstyled pages.
Hey, I'm just wondering if i'm doing something wrong if i need to write all my transformation calls backwards for example:
mat4.identity.rotatey(roty).rotatex(rotx).translate(x, y, z)
When I read the documentation for gl3n you write it in this order.
mat4.identity.translate(x, y, z).rotatex(rotx).rotatey(roty);
And other example is:
This does not work
mat4.identity.translate(x, y, z);
// Which is the same as
mat4.translation(x, y z) * mat4.identity;
This does work
mat4.identity * mat4.translation(x, y z);
Am I doing something wrong or is this a bug?
I am using ldc (which is the default for dub)
Hello,
i am currently writing a rpg engine in D. I recently ran into a confusing problem caused by the following:
In older OpenGL versions, especially when you only have access to ES Core 2.0 contexts, glUniformMatrix only accepts GL_FALSE as transpose argument and otherwise generates a GL_INVALID_VALUE [1]. While i can simply call transpose() on the matrix, thats extra-stuff that needs be done every time i submit matrixes to the pipeline.
Is there an alternative way?
[1] https://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
It's missing size_t toHash() const nothrow @safe
all Matrix.invert():
currently the mixin AFAIK creates a dynamic array even though the matrix already contains one, just assignments would be enough.
for example: https://github.com/Dav1dde/gl3n/blob/master/gl3n/linalg.d#L1036
Matrix.perspective() with FOV:
https://github.com/Dav1dde/gl3n/blob/master/gl3n/linalg.d#L1179
Switch from cuteDoc to https://github.com/JakobOvrum/bootDoc
Wouldn't it be neat to be able to write:
assert(clamp(vec2(-4.3, 2), -3, 4) == vec2(-3, 2));
assert(clamp(vec2(-2, 4), vec2(0, 0), vec2(1, 3)) == vec2(0, 3));
A replacement for calls such as glFrustum
and glOrtho
would be nice. I can work on it if you're open to it.
I don't know what to put for the import thing.
import gl3n.aabb : vec3;
void main() {
vec4 v4 = vec4(1.0f, vec3(2.0f, 3.0f, 4.0f));
vec4 v4_2 = vec4(1.0f, vec4(1.0f, 2.0f, 3.0f, 4.0f).xyz); // "dynamic" swizzling with opDispatch
vec4 v4_3 = v4_2.xxyz; // opDispatch returns a static array which you can pass directly to the ctor of a vector!
vec3 v3 = my_3dvec.rgb;
vec3 foo = v4.xyzzzwzyyxw.xyz; // not useful but possible!
mat4 m4fv = mat4.translation(-0.5f, -0.54f, 0.42f).rotatex(PI).rotatez(PI/2);
glUniformMatrix4fv(location, 1, GL_TRUE, m4fv.value_ptr); // yes they are row major!
alias Matrix!(double, 4, 4) mat4d;
mat4d projection;
glGetDoublev(GL_PROJECTION_MATRIX, projection.value_ptr);
mat3 inv_view = view.rotation;
mat3 inv_view = mat3(view);
mat4 m4 = mat4(vec4(1.0f, 2.0f, 3.0f, 4.0f), 5.0f, 6.0f, 7.0f, 8.0f, vec4(1,2,3,4), vec4(1,2,3,4));
}
The initial min/max vectors might not be part of the minimal AABB containing the provided points.
Greetings.
I wonderd if it would be usefull to use https://dlang.org/spec/simd.html in gl3n. This could come in handy if you use gl3n alot in collision detection or something similar.
Would that make sense to do?
shared vec2 pos;
vec2 getPosition() {
return cast(vec2)pos; //does not work
return vec2(pos.x, pos.y); //does not work
return vec2(pos.vector[0], pos.vector[1]); //does work
}
am I doing something wrong?
copy paste from issue #49:
i cannot reproduce the issue on win32 using dmd2.065. @Dav1dde maybe a travis-ci integration can prevent those issues in the future? it is easy to integrate to even test multiple compiler flavours and its free ;)
Hi
I would like to do some general linear algebra using the Matrix type but I ran into a couple of issues.
Matrix!(float, 2, 5) A;
A[0][0] = 0; A[0][1] = 1; A[0][2] = 2; A[0][3] = 3; A[0][4] = 4;
A[1][0] = 5; A[1][1] = 6; A[1][2] = 7; A[1][3] = 8; A[1][4] = 9;
writeln(A.as_pretty_string);
Matrix!(float, 5, 2) B;
B[0][0] = 0; B[0][1] = 1;
B[1][0] = 2; B[1][1] = 3;
B[2][0] = 4; B[2][1] = 5;
B[3][0] = 6; B[3][1] = 7;
B[4][0] = 8; B[4][1] = 9;
writeln(B.as_pretty_string);
// Compiles but produces the wrong result (half of the matrix is filled with nan's)
auto res1 = B * A;
writeln(res1.as_pretty_string);
// Gives loads of out of bounds errors on compile time.
auto res2 = A * B;
// Gives a couple of out of bounds errors on compile time.
Matrix!(float, 1, 5) C;
// Ditto
Matrix!(float, 5, 1) D;
There is no way to do decomposition on gl3n , right?
Like on glm:
glm::decompose(transformation, scale, rotation, translation, skew, perspective);
Produced weird results, so I redid it using http://www.flipcode.com/documents/matrfaq.html#Q55 as a reference and now it seems to work. fingers crossed
/// Creates a quaternion from a 3x3 matrix.
/// Params:
/// matrix = 3x3 matrix (rotation)
/// Returns: A quaternion representing the rotation (3x3 matrix)
static Quaternion from_matrix(Matrix!(qt, 3, 3) matrix) {
Quaternion ret;
auto mat = matrix.matrix;
qt trace = mat[0][0] + mat[1][1] + mat[2][2] + 1.0;
if(trace > 0) {
real s = 0.5 / sqrt(trace);
ret.w = to!qt(0.25 / s);
ret.x = to!qt((mat[2][1] - mat[1][2]) * s);
ret.y = to!qt((mat[0][2] - mat[2][0]) * s);
ret.z = to!qt((mat[1][0] - mat[0][1]) * s);
} else if((mat[0][0] > mat[1][1]) && (mat[0][0] > mat[2][2])) {
real s = 2.0 * sqrt(1 + mat[0][0] - mat[1][1] - mat[2][2]);
ret.w = to!qt((mat[2][1] + mat[1][2]) / s);
ret.x = to!qt(0.5 / s);
ret.y = to!qt((mat[0][1] + mat[1][0]) / s);
ret.z = to!qt((mat[0][2] + mat[2][0]) / s);
} else if(mat[1][1] > mat[2][2]) {
real s = 2.0 * sqrt(1 + mat[1][1] - mat[0][0] - mat[2][2]);
ret.w = to!qt((mat[0][2] + mat[2][0]) / s);
ret.x = to!qt((mat[0][1] + mat[1][0]) / s);
ret.y = to!qt(0.5 / s);
ret.z = to!qt((mat[1][2] + mat[2][1]) / s);
} else {
real s = 2.0 * sqrt(1 + mat[2][2] - mat[0][0] - mat[1][1]);
ret.w = to!qt((mat[1][0] + mat[0][1]) / s);
ret.x = to!qt((mat[0][2] + mat[2][0]) / s);
ret.y = to!qt((mat[1][2] + mat[2][1]) / s);
ret.z = to!qt(0.5f / s);
}
return ret;
}
I hope the code compiles as I did it in a text editor using the separate function I got working in my project =)
When dmd 2.067 comes out, gl3n v1.0.0 won't compile with it due to not having (some of) the changes from #43
A v1.0.1 patch release would be nice.
I have absolutely no idea why this is happening, but apprantly there are certain magical quaternions that cannot be interpolated between.
quat a = quat.yrotation(-1.238796f);
quat b = quat.yrotation(-1.238796f);
quat bad = slerp(a, b, 0.5);
quat a2 = quat.yrotation(-1.23879f);
quat b2 = quat.yrotation(-1.23879f);
quat good = slerp(a2, b2, 0.5);
writeln(a, " ", b, " ", bad, " ", good, ".");
Having done a bit of research on slerp it turns out that its "bad practice" anyway:
http://physicsforgames.blogspot.com/2010/02/quaternions.html
http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/
If it is not too much trouble, I'd like to see nlerp along with a fixed version of slerp in the interpolate module.
My version looks like this:
quat nlerp(quat a, quat b, float t) {
float dot = a.w * b.w + a.x * b.x + a.y * b.y + a.z * b.z;
quat result;
if(dot < 0) { // Determine the "shortest route"...
result = a - (b + a) * t; // use -b instead of b
} else {
result = a + (b - a) * t;
}
result.normalize();
return result;
}
, but I guarrantee nothing as the bug above is completely blowing my mind.
I'm doing 2d calculations, and having a 2d AABB would be nice.
I'm currently working on a PR for n-dimension AABB which dimensions are defined at compile time (inspired from how Vector
works)
This will produce tons of errors (at least with dmd 2.059):
alias Matrix!(int, 2, 2) mat2i;
alias Matrix!(int, 3, 3) mat3i;
alias Matrix!(int, 4, 4) mat4i;
alias Matrix!(long, 2, 2) mat2l;
alias Matrix!(long, 3, 3) mat3l;
alias Matrix!(long, 4, 4) mat4l;
Interestingly the real
type also fails to compile
This needs to be tested, but I believe it should work:
private Matrix invert(ref Matrix mat) const {
mt d = 1.0 / det;
mat.matrix = [[
( ... ) * d,
// etc...
]];
return mat;
}
vec3 a = cast(vec3)vec3i(1, 2, 3);
it took me hours to finally realize those methods are broken instead of my code using them ^^
consider the following test case:
unittest{
enum startPitch = 0.1;
enum startYaw = -0.2;
enum startRoll = 0.6;
import std.stdio;
writefln("%s,%s,%s",startPitch,startYaw,startRoll);
auto q = quat.euler_rotation(startRoll,startPitch,startYaw);
writefln("%s,%s,%s",q.pitch,q.yaw,q.roll);
assert(almost_equal(q.pitch,startPitch),.format("%s != %s",q.pitch,startPitch));
assert(almost_equal(q.yaw,startYaw),.format("%s != %s",q.yaw,startYaw));
assert(almost_equal(q.roll,startRoll),.format("%s != %s",q.roll,startRoll));
}
essentially we take euler angles, create a quaternion of them and get the euler angles from that quaternion again. this should work without loosing any information. the above test case tries that. it fails.
then i examined the wiki page for euler angles and found that all four methods are defined different than in your implementation: http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
my implementation looks like this and solves the issue but breaks some of your unittests where u hardcoded what seems to be wrong results:
/// Returns the yaw.
@property real yaw() const {
return atan2(2.0*(w*z + x*y), 1.0 - 2.0*(y*y + z*z));
}
/// Returns the pitch.
@property real pitch() const {
return asin(2.0*(w*y - z*x));
}
/// Returns the roll.
@property real roll() const {
return atan2(2.0*(w*x + y*z), 1.0 - 2.0*(x*x + y*y));
}
static Quaternion euler_rotation(real roll, real pitch, real yaw) {
Quaternion ret;
auto cr = cos(roll / 2.0);
auto cp = cos(pitch / 2.0);
auto cy = cos(yaw / 2.0);
auto sr = sin(roll / 2.0);
auto sp = sin(pitch / 2.0);
auto sy = sin(yaw / 2.0);
ret.w = cr * cp * cy + sr * sp * sy;
ret.x = sr * cp * cy - cr * sp * sy;
ret.y = cr * sp * cy + sr * cp * sy;
ret.z = cr * cp * sy - sr * sp * cy;
return ret;
}
As the library looks like it should be possible to mark everything as @nogc
, perhaps it would be a good idea to actually do so? This would give the extra assurance that the library is perfect for use in an environment where the GC is the enemy.
Hey, I cannot create a vector of ubytes because of this error:
Building configuration "application", build type debug
Compiling...
../../../../../.dub/packages/gl3n-master/gl3n/linalg.d(147): Error: static assert "Vector constructor argument must be of type ubyte or Vector, not int"
../../../../../.dub/packages/gl3n-master/gl3n/linalg.d(167): instantiated from here: construct!(0, int, int, int)
../../../../../.dub/packages/gl3n-master/gl3n/linalg.d(93): instantiated from here: __ctor!(int, int, int)
source/loadpnm.d(12): instantiated from here: Vector!(ubyte, 3)
Error: DMD compile run failed with exit code 1
Run 'dub help' for usage information.
It isn't possible to instantiate the AABBT
-template with an int
, it gives an error on this line since the constructor of the vec3
s are hardcoded to be of type float
.
Proposed solution: instantiate with cast(type)0.0
instead
Problem observed with DMD32 D Compiler v2.074.0
on windows
I have a problem getting the following code to run. I'm not sure whether the problem lies with the compiler, the library or with me.
I want to do the following:
alias Vector!(ushort,3) TriIndices;
auto Test = TriIndices(1,2,3);
But I get the following error from the compiler:
"gl3n/linalg.d(125): Error: static assert "Vector constructor argument must be of type ushort or Vector, not int"
Thanks for your help.
I having run dub test
, many linker errors happen.
/dub.json
{
"name": "temp",
"dependencies": {
"gl3n": "~>1.3.1"
}
}
/src/main.d
import std;
import gl3n.linalg;
void main() {
Tuple!vec2 tuple;
}
$ dub test
No source files found in configuration 'library'. Falling back to "dub -b unittest".
Performing "unittest" build using /usr/bin/dmd for x86_64.
gl3n 1.3.1: target for configuration "library" is up to date.
temp ~master: building configuration "application"...
Linking...
/usr/bin/ld: .dub/build/application-unittest-linux.posix-x86_64-dmd_2087-6042B5CA26865B98B64101D410178581/temp.o: in function `_D4gl3n6linalg__T6VectorTfVii2ZQo20__unittest_L388_C5_1FNaNbNfZv':
/home/username/temp/../.dub/packages/gl3n-1.3.1/gl3n/gl3n/linalg.d:392: undefined reference to `_D4gl3n6linalg__T6VectorTfVii3ZQo__T10opDispatchVAyaa6_7879627a7972ZQBgMxFNaNbNdNiNfZSQDgQDe__TQDaTfVii6ZQDk'
/usr/bin/ld: /home/username/temp/../.dub/packages/gl3n-1.3.1/gl3n/gl3n/linalg.d:396: undefined reference to `_D4gl3n6linalg__T6VectorTfVii4ZQo__T10opDispatchVAyaa6_7767797a6178ZQBgMxFNaNbNdNiNfZSQDgQDe__TQDaTfVii6ZQDk'
/usr/bin/ld: .dub/build/application-unittest-linux.posix-x86_64-dmd_2087-6042B5CA26865B98B64101D410178581/temp.o: in function `_D4gl3n6linalg__T6VectorTfVii6ZQo20__unittest_L388_C5_2FNaNbNfZv':
/home/username/temp/../.dub/packages/gl3n-1.3.1/gl3n/gl3n/linalg.d:392: undefined reference to `_D4gl3n6linalg__T6VectorTfVii3ZQo__T10opDispatchVAyaa6_7879627a7972ZQBgMxFNaNbNdNiNfZSQDgQDe__TQDaTfVii6ZQDk'
/usr/bin/ld: /home/username/temp/../.dub/packages/gl3n-1.3.1/gl3n/gl3n/linalg.d:396: undefined reference to `_D4gl3n6linalg__T6VectorTfVii4ZQo__T10opDispatchVAyaa6_7767797a6178ZQBgMxFNaNbNdNiNfZSQDgQDe__TQDaTfVii6ZQDk'
/usr/bin/ld: .dub/build/application-unittest-linux.posix-x86_64-dmd_2087-6042B5CA26865B98B64101D410178581/temp.o: in function `_D4gl3n6linalg__T6VectorTfVii3ZQo20__unittest_L388_C5_3FNaNbNfZv':
/home/username/temp/../.dub/packages/gl3n-1.3.1/gl3n/gl3n/linalg.d:392: undefined reference to `_D4gl3n6linalg__T6VectorTfVii3ZQo__T10opDispatchVAyaa6_7879627a7972ZQBgMxFNaNbNdNiNfZSQDgQDe__TQDaTfVii6ZQDk'
/usr/bin/ld: /home/username/temp/../.dub/packages/gl3n-1.3.1/gl3n/gl3n/linalg.d:396: undefined reference to `_D4gl3n6linalg__T6VectorTfVii4ZQo__T10opDispatchVAyaa6_7767797a6178ZQBgMxFNaNbNdNiNfZSQDgQDe__TQDaTfVii6ZQDk'
/usr/bin/ld: .dub/build/application-unittest-linux.posix-x86_64-dmd_2087-6042B5CA26865B98B64101D410178581/temp.o: in function `_D4gl3n6linalg__T6VectorTfVii4ZQo20__unittest_L388_C5_4FNaNbNfZv':
/home/username/temp/../.dub/packages/gl3n-1.3.1/gl3n/gl3n/linalg.d:392: undefined reference to `_D4gl3n6linalg__T6VectorTfVii3ZQo__T10opDispatchVAyaa6_7879627a7972ZQBgMxFNaNbNdNiNfZSQDgQDe__TQDaTfVii6ZQDk'
/usr/bin/ld: /home/username/temp/../.dub/packages/gl3n-1.3.1/gl3n/gl3n/linalg.d:396: undefined reference to `_D4gl3n6linalg__T6VectorTfVii4ZQo__T10opDispatchVAyaa6_7767797a6178ZQBgMxFNaNbNdNiNfZSQDgQDe__TQDaTfVii6ZQDk'
/usr/bin/ld: .dub/build/application-unittest-linux.posix-x86_64-dmd_2087-6042B5CA26865B98B64101D410178581/temp.o: in function `_D4gl3n6linalg__T6VectorTfVii5ZQo20__unittest_L388_C5_7FNaNbNfZv':
/home/username/temp/../.dub/packages/gl3n-1.3.1/gl3n/gl3n/linalg.d:392: undefined reference to `_D4gl3n6linalg__T6VectorTfVii3ZQo__T10opDispatchVAyaa6_7879627a7972ZQBgMxFNaNbNdNiNfZSQDgQDe__TQDaTfVii6ZQDk'
/usr/bin/ld: /home/username/temp/../.dub/packages/gl3n-1.3.1/gl3n/gl3n/linalg.d:396: undefined reference to `_D4gl3n6linalg__T6VectorTfVii4ZQo__T10opDispatchVAyaa6_7767797a6178ZQBgMxFNaNbNdNiNfZSQDgQDe__TQDaTfVii6ZQDk'
/usr/bin/ld: .dub/build/application-unittest-linux.posix-x86_64-dmd_2087-6042B5CA26865B98B64101D410178581/temp.o: in function `_D4gl3n6linalg__T6VectorTfVii12ZQp20__unittest_L388_C5_8FNaNbNfZv':
/home/username/temp/../.dub/packages/gl3n-1.3.1/gl3n/gl3n/linalg.d:392: undefined reference to `_D4gl3n6linalg__T6VectorTfVii3ZQo__T10opDispatchVAyaa6_7879627a7972ZQBgMxFNaNbNdNiNfZSQDgQDe__TQDaTfVii6ZQDk'
/usr/bin/ld: /home/username/temp/../.dub/packages/gl3n-1.3.1/gl3n/gl3n/linalg.d:396: undefined reference to `_D4gl3n6linalg__T6VectorTfVii4ZQo__T10opDispatchVAyaa6_7767797a6178ZQBgMxFNaNbNdNiNfZSQDgQDe__TQDaTfVii6ZQDk'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
/usr/bin/dmd failed with exit code 1.
$ dub --version
DUB version 1.16.0, built on Jul 02 2019
$ dmd --version
DMD64 D Compiler v2.087.0
Copyright (C) 1999-2019 by The D Language Foundation, All Rights Reserved written by Walter Bright
$ uname -r
5.2.1-arch1-1-ARCH
gl3n 1.2.0: building configuration "library"...
../../../../../.dub/packages/gl3n-1.2.0/gl3n/util.d(14,12): Error: module std.typecons import 'TypeTuple' not found, did you mean template 'isTypeTuple(T...)'?
It looks like this repo has not been modified since January. Is that because the code is stable and works well, or because the project is dead, or maybe just that no one is using it? I'm doing some OpenGL work in D and wanted to use an existing library for GLM instead of writing my own. In your opinion, is this the right project to go with, or another project?
So basically, I'm trying to replicate what I've written in C++ into Dlang.
I have this as the Dlang code.
vec2 pos;
vec2 size;
float rotate;
pos.x = pos.y = 0;
size.x = size.y = 500;
rotate = 0;
mat4 model = mat4.identity;
writeln("Initial :");
writeln(model);
SDL_Delay(2000);
model = model.translate(vec3(pos,0.0f));
writeln("First :");
writeln(model);
SDL_Delay(2000);
model = model.rotation(rotate,vec3(pos,1.0f));
writeln("Second :");
writeln(model);
SDL_Delay(2000);
model = model.translate(vec3(-0.5f * size.x, -0.5f * size.y, 0.0f));
writeln("Third :");
writeln(model);
SDL_Delay(2000);
model = model.scale(size.x,size.y,1.0f);
writeln("Fourth :");
writeln(model);
SDL_Delay(2000);
And this as the C++ code:
glm::vec2 pos;
glm::vec2 size;
GLfloat rotate;
pos.x = pos.y = 0;
size.x = size.y = 500;
rotate = 0;
glm::mat4 model;
std::cout << "Initial : \n" << glm::to_string(model) << std::endl;
SDL_Delay(2000);
model = glm::translate(model,glm::vec3(pos, 0.0f));
std::cout << "First : \n" << glm::to_string(model) << std::endl;
SDL_Delay(2000);
model = glm::rotate(model,rotate,glm::vec3(pos,1.0f));
std::cout << "Second : \n" << glm::to_string(model) << std::endl;
SDL_Delay(2000);
model = glm::translate(model,glm::vec3(-0.5f * size.x, -0.5f * size.y, 0.0f));
std::cout << "Third :\n" << glm::to_string(model) << std::endl;
SDL_Delay(2000);
model = glm::scale(model,glm::vec3(size,1.0f));
std::cout << "Fourth :\n" << glm::to_string(model) << std::endl;
SDL_Delay(2000);
And the results are different:
Dlang code:
C++ code:
At first, the values are basically the same, then it starts to differ at the third output.
Dlang code:
model = model.translate(vec3(-0.5f * size.x, -0.5f * size.y, 0.0f))
C++ code:
model = glm::translate(model,glm::vec3(-0.5f * size.x, -0.5f * size.y, 0.0f))
I'm not sure if this is a bug or not, I just don't know where to post it.
I am probably doing something wrong here, but I'm still trying to wrap my head around matrices in general.
If this is not a bug, then I'm very sorry for wasting your time.
The documentation at http://dav1dde.github.io/gl3n/index.html is incomplete/outdated. I was using it as a reference and didn't find the perspective/look_at methods and attempted doing them myself. After failing for a good amount of time i read your BraLa code and found they actually do exist! Updating the online documentation would be very helpful or at least a warning that it is not up to date to save other people my issue.
Thanks!
Please add these lines to a .gitignore, so one can directly use your repo as a submodule and build inside, without having the "files changed" info all the time...
build/
doc/
gl3n.pc
import/
lib/
Hope I'm not spamming, but I wanted to get this down before I knocked off for the night in case I forgot.
I haven't looked carefully yet, but I think rgb2hsv returns hue in 360 degrees, while hsv2rgb expects hue in 0-1 range.
A comment in the source code would be very helpful!
After compilation math.di interface is generated with errors. Return type for "clamp" and "smoothstep" functions is missing (must be "auto"). It can be not related to specific compiler version, but it used to work properly with previous compiler version.
mat3 = mat3 * mat3 works though
You may forgot to do opOpAssign in addition to opBinary
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.