Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (798)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (865)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2] 3 4 ... 13
  ignore  |  Print  
  Java OpenGL Math Library (JOML)  (Read 205718 times)
0 Members and 1 Guest are viewing this topic.
Offline KaiHH

JGO Kernel


Medals: 707



« Reply #30 - Posted 2015-02-28 22:50:19 »

We are beginning to run in circles, it seems... Smiley
I will go ahead and first write a tutorial on IEEE 754, then we can continue discussing, but in another thread. Wink
Sorry, Neoptolemus, for spamming your thread!
Offline Neoptolemus
« Reply #31 - Posted 2015-03-01 17:49:25 »

We are beginning to run in circles, it seems... Smiley
I will go ahead and first write a tutorial on IEEE 754, then we can continue discussing, but in another thread. Wink
Sorry, Neoptolemus, for spamming your thread!

Hehe no problem. I am following the thread but I have to admit that I have gaps in my knowledge as far as this stuff goes, I'm entirely self taught in the maths, OpenGL and even programming full-stop, so it's interesting to track the debate and then research what you've been discussing Wink
Offline KaiHH

JGO Kernel


Medals: 707



« Reply #32 - Posted 2015-06-23 13:51:54 »

Hello there,

it's been almost four months now since the last post here on JGO about JOML.
So, what has changed since then?

During June, Neoptolemus took some time off and I decided to work towards JOML becoming really broadly usable and well documented.
Literally about 90% of the time was spent writing JavaDocs and Wiki documentation instead of "code," which is not surprising for such a small and simple library.
However JOML did get alot of additions in functionality too during the last month and is now comparable to the math classes of XNA, Unity, libGDX and javax.vecmath/gwt-vecmath, with both essential and convenient stuff in it, but still with the goal of keeping it feel very "lightweight."

The design (including semantics and naming conventions of methods) has been very strict to comply with the "principle of least astonishment" in order for JOML to be very similar to existing math libraries and how OpenGL and the OpenGL Utility Library handles math, also considering what is generally possible with Java on the syntax level.

You can read all about the design choices on JOML's GitHub Wiki page.
If you have any suggestions/enhancements/bugs, we will be happy to hear about them on JOML's GitHub Issues section.

Last but not least, we hope, that JOML is useful for some of you. For us, it already is. Smiley

Cheers,
the JOML team, Neoptolemus and Kai
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ClaasJG

JGO Coder


Medals: 43



« Reply #33 - Posted 2015-06-23 17:21:41 »

What are the with functions for?

Example: V4f 705

-ClaasJG

My english has to be tweaked. Please show me my mistakes.
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 486
Exp: 7 years



« Reply #34 - Posted 2015-06-23 17:27:36 »

Probably to allow switching to a different instance in the middle of a long method chain, just in case you want to do that.
Offline Kefwar
« Reply #35 - Posted 2015-06-23 17:28:04 »

What are the with functions for?

Example: V4f 705

-ClaasJG

I found an usage here: https://github.com/JOML-CI/JOML#method-chaining-and-context-switching  Pointing

EDIT: was too slow  Sad

Offline childofgod

Senior Newbie


Exp: 50 years



« Reply #36 - Posted 2015-06-23 17:32:40 »

1  
2  
3  
public Vector3f with(Vector3f v) {
        return v;
}


Day and day I'm more and more confident about the fact that people are dumber and dumber, presenting themselves as wiser and wiser. Congratulations, you did epic shit. Literally.
Offline ClaasJG

JGO Coder


Medals: 43



« Reply #37 - Posted 2015-06-23 17:34:40 »

While a 'with' indicates the need of a ';' for me I can see the use.
A neat little library. I like it.

-ClaasJG

p.s. no need to insult anybody!

My english has to be tweaked. Please show me my mistakes.
Offline childofgod

Senior Newbie


Exp: 50 years



« Reply #38 - Posted 2015-06-24 08:31:54 »

While a 'with' indicates the need of a ';' for me I can see the use.
A neat little library. I like it.

-ClaasJG

p.s. no need to insult anybody!

You can see the use of a method that returns a the only paramater that is passed to it? Congratulations to you!
But honestly, go home and take your medicines.
Offline childofgod

Senior Newbie


Exp: 50 years



« Reply #39 - Posted 2015-06-24 08:44:22 »

