Thanks for the reply.  I think your suggestion of going binary is one
of the better ones I had considered.  Especially because I can avoid
the parseFloat() calls altogether using this method.

As for the quaternion vs axis/angle, I had thought I HAD to translate
them originally (I found out later with more research that I just had
to use the more complicated matrix math rather than simple glrotate
and gltranslate calls if I didn't).  I don't suppose you could direct
me to a tutorial or good description that will help a 3D rendering
newbie like me use the quaternions?  If it really is better/faster, I
want to go that route rather than finding out later I should have.

I'm still looking for any additional suggestions on what particular
parts of the code might be killing my load times, although I'm sure
switching to binary and not using acos and sqrt will help quite a bit.

Thanks,
Glen

On Sep 22, 5:03 am, a1 <arco...@gmail.com> wrote:
> On 20 Wrz, 20:28, Glen Kimsey <gkim...@gmail.com> wrote:
>
> > Hello!
> > I'm fairly new to both Android and Java (pretty experienced in C/C++),
> > and (stupidly, perhaps) took on a big project.  In it, I need to load
> > information about 3D models and their respective animations from a
> > text file (proprietary file format based on PSK/PSA).
>
> <cut>
>
>
>
>
>
> >         private static float[] parseRotLine(String line) {
> >                 float[] retFloat = new float[4];
> >                 StringTokenizer tok = new StringTokenizer(line);
>
> >                 // Ignore "rot"
> >                 tok.nextToken();
> >                 // theta
> >                 tok.nextToken();
> >                 retFloat[0] = wToTheta(Float.parseFloat(tok.nextToken()));
> >                 // x
> >                 tok.nextToken();
> >                 retFloat[1] = Float.parseFloat(tok.nextToken());
> >                 // y
> >                 tok.nextToken();
> >                 retFloat[2] = Float.parseFloat(tok.nextToken());
> >                 // z
> >                 tok.nextToken();
> >                 retFloat[3] = Float.parseFloat(tok.nextToken());
>
> >                 // Need to scale this vector to make glRotate happy
> >                 retFloat = scaleAxisAngleVector(retFloat);
>
> >                 return retFloat;
> >         }
>
> >         private static float wToTheta(float w) {
> >                 // w = cos(theta/2)
> >                 float theta = (float)Math.acos((double)w) * 2;
> >                 // convert theta to degrees
> >                 theta = 180 * theta / (float)Math.PI;
> >                 // The above calculation only gave us a value from 0 to 180 
> > because
> > of arccosine
> >                 // TODO: Determine if this is a problem.  Note that w can be
> > negative, and this implies 180 degrees
> >                 if (w < 0) {
> >                         theta += 180;
> >                 }
> >                 return theta;
> >         }
>
> >         private static float[] scaleAxisAngleVector(float[] unscaled) {
> >                 float[] scaled = new float[4];
> >                 // scale = sqrt(x^2 + y^2 + z^2);
> >                 float scale = (float)Math.sqrt(unscaled[1] * unscaled[1] + 
> > unscaled
> > [2] * unscaled[2] + unscaled[3] * unscaled[3]);
>
> >                 if (scale != 0) {
> >                         scaled[0] = unscaled[0];
> >                         scaled[1] = unscaled[1] / scale;
> >                         scaled[2] = unscaled[2] / scale;
> >                         scaled[3] = unscaled[3] / scale;
> >                 }
> >                 else
> >                 {
> >                         // Scale can be 0, which means we're not rotating
> >                         // but dividing by zero is bad, and glRotate still
> >                         // needs a normalized vector.
> >                         scaled[0] = 0;
> >                         scaled[1] = 1;
> >                         scaled[2] = 0;
> >                         scaled[3] = 0;
> >                 }
> >                 return scaled;
> >         }}
>
> > ====End of Loader Code====
>
> Ugh, why oh why are you transforming quaterninions to axis/angle
> representation? Quaternion interpolation is easier, and gives better
> result (you will also save a lot of time on calculations).
>
> About performance, if it's possible (eg. you are not downloading the
> scene files from network or smth), write a small utility that will
> convert text file to binary representation offline, and then read the
> binary files on android. Also try to minimize number of allocation
> during file loading.
>
> --
> Bart 'arcone1' janusz
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to