Karuzo Posted March 2, 2014 Share Posted March 2, 2014 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 Regards, KRZO. Link to comment
Bonsai Posted March 2, 2014 Share Posted March 2, 2014 Like Map Editor Browser? But its not 360°, you just rotate the objects. Link to comment
Karuzo Posted March 2, 2014 Author Share Posted March 2, 2014 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 ? Link to comment
cheez3d Posted March 2, 2014 Share Posted March 2, 2014 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 Citizen Posted March 2, 2014 Moderators Share Posted March 2, 2014 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 You had to rotatate him on the Z axis actually 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
Jesseunit Posted March 2, 2014 Share Posted March 2, 2014 (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 March 2, 2014 by Guest Link to comment
Moderators Citizen Posted March 2, 2014 Moderators Share Posted March 2, 2014 Wasn't my function btw. Link to comment
Jesseunit Posted March 2, 2014 Share Posted March 2, 2014 Wasn't my function btw. Thanks for the headsup, edited the quote. Link to comment
Karuzo Posted March 2, 2014 Author Share Posted March 2, 2014 Wow! Thank you all for your help! I think i'm gonna use Jesseunit's code Link to comment
Jesseunit Posted March 2, 2014 Share Posted March 2, 2014 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
Karuzo Posted March 2, 2014 Author Share Posted March 2, 2014 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 ? Link to comment
WhoAmI Posted March 2, 2014 Share Posted March 2, 2014 Just create vehicle and use Jesseunit's function. Everything in client side, so only client is able to see it. Link to comment
Karuzo Posted March 2, 2014 Author Share Posted March 2, 2014 Yeah i know that part, but how can i get the selected item ? Link to comment
WhoAmI Posted March 2, 2014 Share Posted March 2, 2014 Check gridlist functions on wiki. guiGridListGetSelectedItem Link to comment
Karuzo Posted March 2, 2014 Author Share Posted March 2, 2014 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 Citizen Posted March 2, 2014 Moderators Share Posted March 2, 2014 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
WhoAmI Posted March 2, 2014 Share Posted March 2, 2014 Any errors? And can I see your gridlist with added rows? Link to comment
Karuzo Posted March 2, 2014 Author Share Posted March 2, 2014 Yeah got it. But now it gives me an awkward error. 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
WhoAmI Posted March 2, 2014 Share Posted March 2, 2014 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. Link to comment
Karuzo Posted March 2, 2014 Author Share Posted March 2, 2014 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
WhoAmI Posted March 2, 2014 Share Posted March 2, 2014 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. Link to comment
Karuzo Posted March 2, 2014 Author Share Posted March 2, 2014 I don't understand what you mean Link to comment
WhoAmI Posted March 2, 2014 Share Posted March 2, 2014 I'd help you tomorrow morning. Link to comment
Jesseunit Posted March 2, 2014 Share Posted March 2, 2014 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. Link to comment
WhoAmI Posted March 3, 2014 Share Posted March 3, 2014 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
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