Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (806)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 ... 9 10 [11] 12 13
  ignore  |  Print  
  Java OpenGL Math Library (JOML)  (Read 216506 times)
0 Members and 1 Guest are viewing this topic.
Offline KaiHH

JGO Kernel


Medals: 798



« Reply #300 - Posted 2015-08-20 10:51:30 »

I'd like to use JOML for 2D transformations, to get away from the rather naive calculations I do with trig functions...
That's nice to hear. Smiley You might want to give joml-2d a try. So please do mention anything that you see is probably lacking there.

As for using joml-2d:
Do you intend to interface with OpenGL for rendering or do you want to use Java2D or JavaFX?
I'm asking since I observed that most people doing 2D do not want the high learning-curve of OpenGL and then reasonably choose Java2D or JavaFX for that.
JOML is rather geared towards integration with Java/OpenGL bindings, because everything is centered around matrices and NIO buffers, which are a perfect fit for OpenGL.
It may not be such a good fit for Java2D or JavaFX, which both provide their own facilities for representing transformations (AffineTransformation and such) and applying those transformations when drawing/rendering stuff.
With that I just want to see, whether joml-2d is really a fit for you.

As for a tutorial on how to use JOML:
I guess it boils down to understanding raw linear algebra, which JOML cannot help you with to be honest.
There are some few examples on JOML's README and you can have a look at JOML's Wiki (see the navigation bar to the right).
There is also the joml-lwjgl3-demos repository containing some example programs using LWJGL3 for rendering.
But in the end, what you might want to know is raw linear algebra. I am sure there are great tutorials or books out there, too, for that.
Offline Roquen

JGO Kernel


Medals: 518



« Reply #301 - Posted 2015-08-20 19:31:16 »

@Riven:
      int x = Float.floatToRawIntBits(s);
      {do stuff}
      f = Float.intBitsToFloat(x);

is being translated into (by C1):  SSE register has float, moves to regular register..do stuff..move back to SSE.  So they're both move operations.  So fast.  The odd thing is even if do stuff could be performed in SSE.  So I was indeed complete full of poop.
Offline theagentd
« Reply #302 - Posted 2015-08-20 21:53:56 »

Finally home and ready to try out JOML stuff in WSW. Still missing three functions:



Matrix**.getScale(Vector**): gets the scaling of each axis. Used to calculate LOD level based on scale of model from a model's matrix.

Vector3*.mulRotate(Matrix4*): multiplies the vector by the matrix with w=0, i.e. multiply by matrix but ignore translation. I use this to rotate directional and cone light direction vectors by the view matrix's rotation.

Matrix4d.getFloat(int index, ByteBuffer buffer): stores the double matrix in a ByteBuffer as floats. Currently limited to doubles only for ByteBuffers. I use this to store model matrices in a mapped VBO (a ByteBuffer).



I really think that the "get" functions should be renamed to "store". The name really makes no sense right now. LWJGL's math library called it store(), since you store the matrix in the buffer. The "set" functions make more sense as you set the value of the matrix to that of the data in the buffer/array. LWJGL called this operation "load" which I prefer, but "set" is okay IMO.


EDIT: Minor note: the Vector**.distance() and distanceSquared() functions recalculate (x - this.x) etc twice (although the compiler probably caches that for you). Might want to compute those to local variables just to be sure. It makes the code more readable as well.

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

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #303 - Posted 2015-08-20 22:10:17 »

It should be either load/store or get/set, not store/set.

My two cents. Kiss

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

JGO Kernel


Medals: 798



« Reply #304 - Posted 2015-08-20 22:22:14 »

It will remain get/set, as this is familiar with NIO and really is symmetric to all the other get*/set* methods. Let me explain:

Get means: Get all or some parts of 'this' into another representation
Set means: Set all or some parts of 'this' from another representation

