Jump to content

CameraMatrix 360°


Karuzo

Recommended Posts

Posted

Yo,

How can i create a Camera-Matrix which looks 360° all the time of a skin/car ?

Like in a Skin-Selection or smth like that.

Hope you understand what i mean :-D

Regards,

KRZO.

Posted

Well yeah that's what i mean.

Just rotate them with

  
setElementRotation 

?

I think i need a loop or smth like that.

How would that loop go ?

Posted
  
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 
  

  • Moderators
Posted
  
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.

Posted (edited)
  
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
Posted
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 ) 

Posted

Thanks,

and lets say i have GUI with a Gridlist which contains a few Vehicles.

How can i make it that if he clicks e.g.: on Infernus it will show an Infernus and rotate it ?

Posted

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.

  • Moderators
Posted
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.

Posted

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 

Posted

Well, the function didn't got target as element. Check if vehicle was created.

And try to put 3 more arguments when calling this function, not only the target.

Posted

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 
  

Posted

Right, but this camera function need update, so insert this function call into another and in showAutos function put line which would render this camera function.

Posted
I don't understand what you mean

He means that you'll need to use the onClientPreRender event to keep it updating, the function that you have right now will only execute it once.

Posted
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 

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