Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (711)
Games in Android Showcase (213)
games submitted by our members
Games in WIP (785)
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 3706 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?

Online Riven

« JGO Overlord »

Medals: 1260
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  
You cannot reply to this message, because it is very, very old.

Archive (159 views)
2017-02-27 19:41:49

numerical (503 views)
2017-02-21 07:32:16

numerical (505 views)
2017-02-21 07:31:46

theagentd (618 views)
2017-02-18 13:42:33

theagentd (613 views)
2017-02-18 13:35:16

h.pernpeintner (1785 views)
2017-01-24 22:39:11

h.pernpeintner (1726 views)
2017-01-24 22:38:32

Galdo (2298 views)
2017-01-12 13:44:09

Archive (2189 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2724 views)
2016-12-16 03:58:39
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 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!