Jump to content

CameraMatrix 360°


Karuzo

Recommended Posts

  
showcaseObject = function(object) 
    local rotationProgress = 0 
    local function rotateObject() 
        rotationProgress = rotationProgress+0.01 
        local rotationValue = interpolateBetween(0,0,0,360,0,0,rotationProgress,"InOutQuad") 
        local _,y,z = getElementRotation(object) 
        setElementRotation(object,rotationValue,y,z) 
        if rotationProgress>=1 then 
            rotationProgress = 0 
        end 
    end 
    addEventHandler("onClientRender",root,rotateObject) 
end 
  

Link to comment
  • Moderators
  
showcaseObject = function(object) 
    local rotationProgress = 0 
    local function rotateObject() 
        rotationProgress = rotationProgress+0.01 
        local rotationValue = interpolateBetween(0,0,0,360,0,0,rotationProgress,"InOutQuad") 
        local _,y,z = getElementRotation(object) 
        setElementRotation(object,rotationValue,y,z) 
        if rotationProgress>=1 then 
            rotationProgress = 0 
        end 
    end 
    addEventHandler("onClientRender",root,rotateObject) 
end 
  

If that code work, why using InOutQuad as easing type ? linear would be better imo.

Also, why rotating the player on X axis ? The character will just do front flips :lol: You had to rotatate him on the Z axis actually :wink:

It's a good practice to use interpolateBetween in onClientRender but you had to use it with getTickCount to control the execution speed. The more FPS you will get, the faster your character will spin.

A simple setTimer would do the trick.

Link to comment
  
showcaseObject = function(object) 
    local rotationProgress = 0 
    local function rotateObject() 
        rotationProgress = rotationProgress+0.01 
        local rotationValue = interpolateBetween(0,0,0,360,0,0,rotationProgress,"InOutQuad") 
        local _,y,z = getElementRotation(object) 
        setElementRotation(object,rotationValue,y,z) 
        if rotationProgress>=1 then 
            rotationProgress = 0 
        end 
    end 
    addEventHandler("onClientRender",root,rotateObject) 
end 
  

This can also be done with simple maths, and it looks cleaner.

  
local angle = 0 
  
function renderCameraRotation( targetX, targetY, targetZ, cameraHeight, radius, speed, roll, fov ) -- cameraHeight, radius, speed, roll and fov are optional arguments. 
    local cameraHeight = cameraHeight or 5 
    local radius = radius or 20 
    local speed = speed or 0.2 
    local startangle = startangle or 0 
    local roll = roll or 0 
    local fov = fov or 70 
  
    local camX = targetX + radius * math.cos( math.rad( angle ) ) 
    local camY = targetY + radius * math.sin( math.rad( angle ) ) 
  
    if ( angle <= 360 ) then angle = angle + speed else angle = 0 end 
  
    setCameraMatrix( camX, camY, targetZ + cameraHeight, targetX, targetY, targetZ, roll, fov ) 
end 
  
function renderCameraTest() 
    renderCameraRotation( -1342.0641, -26.8057, 14.14844, 5, 10, 0.3, 0, 70 ) 
    -- renderCameraRotation( -1342.0641, -26.8057, 14.14844 ) // Without optional arguments for the lazy people. 
end 
addEventHandler( "onClientRender", root, renderCameraTest ) 
  

Edited by Guest
Link to comment
Wow! Thank you all for your help!

I think i'm gonna use Jesseunit's code :-)

Here's a newer version of the code, now you can also use an element.

local angle = 0 
  
function renderCameraRotation( target, targetX, targetY, targetZ, cameraHeight, radius, speed, roll, fov ) 
    local target = target or nil 
    local cameraHeight = cameraHeight or 5 
    local radius = radius or 20 
    local speed = speed or 0.2 
    local roll = roll or 0 
    local fov = fov or 70 
  
    if isElement( target ) then 
        targetX, targetY, targetZ = getElementPosition( target ) 
    end 
  
    local camX = targetX + radius * math.cos( math.rad( angle ) ) 
    local camY = targetY + radius * math.sin( math.rad( angle ) ) 
  
    if ( angle <= 360 ) then angle = angle + speed else angle = 0 end 
  
    setCameraMatrix( camX, camY, targetZ + cameraHeight, targetX, targetY, targetZ, roll, fov ) 
end 
  
function renderCameraTest() 
    renderCameraRotation( localPlayer ) -- This will make the camera follow and rotate around the player. 
    -- renderCameraRotation( nil, 0, 0, 3 ) // Static X, Y, Z 
    -- renderCameraRotation( nil, 0, 0, 3, 5, 15, 0.3, 0, 70 ) // Static X, Y, Z with optional arguments. 
end 
addEventHandler( "onClientRender", root, renderCameraTest ) 

Link to comment

Why doesn't this work ?

function ShowAutos() 
    local car = guiGridListGetItemText ( vehicleList, guiGridListGetSelectedItem ( vehicleList ), 1 ) 
    local carshow = createVehicle(car,544.74103, -1298.83533, 32.54056) 
    renderCameraRotation( carshow ) 
end 

im adding the EventHandler onClientMarkerHit.

Link to comment
  • Moderators
Why doesn't this work ?
function ShowAutos() 
    local car = guiGridListGetItemText ( vehicleList, guiGridListGetSelectedItem ( vehicleList ), 1 ) 
    local carshow = createVehicle(car,544.74103, -1298.83533, 32.54056) 
    renderCameraRotation( carshow ) 
end 

im adding the EventHandler onClientMarkerHit.

You can't do that since guiGridListGetSelectedItem returns two values. You have to store its result using a variable and then send it in guiGridListGetItemText.

I guess it's clear enough to not write you the soltution.

Link to comment

Yeah got it.

But now it gives me an awkward error.

wmFQIGE.png

Code:

  
        local angle = 0 
      
    function renderCameraRotation( target, targetX, targetY, targetZ, cameraHeight, radius, speed, roll, fov ) 
        local target = target or nil 
        local cameraHeight = cameraHeight or 5 
        local radius = radius or 20 
        local speed = speed or 1 
        local roll = roll or 0 
        local fov = fov or 70 
      
        if isElement( target ) then 
            targetX, targetY, targetZ = getElementPosition( target ) 
        end 
      
        local camX = targetX + radius * math.cos( math.rad( angle ) )--This line. 
        local camY = targetY + radius * math.sin( math.rad( angle ) ) 
      
        if ( angle <= 360 ) then angle = angle + speed else angle = 0 end 
      
        setCameraMatrix( camX, camY, targetZ + cameraHeight, targetX, targetY, targetZ, roll, fov ) 
    end 

Link to comment

Works now ,

but the car isn't created.

Do i have to update it or smth like that ? i don't think so cause onClientRender would get the Selected Item every frame right ?

  
function ShowAutos() 
    local row = guiGridListGetSelectedItem(vehicleList) 
    local carget = guiGridListGetItemText(vehicleList, row, 1)  
    local carshow = createVehicle(carget,544.74103, -1298.83533, 32.54056) 
    renderCameraRotation( carshow,544.74103, -1298.83533, 32.54056 ) 
end 
  

Link to comment
function ShowAutos() 
    local row = guiGridListGetSelectedItem(vehicleList) 
    local carget = guiGridListGetItemText(vehicleList, row, 1) 
    local carshow = createVehicle(carget,544.74103, -1298.83533, 32.54056) 
    addEventHandler ( "onClientPreRender", root, 
        function ( ) 
            renderCameraRotation ( carshow, 544.74103, -1298.83533, 32.54056 ) 
        end 
    ) 
end 

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