Sunday, August 26, 2012

Ant, Javadoc, Libgdx, CreateProcess error=87, and YOU!

Gratuitously copied from the Western Skies blog since I *just* got bit by this -- and apparently got bit by it before 'cuz Google showed that I had visited this link sometime in the past:

I've been developing an Ant build file for a large-ish base of existing code. I've been using my Mac as the primary devleopment platform, but the ultimate target (for the other developers) is Windows. My task to build the javadocs runs fine on OS X, but the first time I rant it on Windows, I got the following:

c:\demo\build.xml:180: Javadoc failed: Cannot run program "c:\Program Files\Java\jdk1.6.0\bin\javadoc.exe": CreateProcess error=87, The parameter is incorrect

After about 10 minutes of Googling, I found a/the simple solution: add the useexternalfile attribute to the javadoc task in Ant. Voila , back in business, on the PC at least, and it didn't seem to break the build on the Mac.

 I got bit by the most recent version libgdx when trying to run "ant" in order to build the "dist", which includes the API documentation that I was really aiming for.

Monday, August 20, 2012

3D Math Primer for Graphics and Game Development, 2nd Edition

I've picked up a copy of 3D Math Primer on Graphics and Game Development recently and have been slowly going through it.  It's been around 15 years since I took Linear Algebra, or had to do any real matrix or vector based math, so the brain cells are slowly being re-initialized.  Heh.  Hopefully, this turns into a series of posts to share as I relearn things cruising through the book.

Here's what I've covered so far.

Chapter 1 deals with coordinate systems and concepts.  I was always fairly decent at trig so this went by really quick.  Chapter 2 gets into vectors and discusses the importance of the dot and cross products.  I remember learning and using these in school, but their application in game development terms wasn't obvious to me.  There are a couple of really good exercises that hit home the importance of these two operations.

One of the exercises describes an NPC in a game at a point p, that has a forward vector v.  Given this, and a point x, how can you use a dot product for determining whether or not the point x is in front or behind the NPC?

There are a couple of things to know about the dot product.  First, it gives you a scalar.  Big whoop.  How can this be used?  Well, the sign of the scalar gives you an indication of the relative direction / angle between one vector and another.  If the dot product is positive, then the angle between them is between 0 and 90 degrees.  If the dot product is 0, then the vectors are orthogonal (ie. at right angles).  If the dot product is < 0, then the angle between the vectors is greater than 90 degrees (and less than 180).

So, given a NPC location of p, we can calculate a vector x-p that gives us a vector describing the relative position of point x from point p.  If we know the facing of the character (vector v at point p), then we can take the dot product between v and x-p and know the relative positioning.

Recall that the dot product yields a scalar, defined as:

a dot  b =
(ax*bx + ay*by + az*bz).

Given this, we can determine if point x is in front-of or behind the NPC:

If vx*(xx-px)+vy*(xy-py)+vz*(xz-pz) > 0, it's in front.  If it's < 0, is behind.  If it's == 0, then it's to the side of the NPC.


Using the magnitudes of the related vectors and the relation: cos theta = a dot b / (||a|| * ||b||), we can further determine the angle between the two vectors.

Another cool exercise from the book details the practical application of the cross-product.  If the NPC above navigates from point p to point q and then to point r in the x-z plane (using left hand orientation), how can we use a cross-product to determine if the NPC should turn clockwise or counter-clockwise at point q in order to reach r?

Recall that the cross-product yields a new vector, defined as:
a x b =
[ax ay az] x [bx by bz] =
[ay*bz-az*by -(ax*bz-az*bx) ax*by-bx*by]

Here, it helps to know that the cross-product for a couple of vectors yields another vector that is orthogonal to the other two vectors.  This vector gives a magnitude that is proportional to the area of the parallelogram area formed by the vector sides.  We can look at the direction of the vector to clue us in to whether the orientation from one vector to another is clockwise or counter-clockwise.  If the angle from a to b is less than 180 degrees, the resulting vector will point up (left-hand rule orientation) on the orientation is considered clockwise.  If the angle from a to b is greater than 180 degrees (ie.  from b to a is less then 180 degrees), the orientation is considered counter-clockwise and the resulting vector will point down.

In the NPC case above, it's pretty straightforward to calculate the cross-product.  Doing this results in a single vector that either points in the +y direction, or the -y direction. Using this info, we can easily determine which way to rotate the NPC at the point q.  The NPC could actually rotate either way and still reach the same position.  The cross-product ends up giving you the shortest direction to rotate through.

Cool x2!

PDF Xchange Viewer Fu

I do a lot of PDF technical document reading where I'm constantly flipping back and forth between  various document sections.  Although my favorite PDF viewer of choice, PDF XChange Viewer, rocks the house for annotating, searching, saving, etc., it sucks when it comes to intra-document navigation.  It's got bookmarks and capabilities to run multiple instances, but I haven't liked the navigation these implement.  I've also tried using multiple copies of my documents and gotten that to work the way I liked (ie. tabbed document browsing), but having multiple copies seems like a real waste to me.

Enter Chrome.

Using Chrome tabs, you can easily and quickly open up multiple instances of a document by using the address bar to navigate to the local file.  From there, just right-click and select duplicate. You end up creating multiple instances of PDF XChange Viewer in this case, but the navigation is SOOOO much better than clicking on the Windows taskbar.

You may have to disable the built-in PDF Viewer in Chrome to get PDF XChange Viewer working.  To do this, enter "chrome://plugins" and simply disable "Chrome PDF Viewer".