The rationale could be:
- get/set without any addition method name suffix is intended to transform 'this' to another equivalent representation, such as a Matrix3f to a ByteBuffer or a FloatBuffer
- get*/set* methods with suffixes will represent transformations that extract "part of" 'this' into another representation, such as getTranslation() which extracts the translation

I know that there are currently set/get methods that violate the first enumeration point, namely set/get with Quaternion parameter. A quaternion is not a 1:1 full equivalent representation of a matrix, can't be, but only of the rotation property. So, this could and should in fact be renamed to "getRotation".

But I will not rename the get/set methods taking NIO Buffers to store/load.
Offline theagentd
« Reply #305 - Posted 2015-08-20 22:37:03 »

I still vote for renaming it to store/load. I don't think the get-set logic applies in this case since the JOML classes aren't buffers. Getting in NIO implies reading data from a buffer, but getting in JOML implies writing to a buffer. Load/store makes sense as it mimics the old OpenGL functions as well, where glLoadMatrix(FloatBuffer) loads a matrix from a given buffer. The fact that the set() functions are filled with buffer.gets() is a bad sign IMO. >___>

Myomyomyo.
Offline theagentd
« Reply #306 - Posted 2015-08-21 09:03:39 »

G'morning. I just pulled the latest changes. getScale() works well, but removing Vector3*.mul(Matrix4*) broke a lot of my code. It'd be nice if we had mulPoint() and mulDirection() in Vector3* as well. I still need the <store double matrix at float precision in byte buffer> function. >_<

In other news, we're starting the switch to JOML for WSW today.

Myomyomyo.
Offline KaiHH

JGO Kernel


Medals: 798



« Reply #307 - Posted 2015-08-21 10:14:04 »

Vector3.mulPoint/.mulDirection is in, though it somehow feels wrong to ask a 3D vector to multiply itself by a 4x4 matrix. That's what the Matrix4.transformPoint/.transformDirection were supposed to do. I added the vector methods nonetheless, but discourage you to use them, as it tingles in my fingers to mark them deprecated and remove them again. Smiley

Regarding the "storing a double-precision matrix as single-precision via a ByteBuffer": I would request you to use a (premanent) FloatBuffer view on your ByteBuffer to achieve that.
Offline theagentd
« Reply #308 - Posted 2015-08-21 11:27:53 »

I am using mapped VBOs, so generating a new FloatBuffer each time I map it is something I would like to avoid. In addition, I'm storing non-float stuff in it as well, so keeping it as ByteBuffer is optimal for me.

Edit:
Matrix4.get(Quaternion) should be renamed to Matrix4.getRotation(Quaternion), to complement getTranslation() and getScale().

Myomyomyo.
Offline KaiHH

JGO Kernel


Medals: 798



« Reply #309 - Posted 2015-08-21 14:03:11 »

Okay. I understand. Both your change requests are in now.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #310 - Posted 2015-08-21 15:02:53 »

Thanks, works great!

Myomyomyo.
Offline Roquen

JGO Kernel


Medals: 518



« Reply #311 - Posted 2015-08-21 20:29:22 »

To not pollute this thread even more:  http://www.java-gaming.org/topics/case-studies/36562/msg/347355/view.html#msg347355
Offline theagentd
« Reply #312 - Posted 2015-08-21 20:55:56 »

Matrix4d.set(Quaternion*) is missing. >_<

Myomyomyo.
Offline KaiHH

JGO Kernel


Medals: 798



« Reply #313 - Posted 2015-08-21 21:08:10 »

Matrix4d.set(Quaternion*) is missing. >_<
Just saw your post on phone, ran to the computer, turned it on, started Eclipse and emergency-added the missing method. Cheesy
It's in now.
Offline theagentd
« Reply #314 - Posted 2015-08-22 09:54:58 »

 - There's no AxisAngle4d class it seems, and the Quaterniond constructor does not accept AxisAngle4fs. Currently need to do new Quaterniond().set(AxisAngle4f).

 - Matrix4d.translationRotateScale(Vector3d, Quaterniond, Vector3d) is missing, only the version with float Vectors exists (raw double argument version exists).



