philkr / gamehook_gtav

GTA V plugin for gamehook
BSD 2-Clause "Simplified" License
42 stars 7 forks source link

v1.0.1365.1 messes up flow computation #5

Closed philkr closed 6 years ago

philkr commented 6 years ago

@bradyz or I'll have to look into it. It looks like the static flow is messed up too (prev_?? matrix might be wrong).

el3ment commented 6 years ago

I have managed to get flow working fine for me -- but since most of my work was spent getting all of the objects not tracked by the code originally working it's hard to say what applies to this or not.

I can tell you that your D2 function for quaternions is wrong, which can sometimes result in objects not being tracked properly. It would be better to use box-minus for computing this (or, just do the angular difference on the matricies themselves, rather than compute the quanterions in the first place) but this code is at least approximately correct:

inline float D2(const Quaternion & a, const Quaternion & b) {

auto c = b;

    if (a.w * b.w < 0) {
        c.x = -b.x;
        c.y = -b.y;
        c.z = -b.z;
        c.w = -b.w;
    }

    return fabs(a.x - c.x + a.y - c.y + a.z - c.z + a.w - c.w);

You can easily see the old function is wrong when you realize that the distance reported between the same quaterion (i.e D2(a_quat, a_quat) != 0) is wrong.

philkr commented 6 years ago

Any PR to track all objects efficiently is welcome.

Not sure I follow the argument on why D2 is wrong. Isn't the rotation a unit quaternion hence a * a = 1 and 1 - abs(a*a) = 0, right? If I didn't mess up the derivation D2 the dot product should compute the cosine of the half angle between the two rotations: cos(theta/2). 1-abs was just me being lazy and coming up with a function that is 0 if they are the same and scales linearly in the cosine when not.

el3ment commented 6 years ago

I think the issue is that some of the quaternions produced by gta 5 are not unit length, so I was seeing the dot product be less than one. @superjax08 may have more insight here.

philkr commented 6 years ago

thank you for the pointer. It turns out there was a bug in the Quaternion::fromMatrix function which didn't deal with scaling matrices. This is not fixed and both GTA and gamehook quaternions should be normalized.

el3ment commented 6 years ago

no problem. in what might be the most annoying accident, GTA5 updated to the newest version this morning automatically and it now it's too new for the ScriptHookV version. I know it's a lot to ask, but would you be able to zip up update.rpf, gta5.exe and gtavlauncher.exe for me?

bradyz commented 6 years ago

@el3ment send me an email at brady.zhou@utexas.edu

philkr commented 6 years ago

https://github.com/philkr/gamehook/pull/3 should fix this. Flow as fine, just the visualization off.