DJ99X wrote:Does it only look at frills.js? Or should it read any script located in the folder? I guess mx.frame_handler can only be defined once.
It only looks in frills.js. The idea is frills.js will just have cosmetic stuff that doesn't matter for the track checksum. I'm eventually going to add another file for stuff that can physically change things which will have to be part of the checksum.
You can only set mx.frame_handler once. The standard technique to define multiple handlers is to chain them like this:
Depends on what it's doing. For something simple like moving an object at a specific time it wouldn't need help from the server. For moto-soccer it'd definitely need to communicate through the server.
Josh Vanderhoof
Sole Proprietor jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.
JLV, how do you handle the rider bones (or 3d rotations in general)?
I've been struggling to come up with a way deal with the rotation. I initially started by converting a euler rotation to a matrix, and tried running the rotations shown in pose mode in blender, but those rotations are with respect to the bones initial orientation, so it never worked. In the end, I struggled to grasp rotations other than rotating around a single axis.
I am now trying quaternions, as I figured it's fundamentally a 3d vector with rotation , but once I had it operational, I then realised if the rotation angle of the quaternion is 0, then it equates to the unit matrix [1 0 0, 0 1 0, 0 0 1] regardless of the xyz vector, which doesn't make sense to me.
A rotation of 0 has to be the identity matrix. It doesn't move the vertices so the matrix can't either.
A matrix is basically just a coordinate system. The first column is the X axis, the second column is the Y axis and the third is the Z axis. If you want to transform a vector from that coordinate system, you scale each axis vector by its corresponding vector element and add them together like this:
V' = X * v0 + Y * v1 + Z * v2
That's the same as a matrix * vector multplication:
V = [ v0, v1, v2]
X = [ m00, m10, m20]
Y = [ m01, m11, m21]
Z = [ m02, m12, m22]
Now say you want to aim the Z axis at the vector P.
First set Z. Since you want it to point at P you set it to P, but since you don't want it to scale, divide by the length of P to get a unit length vector.
Z = P / |P|
Now for Y. Say you want it to generally point up, so we temporarily set it to the global Y. This is going to make it a shear matrix which we don't want, but we'll fix that later.
Y = [ 0, 1, 0 ]
For X you just want it to be perpendicular to Y and Z. So you set it to the cross product:
X = Z x Y
Now fix Y so it's perpendicular to X and Z:
Y = X x Z
Normalize X and Y and you're done.
X = X / |X|
Y = Y / |Y|
Now you should have a square and unit length rotation matrix where Z points at P. I didn't give any thought to the cross product order, so you'll probably have to flip either X or Y to get the right sign.
Since OpenGL stores matrices in column major order, your matrix should look like this:
m = [
x0, x1, x2,
y0, y1, y2,
z0, z1, z2
];
(If you remember the Patriot missile bug, this is related. They continuously concatenated rotation matrices without squaring them up and normalizing them. If the guidance system ran long enough the matrix would turn into a scaling and shearing matrix as the numeric errors accumulated.)
Josh Vanderhoof
Sole Proprietor jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.
Thanks JLV, that's all pretty helpful. This has definitely been a mission of extracting some long lost mathematics from deep within my memory. The cross product came in helpful for working out terrain normals
I've got a soccer ball with some good physics going, but I was just neatening up the code, and I must have changed something, because now the ball wants to accelerate up steep vertical terrain :'(
Generally works pretty well, 2 things I need to fix:
-Handle the y-axis rotation with the bones only, to stop the jerky rotation at slow speeds and the rotation effect of the terrain under the object
-I set the y position to the ground position if it is calculated lower. Unfortunately, the y velocity isn't adjusted to reflect this change when it's rolling, so it ends up a bit mismatched to what the ball is meant to be doing. This generally occurs on steep surfaces where sudden changes in ground height means the y position requires adjustment, so it looks like it accelerates up hills. I tried to predict the ground in front of the ball and adjust the velocity to suit, but it didn't really work out.
It does change directions slightly in that particular gif. But yeah, next thing to try and do is change its behaviour with speed. Just need to work out the best way to collapse it on low wind speed.
DJ99X wrote:It does change directions slightly in that particular gif. But yeah, next thing to try and do is change its behaviour with speed. Just need to work out the best way to collapse it on low wind speed.
That's pretty neat! How do you have it rigged? Looking at some flag waving videos it looks like the waves tend to run across the flag radially from the inner top corner. So maybe try making the bone influence run across the flag something like this:
44444444
01223333
00112233
00111122
Put the bone centers on the inner top corner and then just rotate the bones to make the waves.
Josh Vanderhoof
Sole Proprietor jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.