A problem I'm continuously getting is converting between float and double versions of objects.

Examples:
 - Getting the world position of bones. Object matrix is a Matrix4d, calculated local bone position is Vector3f. This works reasonably well as Matrix4d can take in a Vector3f.
 - Particles use float precision, but I have most matrices as double matrices. Matrix4f.set(Matrix4d) does not exist, which would be useful.

In my opinion, the float versions should at the minimum have setters for reading from the double versions (Vector3f.set(Vector3d), etc), but actually having all functions being able to take in double arguments (like how the double versions have functions that take in the float versions) would be really useful.

Also, Quaterniond seems to miss float versions of its functions.

Myomyomyo.
Offline theagentd
« Reply #315 - Posted 2015-08-22 10:33:30 »

Also badly missing the ability to initialize matrices and quaternions from Euler angles.

Myomyomyo.
Offline KaiHH

JGO Kernel


Medals: 798



« Reply #316 - Posted 2015-08-22 11:34:40 »

Quote
There's no AxisAngle4d class it seems, and the Quaterniond constructor does not accept AxisAngle4fs. Currently need to do new Quaterniond().set(AxisAngle4f).
Thanks, I'll take care of this.

Quote
Matrix4d.translationRotateScale(Vector3d, Quaterniond, Vector3d) is missing, only the version with float Vectors exists (raw double argument version exists).
I'll also take care of that.

Quote
Getting the world position of bones. Object matrix is a Matrix4d, calculated local bone position is Vector3f. This works reasonably well as Matrix4d can take in a Vector3f.
Don't understand what it is here that you want to have changed.

Or was it just meant as a transition to:
Quote
Matrix4f.set(Matrix4d) does not exist, which would be useful.
The reason why "most" floatPrecisionThing.set(doublePrecisionThing) does not exist, is, because you are losing precision and explicit casts are needed.

Quote
In my opinion, the float versions should at the minimum have setters for reading from the double versions (Vector3f.set(Vector3d), etc), but actually having all functions being able to take in double arguments (like how the double versions have functions that take in the float versions) would be really useful.
Okay. I'll add those.

Quote
Also, Quaterniond seems to miss float versions of its functions.
What do you mean? If you mean functions that originally took double primitives, then there is no need for a float primitives overload, as float can always safely coalesced to double. Another thing it is of course with double-vector arguments. I'll see where I can augment it with float-vector arguments.

Quote
Also badly missing the ability to initialize matrices and quaternions from Euler angles.
There is
Quaternion.setEulerAnglesXYZ/setEulerAnglesZYX
, depending on your wanted rotation order.
If you desperately need also that function in Matrix, then that could be added. Otherwise, you could initialize a quaternion with that and then set a matrix to that quaternion.
Offline theagentd
« Reply #317 - Posted 2015-08-22 11:38:52 »

Thanks, you understood everything correctly.  Wink

Quote
Also badly missing the ability to initialize matrices and quaternions from Euler angles.
There is
Quaternion.setEulerAnglesXYZ/setEulerAnglesZYX
, depending on your wanted rotation order.
If you desperately need also that function in Matrix, then that could be added. Otherwise, you could initialize a quaternion with that and then set a matrix to that quaternion.
It'd be really nice to have in Matrix** as well.

I've just manually "fixed" ~3000 errors over 2 days in WSW as a result of the switch. I literally dreamt about code last night.

Myomyomyo.
Offline Roquen

JGO Kernel


Medals: 518



« Reply #318 - Posted 2015-08-22 12:32:04 »

Inject a proxy method, then refactor.
Offline theagentd
« Reply #319 - Posted 2015-08-22 13:12:15 »

Inject a proxy method, then refactor.
It's not that simple as I'm selectively converting part of it to use doubles.

