Jump to content

[Question] Animating dxDrawMaterialLine3D


kieran

Recommended Posts

Hey, so I know how to make a 3D image in the GTA world, but I want to animate it to turn like a gif, I don't know any way of doing this though...  Is there any suggestions/solutions to how I can move it when the client renders? 

Here is code to create the image

size = 3

local img = dxCreateTexture("circle.png") --The image

function createIMG()  -- x,y,z, targetx,targety,targetz,texture,width,color,lookx,looky,lookz
	x,y,z = -2329.3, -1605.6, 483.2 --Coordinates
	image = dxDrawMaterialLine3D (x, y, z, x+size, y, z+size/2,img, size, tocolor(255,255,255,255), x, y+10, z) --draw the image
  
--How would I rotate the image? 
end

addEventHandler("onClientRender", root, createIMG)

The only way I could think of is making the image an element somehow and then rotating it...  But I don't know how I'd do that, thanks for any advice/help. :D 

Link to comment

For it to rotate you need to use the lookAt args and and use sine and cosine to rotate around the x and y.

Also the way u calculated the size made the image oval and i fixed that.

local size = 3
local img = point(500,-1)
local rot = 0

function createIMG()
	local x,y,z = 
	local rx = math.sin(rot)*1
	local ry = math.cos(rot)*1
	dxDrawMaterialLine3D( x, y, z, x, y, z+size, img, size, -1, x+rx, y+ry, z )
	rot = rot +.01
end
addEventHandler("onClientRender", root, createIMG)

 

Link to comment
1 hour ago, kieran said:

@Mr.Loki Thanks, but I want it to rotate clockwise, not spin on the z axis...

Try this

local size = 1
local img = point(100,-1)
local rot = 0

function createIMG(dt)
	local x,y,z = getElementPosition( localPlayer )
	local rx = math.sin(rot)*size
	local rz = math.cos(rot)*size
	dxDrawMaterialLine3D( x-rx, y, 1+z-rz, x+rx, y, 1+z+rz, img, size*2, -1, x, y+1, 1+z )
	rot = rot +(.01*dt/17)
end
addEventHandler("onClientPreRender", root, createIMG)

 

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