And to be not without an explanation, let me tell you what is wrong with your head. In the Java language we have a notion of referring to a variable:
1  
2  
3  
4  
5  
6  
Foo foo = new Foo();
Baz baz = new Baz();
foo.doThis();
foo.doThat().doWhatever(baz);
baz.doElse();
baz.beBaz();


Now the world is simple and easy. But some moron came in with a magnificient "with" method that takes an object and returns it so now we write:

1  
2  
3  
4  
Foo foo = new Foo();
Baz baz = new Baz();
foo.doThis();
foo.doThat().doWhatever(baz).with(baz).doElse().with(baz).beBaz();


Great, now you've f**ked up the language. The readability is null, the idea of simply referring to a variable like a sane person is on it's knees.

But really - I don't know why I even bother - live in the shit you made for ever and ever. I'm glad I don't have to read or change or to exist with your code, because else I would get a cancer.

Bye.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

« JGO Spiffy Duke »


Medals: 1103
Projects: 3
Exp: 20 years


Eh? Who? What? ... Me?


« Reply #40 - Posted 2015-06-24 09:10:52 »

Hm, someone got out the wrong side of bed today. Here's how I would approach this without apparently exploding in rage at the injustice of the universe:

What is the design purpose of this method? Perhaps it is redundant.
1  
2  
3  
public Vector3f with(Vector3f v) {
        return v;
}


Cas Smiley

Offline basil_

« JGO Bitwise Duke »


Medals: 418
Exp: 13 years



« Reply #41 - Posted 2015-06-24 10:56:40 »

it's about chaining.

for example, just as seen here :
q1.slerp(q2, alpha, dest).with(dest).transform(v);
- slerp returns the quaternion itself - if you want to continue the "chain" with the output vector of the quat.slerp() method you can use .. the
with()
method. methods with multiple arguments and return values breaking the chain. @childofgod : try again.

might look useles when you look on the source but if you like the "chain-sugar" it makes sense. if you dont like it dont use it, if you dont understand it dont bitch.
Offline childofgod

Senior Newbie


Exp: 50 years



« Reply #42 - Posted 2015-06-24 11:09:05 »

"Redundant"?! If it was written by mistake or just as a stub for later - I would call that a redundant code. But in this case it's an ill-minded idea to allow so called "switching contexts"(yuckh) that was planned ahead. So no, your lies and combinations dont work on me.

Haha "chain sugar", you're funny.

Oh I guess there should be a method called "with" for every class in the Java library so you can chain for ever and ever:
1  
2  
3  
4  
5  
class Object {
  Object with(Object o) {
    return o;
  }
}


Oh look, now you can chain everything (though you will have to do some  casting). But yeah - essentially you got chain-sugar. Chain-sugar for life!

I'm probably a genius and should post that to Oracle as proposal on Java Object class.

Because why just use the simple:

1  
2  
q1.slerp(q2, alpha, dest);
dest.transform(v);


It's so f**king mainstream!
Offline princec

« JGO Spiffy Duke »


Medals: 1103
Projects: 3
Exp: 20 years


Eh? Who? What? ... Me?


« Reply #43 - Posted 2015-06-24 11:24:37 »

Seems reasonable to do things either way to me. I'm not a great fan of method chaining though it can produce some prettier looking code; seems like it's really just making up for some syntax that's missing from Java generally. All hail LISP etc.

Cas Smiley

Offline basil_

« JGO Bitwise Duke »


Medals: 418
Exp: 13 years



« Reply #44 - Posted 2015-06-24 11:35:44 »

1  
2  
3  
4  
public <T> T chain( T t )
{
  return t;
}


i'm not a fan of chaining either.
Offline childofgod

Senior Newbie


Exp: 50 years



« Reply #45 - Posted 2015-06-24 11:53:29 »

Seems reasonable to do things either way to me. I'm not a great fan of method chaining though it can produce some prettier looking code; seems like it's really just making up for some syntax that's missing from Java generally. All hail LISP etc.

<a href="http://www.youtube.com/v/bzkRVzciAZg?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/bzkRVzciAZg?version=3&amp;hl=en_US&amp;start=</a>

There are people who think, they made something new, but what they did is a retarded way of solving well known problem, that had solutions way before.

And yeah if I was to bring some C++ into the Java , why just dont make the new keyword go away?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
class Boo {

  public static void main() {
    Vector3f v = Vector3f(10.0f,15.0f,30.0f); // Who cares about "new" keyword????
   
  }