Myomyomyo.
Offline KaiHH

JGO Kernel


Medals: 798



« Reply #320 - Posted 2015-08-22 22:42:38 »

Had little time today to implement and test everything.
But so far those are a lot of additions and even one small fix. Smiley
I will be pushing the changes tomorrow evening (about 22:00 CEST).
So far, creating an euler rotation matrix is waaaay faster compared to libGDX. Handcrafted and optimized and tested that.
(Not going through a quaternion was a good choice of yours to want that. Smiley )
And it is kinda intelligibly (IMHO) named in both the matrix and quaternion classes: rotationXYZ/rotationZYX and rotateXYZ/rotateZYX, which do equivalent things in both kinds of classes and are always equivalent to the call sequence:
rotateX/rotationX(..).rotateY(..).rotateZ(..)
and
rotateZ/rotationZ(..).rotateY(..).rotateX(..)
, although of course alot faster.
Offline theagentd
« Reply #321 - Posted 2015-08-22 22:55:16 »

We're having problems with Euler angles in WSW. It seems like the order we're supposed to use depends on if you use a Y-up or Z-up coordinate system. We're investigating how to solve it (it was basically hacked before), but if possible it'd be great if you could implement all 6 orders (XYZ, XZY, etc) so we can try them out. I realize that that might be a bit tedious, but I think it will be useful for people with odd coordinate systems. If you think it's a bad idea, I can give you our specific requirements when we figure them out.

Myomyomyo.
Offline KaiHH

JGO Kernel


Medals: 798



« Reply #322 - Posted 2015-08-22 23:05:20 »

Yes, please figure this out first. I pushed a hotfix for Matrix.rotationZ, and now you can always use the expanded form to figure out your rotation order:
rotationX(..).rotateY(..).rotateZ(..)
(first must be 'rotation' instead of 'rotate') with any order to create a rotation matrix from euler angles.
Offline Roquen

JGO Kernel


Medals: 518



« Reply #323 - Posted 2015-08-23 08:20:23 »

What are you using euler angles for?  IMHO the only sane place is certain styles of 3rd person camera control (and maybe avionics).  Where do you think are they helping vs. hurting you?

For the library...one trick here is that are are (if memory serves) 26 unique euler angle like systems.
Offline theagentd
« Reply #324 - Posted 2015-08-23 22:57:21 »

I've found a bug. Quaternion*.set(Matrix**) does not work correctly with scaled matrices:

1  
2  
3  
4  
5  
6  
7  
      Quaternionf q = new Quaternionf();
      Matrix4f m = new Matrix4f();
      for(int i = 1; i <= 20; i++){
         float scale = i / 10f;
         q.set(m.identity().rotate(45, 0, 0, 1).scale(scale));
         System.out.println("Scale " + scale + ": " + q.x + ", " + q.y + ", " + q.z + ", " + q.w);
      }


Prints:
Quote
Scale 0.1: 0.0, 0.0, 0.13983375, 0.99017495
Scale 0.2: 0.0, 0.0, 0.23463109, 0.97208446
Scale 0.3: 0.0, 0.0, 0.30138966, 0.9535011
Scale 0.4: 0.0, 0.0, 0.350278, 0.9366458
Scale 0.5: 0.0, 0.0, 0.38733634, 0.92193854
Scale 0.6: 0.0, 0.0, 0.41625845, 0.9092463
Scale 0.7: 0.0, 0.0, 0.43938872, 0.898297
Scale 0.8: 0.0, 0.0, 0.4582705, 0.88881266
Scale 0.9: 0.0, 0.0, 0.47395375, 0.8805497
Scale 1.0: 0.0, 0.0, 0.4871745, 0.8733046
Scale 1.1: 0.0, 0.0, 0.49846226, 0.8669115
Scale 1.2: 0.0, 0.0, 0.5082066, 0.8612352
Scale 1.3: 0.0, 0.0, 0.51670027, 0.8561664
Scale 1.4: 0.0, 0.0, 0.52416706, 0.8516155
Scale 1.5: 0.0, 0.0, 0.53078103, 0.8475091
Scale 1.6: 0.0, 0.0, 0.53667897, 0.8437865
Scale 1.7: 0.0, 0.0, 0.54197043, 0.84039754
Scale 1.8: 0.0, 0.0, 0.54674363, 0.83730006
Scale 1.9: 0.0, 0.0, 0.5510708, 0.8344585
Scale 2.0: 0.0, 0.0, 0.5550113, 0.8318429
If it does not work for scaled matrices, it is pretty much a useless feature IMO. Example: I want to find the world orientation of a bone. Convert object matrix rotation to quaternion, multiply together bone rotation with model rotation. Currently this fails if the model is scaled, which it pretty much always is.

