Quaternions, Vectors and 3D Geometry... My Head Hurts

Avatar image for wazzam
WazzaM

5

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

Edited By WazzaM

I've tried a couple of game engines now - Unity and JMonkeyEngine 3 (JME3). They are both pretty good but Unity wins over JME3 for a couple of simple reasons. Unity is better supported by a commercial business and has a lot of active users and community. Unity uses Mono's .NET implementation sits on top of their native engine and the performance is pretty good. It's also quite easy to build a version of your game for any supported platform: PC Windows, PC Linux, Desktop MacosX, iOS, Android, Windows Mobile, XBox and Playstation (past gen and next-gen). JME3 runs on Java with a much smaller native component. The main native-backed Java API being LWJGL (Light Weight Java Game Library). [Minor aside: LWJGL was also used by Notch in Minecraft's custom game engine on PC and Mac.] JME3's Performance is OK but the portability is the real problem. Windows and Linux are pretty easy. There's a beta port for Android. I think it will compile for MacOSX (don't take my word for it) and iOS is a "no" at the moment to the best of my knowledge. Both use Quaternions and Vectors to represent 3D geometry. These get a bit tricky to understand but they are bread-and-butter for 3D games and graphics.

Vectors are relatively easy to understand as a concept. They have 3 points in space - see easy. The fun part comes when you start combining multiple vectors to determine direction, rotation and relative position. Vectors let you do just that when you start applying vector algebra. Another term you might find is Vertex which can be used interchangeably with Vectors for a point in space. However if you find a point being described by an API or library as a Vertex, that API might not support vector operations on the vertices even though both are (generally, give or take a dimension) 3 floating point numbers holding one position in space. Let's pretend I never brought up Vertices and focus on Vectors.

Vectors can be considered to be direction and magnitude in a single object. The direction is generally relative to the Origin of the axes. The magnitude is determine using Pythagoras' Theorem and represents linear distance. Now let's say you have the Origin at (0,0,0) and away from the Origin you have a player's character - a humanoid figure. The figure, let's call him Fred, has a balloon on the end of a string and the string in his hand. Let's say there's another figure, call them Zac, that holds in their hand a dart. Now let's say you want to determine the distance between the dart and the balloon. How? (Hint: algebra)

O is the origin

F is Fred's position as a vector, relative to O

Z is Zac's position as a vector, relative to O.

B[F] is the balloon's position relative to F. B is the balloon's position relative to O.

D[Z] is the dart's position relative to Z. D is the dart's position relative to O.

As base terms, you might have F and B[F] because they are part of Fred's 3D model. You would probably also have Z and D[Z] for the same reason - Z has a 3D model and D[Z] is part of that.

D = D[Z] + Z

B = B[F] + F

The distance between D and B is given by:

distance = |DB| = |D - B|

DB = D - B

DB = (D[Z] + Z) - (B[F] + F)

I'll discuss Quaternions in my next blog entry.