  public static static Vector3f Vector3f(float x, float y, float z) {
    return new Vector3f(x,y,z);
  }

}


Not to mention I would have to create such methods for every class.

Offline SHC
« Reply #46 - Posted 2015-06-24 12:18:11 »

Not to mention I would have to create such methods for every class.

Or create once in a utility class and static import them. I wouldn't prefer this though, I'm pretty fine with the new keyword.

Offline BurntPizza

« JGO Bitwise Duke »


Medals: 486
Exp: 7 years



« Reply #47 - Posted 2015-06-24 15:17:44 »

Nobody said it was particularly useful or was better.
My 'diagnosis' is that whoever came up with it didn't realize it was possible someone would have such strong opinions about such an inconsequential detail and just wanted a method of "switching context" with syntax consistent with how the rest of the library is idiomatically used (i.e. method chains).

Whether or not it was ill-minded or retarded or genius I don't know, because I don't actually give a damn.

I await the monster.
Offline KaiHH

JGO Kernel


Medals: 707



« Reply #48 - Posted 2015-06-24 16:43:13 »

Thank you all for your throughout positive, kind and encouraging feedback and constructive criticism!
The JGO community is really great! Wink It is much appreciated!
If you feel that you can improve JOML's design or functionality and would like to contribute additions/changes in the form of code that would help you in your projects, you are very welcome to make a contribution.
Just make sure to read about JOML's design goals first, before investing in some code.
If you instead just want to tell us about enhancements that come to your mind or about bugs you found, you can happily post an issue at GitHub.
Your contributions can only help us improve JOML and reach a wider array of potential users.
We are looking forward to hearing from you over at GitHub!
- the JOML team
Offline childofgod

Senior Newbie


Exp: 50 years



« Reply #49 - Posted 2015-06-25 08:54:16 »

1  
design goals


Get your medicines, quickly.
Offline MrPizzaCake

Senior Devvie


Medals: 8
Exp: 3 years


Hello, another wonderful human being :)


« Reply #50 - Posted 2015-06-25 11:48:39 »

@childofgod
Please, if you don't like the chaining, okay, I understand, I don't like it either. But it in no way destroys the language. If you don't like it, don't use it, simple as that. No need to be so darn rude about it. Yes, it may be a stupid idea (no offense, OP), but it's in no way required of you to use it.

I honestly don't give a fudge about a command that I don't have to use (both directly and indirectly), so, yeah. The OP may have wanted to watch the world burn because of the with() command, but I really don't care.

How am I? Tough question, since emotions are confusing as heck Tongue
Offline nsigma
« Reply #51 - Posted 2015-06-25 12:00:14 »

@childofgod somewhere you may have a valid point, but your attitude sucks so I couldn't really be bothered reading between the lines to find out!  Wink

I can't really say it better than @CommanderKeith put it in another recent thread -

Try to give constructive criticism. Comments like this bring down the tone of the forum.
One of the many good things about this community is that people who have nothing nice to say know how to keep it to themselves.

PS. I will partly forgive you because I enjoyed the node.js video.  Smiley

Praxis LIVE - hybrid visual IDE for (live) creative coding
Offline theagentd
« Reply #52 - Posted 2015-06-25 12:42:56 »

This looks really interesting. Due to the major flaws of LWJGL's math library (missing lots of important functions, like slerp for quaternions and vectors) I opted to rip out LibGDX's math library for We Shall Wake/Insomnia. This has both the advantage and drawback of having native code for certain slow functions (matrix multiplication, matrix inverting, etc), but the additional dependencies and natives inflate the size of the game, and more code means that things can go wrong in more places. In addition, LibGDX's math library is completely dependent on static temporary variables, making it useless for multithreading, which I've had to hack around by replacing certain functions and/or add thread-local temp variables instead. All in all, between those two LibGDX's lib was the better one despite all its flaws.

