Jump to content

Drag'N'Drop


GIMPY73
 Share

Recommended Posts

Ok after going through the BMax tut's that Foolish converted , I started to play about with the Pick commands.

 

Now what i'm after is :

 

Select a cube with the mouse.

Attach the cube to the mouse's x,y,z coordinates while the mouse button is held.

Drop the cube when mouse button is released.

 

Here is what i have sofar:

 

'Use the Leadwerks Engine module as our base

Framework leadwerks.engine

'Create an OpenGL graphics window 
Graphics 800, 600

'Allows the engine to find files and load files from zip packages 
RegisterAbstractPath AppDir

'Create a world 
If Not CreateWorld() RuntimeError "Failed to create world."

'Create a camera 
cam:TCamera = CreateCamera()
CameraClearColor(cam, Vec4(0, 0, 1, 1))
MoveEntity cam, Vec3(0, 20, - 35)

'create a ligt
light:TLight = CreateDirectionalLight()
RotateEntity(light, Vec3(65, 45, 0))

'Create a render Buffer
buffer:TBuffer = CreateBuffer(800, 600, BUFFER_COLOR | BUFFER_DEPTH | BUFFER_NORMAL)

'create a mesh
cube:TMesh = CreateCube()

Local pick:TPick

'create materials
selectionmaterial:TMaterial = CreateMaterial()
SetMaterialColor(selectionmaterial, Vec4(1, 0, 0, 1))

pointentity cam , cube
'Main loop 
While Not KeyHit(KEY_ESCAPE) 

'pick objects with the mouse
If MouseDown(1)
	PaintEntity(cube, 0)

	pick = CameraPick(cam, Vec3(MouseX(), MouseY(), 1000))

	If pick Then
		PaintEntity(pick.entity, selectionmaterial)
		positionentity (pick.entity , vec3(pick.x,0,pick.z))
	End If

End If

'Update timing, physics, and other miscellaneous updates 
UpdateWorld

'Draw the world 
SetBuffer(buffer)
RenderWorld

'render lighting
SetBuffer(BackBuffer())
RenderLights(buffer)


'Swap the graphics buffers so we can see what we drew 
Flip
Wend

 

It kinda works , but the cube keeps letting go , even if i still have the mouse button held down???

 

 

Any ideas :D

 

Thanks

Gimpy73 :)

Link to comment
Share on other sites

This maybe of help

 

 

I'll have a run through your code in a few :)

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

You might need to press the mouse button with both hands.

 

 

No just move the mouse really .. really slowly :P

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

You can also stop taking a new pick in each loop, since it will sometimes grab nothing and then the box falls down and may get damaged:

        If MouseDown(1)
               PaintEntity(cube, 0)

               If Not pick Then pick = CameraPick(cam, Vec3(MouseX(), MouseY(), 1000))

               If pick Then
                       PaintEntity(pick.entity, selectionmaterial)
                       positionentity (pick.entity , vec3(pick.x,0,pick.z))
               End If
       Else
               pick = Null                
       End If

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

but a single pick will only create one new position to move to and then only if the distance the cursor is moved still keeps the pick on the cube then another click will have to be made surely? The problem seems to be the method for picking and the speed the mouse cursor moves in Gimpys original code.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Yep thats what is happening MG :)

 

Maybe i need to add somit about the mouse speed ??

 

Anyway thanks for looking :)

 

@Lumooja

I'll try holding the mouse button down with 2 hands lol :)

 

Thanks

Gimpy73 :P

Link to comment
Share on other sites

Yep thats what is happening MG :P

 

Maybe i need to add somit about the mouse speed ??

 

 

 

Well think about the pick, if its not on the cube then no pick results.

 

This can be seen in this slight alteration to your code:

 

 

'Use the Leadwerks Engine module as our base

Framework leadwerks.engine

'Create an OpenGL graphics window 
Graphics 800, 600

'Allows the engine to find files and load files from zip packages 
RegisterAbstractPath AppDir

'Create a world 
If Not CreateWorld() RuntimeError "Failed to create world."

'Create a camera 
cam:TCamera = CreateCamera()
CameraClearColor(cam, Vec4(0, 0, 1, 1))
MoveEntity cam, Vec3(0, 20, - 35)

