Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (843)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  YAVMA - Yet Another Vector Math API  (Read 4494 times)
0 Members and 1 Guest are viewing this topic.
Offline zingbat

Senior Devvie

Medals: 1

Java games rock!

« Posted 2009-07-03 22:29:35 »

I'm writing a vector math api with a design that some may consider strange and myself have some doubts of it's usefulness.

The design is similar to the vecmath api from Java 3D in which classes are used to store vector data but in my case i have Float2,Float3,... Int2,Int3,... which are all final. Attributes correspond to the name of the class (the primitive) and are all public e0,e1,e2,... matching the count given by the class suffix number. For example:
public final class Float4 { public float e0,e1,e2,e3; }.

I don't have classes that extend other classes like VectorX extends TupleX to avoid virtual methods.

Storage classes don't have any methods, only public attributes.

I have a final class called Vec which supports static final methods (again to avoid virtual methods) and uses the storage classes above as arguments. For example 'Vec.clear(aFloat4)', 'Vec.fill(aDouble3,1.0)' or 'double d=Vec.len(aFloat4)' which returns the length of aFloat4.

Since there are too many methods for every possible combination of vector operation and storage class and the code is too I'm generating the file using another java file called The storage types are Byte, Short, Int, Float, Double and the dimensions are 2, 3, 4, 9, 16. 9 and 16 is because i'm encoding matrices in a linear array. There's 30 storage classes and thus 30 clear methods for maximum efficiency. With all the other methods to do vector math there will be something like 1000 methods, maybe more.

I have some doubts about this.

Should i use storage classes like the ones described above or don't use any storage classes and work with arrays of primitives or primitive data buffers directly in method arguments?

Is the decision to use final and non-virtual methods for the vector math operations a good decision for performance?

Should i have final storage classes and avoid extending classes like what happens with the vecmath api?

Will having classes with thousands of static final methods cause any performance problems?

Offline Riven

« JGO Overlord »

Medals: 1340
Projects: 4
Exp: 16 years

Hand over your head.

« Reply #1 - Posted 2009-07-03 23:39:06 »

Your bytecode must be less than 64KB, so you probably won't be able to stuff thousands of methods on a class.

Anyway, what's the use of yet another primitive holder class (set). Everybody and their dog have their own Vector3, Point2, Matrix4x3, etc. Now think about the user, he'd constantly have to convert his datatype to your datatype. Now you may ask why he wouldn't switch to all your datatypes... well, first there are dependencies in his code, second, it's just a royal pain in the ass to write pA.e1 + pB.e2, if you're used to pA.x + pB.y

Honestly, I'd give such a vector math API zero chance.

My $0.02 Undecided

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

Senior Devvie

Medals: 1

Java games rock!

« Reply #2 - Posted 2009-07-04 02:03:59 »

I could put those methods inside the storage classes. Instead of doing something like Vec.clear(aFloat4) it would become aFloat4.clear() and generate each class, but i'm still a bit suspicious of the performance issues of working with non-final classes. So it could be something like this:

public final class  Float4 {
public float e0,e1,e2,e3;
//Methods for vectors
public void clear() {...}
public void fill(float s) {...}
public void neg(Float4 v) {...}

And the same methods generated for all the other classes. Except no use inheritance or virtual methods.

What do you think?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jezek2
« Reply #3 - Posted 2009-07-04 07:00:35 »

I don't see a reason for this. Vecmath is already optimal performance-wise, nearly all the methods are final and not overriding anything so no virtual overhead. Also it's a standard API and you have better chances to interoperate between different libraries. There were numerous attempts to create better library, but every enhancement ideas had some flaws (like malicious side effects).

But thank you for trying, you never know when you create something better Smiley

Your bytecode must be less than 64KB, so you probably won't be able to stuff thousands of methods on a class.

The 64KB limit is per-method not for whole class.
Offline zingbat

Senior Devvie

Medals: 1

Java games rock!

« Reply #4 - Posted 2009-07-04 13:17:40 »

I guess there's no trouble if i just copy paste code from inside the vecmath api if i keep the GPL. My problem with vecmath is maintenance and using inheritance. Maintenance is by far the biggest issue. Vecmath has a lot of classes style Vector<N><T> and editing one class implies editing all the others. So what i'm going to do is to create a class that generates the java source. The files generated are a combo of: Byte, Int, Short, Float, Double types and 2,3,4,9,16 dimensions. There's no inheritance and all classes are final. With a few differences with the interface, like for example most methods return this at the end to allow chaining operations, this should work in a similar way to vecmath.


Pages: [1]
  ignore  |  Print  

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

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

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

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

nelsongames (122 views)
2018-04-24 18:15:36

nelsongames (121 views)
2018-04-24 18:14:32

ivj94 (861 views)
2018-03-24 14:47:39

ivj94 (122 views)
2018-03-24 14:46:31

ivj94 (758 views)
2018-03-24 14:43:53

Solater (139 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!