Jump to content

[HELP] 3D Object moving with Cursor by axis


Steve Scott

Recommended Posts

Hey Community, 

My conception is that I want to move a random created object with the cursor along an axis.  I could create the axises with the function dxDrawLine3D and I made 3 rectangles on the end of the axis with dxDrawRectangle with help of getScreenFromWorldPosition(). A picture of it: l2CvJMw.png

My problem is that I can't find out the calculation which I could the object move with.  

Thanks for all the help!

Edited by tacsa
Link to comment
37 minutes ago, AlexRazor said:

I'd try something with OnClientRender, GetCursorPosition and SetElementPosition.

 

35 minutes ago, Dimos7 said:

Use onClientClick 

Thanks guys, but I'm not a beginner. I know how to get these things. I only need a calculation for the moving along the axises. 

Link to comment
  • Moderators
On 08/01/2019 at 18:03, tacsa said:

 

Thanks guys, but I'm not a beginner. I know how to get these things. I only need a calculation for the moving along the axises. 

See the first example of this page:

https://wiki.multitheftauto.com/wiki/GetElementMatrix

 

Maybe this:

https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPointAndSegment2D

(might need a 3D version of it)

 

And this:

function findClosestPointOf2Lines3D (line1X,line1Y,line1Z,line1VectorX,line1VectorY,line1VectorZ,line2X,line2Y,line2Z,line2VectorX,line2VectorY,line2VectorZ)
	
	local Vec1 = Vector3 (line1VectorX,line1VectorY,line1VectorZ)
	local Vec2 = Vector3 (line2VectorX,line2VectorY,line2VectorZ)
	
	local line1 = Vector3 (line1X,line1Y,line1Z)
	local line2 = Vector3 (line2X,line2Y,line2Z)
	
	local a = Vec1:dot(Vec1)
	local b = Vec1:dot(Vec2)
	local e = Vec2:dot(Vec2)
 
	local d = a*e - b*b
	
	if tostring(d) ~= "0.0f" then
		local r = line1 - line2
		local c = Vec1:dot(r)
		local f = Vec2:dot(r)
 
		local s = (b*f - c*e) / d
		local t = (a*f - c*b) / d
 
		local closestPointLine1 = line1 + Vec1 * s

		
		local x,y,z = vectorUnpack(closestPointLine1)

		return x,y,z
	end
	return false,false,false
end

function vectorUnpack(v)
    return v.x, v.y, v.z
end

 

Edited by IIYAMA
Link to comment
  • 2 months later...

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