EDIT: This is the Euler angle rotations we need:
1  
quaternion.identity().rotateY(yaw).rotateX(pitch).rotateZ(roll);

This is most likely due to us using Y-up instead of Z-up.

Myomyomyo.
Offline KaiHH

JGO Kernel


Medals: 798



« Reply #325 - Posted 2015-08-24 11:19:59 »

I've found a bug. Quaternion*.set(Matrix**) does not work correctly with scaled matrices:
Thanks for reporting! That could be interpreted as a bug in the method contract specification in the JavaDocs.
That method only supports orthogonal matrices (those with orthonormal column vectors) as input.
I renamed that method to "setFromNormalized" and added a "setFromUnnormalized" that supports any matrix with possible scaling.
That new method uses the same approach as libGDX by first normalizing the column vectors.

EDIT: This is the Euler angle rotations we need:
1  
quaternion.identity().rotateY(yaw).rotateX(pitch).rotateZ(roll);

This is most likely due to us using Y-up instead of Z-up.
It's in now. Use
Quaternion.rotationYXZ(..)
or
Matrix.rotationYXZ(..)
.
Offline Roquen

JGO Kernel


Medals: 518



« Reply #326 - Posted 2015-08-25 07:17:22 »

How would you feel about me doing a series of "Golden Axe of Refactorization" push requests?  With an explanation of each?
Offline Spasi
« Reply #327 - Posted 2015-08-25 08:27:09 »

How would you feel about me doing a series of "Golden Axe of Refactorization" push requests?  With an explanation of each?

To anyone thinking about contributing to an open source project:

Just do it, you don't have to ask.

You'll feel better and the project owner will feel better. A pull request is a clean, fast and simple way to contribute. Even if it gets rejected, the discussion under the PR will be useful. You don't have to commit too much time either. Even if you've got big ideas, it's generally best to submit contributions in small batches.
Offline Roquen

JGO Kernel


Medals: 518



« Reply #328 - Posted 2015-08-25 08:54:29 »

Yeah I'm a firm believer in "It's better to ask forgiveness than permission".  What I had in mind was removing trivially inlinable (aka hotspot doesn't even think about it...just does it) code repeats into methods.  So it would be probably hundreds of small changes which produce identical native code.
Offline KaiHH

JGO Kernel


Medals: 798



« Reply #329 - Posted 2015-08-25 10:04:00 »

I highly agree with @Spasi.

Providing something (i.e. code) to discuss about is always better than asking "maybe, should I do something?," where no one knew the answer to that question because there is no basis on which to discuss. Smiley

By the way: It might have disappeared under all the other discussions, but you might remember that everytime someone wanted to have something in JOML I always asked for a pull request.
And if the discussion went along and detailed more and more what it concretely was that the person wanted to have and why he/she wanted to have that, I opted in and implemented it myself once I undestood.
Pages: 1 ... 9 10 [11] 12 13
  ignore  |  Print  
 
 

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

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

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

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

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

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

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

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

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

nelsongames (5135 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

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
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!