Post by Kjelle69 on Jul 23, 2004 6:06:06 GMT 1
a few people have asked for an explanation of matrix math (with regards to Newton), so here goes.
Users of DBPro are familiar with placing/rotating objects based on 3values for x,y, and z. This is one way to describe an object's orientation in space. another way is through matrices, which is what most 3D engines use internally, and also what Newton uses.
To put it simply, a translation/rotation matrix is basically a set of vectors. 4 vectors to be exact. the first 3 vectors represent the rotation of the object and are unit vectors. Unit vectors are simply vectors that have an overall length of 1 unit. The 4th vector represents the translation of the object. So first have a look at this matrix:
[1][0][0]
[0][1][0]
[0][0][1]
[X][Y][Z]
the first row is a unit vector, describing the orientation of the object's local X-axis in global space.
likewise, the 2nd row represents the local Y-axis in global space, and the 3rd row is for the Z-axis.
so in this first example, the X axis is pointing off in the X direction (1,0,0), the Y axis is pointing up (0,1,0), and the Z axis is pointing into the world (0,0,1). therefore this matrix represents NO rotation on an object, and is therefore called the "identity matrix".
now let's imagine we rotate our object 180 degrees around the Z axis. we get a matrix looking like this:
[-1][0][0]
[0][-1][0]
[0][0][1]
[X][Y][Z]
now you can see that the X-axis is pointing off in the negative X direction (-1,0,0), the Y axis is pointing down (0,-1,0), and the Z-axis remains unchanged.
That's basically now matrix rotation works. Once you understand that the top 3 rows show which direction each axis of the object is facing, they become VERY usefull.
for example, let's say you have a spaceship, and you want it to fly forward when the user pressed the UP key. just using the "object rotation" commands (3 angles), it's difficult to determine which way the ship is facing. however it's REALLY simple with matrices. imagine your ship's model loads with the ship facing the X direction.
when you want to find the direction your ship is facing, you simply call NDB_NewtonBodyGetMatrix on the body, and then get the values for the X axis like so:
shipdirx# = NDB_GetVector_X(1)
shipdiry# = NDB_GetVector_Y(1)
shipdirz# = NDB_GetVector_Z(1)
now you can apply a force based on these values, and it will push the ship forward!! very simple!!!
In my Ragdoll Monkey Bowling game, I use a similar method to determin if pins have fallen down or not. I check the Y component of the Y row (NDB_GetVector_Y(2)), and see if it's less than 0.95. if so, the object must be tipped over, and can count for a point!
Once you get the hang of Matrices, you can do things that used to be very difficult VERY easily.
I hope this helps explain the uses for matrix math with regards to Newton in DBPro.
Users of DBPro are familiar with placing/rotating objects based on 3values for x,y, and z. This is one way to describe an object's orientation in space. another way is through matrices, which is what most 3D engines use internally, and also what Newton uses.
To put it simply, a translation/rotation matrix is basically a set of vectors. 4 vectors to be exact. the first 3 vectors represent the rotation of the object and are unit vectors. Unit vectors are simply vectors that have an overall length of 1 unit. The 4th vector represents the translation of the object. So first have a look at this matrix:
[1][0][0]
[0][1][0]
[0][0][1]
[X][Y][Z]
the first row is a unit vector, describing the orientation of the object's local X-axis in global space.
likewise, the 2nd row represents the local Y-axis in global space, and the 3rd row is for the Z-axis.
so in this first example, the X axis is pointing off in the X direction (1,0,0), the Y axis is pointing up (0,1,0), and the Z axis is pointing into the world (0,0,1). therefore this matrix represents NO rotation on an object, and is therefore called the "identity matrix".
now let's imagine we rotate our object 180 degrees around the Z axis. we get a matrix looking like this:
[-1][0][0]
[0][-1][0]
[0][0][1]
[X][Y][Z]
now you can see that the X-axis is pointing off in the negative X direction (-1,0,0), the Y axis is pointing down (0,-1,0), and the Z-axis remains unchanged.
That's basically now matrix rotation works. Once you understand that the top 3 rows show which direction each axis of the object is facing, they become VERY usefull.
for example, let's say you have a spaceship, and you want it to fly forward when the user pressed the UP key. just using the "object rotation" commands (3 angles), it's difficult to determine which way the ship is facing. however it's REALLY simple with matrices. imagine your ship's model loads with the ship facing the X direction.
when you want to find the direction your ship is facing, you simply call NDB_NewtonBodyGetMatrix on the body, and then get the values for the X axis like so:
shipdirx# = NDB_GetVector_X(1)
shipdiry# = NDB_GetVector_Y(1)
shipdirz# = NDB_GetVector_Z(1)
now you can apply a force based on these values, and it will push the ship forward!! very simple!!!
In my Ragdoll Monkey Bowling game, I use a similar method to determin if pins have fallen down or not. I check the Y component of the Y row (NDB_GetVector_Y(2)), and see if it's less than 0.95. if so, the object must be tipped over, and can count for a point!
Once you get the hang of Matrices, you can do things that used to be very difficult VERY easily.
I hope this helps explain the uses for matrix math with regards to Newton in DBPro.