.:HyPeX:. Posted July 16, 2014 Share Posted July 16, 2014 hey guys, how can i calculate a XYZ position by having a rotation and distance? For example, setting up the camera according to the rotation of my car in a place. Link to comment
12p Posted July 16, 2014 Share Posted July 16, 2014 https://wiki.multitheftauto.com/wiki/Ge ... ceRotation This works for a two-dimensional point. It can be a good start. Link to comment
RenanPG Posted July 16, 2014 Share Posted July 16, 2014 (edited) addEventHandler("onClientRender", root, function() local height = 3 local weight = 20 local veh = getPedOccupiedVehicle(localPlayer) local x, y, z = getElementPosition(veh) local rx, ry, rz = getElementRotation(veh) local ax, ay = getPointFromDistanceRotation(x, y, weight, (-rz) - 180) setCameraMatrix(ax, ay , z+height, x, y, z) end) function getPointFromDistanceRotation(x, y, dist, angle) local a = math.rad(90 - angle); local dx = math.cos(a) * dist; local dy = math.sin(a) * dist; return x+dx, y+dy; end i didn't tested, adjust Edited July 17, 2014 by Guest Link to comment
.:HyPeX:. Posted July 17, 2014 Author Share Posted July 17, 2014 Well, it is not taking my vehicle rotation into account, its taking it as if it always rz was 0.. wich is not. local px,py,pz = getElementPosition(getPedOccupiedVehicle(getLocalPlayer())) local rx,ry,rz = getElementRotation(getPedOccupiedVehicle(getLocalPlayer())) local cx,cy = getPointFromDistanceRotation (px,py,10,rz +75) local cx2,cy2 = getPointFromDistanceRotation(px,py,10,rz +90) local cx,cy = interpolateBetween(cx,cy,0,cx2,cy2,0,progress,"Linear") setCameraMatrix(cx,cy,pz+10,px,py,pz) Link to comment
RenanPG Posted July 17, 2014 Share Posted July 17, 2014 Well, it is not taking my vehicle rotation into account, its taking it as if it always rz was 0.. wich is not. local px,py,pz = getElementPosition(getPedOccupiedVehicle(getLocalPlayer())) local rx,ry,rz = getElementRotation(getPedOccupiedVehicle(getLocalPlayer())) local cx,cy = getPointFromDistanceRotation (px,py,10,rz +75) local cx2,cy2 = getPointFromDistanceRotation(px,py,10,rz +90) local cx,cy = interpolateBetween(cx,cy,0,cx2,cy2,0,progress,"Linear") setCameraMatrix(cx,cy,pz+10,px,py,pz) function getPointFromDistanceRotation(x, y, dist, angle) local a = math.rad(90 - angle); local dx = math.cos(a) * dist; local dy = math.sin(a) * dist; return x+dx, y+dy; end Do you put this in your code? Link to comment
.:HyPeX:. Posted July 17, 2014 Author Share Posted July 17, 2014 Yes of course, it works, but the rotation taken into account was if like rz never existed (Or was always 0) wich i do not understand is why, i output the RZ before those lines and it is perfect... but it is not considered somehow. Link to comment
.:HyPeX:. Posted July 17, 2014 Author Share Posted July 17, 2014 Bump, this is the complete function, what am i doing wrong? local px,py,pz = getElementPosition(getPedOccupiedVehicle(getLocalPlayer())) local rx,ry,rz = getElementRotation(getPedOccupiedVehicle(getLocalPlayer())) local now = getTickCount() local start = start local finish = start + 5000 local duration = 5000 local elapsed = now - start local progress = elapsed / duration if elapsed < 1000 then local duration = 1000 local ending = start + duration local elapsed = now - start local progress = elapsed / duration ---- local alpha = interpolateBetween(0,0,0,255,0,0, progress, "Linear") dxDrawImage(0,0,x,y,myRender,0,0,0, tocolor(255,255,255,alpha),true) elseif elapsed >1000 and elapsed < 1500 then local duration = 500 local start = start + 1000 local ending = start + duration local elapsed = now - start local progress = elapsed / duration ---- local rz1 = rz + 75 local cx,cy = getPointFromDistanceRotation (px,py,10,rz1) local rz2 = rz + 90 local cx2,cy2 = getPointFromDistanceRotation(px,py,10,rz2) local cx,cy = interpolateBetween(cx,cy,0,cx2,cy2,0,progress,"Linear") setCameraMatrix(cx,cy,pz+5,px,py,pz) local alpha = interpolateBetween(255,0,0,0,0,0,progress,"Linear") dxDrawImage(0,0,x,y,myRender,0,0,0, tocolor(255,255,255,alpha),true) elseif elapsed > 1500 and elapsed < 2000 then local duration = 500 local start = start + 1500 local ending = start + duration local elapsed = now - start local progress = elapsed / duration ---- local rz1 = rz + 90 local cx,cy = getPointFromDistanceRotation (px,py,10,rz1) local rz2 = rz + 105 local cx2,cy2 = getPointFromDistanceRotation(px,py,10,rz2) local cx,cy = interpolateBetween(cx,cy,0,cx2,cy2,0,progress,"Linear") setCameraMatrix(cx,cy,pz+5,px,py,pz) local alpha = interpolateBetween(0,0,0,255,0,0,progress,"Linear") dxDrawImage(0,0,x,y,myRender,0,0,0, tocolor(255,255,255,alpha),true) elseif elapsed > 2000 and elapsed < 2500 then local duration = 500 local start = start + 2000 local ending = start + duration local elapsed = now - start local progress = elapsed / duration ---- local rz1 = rz - 75 local cx,cy = getPointFromDistanceRotation (px,py,10,rz1) local rz2 = rz - 90 local cx2,cy2 = getPointFromDistanceRotation(px,py,10,rz2) local cx,cy = interpolateBetween(cx,cy,0,cx2,cy2,0,progress,"Linear") setCameraMatrix(cx,cy,pz+5,px,py,pz) local alpha = interpolateBetween(255,0,0,0,0,0,progress,"Linear") dxDrawImage(0,0,x,y,myRender,0,0,0, tocolor(255,255,255,alpha),true) elseif elapsed > 2500 and elapsed < 3000 then local duration = 500 local start = start + 2500 local ending = start + duration local elapsed = now - start local progress = elapsed / duration ---- local rz1 = rz - 90 local cx,cy = getPointFromDistanceRotation (px,py,10,rz1) local rz2 = rz - 105 local cx2,cy2 = getPointFromDistanceRotation(px,py,10,rz2) local cx,cy = interpolateBetween(cx,cy,0,cx2,cy2,0,progress,"Linear") setCameraMatrix(cx,cy,pz+5,px,py,pz) local alpha = interpolateBetween(0,0,0,255,0,0,progress,"Linear") dxDrawImage(0,0,x,y,myRender,0,0,0, tocolor(255,255,255,alpha),true) elseif elapsed > 3000 and elapsed < 3500 then local duration = 500 local start = start + 3000 local ending = start + duration local elapsed = now - start local progress = elapsed / duration ---- local rz1 = rz + 180 local cx,cy = getPointFromDistanceRotation (px,py,10,rz1) local alt = interpolateBetween(pz+10,0,0,pz+5,0,0,progress,"Linear") setCameraMatrix(cx,cy,alt,px,py,pz) local alpha = interpolateBetween(255,0,0,0,0,0,progress,"Linear") dxDrawImage(0,0,x,y,myRender,0,0,0, tocolor(255,255,255,alpha),true) elseif elapsed > 3500 and elapsed < 4000 then local duration = 500 local start = start + 3500 local ending = start + duration local elapsed = now - start local progress = elapsed / duration ---- local rz1 = rz + 180 local cx,cy = getPointFromDistanceRotation (px,py,10,rz1) local alt = interpolateBetween(pz+5,0,0,pz,0,0,progress,"Linear") setCameraMatrix(cx,cy,alt,px,py,pz) local alpha = interpolateBetween(0,0,0,255,0,0,progress,"Linear") dxDrawImage(0,0,x,y,myRender,0,0,0, tocolor(255,255,255,alpha),true) elseif elapsed > 4000 and elapsed < 4500 then local duration = 500 local start = start + 4000 local ending = start + duration local elapsed = now - start local progress = elapsed / duration ---- local cx,cy = getPointFromDistanceRotation (px,py,15,rz) local cx2,cy2 = getPointFromDistanceRotation(px,py,10,rz) local alt,cx,cy = interpolateBetween(pz+10,cx,cy,pz+5,cx2,cy2,progress,"Linear") setCameraMatrix(cx,cy,alt,px,py,pz) local alpha = interpolateBetween(255,0,0,0,0,0,progress,"Linear") dxDrawImage(0,0,x,y,myRender,0,0,0, tocolor(255,255,255,alpha),true) elseif elapsed > 4500 and elapsed < 4950 then local duration = 450 local start = start + 4500 local ending = start + duration local elapsed = now - start local progress = elapsed / duration ---- local cx,cy = getPointFromDistanceRotation (px,py,10,rz) local cx2,cy2 = getPointFromDistanceRotation(px,py,7,rz) local alt,cx,cy = interpolateBetween(pz+5,cx,cy,pz+1.5,cx2,cy2,progress,"Linear") setCameraMatrix(cx,cy,alt,px,py,pz) elseif elapsed > 4950 then setCameraTarget(getLocalPlayer()) dxDrawText("GOGOGOGO", x*0.4, y*0.4, x*0.2,y*0.1, tocolor(180,0,0,255), 3, "default-bold") dxDrawRectangle(0,y*0.4,x,y*0.05, tocolor(0,0,0,180)) toggleAllControls(true) end Link to comment
monday Posted November 12, 2014 Share Posted November 12, 2014 function getPointFromDistanceRotation(x, y, dist, angle) local a = math.rad(90 - angle); local dx = math.cos(a) * dist; local dy = math.sin(a) * dist; return x+dx, y+dy; end I was struggling to make it work properly but changing this: return x+dx, y+dy; into this: return x+dx, y-dy; made it working properly for me 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