'create a ligt
light:TLight = CreateDirectionalLight()
RotateEntity(light, Vec3(65, 45, 0))

'Create a render Buffer
buffer:TBuffer = CreateBuffer(800, 600, BUFFER_COLOR | BUFFER_DEPTH | BUFFER_NORMAL)

'create a mesh
cube:TMesh = CreateCube()
ScaleEntity(cube,Vec3(2,2,2))

ground:TMesh = CreateCube()
ScaleEntity(ground,Vec3(40,0.01,40))
PositionEntity(ground,Vec3(0,-2,0))

Local pick:TPick

'create materials
selectionmaterial:TMaterial = CreateMaterial()
SetMaterialColor(selectionmaterial, Vec4(1, 0, 0, 1))

pointentity cam , cube
'Main loop

Global loctite:Int = 1

While Not KeyHit(KEY_ESCAPE) 

       If MouseDown(1)
               PaintEntity(cube, 0)
			PaintEntity(ground, 0)

           	pick = CameraPick(cam, Vec3(MouseX(), MouseY(), 1000))

               	If pick
                       PaintEntity(pick.entity, selectionmaterial)
                       positionentity (pick.entity , vec3(pick.x,0,pick.z))
               	End If               
       End If

       'Update timing, physics, and other miscellaneous updates 
       UpdateWorld

       'Draw the world 
       SetBuffer(buffer)
       RenderWorld

       'render lighting
       SetBuffer(BackBuffer())
       RenderLights(buffer)


       'Swap the graphics buffers so we can see what we drew 
       Flip
Wend

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

if you turn the pick off you are no longer getting getting a new position to move the cube to. You could use the pick to maybe select the cube but then use something like CameraProject to create world cordinates from the mouse pointer and move the cube to that position?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

will try CameraProject

 

not really looked into it but I think cameraproject takes 2D to 3D.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Ok had a play with CameraProject , aint gota clue what im doing lol

 

'Use the Leadwerks Engine module as our base

Framework leadwerks.engine

'Create an OpenGL graphics window 
Graphics 800, 600

'Allows the engine to find files and load files from zip packages 
RegisterAbstractPath AppDir

'Create a world 
If Not CreateWorld() RuntimeError "Failed to create world."

'Create a camera 
cam:TCamera = CreateCamera()
CameraClearColor(cam, Vec4(0, 0, 1, 1))
MoveEntity cam, Vec3(0, 30, -10)

'create a ligt
light:TLight = CreateDirectionalLight()
RotateEntity(light, Vec3(65, 45, 0))

'Create a render Buffer
buffer:TBuffer = CreateBuffer(800, 600, BUFFER_COLOR | BUFFER_DEPTH | BUFFER_NORMAL)

'create a mesh
cube:TMesh = CreateCube()
sphere:TMesh = Createsphere()
positionentity sphere,vec3(0,10,0)

Local pick:TPick

'create materials
selectionmaterial:TMaterial = CreateMaterial()
SetMaterialColor(selectionmaterial, Vec4(1, 0, 0, 1))

pointentity cam , cube

debugphysics(1)

depth:Float = 0.0
near:Float = 1.0
far:Float = 10.0

'Main loop 
While Not KeyHit(KEY_ESCAPE) 

'pick objects with the mouse
If MouseDown(1)

	PaintEntity(cube, 0)
	PaintEntity(sphere, 0)

	pick = CameraPick(cam, Vec3(MouseX(), MouseY(), 1000))

	If pick Then
		PaintEntity(pick.entity, selectionmaterial)
		glReadPixels(MouseX(), GraphicsHeight() - MouseY(), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, Varptr(depth))
		z:Float = near / (far - depth * (far - near)) * far;
		pos:TVec3 = CameraProject(cam, Vec3(MouseX(), MouseY(), z))
		positionentity (pick.entity, Vec3(pos.x,pos.y,pos.z))
	End If

End If

'Update timing, physics, and other miscellaneous updates 
UpdateWorld

'Draw the world 
SetBuffer(buffer)
RenderWorld

DrawText "Depth: " + depth, 0, 0
DrawText "Projected: " + pos.x + ", " + pos.y + ", " + pos.z,0,12