JOML seems to offer some really interesting features, but also seems to lack a few extra features I could really use. I took a look at it, and here's a list of my feedback.

  • Quaternion should be renamed to Quaternionf to follow the same convention as everything else.
  • Generally, AngleAxis is called AxisAngle. AngleAxis just doesn't ring the same. =P
  • In some rare cases, Insomnia suffers from floating point precision problems in some matrix calculations. Many game engines calculate all matrices at double precision and finally converts everything to single precision when uploading it to OpenGL, but neither LibGDX or LWJGL's library has support for that. JOML actually does, but it's incomplete. For this to work, I would need an identical set of functions for both Matrix4f and Matrix4d, but the double version doesn't have many important functions. Also, a function to store a Matrix4d in a FloatBuffer would be nice.
  • The performance of my skeleton animation is probably THE most performance critical section in the entire engine, and it involves constructing a matrix from a translation, a scale and a quaternion rotation. LibGDX has an excellent extremely fast method for doing this (line 202).
  • I calculate a lot of normal matrices from view matrices. A function that can extract a 3x3 normal matrix from a 4x4 matrix would be nice.
  • Many calculations actually only require a 4x3 matrix (view matrix, object transform matrices, bone matrices). A separate 4x3 matrix class would be overkill, but functions to only store the rotation and translation part of the matrix (12 floats) in a float buffer would be nice. It's also possible to make an optimized matrix multiplication function if you know that the last row is (0, 0, 0, 1), which could help you beat LibGDX's native performance in my skeleton calculation.
  • LibGDX doesn't actually have a Vector4 class, only Vector3. Matrix4s can transform Vector3s by mul() (assumes W is 1.0 and discards the calculated W value) and proj() (assumes W is 1.0 and divides by the calculated W value). Such a function would definitely ease porting from LibGDX and save me a lot of time.

All that's left after that would be performance, but I strongly believe you can beat LibGDX due to the questionable design choices they made. Matrix multiplication is definitely the slowest part of my engine (taking up a sizeable percentage on the CPU time taken by an entire frame), and an optimized 4x3 matrix multiplication would be able to cut the matrix multiplication cost by a lot. Add the better naming convention, multithreading readiness and double precision calculations and you have a really attractive library for me.

EDIT:
Would also prefer radians instead of degrees. It's so confusing when I have to mix Java's Math functions with the library. Also, your rotation functions have this:
1  
2  
        float cos = (float) Math.cos(Math.toRadians(ang));
        float sin = (float) Math.sin(Math.toRadians(ang));

You should cache the radian angle instead of calculating it twice. Not sure if Hotspot takes care of that for you, probably not.

Myomyomyo.
Offline KaiHH

JGO Kernel


Medals: 707



« Reply #53 - Posted 2015-06-25 13:10:15 »

Thanks a lot @theagentd for your very detailed evaluation and assessment of JOML.
We would be very glad to help you with your use cases.

Quote
but the double version doesn't have many important functions.
That is definitely true. The double-precision classes always somewhat lagged behind, because they were not as important for existing use-cases of JOML, but now that we know that these really are important, we will sync them.

Quote
it involves constructing a matrix from a translation, a scale and a quaternion rotation
Yes, JOML used to have such a method too, but in general, the order of the operations then needs to be defined properly for such a compound method, that's why JOML only has methods for the primitives, which would then be needed to chain/multiply together.
But again, now that we know that this is an important use-case regarding performance, that compound method will definitely be useful, I agree, and will sure be added in the next JOML release!

Quote
Matrix4s can transform Vector3s by mul()
JOML's Matrix4f also has this ability with transform(Vector3f).

Thank you again for your time and your valuable input!
- the JOML team
Offline theagentd
« Reply #54 - Posted 2015-06-25 17:59:20 »

Another really useful function is setTranslation(), which explicitly sets the translation part of a 4x4 matrix. In some cases it's a lot faster to just do it that way instead of having to translate the matrix.

EDIT: AND PLEASE, add a multiply-and-add function. Literally the most common thing I do in the engine is (position = position + velocity*delta). Add a function (I usually call it mad for multiply-and-and, which is what we call it for GLSL) that can be used like this
1  
position.mad(velocity, delta);

and I'll give you my firstborn son when I get him (ETA ~10 years I guess).

Myomyomyo.
Offline KaiHH

JGO Kernel


Medals: 707



« Reply #55 - Posted 2015-06-25 18:57:46 »

