Xeon06 Posted June 15, 2012 Posted June 15, 2012 Hey folks, I'm trying to draw 3D lines around various vehicles, using dxDrawLine3D. For now I'm just trying to draw a line in front of the vehicle. I'm using some basic trig, with the distances and angles hardcoded (and that's fine, I won't need to do it with many different types of vehicles). Here is what I have: addEventHandler("onClientRender", getRootElement(), function() local veh = getPedOccupiedVehicle(getLocalPlayer()) if (not veh) then return end local vx, vy, vz = getElementPosition(veh) local vrx, vry, vrz = getElementRotation(veh) local a1 = 100 local a2 = 80 local dist = 2.5 local x1 = vx + math.cos((vrz + a1) * (math.pi / 180)) * dist local y1 = vy + math.sin((vrz + a1) * (math.pi / 180)) * dist local z1 = vz local x2 = vx + math.cos((vrz + a2) * (math.pi / 180)) * dist local y2 = vy + math.sin((vrz + a2) * (math.pi / 180)) * dist local z2 = vz dxDrawLine3D(x1, y1, z1, x2, y2, z2, 0xFFFF0000, 10) dxDrawText(tostring(x) .. "\n" .. tostring(y) .. "\n" .. tostring(z) .. "\n" .. tostring(vrx) .. "\n" .. tostring(vry) .. "\n" .. tostring(vrz), 300, 0) end ) This works fine, and the line follows the vehicle's yaw and stays out front. My problem is with the z component of the line. I need to find a way to combine the pitch and the roll of the vehicle to get the line to stay perfectly in sync with the vehicle in whatever rotation it is. I can get either the pitch or roll to work, but can't for the life of me figure out how to combine the two. I basically need to get a 3D line to draw always between the two front headlights, following the vehicle rotation. Does anyone know how I can achieve that? Thanks.
50p Posted June 15, 2012 Posted June 15, 2012 https://wiki.multitheftauto.com/wiki/GetElementMatrix Have a look at the first example. There is a function that will help you out.
Xeon06 Posted June 16, 2012 Author Posted June 16, 2012 https://wiki.multitheftauto.com/wiki/GetElementMatrixHave a look at the first example. There is a function that will help you out. Wow that does wonders. Thanks a lot!
50p Posted June 16, 2012 Posted June 16, 2012 No problem. Keep it up. I get to like maths more and more everyday, even though I've always like it.
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