Jump to content

find XYZ from rotation + dist


Recommended Posts

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 by Guest
Link to comment

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
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

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
  • 3 months later...
  
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...