'render lighting
SetBuffer(BackBuffer())
RenderLights(buffer)


'Swap the graphics buffers so we can see what we drew 
Flip
Wend

 

It seems to hold onto the mouse better , but it still don't seem right.

 

Thanks

Gimpy73 :P

Link to comment
Share on other sites

Not sure what it is you want to do with this but have a quick look at this thread on the old forum

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Cheers For the link MG , will take a look :)

 

I'm also going over Aggror's lua code again :)

 

I'm just after selecting a cube/sphere/model etc.. , then lock it to the mouse's X,Y,Z.

Then release the mouse button to place the cube/sphere/model etc..

 

The code i did kinda works , but as you've seen if the mouse is moved fast it lets go of the selected object.

 

Thanks

 

Gimpy73 :P

Link to comment
Share on other sites

This probably is a pick-positionentity issue.

Remeber that pick is done on updateworld, so probably if you move fast it "lost" the the object, you should just do a pick, something like this:

 

Check if mousedown, check if a boolean pick is true, if not cast a raycast, if yes just position the object till you don't release the button (to do this you can simply put another boolean on top of loop and set it to false, if mouse is down you reset i to true, on the end of the loop you check that variable, if false put the pick to nulland release the object)

In this case you'll never lose the object.

Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10.

Link to comment
Share on other sites

Yeah something like this.. I haven't tested it.

 

'Use the Leadwerks Engine module as our base

Framework leadwerks.engine

'Create an OpenGL graphics window 
Graphics 800, 600

'Allows the engine to find files and load files from zip packages 
RegisterAbstractPath AppDir

'Create a world 
If Not CreateWorld() RuntimeError "Failed to create world."

'Create a camera 
cam:TCamera = CreateCamera()
CameraClearColor(cam, Vec4(0, 0, 1, 1))
MoveEntity cam, Vec3(0, 30, -10)

'create a ligt
light:TLight = CreateDirectionalLight()
RotateEntity(light, Vec3(65, 45, 0))

'Create a render Buffer
buffer:TBuffer = CreateBuffer(800, 600, BUFFER_COLOR | BUFFER_DEPTH | BUFFER_NORMAL)

'create a mesh
cube:TMesh = CreateCube()
sphere:TMesh = Createsphere()
positionentity sphere,vec3(0,10,0)

Local pick:TPick

'create materials
selectionmaterial:TMaterial = CreateMaterial()
SetMaterialColor(selectionmaterial, Vec4(1, 0, 0, 1))

pointentity cam , cube

debugphysics(1)

depth:Float = 0.0
near:Float = 1.0
far:Float = 10.0
'MODIFY
local pick:TPick = null

'Main loop 
While Not KeyHit(KEY_ESCAPE) 
       'MODIFY
       local check:int = false
       'pick objects with the mouse
       If MouseDown(1)
               'MODIFY
               check = true
               PaintEntity(cube, 0)
               PaintEntity(sphere, 0)
               'MODIFY
               if pick = null 
                       pick = CameraPick(cam, Vec3(MouseX(), MouseY(), 1000))
               endif

               If pick Then
                       PaintEntity(pick.entity, selectionmaterial)
                       glReadPixels(MouseX(), GraphicsHeight() - MouseY(), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, Varptr(depth))
                       z:Float = near / (far - depth * (far - near)) * far;
                       pos:TVec3 = CameraProject(cam, Vec3(MouseX(), MouseY(), z))
                       positionentity (pick.entity, Vec3(pos.x,pos.y,pos.z))
               End If

       End If

       'Update timing, physics, and other miscellaneous updates 
       UpdateWorld

       'Draw the world 
       SetBuffer(buffer)
       RenderWorld
       'MODIFY
       if check = flase then pick=null

       DrawText "Depth: " + depth, 0, 0
       DrawText "Projected: " + pos.x + ", " + pos.y + ", " + pos.z,0,12

       'render lighting
       SetBuffer(BackBuffer())
       RenderLights(buffer)


       'Swap the graphics buffers so we can see what we drew 
       Flip
Wend

Intel Corei7-6700, NVIDIA GeForce GTX 980, 32GB DDR4, W-10.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...