Fix has been found!
Apparently looking as much up as you can made the vector slightly backwards, resulting in the entire calculation going wrong.
This is the end result:
function relativeVector(%dir, %vec)
{
%x = getWord(%vec, 0);
%y = getWord(%vec, 1);
%z = getWord(%vec, 2);
%relYvec = vectorNormalize(%dir);
%relYx = getWord(%relYvec, 0);
if (%relYx < 0)
%relYx *= -1;
%relYy = getWord(%relYvec, 1);
if (%relYy < 0)
%relYy *= -1;
if (%relYx < 0.00001 && %relYy < 0.00001)
{
%relYvec2 = vectorNormalize(vectorScale((getWord(%relYvec, 0) SPC getWord(%relYvec, 1) SPC "0"), -1));
%relXvec = vectorNormalize(vectorCross(%relYvec2, "0 0 1"));
%relZvec = vectorNormalize(vectorCross(%relXvec, %relYvec));
}
else
{
%relXvec = vectorNormalize(vectorCross(%relYvec, "0 0 1"));
%relZvec = vectorNormalize(vectorCross(%relXvec, %relYvec));
}
%relVec = vectorAdd(vectorAdd(vectorScale(%relYvec, %y), vectorScale(%relZvec, %z)), vectorScale(%relXvec, %x));
return %relVec;
}
Please note that the fix is only really relevant in this situation where you try to get a relative vector to the eyepoint and the player is looking so much up it is actually slightly backwards.
Very specific, but i had to fix it. :X
Use the above code if you want, no credits needed or anything, just USE IT.
Original problem and fix and the last problem have been documented below this line for documentation purposes.
First problem (see below) fixed, had to normalize the relative vectors that we got after crossing the vectors.
New problem found! :C
Apparently, the second problem i encountered (looking straight up) did not neccisarily have to be directly up since the vector was actually normalized to something like: "3.49925e-006 9.2714e-007 1"
Which apparently is a vector with length 1 (a quick check confirmed this).
Bit stumped at this problem.
My current try to solve it:
function relativeVector(%dir, %vec)
{
%x = getWord(%vec, 0);
%y = getWord(%vec, 1);
%z = getWord(%vec, 2);
%relYvec = vectorNormalize(%dir);
%relYx = getWord(%relYvec, 0);
if (%relYx < 0)
%relYx *= -1;
%relYy = getWord(%relYvec, 1);
if (%relYy < 0)
%relYy *= -1;
if (%relYx < 0.00001 && %relYy < 0.00001)
{
%relYvec2 = vectorNormalize(getWord(%relYvec, 0) SPC getWord(%relYvec, 1) SPC "0");
echo(%relYvec2 SPC " -len:" SPC vectorLen(%relYvec2));
%relXvec = vectorNormalize(vectorCross(%relYvec2, "0 0 1"));
%relZvec = vectorNormalize(vectorCross(%relXvec, "0 0 1"));
}
//else if (%relYvec $= "0 0 1")
//%relXvec = "1 0 0"; //Not sure if this is the best solution, but it is the most realistic one
else
{
%relXvec = vectorNormalize(vectorCross(%relYvec, "0 0 1"));
%relZvec = vectorNormalize(vectorCross(%relXvec, %relYvec));
}
%relVec = vectorAdd(vectorAdd(vectorScale(%relYvec, %y), vectorScale(%relZvec, %z)), vectorScale(%relXvec, %x));
return %relVec;
}
It did not solve it though, not at all.
Any ideas?
ORIGINAL ORIGINAL POSTFirst of all, let me note that i used this topic for guidance:
https://forum.blockland.us/index.php?topic=286014.0I am trying to basically do the same thing as there, track points relative from the player's eyepoint.
And while the solution given there works when looking straight forward, it seems to have some weird effect when looking up.
I found this out because i am drawing lines from point to point from specific points.
(blue lines are lines between points, red cubes are the points and the green line is the muzzleVector)
Here is it when looking forward, which is right.

And here i look more up and it seems to become more and more condensed around the z axis.

Which is not at all what i want.
Code for relative vector calculation i use right now:
function relativeVector(%dir, %vec)
{
%x = getWord(%vec, 0);
%y = getWord(%vec, 1);
%z = getWord(%vec, 2);
%relYvec = vectorNormalize(%dir);
%relXvec = vectorCross(%relYvec, "0 0 1");
%relZvec = vectorCross(%relXvec, %relYvec);
%relVec = vectorAdd(vectorAdd(vectorScale(%relYvec, %y), vectorScale(%relZvec, %z)), vectorScale(%relXvec, %x));
return %relVec;
}
Code that uses this:
function Player::calculateTrackPoint(%obj, %slot, %pointRelPos)
{
if (%pointRelPos $= "" || !isObject(%obj))
return;
%location = %obj.getMuzzlePoint(%slot);
if (%pointRelPos !$= "0 0 0")
{
%dir = %obj.getMuzzleVector(0);
%relPos = relativeVector(%dir, %pointRelPos);
%location = vectorAdd(%location, %relPos);
}
return %location;
}
This gets the muzzlepoint and adds the vector of a point relative from the muzzleVector, if that makes sense.
For a good explanation of what i want, see the topic i linked at the top.
Together with the following points put in the above function:
$AdvMel::Point[0] = "2 -1 1.5";
$AdvMel::Point[1] = "0 1.5 0";
$AdvMel::Point[2] = "-2 1 -1";
$AdvMel::Point[3] = "-2.5 -0.6 -1";
Can someone enlighten me on how i solve this problem?
For those interested,
the add-on so far.
To see the points, type /togglemuzzletrack.
Other interesting things to do, but unrelated to this problem is to type "$Server::DebugMelee = 1;" into the console and swing a bit with the testSword that comes with it.