Home
Servers
Community
Support
TribesNext
Home
Help
Search
Calendar
Login
Register
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
TribesNext
>
TribesNext.com Forums
>
Tribes 2
>
Mods and Customization
>
Tribes 2 RPG - Ironsphere II Mod
« previous
next »
Pages:
1
2
3
[
4
]
Print
Author
Topic: Tribes 2 RPG - Ironsphere II Mod
Ragora
Seņor Nugget
Posts: 221
45:
January 14, 2016, 12:00:13 PM »
The description on both functions for the engine registration said that, one uses w =1 and the other uses w = 0.
Quote from: kyred on January 14, 2016, 11:53:00 AM
Quote from: Ragora on January 14, 2016, 10:17:37 AM
The engine is filled with all sorts of other useless bits. I wouldn't be surprised. Here's the definition for both anyway (they're right next to each other):
https://github.com/GarageGames/Torque3D/blob/1a009d6dd31b66832de3b67e76465ad1f313a9dc/Engine/source/math/mathTypes.cpp#L938
Okay, the differences is slight, but still there. Both functions end up here:
Code:
inline void m_matF_x_point3F(const F32 *m, const F32 *p, F32 *presult)
{
AssertFatal(p != presult, "Error, aliasing matrix mul pointers not allowed here!");
#ifdef TORQUE_COMPILER_GCC
const F32 p0 = p[0], p1 = p[1], p2 = p[2];
const F32 m0 = m[0], m1 = m[1], m2 = m[2];
const F32 m3 = m[3], m4 = m[4], m5 = m[5];
const F32 m6 = m[6], m7 = m[7], m8 = m[8];
const F32 m9 = m[9], m10 = m[10], m11 = m[11];
presult[0] = m0*p0 + m1*p1 + m2*p2 + m3;
presult[1] = m4*p0 + m5*p1 + m6*p2 + m7;
presult[2] = m8*p0 + m9*p1 + m10*p2 + m11;
#else
presult[0] = m[0]*p[0] + m[1]*p[1] + m[2]*p[2] + m[3];
presult[1] = m[4]*p[0] + m[5]*p[1] + m[6]*p[2] + m[7];
presult[2] = m[8]*p[0] + m[9]*p[1] + m[10]*p[2] + m[11];
#endif
}
//--------------------------------------
inline void m_matF_x_vectorF(const F32 *m, const F32 *v, F32 *vresult)
{
AssertFatal(v != vresult, "Error, aliasing matrix mul pointers not allowed here!");
#ifdef TORQUE_COMPILER_GCC
const F32 v0 = v[0], v1 = v[1], v2 = v[2];
const F32 m0 = m[0], m1 = m[1], m2 = m[2];
const F32 m4 = m[4], m5 = m[5], m6 = m[6];
const F32 m8 = m[8], m9 = m[9], m10 = m[10];
vresult[0] = m0*v0 + m1*v1 + m2*v2;
vresult[1] = m4*v0 + m5*v1 + m6*v2;
vresult[2] = m8*v0 + m9*v1 + m10*v2;
#else
vresult[0] = m[0]*v[0] + m[1]*v[1] + m[2]*v[2];
vresult[1] = m[4]*v[0] + m[5]*v[1] + m[6]*v[2];
vresult[2] = m[8]*v[0] + m[9]*v[1] + m[10]*v[2];
#endif
}
The difference is that MatrixMulPoint is the [X Y Z] of the point and sticks a 1 on the end => [X Y Z 1]. So when the Point and Transform are multiplied, indexes 3, 7, and 11 of the transform matrix are added into the result. MatrixMulVector just uses [X Y Z 0]. I have no idea what this accomplishes, in game.
The description on both functions for the engine registration said that, one uses w =1 and the other uses w = 0.
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Supposedly Einstein
kyred
Nugget
Posts: 24
46:
January 14, 2016, 02:51:28 PM »
Quote from: Ragora on January 14, 2016, 12:00:13 PM
The description on both functions for the engine registration said that, one uses w =1 and the other uses w = 0.
Right, but that brought up the question "what is 'W'?" I still don't quite know qualitatively what it is. Just what it being 1 or 0 implies for these functions, now that I've stepped through them.
Ragora
Seņor Nugget
Posts: 221
47:
January 14, 2016, 04:00:20 PM »
It's just a 4x4 transformation matrix:
http://www.euclideanspace.com/maths/geometry/affine/matrix4x4/
http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/
You'll want to look around for a more complete description of the purpose of such transformation matrices.
«
Last Edit: January 14, 2016, 04:13:58 PM by Ragora
»
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Supposedly Einstein
Thyth
Apotheosis Incarnate
Posts: 797
48:
January 14, 2016, 10:45:21 PM »
Interesting. In almost all situations I can think of, you'll want to use the version with w=1 -- I'm not actually sure when you would ever want to use w=0.
You can use homogeneous coordinate vectors (X, Y, Z, and W) with a 4x4 transformation matrix to concisely express an arbitrary set of rotation, transformation, and scale operations on a set of 3D points. The W value is added to the vector to enable free transformation in 3D space -- if you stick to 3x3 matrices for 3D transformations, you're restricted to the 3D equivalent of affine transforms (e.g. scale, translation, and shearing), and can't freely express rotation. In order to have a meaningful application of one of these transform matrices, you set w=1.
It's reasonably straightforward to express scale and transformation matrices as 4x4's. Scale matrices take the form:
a 0 0 0
0 b 0 0
0 0 c 0
0 0 0 1
To scale a point (relative to origin) by 'a' on the x-axis, 'b' on the y-axis, and 'c' on the z-axis.
Transform matrices take the form:
1 0 0 a
0 1 0 b
0 0 1 c
0 0 0 1
Which will add (relative to the origin), 'a' to the x-axis, 'b' to the y-axis, and 'c' to the z-axis.
Rotations end up being a little bit more complex, defined in terms of sine/cosine of the 3 rotation angles in the first 3x3 part of the matrix, but are fundamentally about re-defining the X, Y, and Z axis values in the new rotated reference coordinate system. You can kind of see an artifact of that in the first 3x3 of the above matrices where the first 3 elements of the first row are "1 0 0", which is the definition of a vector along the X axis; ditto for the next two rows, specifying "0 1 0" as the Y axis, and "0 0 1" as the Z axis. The rotation matrix redefines them to still be unit vectors that are orthogonal (dot product between them is 0). I don't remember the formula definitions off hand, but you can probably derive them with the intuition about the axis representation within the matrix, and thinking through the behavior of matrix-vector multiplication at the different 90 degree turns (where all of the values in the first 3x3 are 1, 0 or -1) -- or just look up the formula for calculating new basis vectors for a particular set of rotation angles.
You can use this representation to compose multiple operations by matrix-matrix multiplication. E.g. rotate by 45 degrees on x axis, translate along the y axis by 5 units, scale by 3 units on all axes. You can create the individual matrices for each of those operations and then compose them into a single transform matrix that you can multiply against a set of vectors to apply that change to e.g. a mesh of points represented by those vectors. The order sensitivity to the transformations is mirrored in the order sensitivity of matrix multiplication (because A*B != B*A with matrix multiplication -- i.e. not commutative). For an object relative rotation, as an example, you typically see a translation from worldspace to objectspace coordinates (subtracting the object position in the world out, so it's centered at the origin), a rotation (or scale) relative to the center of the object at the new origin, and a reverse translation to bring the rotated/scaled points back into worldspace coordinates. Rotating prior to the initial recentering transform, as an example, would mean the rotation would be pivoted around the world origin coordinate instead of around the center of the object.
If you want to know more about how this stuff works, you should learn linear algebra.
Sarcastic, narcissistic, genius, resurrecting the game with brilliant strokes of wizardry.
kyred
Nugget
Posts: 24
49:
January 15, 2016, 11:14:28 AM »
Quote from: Thyth on January 14, 2016, 10:45:21 PM
Interesting. In almost all situations I can think of, you'll want to use the version with w=1 -- I'm not actually sure when you would ever want to use w=0.
Well, according to T2 scripts, handling projectile spread uses w=0 (ie. MatrixMulVector). However, in that scenario the matrix itself is not a transform, but instead a rotation matrix (created via MatrixCreateFromEuler). And the vector is actually a direction, not a position. Which now makes a ton of sense now that I have typed it. It is rotating direction, and disregarding the location in space (since it's 0 anyway).
Quote from: Thyth on January 14, 2016, 10:45:21 PM
If you want to know more about how this stuff works, you should learn linear algebra.
I got a "B" in that class. Which was enough to be able to follow along with everything that you said.
Pages:
1
2
3
[
4
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
TribesNext.com Forums
-----------------------------
=> General Discussion
=> Tribes 2
===> Mods and Customization
===> Competition and Pick-ups
===> Strategies and Guides
=> Support
===> Server Support
===> Frequently Asked Questions
irc.quakenet.org / #TribesNext
Powered by SMF
© Simple Machines
anything