Most of your proposed changes made it into JOML now (sync'ing Matrix4f to Matrix4d is still in progress, however). So, thanks for driving JOML!

Regarding radians vs. degrees:
I tried to stick with what existing and common APIs like OpenGL, GLU, Unity and XNA use in their methods taking angles as parameters, which is degrees. I chose this way in order to make migrating between those libraries and JOML as easy as possible, and to comply with the expectations of those users.

Debatable however is the use of degrees in AxisAngle4f, which I am willing to change, since this is inconsistently being used in other libraries (Unity uses degrees, XNA uses radians, ...), however mostly radians.
But using radians in AxisAngle4f and degrees in other interface methods in JOML would also be inconsistent, that's why initially I chose degrees everywhere.
What do you think about it?

(and please, I do not want to get drawn into a discussion of why degrees are or aren't better than radians. This is of no concern to me, really. Pragmatism and reaching user's expectations is key for JOML here. :-)
Offline theagentd
« Reply #56 - Posted 2015-06-25 19:10:38 »

In my opinion, radians is the way to go, solely because that's what Java uses. JOML isn't meant to emulate OpenGL's legacy matrix system, it's meant to replace it. There are lots of things that are different between OpenGL and JOML's matrix management (function names, etc), so it really won't ease the conversion as OpenGL is the odd one here. It makes more sense to do the same way that Java's math functions do it or you'll end up with really weird situations where you want to calculate some camera angle manually using cos() and sin() and need to keep track of if it's radians or degrees. I'd rather just have one type of angle.

Example: I have cone lights in my game, and the angle of the cone is controlled by an angle variable. The cutoff in the GLSL shader is handled by comparing dot products (cosine of angles), so I compute Math.cos() which uses radians. I then need to compute a perspective matrix for the shadow map, which is done by LibGDX's Matrix4 class which uses degrees. This leads to some intuition problems. Should the user-controlled cone angle be stored in radians or degrees? No matter which one you choose, it's not clear for the user which one to use at first glance. I can't make the entire engine use either degrees or radians as the user is inevitably exposed to both java.lang.Math and the vector library. It ends up being a massive clarity problem which is very prone to potentially hard to detect problems. If JOML uses radians like Math, the entire problem is solved.

Myomyomyo.
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 123
Projects: 15


★★★★★


« Reply #57 - Posted 2015-06-25 19:33:34 »

Personally prefer degrees over radians, just find them easier to wrap my head round when thinking about rotations. Guess it ultimately boils down to personal preference.

Just curious and not sure how feasible it is, would it be possible to support both? like having a method in the library that can be used to switch all the methods globally in the library to use either DEG or RAD?

Would end the debate over which type of angle measurement to use Smiley
Offline Riven
Administrator

« JGO Overlord »


Medals: 1369
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #58 - Posted 2015-06-25 19:41:30 »

kappa: that would break half of the tutorials, and lead to major confusion when using two tutorials that define different units for their angles.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline KaiHH

JGO Kernel


Medals: 707



« Reply #59 - Posted 2015-06-25 19:44:41 »

There are lots of things that are different between OpenGL and JOML's matrix management (function names, etc) [...]
Hm... I tried to stick as closely as possible to the naming and semantics of OpenGL's and GLU's matrix methods.

So, except for the obvious drop of the "gl" prefix, there should not be any other differences between OpenGL's matrix stack functions and JOML's methods: They take the same parameters, in the same order, and they have the exact same semantics (post-multiplying transformations).
Okay, JOML also provides ways to write the result to another matrix than to 'this', because that came convenient.

In my opinion, JOML does not and should not want to replace OpenGL's matrix stack by changing the interface, but instead try to make the same functionality accessible to modern OpenGL programs.

This is so that OpenGL programmers comfortable with the legacy matrix stack immediately feel home when using JOML when they decide to switch from OpenGL's legacy matrix stack to doing the math in Java with JOML.
However, this was the first thing that drove JOML's design, since many LWJGL 3 users complained about how they would do the math with modern OpenGL and without LWJGL 2's utility package around anymore.

I'm not saying, that this is the ultimate fix design, but it's just what drove JOML so far. Smiley
Pages: 1 [2] 3 4 ... 13
  ignore  |  Print  
 
 

 
Riven (28 views)
2019-09-04 15:33:17

hadezbladez (3957 views)
2018-11-16 13:46:03

hadezbladez (1434 views)
2018-11-16 13:41:33

hadezbladez (3954 views)
2018-11-16 13:35:35

hadezbladez (765 views)
2018-11-16 13:32:03

EgonOlsen (4079 views)
2018-06-10 19:43:48

EgonOlsen (4647 views)
2018-06-10 19:43:44

EgonOlsen (2748 views)
2018-06-10 19:43:20

DesertCoockie (3643 views)
2018-05-13 18:23:11

nelsongames (3834 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!