Object offset to a vehicle -
Omirrow - 10.08.2017
Hey,
I've been looking for a valid solution to get an object's offset to a vehicle but I couldn't find any, at least couldn't find a working one (some of them works but the calculation is not proper).
Do any of you know a way to calculate it or is there a valid include/filterscript that calculates it properly?
Re: Object offset to a vehicle -
FuNkYTheGreat - 10.08.2017
1 -
https://sampforum.blast.hk/showthread.php?tid=541980
2-
Код:
stock GetObjectOffset(objectid, vehicleid, &Float: X, &Float: Y, &Float: Z)
{
new Float: pos[3], vpos[3];
GetObjectPos(objectid, pos[0], pos[1], pos[2]);
GetVehiclePos(vehicleid, vpos[0], vpos[1], vpos[2]);
new calcpos[3];
calcpos[0] = pos[0]-vpos[0];
calcpos[1] = pos[1]-vpos[1];
calcpos[2] = pos[2]-vpos[2];
X = calcpos[0];
Y = calcpos[1];
Z = calcpos[2];
return 1;
}
By Abagail
3 -
https://sampwiki.blast.hk/wiki/GetVehicleModelInfo
4 -
https://sampforum.blast.hk/showthread.php?tid=489229 - it can be helpful as well
Re: Object offset to a vehicle -
Omirrow - 10.08.2017
1- The link is broken, I saw it before.
2- This only works when the angle of the vehicle is zero or something like that, it's one of those I stated in my first post which doesn't calculate it properly.
3- I'm aware of this function but I've never tried to calculate offsets using it.
4- These looks way better, I'll give them a shot.
If you have a better idea, feel free to post please!
Re: Object offset to a vehicle -
Omirrow - 10.08.2017
Well, seems like we have an include created by Gamer_Z to GetVehicleMatrix and POSITION from VEHICLE OFFSET but that's actually not what I'm looking for.
What I'm looking for is, getting offsets from x, y, z coordinates. Basically, it's for a vehicle-object-attach editor.
-
Sew_Sumi - 11.08.2017
-edit-
Yea, I didn't understand that post.
Re: Object offset to a vehicle -
Nero_3D - 11.08.2017
Well you need the VehicleMatrix, either use Gamer_Z include or any other which allows you to calculate the direction vectors (forward right up)
I will give you two versions, one with my include "rotation.inc" which does everything step by step and one version with the VehicleMatrix
Both include offer function/s to calculate the position with the given offset but how to get the offsets from the given coordinates?
This is no hidden magic or something, you need to use basic 3d geometry, first you get the offset (world coordinates), than you use the dot product to project this vector on the relative system (right, forward, up / pitch, roll, yaw)
Rotation.inc
Re: Object offset to a vehicle -
Omirrow - 11.08.2017
Well, this seems to be working, thanks.
Can't we actually calculate offsetRX, ry, rz? Well, I attach the object to vehicle with object's last rx, ry, rz but they're not correct when it's attached to the vehicle.
- Your include works fine and calculates offsetx, y, z properly, what about rx, ry and rz?
Re: Object offset to a vehicle -
Nero_3D - 11.08.2017
Sure we can, I put these function inside the include and renamed them
Quote:
Originally Posted by Nero_3D
Added GetVehicleObjectPositionOffset / GetVehicleObjectPositionWorld to calculate the position and rotation from a normal object to an attached object / vice versa
PHP код:
GetVehicleObjectPositionWorld(vehicleid, Float: att_X, Float: att_Y, Float: att_Z, Float: att_rotX, Float: att_rotY, Float: att_rotZ, &Float: X, &Float: Y, &Float: Z, &Float: rotX, &Float: rotY, &Float: rotZ)
GetVehicleObjectPositionOffset(vehicleid, Float: X, Float: Y, Float: Z, Float: rotX, Float: rotY, Float: rotZ, &Float: att_X, &Float: att_Y, &Float: att_Z, &Float: att_rotX, &Float: att_rotY, &Float: att_rotZ)
Well, I didn't intend to add functions for special cases but putting these in the example section would be copy and paste
|
Re: Object offset to a vehicle -
Omirrow - 19.08.2017
Thanks a lot!