draobrehtom Posted September 11, 2016 Share Posted September 11, 2016 (edited) How to compute Velocity vector of Vehicle turret relative to Global World? I did some calculations and this is what I have been able to reach: local lrotX, lrotY = getVehicleTurretPosition(occupiedVehicle) -- Compute local 3D vector from bearing and elevation math local tVx,tVy,tVz = math.cos(lrotX) * math.cos(lrotY), math.sin(lrotX) * math.cos(lrotY), math.sin(lrotY) Maybe I need to calculate the difference of rotation angles turret and my vehicle, and then to compute Vector by formula above? Edited September 11, 2016 by draobrehtom Link to comment
draobrehtom Posted September 11, 2016 Author Share Posted September 11, 2016 Maybe it's will be better, if I told you, that I need this vector for setting velocity of createProjectile. Have you any ideas? Link to comment
Captain Cody Posted September 11, 2016 Share Posted September 11, 2016 Can you explain what you are trying to do a bit better please? Link to comment
draobrehtom Posted September 11, 2016 Author Share Posted September 11, 2016 (edited) 47 minutes ago, CodyL said: Can you explain what you are trying to do a bit better please? local lrotX, lrotY = getVehicleTurretPosition(occupiedVehicle) -- Compute local 3D vector from bearing and elevation math local tVx,tVy,tVz = math.cos(lrotX) * math.cos(lrotY), math.sin(lrotX) * math.cos(lrotY), math.sin(lrotY) -- Compute global 3D vector from above -- Create projectile (for vehicle, with x, y, z start position, xr, yr, zr for rotation vector, xvel, yvel, zvel for velocity vector) I need send rocket from turret of S.W.A.T vehicle. For that I need xvel, yvel, zvel. Edited September 11, 2016 by draobrehtom Link to comment
Captain Cody Posted September 11, 2016 Share Posted September 11, 2016 Will this be of use?? getElementMatrix Link to comment
_DrXenon Posted September 11, 2016 Share Posted September 11, 2016 I would like to point out that getVehicleTurretPosition returns the degree in radians not in degrees. Therefore, convert from radians to degrees using math.deg(angel).. Not sure if that gets the global rotation but if it doesn't, I guess figuring out the global angel by getting the rotation of your vehicle and your turrent wouldn't be hard. But I believe that if you use math.deg to the returns of the function, You gonna get the global degree. Link to comment
draobrehtom Posted September 11, 2016 Author Share Posted September 11, 2016 (edited) 48 minutes ago, SuperCroz said: I would like to point out that getVehicleTurretPosition returns the degree in radians not in degrees. Therefore, convert from radians to degrees using math.deg(angel).. Not sure if that gets the global rotation but if it doesn't, I guess figuring out the global angel by getting the rotation of your vehicle and your turrent wouldn't be hard. But I believe that if you use math.deg to the returns of the function, You gonna get the global degree. How to get difference (x,y,z - vehicle rotation) and (x,y - turret rotation)? Edited September 11, 2016 by draobrehtom Link to comment
_DrXenon Posted September 11, 2016 Share Posted September 11, 2016 3 minutes ago, draobrehtom said: How to get difference (x,y,z - vehicle rotation) and (x,y - turret rotation)? turning the turret x,y rotation into degrees did not help? because I think the x,y rotation of the turret are global and not according to the vehicle rotation (local) well anyway.... if it is not; the real (global) turret rotation would be: rotx = (the vehicle horzintal rotation + turrent horezintal rotation) and roty= (the vehicle's vertical rotation + the turret's vertical rotation) ^ probably. Link to comment
draobrehtom Posted September 11, 2016 Author Share Posted September 11, 2016 (edited) 2 minutes ago, SuperCroz said: turning the turret x,y rotation into degrees did not help? because I think the x,y rotation of the turret are global and not according to the vehicle rotation (local) well anyway.... if it is not; the real (global) turret rotation would be: rotx = (the vehicle horzintal rotation + turrent horezintal rotation) and roty= (the vehicle's vertical rotation + the turret's vertical rotation) ^ probably. No, because you have a two axis Eulers in 3D World in Turret. We need to convert it to 3 axis, but how? I will try to find formula. Edited September 11, 2016 by draobrehtom Link to comment
Walid Posted September 11, 2016 Share Posted September 11, 2016 Sorry i don't undrestand what you want exactly, if you want to get the target position just get the aiming vector from turret's rotation and combine it with turret's position using getVehicleComponentPosition and then transform the result into world coordinate by multiplying it by vehicle's matrix (you need to use getElementMatrix). in case you don't know the turrent component (misc_a, misc_d , misc_b) . 1 Link to comment
_DrXenon Posted September 11, 2016 Share Posted September 11, 2016 1 hour ago, draobrehtom said: No, because you have a two axis Eulers in 3D World in Turret. We need to convert it to 3 axis, but how? I will try to find formula. mate, you don't need 3 axis for the turret rotation, Just get the vertical degree (up/down) and horizontal degree (left/right) and set the last - useless - degree as 0 since it would not really matter. Link to comment
draobrehtom Posted September 11, 2016 Author Share Posted September 11, 2016 (edited) 3 minutes ago, SuperCroz said: mate, you don't need 3 axis for the turret rotation, Just get the vertical degree (up/down) and horizontal degree (left/right) and set the last - useless - degree as 0 since it would not really matter. Ok, and which will be "up/down" in my vector velocity createprojectile, uh? Edited September 11, 2016 by draobrehtom Link to comment
Captain Cody Posted September 11, 2016 Share Posted September 11, 2016 Z axis would be up and down. Link to comment
_DrXenon Posted September 11, 2016 Share Posted September 11, 2016 well probably the vertical rot is probably the rotY in the projectile and the horizontal rot is the rotX in the projectile and rotY as 0. If I'm wrong you can try other options than the one mentioned above.. 14 minutes ago, draobrehtom said: Ok, and which will be "up/down" in my vector velocity createprojectile, uh? velx,vely,velz are not required. It just decide the velocity of the projectile on it is creation. velocity is the speed of the projectile, If you want it to start from 0 and let accelrate normally, you just leave them blank or 0,0,0 Link to comment
draobrehtom Posted September 11, 2016 Author Share Posted September 11, 2016 (edited) 28 minutes ago, SuperCroz said: velx,vely,velz are not required. It just decide the velocity of the projectile on it is creation. velocity is the speed of the projectile, If you want it to start from 0 and let accelrate normally, you just leave them blank or 0,0,0 "velocity" in projectile it is a vector direction flying of rocket and I need this direction from turret direction. I think it work's in such way (projectile). Edited September 12, 2016 by draobrehtom Link to comment
draobrehtom Posted September 12, 2016 Author Share Posted September 12, 2016 (edited) 1 hour ago, Walid said: Sorry i don't undrestand what you want exactly, if you want to get the target position just get the aiming vector from turret's rotation and combine it with turret's position using getVehicleComponentPosition and then transform the result into world coordinate by multiplying it by vehicle's matrix (you need to use getElementMatrix). in case you don't know the turrent component (misc_a, misc_d , misc_b) . Thank's for the helping answer (misc elements). I was did that by this way: local mis_x, mis_y, mis_z = getVehicleComponentPosition(occupiedVehicle, "misc_c", "world") local miss_x, miss_y, miss_z = getVehicleComponentPosition(occupiedVehicle, "misc_b", "world") mis_x,mis_y,mis_z = mis_x - miss_x, mis_y - miss_y, mis_z - miss_z local matrix = getElementMatrix(occupiedVehicle) x = 0 * matrix[1][1] + 0 * matrix[2][1] + 4 * matrix[3][1] + 1 * matrix[4][1] y = 0 * matrix[1][2] + 0 * matrix[2][2] + 4 * matrix[3][2] + 1 * matrix[4][2] z = 0 * matrix[1][3] + 0 * matrix[2][3] + 4 * matrix[3][3] + 1 * matrix[4][3] createProjectile(g_P, 19, x, y, z, 200, nil, 0, 0, 0, mis_x, mis_y, mis_z) Thank you guys, I hope our discussion and this code will help other people. Edited September 12, 2016 by draobrehtom 1 Link to comment
Jusonex Posted September 12, 2016 Share Posted September 12, 2016 Just for the sake of completeness: I suggest you use MTA's matrix functions instead. If you also use getVehicleTurretPosition it would look like this (getVehicleComponentPosition is fine though): bindKey("space", "down", function() local vehicle = localPlayer:getOccupiedVehicle() if not vehicle then return end -- Get vehicle turret angles in radians local rotHorz, rotVert = getVehicleTurretPosition(vehicle) -- Calculate vector from this rotation local turretDirection = Vector3(-math.tan(rotHorz), 1, math.tan(rotVert)) -- Transform vector into world coordinate system local projectileDirection = vehicle.matrix:transformDirection(turretDirection) -- Create projectile createProjectile(localPlayer, 19, vehicle:getPosition() + Vector3(0, 0, 2), 1, nil, 0, 0, 0, projectileDirection) end ) 2 Link to comment
obuhhh Posted September 12, 2016 Share Posted September 12, 2016 20 hours ago, draobrehtom said: No, because you have a two axis Eulers in 3D World in Turret. We need to convert it to 3 axis, but how? I will try to find formula. Z-turret's axis - its x-axis vehicle, I thing. Link to comment
NegativeIQ Posted September 14, 2016 Share Posted September 14, 2016 On 9/12/2016 at 11:33 AM, Jusonex said: Just for the sake of completeness: I suggest you use MTA's matrix functions instead. If you also use getVehicleTurretPosition it would look like this (getVehicleComponentPosition is fine though): bindKey("space", "down", function() local vehicle = localPlayer:getOccupiedVehicle() if not vehicle then return end -- Get vehicle turret angles in radians local rotHorz, rotVert = getVehicleTurretPosition(vehicle) -- Calculate vector from this rotation local turretDirection = Vector3(-math.tan(rotHorz), 1, math.tan(rotVert)) -- Transform vector into world coordinate system local projectileDirection = vehicle.matrix:transformDirection(turretDirection) -- Create projectile createProjectile(localPlayer, 19, vehicle:getPosition() + Vector3(0, 0, 2), 1, nil, 0, 0, 0, projectileDirection) end ) Decided to mess around a bit so i tested code and everything is fine except that when you are looking behind projectiles are launched in in opposite direction from the turret. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now