FuriouZ Posted August 4, 2014 Share Posted August 4, 2014 Hey guys! I am more than sure that this is possible in mta: but how ? What I mean is the world rotation Link to comment
tosfera Posted August 4, 2014 Share Posted August 4, 2014 Dear friend, why don't you spawn an hydra and fly on your side... please. Link to comment
FuriouZ Posted August 4, 2014 Author Share Posted August 4, 2014 Dear friend, why don't you spawn an hydra and fly on your side... please. Well... Can you see the diffrence huh ? Link to comment
Addlibs Posted August 4, 2014 Share Posted August 4, 2014 local m = getElementMatrix( theVehicle ) local pitch = math.deg( math.asin( m[2][3] ) ) -- (-90,90) local roll = math.deg( math.atan2( m[1][3], m[3][3] ) ) --(-180,180) - You should only need this one (roll) local yaw = math.deg( math.atan2( m[2][1], m[2][2] ) ) --(-180,180) You can do the rest. Link to comment
tosfera Posted August 4, 2014 Share Posted August 4, 2014 Oh, ya. That's all about cameraMatrix bud. Thought it was that as default? Link to comment
FuriouZ Posted August 4, 2014 Author Share Posted August 4, 2014 local m = getElementMatrix( theVehicle ) local pitch = math.deg( math.asin( m[2][3] ) ) -- (-90,90) local roll = math.deg( math.atan2( m[1][3], m[3][3] ) ) --(-180,180) - You should only need this one (roll) local yaw = math.deg( math.atan2( m[2][1], m[2][2] ) ) --(-180,180) You can do the rest. Jeez, I am dumb in Matrix functions... So I have to set the matrix to the plane ? I don't get it, I need to use only roll, right ? but the damn script needs 3rd argument, then 4,5 ... Code makes no sense addEventHandler("onClientVehicleEnter", root, function(theVehicle, seat, jacked) local m = getElementMatrix( theVehicle ) local pitch = math.deg( math.asin( m[2][3] ) ) -- (-90,90) local roll = math.deg( math.atan2( m[1][3], m[3][3] ) ) --(-180,180) - You should only need this one (roll) local yaw = math.deg( math.atan2( m[2][1], m[2][2] ) ) --(-180,180) if (isPedInVehicle( getLocalPlayer() )) then setElementMatrix ( theVehicle, roll) end end) Link to comment
MTA Team botder Posted August 5, 2014 MTA Team Share Posted August 5, 2014 SetCameraMatrix Use the calculated roll variable and pass it to the camera matrix (get the other values from getCameraMatrix) Link to comment
FuriouZ Posted August 5, 2014 Author Share Posted August 5, 2014 SetCameraMatrixUse the calculated roll variable and pass it to the camera matrix (get the other values from getCameraMatrix) What I am doing wrong.. Code is messed up I do not neeed x, y, z or or only z ? Damn I am dumb addEventHandler("onClientVehicleEnter", root, function(theVehicle, seat, jacked) local eM = getElementMatrix( theVehicle ) local x, y, z, lx, ly, lz = getCameraMatrix( theVehicle ) local pitch = math.deg( math.asin( eM[2][3] ) ) -- (-90,90) local roll = math.deg( math.atan2( eM[1][3], eM[3][3] ) ) --(-180,180) - You should only need this one (roll) local yaw = math.deg( math.atan2( eM[2][1], eM[2][2] ) ) --(-180,180) if (isPedInVehicle( getLocalPlayer() )) then if ( getVehicleType( source ) == "Plane" ) then --setElementMatrix ( theVehicle, roll, y, z, lx, ly, lz) setCameraMatrix ( theVehicle, roll, x, y, z, lx, ly, lz) end end end) Link to comment
Anubhav Posted August 5, 2014 Share Posted August 5, 2014 addEventHandler("onClientVehicleEnter", root, function(theVehicle, seat, jacked) local eM = getElementMatrix( theVehicle ) local x, y, z, lx, ly, lz = getCameraMatrix( theVehicle ) local pitch = math.deg( math.asin( eM[2][3] ) ) -- (-90,90) local roll = math.deg( math.atan2( eM[1][3], eM[3][3] ) ) --(-180,180) - You should only need this one (roll) local yaw = math.deg( math.atan2( eM[2][1], eM[2][2] ) ) --(-180,180) if (isPedInVehicle( getLocalPlayer() )) then if ( getVehicleType( source ) == "Plane" ) then --setElementMatrix ( theVehicle, roll, y, z, lx, ly, lz) setCameraMatrix ( x, y, z, lx, ly, lz, roll) end end end) Link to comment
MTA Team botder Posted August 5, 2014 MTA Team Share Posted August 5, 2014 (edited) * not working Edited August 6, 2014 by Guest Link to comment
FuriouZ Posted August 5, 2014 Author Share Posted August 5, 2014 Almost works, but camera stays in one positsion, I tryed setCameraTarget to the localPlayer and theVehicle, but if I used localPlayer, then world didn't rotate and if theVehicle, then camera stayed in one pos like without setCameraTarget.. addEventHandler("onClientPreRender", root, function(thePlayer) local theVehicle = getPedOccupiedVehicle ( localPlayer ) if not ( theVehicle ) then return end local eM = getElementMatrix( theVehicle ) local x, y, z, lx, ly, lz = getCameraMatrix() local pitch = math.deg( math.asin( eM[2][3] ) ) -- (-90,90) local roll = math.deg( math.atan2( eM[1][3], eM[3][3] ) ) --(-180,180) local yaw = math.deg( math.atan2( eM[2][1], eM[2][2] ) ) --(-180,180) -- if ( getVehicleType( source ) == "Plane" ) then setCameraMatrix ( x, y, z, lx, ly, lz, roll) --setCameraTarget( theVehicle ) --end end) Link to comment
FuriouZ Posted August 5, 2014 Author Share Posted August 5, 2014 Still don't know what's the problem Link to comment
MTA Team botder Posted August 6, 2014 MTA Team Share Posted August 6, 2014 *Edit, now tested & works Video: Dropbox addEventHandler("onClientPreRender", root, function() local theVehicle = getPedOccupiedVehicle(localPlayer) if (not theVehicle) then return end local eM = getElementMatrix( theVehicle ) local vx, vy, vz = getElementVelocity( theVehicle ) local speed = math.sqrt(math.pow(vx, 2) + math.pow(vy, 2) + math.pow(vz, 2)) + 0.5 local distance = 5 * speed + 12 local heightAboveVehicle = 2.5 local roll = math.deg(math.atan2(eM[1][3], eM[3][3])) local x = -distance * eM[2][1] + eM[4][1] local y = -distance * eM[2][2] + eM[4][2] local z = -distance * eM[2][3] + heightAboveVehicle * eM[3][3] + eM[4][3] local lx = 4 * eM[2][1] + eM[4][1] local ly = 4 * eM[2][2] + eM[4][2] local lz = 4 * eM[2][3] + eM[4][3] if ( getVehicleType( theVehicle ) == "Plane" ) then setCameraMatrix( x, y, z, lx, ly, lz, roll) end end ) Link to comment
yoya99 Posted October 31, 2014 Share Posted October 31, 2014 hey i haev something like that too but when i exit the vehicle the camera matrix is not set to rthge player again... Link to comment
Woovie Posted October 31, 2014 Share Posted October 31, 2014 Holy hell that's overly complicated... I made this as a test one. Works fairly well IIRC. -- Changes the camera position on pre-render (to avoid stuttering) local function clientPreRender() if not isPilotingCompatibleVehicle() then return end local vehicle = getPedOccupiedVehicle(localPlayer) local cameraX, cameraY, cameraZ = getPositionFromElementOffset(vehicle, 0, -7, 4) local lookAtX, lookAtY, lookAtZ = getPositionFromElementOffset(vehicle, 0, 0, 2) local _, rotY= getElementRotation(vehicle) setCameraMatrix(cameraX, cameraY, cameraZ, lookAtX, lookAtY, lookAtZ, (rotY*-1)) end addEventHandler("onClientPreRender", root, clientPreRender) Link to comment
FuriouZ Posted November 1, 2014 Author Share Posted November 1, 2014 Holy hell that's overly complicated... I made this as a test one. Works fairly well IIRC. -- Changes the camera position on pre-render (to avoid stuttering) local function clientPreRender() if not isPilotingCompatibleVehicle() then return end local vehicle = getPedOccupiedVehicle(localPlayer) local cameraX, cameraY, cameraZ = getPositionFromElementOffset(vehicle, 0, -7, 4) local lookAtX, lookAtY, lookAtZ = getPositionFromElementOffset(vehicle, 0, 0, 2) local _, rotY= getElementRotation(vehicle) setCameraMatrix(cameraX, cameraY, cameraZ, lookAtX, lookAtY, lookAtZ, (rotY*-1)) end addEventHandler("onClientPreRender", root, clientPreRender) Error: attempt to call global 'isPilotingCompatibleVehicle' (a nil value) Link to comment
-.Paradox.- Posted November 1, 2014 Share Posted November 1, 2014 (edited) Woovie's code -- List of vehicle models that are compatible with the jetHUD local compatibleModels = { 592, 566, 511, 548, 512, 593, 425, 520, 417, 487, 553, 488, 497, 563, 476, 447, 519, 460, 469, 513 } local sw, sh = guiGetScreenSize() local iw, ih = 514, 514 local lineW = 2 local jetRender = dxCreateRenderTarget ( iw, ih, true ) local jetRender2 = dxCreateRenderTarget ( iw, ih, true ) local color = tocolor(255, 0, 0) -- Returns true if the local player is piloting a vehicle compatible with the jetHUD, false otherwise -- TODO: Check that the player is in the pilot's seat (no MTA function available?) function isPilotingCompatibleVehicle() local vehicle = getPedOccupiedVehicle(localPlayer) if not vehicle then return false end local vehicleModel = getElementModel(vehicle) for _, compatibleModel in ipairs(compatibleModels) do if vehicleModel == compatibleModel then return true end end return false end -- Changes the camera position on pre-render (to avoid stuttering) local function clientPreRender() if not isPilotingCompatibleVehicle() then return end local vehicle = getPedOccupiedVehicle(localPlayer) local cameraX, cameraY, cameraZ = getPositionFromElementOffset(vehicle, 0, -7, 4) local lookAtX, lookAtY, lookAtZ = getPositionFromElementOffset(vehicle, 0, 0, 2) local _, rotY= getElementRotation(vehicle) setCameraMatrix(cameraX, cameraY, cameraZ, lookAtX, lookAtY, lookAtZ, (rotY*-1)) end addEventHandler("onClientPreRender", root, clientPreRender) -- Renders the HUD local function clientRender() if not isPilotingCompatibleVehicle() or not jetRender then return end local vehicle = getPedOccupiedVehicle(localPlayer) dxSetRenderTarget ( jetRender, true ) local x, y, z = getElementPosition ( vehicle ) local rx, ry, rz = getElementRotation ( vehicle ) local sx, sy, sz = getElementVelocity ( vehicle ) local speed = ( sx^2 + sy^2 + sz^2 ) ^ ( 0.5 ) local mps = speed * 50 local kmh = speed * 180 local mph = speed * 111.847 --speed dxDrawLine ( 1, 200, 1, 220, color, lineW ) dxDrawLine ( 51, 200, 51, 220, color, lineW ) dxDrawLine ( 1, 200, 51, 200, color, lineW ) dxDrawLine ( 1, 220, 51, 220, color, lineW ) dxDrawText ( math.round(kmh, 2), 1, 201, 49, 219, color, 1, "clear", "center", "center", true, false, false, false, false ) --altitude dxDrawLine ( 463, 200, 463, 220, color, lineW ) dxDrawLine ( 513, 200, 513, 220, color, lineW ) dxDrawLine ( 463, 220, 513, 220, color, lineW ) dxDrawLine ( 463, 200, 513, 200, color, lineW ) dxDrawText ( math.round(z, 2), 464, 201, 512, 219, color, 1, "clear", "center", "center", true, false, false, false, false ) --pitch rx --yaw rz --200 pixels, 40 degrees, every 5 pixels = 1 degree local pixelOffset = 5 local rotmod = ( rz % 1 ) * pixelOffset local rotcal = math.floor( 200 - rotmod ) / pixelOffset for i=0,rotcal do if (i % 2 == 0) then dxDrawLine ( ( ( ( iw / 2 ) - 100 ) + rotmod + i * pixelOffset ), 40, ( ( ( iw / 2 ) - 100 ) + rotmod + i * pixelOffset ), 35, color, lineW ) else dxDrawLine ( ( ( ( iw / 2 ) - 100 ) + rotmod + i * pixelOffset ), 40, ( ( ( iw / 2 ) - 100 ) + rotmod + i * pixelOffset ), 30, color, lineW ) end end dxDrawText ( math.round(rz, 2), (iw/2)-25, 51, (iw/2)+25, 71, color, 1, "clear", "center", "center", true, false, false, false, false ) dxDrawLine ( (iw/2)-10, 50, (iw/2), 40, color, lineW ) dxDrawLine ( (iw/2)+10, 50, (iw/2), 40, color, lineW ) --level crosshairs dxDrawLine ( (iw/2)-30, 220, (iw/2)+30, 220, color, lineW ) dxDrawLine ( (iw/2), 220, (iw/2), 200, color, lineW ) dxSetRenderTarget() --roll ry ( for rotating pitch ) --400 pixels, 40 degrees, 10 pixels = 1 degree dxSetRenderTarget(jetRender2, true) local pixelOffset = 10 local height = 300 local rotmod = ( rx % 1 ) * pixelOffset local rotcal = math.floor( height - rotmod ) / pixelOffset for i=0,rotcal do if (i % 2 == 0) then dxDrawLine ( 65, ( ( ( iw / 2 ) - ( height / 2 ) ) + rotmod + i * pixelOffset ), 75, ( ( ( iw / 2 ) - ( height / 2 ) ) + rotmod + i * pixelOffset ), color, lineW ) dxDrawLine ( (iw-65), ( ( ( iw / 2 ) - ( height / 2 ) ) + rotmod + i * pixelOffset ), (iw-75), ( ( ( iw / 2 ) - ( height / 2 ) ) + rotmod + i * pixelOffset ), color, lineW ) else dxDrawLine ( 65, ( ( ( iw / 2 ) - ( height / 2 ) ) + rotmod + i * pixelOffset ), 70, ( ( ( iw / 2 ) - ( height / 2 ) ) + rotmod + i * pixelOffset ), color, lineW ) dxDrawLine ( (iw-65), ( ( ( iw / 2 ) - ( height / 2 ) ) + rotmod + i * pixelOffset ), (iw-70), ( ( ( iw / 2 ) - ( height / 2 ) ) + rotmod + i * pixelOffset ), color, lineW ) end end dxSetRenderTarget() dxDrawImage ( (sw/2)-(iw/2), (sh/2)-(ih/2), iw, ih, jetRender ) dxDrawImage ( (sw/2)-(iw/2), (sh/2)-(ih/2), iw, ih, jetRender2,(ry*-1) ) end addEventHandler("onClientRender", root, clientRender) function math.round(number, decimals, method) decimals = decimals or 0 local factor = 10 ^ decimals if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor else return tonumber(("%."..decimals.."f"):format(number)) end end function getPositionFromElementOffset(element,offX,offY,offZ) local m = getElementMatrix ( element ) -- Get the matrix local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] return x, y, z -- Return the transformed point end addEventHandler("onClientPlayerVehicleExit", localPlayer, function() setCameraTarget(localPlayer) end) addEventHandler("onClientResourceStop", localPlayer, function() setCameraTarget(localPlayer) end) Edited November 1, 2014 by Guest Link to comment
MTA Team botder Posted November 1, 2014 MTA Team Share Posted November 1, 2014 The function getPositionFromElementOffset is missing too @edit: Mine code example also moves the camera away, when u accelerate. Link to comment
yoya99 Posted November 9, 2014 Share Posted November 9, 2014 yes but at the andromada you should deative it Nacktrox Link to comment
Tails Posted November 9, 2014 Share Posted November 9, 2014 hey i haev something like that too but when i exit the vehicle the camera matrix is not set to rthge player again... Add this line to your script addEventHandler("onClientPlayerVehicleExit", root, function() setCameraTarget(localPlayer) end ) 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