Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Android 3D and 4D vector classes


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 pcmaster   Members   -  Reputation: 685

Like
0Likes
Like

Posted 24 May 2012 - 06:17 AM

Hi people,

I noticed there's a nice android.opengl.Matrix class with a lot of helper functions. However, there is no stock Vector class that would support 3D and 4D vectors (compatible with those matrices). I want to be able to perform basic operations on my vectors on CPU, too, that means that having simple float[] everywhere really isn't an option. So before I head on to writing a couple classes for this, I wonder if there isn't a ready library for this kind of simple algebra for Android Java, perhaps somehow optimised for fixed-point or something? Writing that again in Android Java is no big deal, just possibly a waste of time.

I must have been asking google wrong questions so far...

Sponsor:

#2 Ameise   Members   -  Reputation: 766

Like
0Likes
Like

Posted 01 June 2012 - 11:54 AM

Last I did Java-GL work in Android, I rolled my own vector library.

However, I would suggest using C/C++ for any graphics work. All OpenGL calls on Android are JNI calls which are quite expensive (even with a JIT). Dalvik overhead (Dalvik is the VM on Android devices) can become quite noticeable with programs requiring good response time, particularly in regards to GC.

Past that, if you use native code, you can write an optimized version using NEON extensions. It's highly unlikely that Dalvik's JIT (assuming Froyo or later) is going to be able to figure out that your vector code can be better written with NEON.

#3 clb   Members   -  Reputation: 1786

Like
1Likes
Like

Posted 01 June 2012 - 12:20 PM

If your game code is in Java, you want to have your math library in Java. If your game code uses Android NDK, you want to have your math library in C/C++. Crossing the interop barrier is more trouble than the small performance difference with Java and C++. This is because for most primitive operations, a single cache miss or a function call is already way more costly than doing the operation inlined in code of same language.

If your game code is in Java, the only benefit for having C++ math code is in batched math operations: transforming a vertex array by a matrix, or doing CPU-side skinning in batches, batch-testing primitives for intersection, and so on. As commented already above, using NEON here can offer even more performance.
Me+PC=clb.demon.fi | C++ Math and Geometry library: MathGeoLib, test it live! | C++ Game Networking: kNet | 2D Bin Packing: RectangleBinPack | Use gcc/clang/emcc from VS: vs-tool | Resume+Portfolio | gfxapi, test it live!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS