drag n' drop?
Blitz3D Forums/Blitz3D Programming/drag n' drop?
| ||
Can someone show me a quick example of how to drag and drop an object up,down,left,right if u hold control and allow it to drag and drop anywhere on the screen if not holding control? any HELP is greatly appreciated, any ignorance is ignored |
| ||
3d or 2d? |
| ||
3d |
| ||
It's a tough one. In this situation you really need to move the mesh to where the mouse pointer is. Which means doing a camera pick every frame, and getting the resulting picked X Y and Z. You will need to move your mesh to this position. So, what i di for my editor, is summit like this: CameraPick(camera,MouseX(),MouseY()) move_waypoints(PickedX()-EntityX(waypoint(waypoint_cursor,1)),0,PickedZ()-EntityZ(waypoint(waypoint_cursor,1))) It looks a little much there, but your simply moving the mesh to the PickedX() PickedY() and PickedZ() co-ords, so it would probably simplify to : CameraPick(camera,MouseX(),MouseY()) PositionEntity mesh,PickedX(),PickedY(),PickedZ() Now, you need something to pick against, like a flat surface works best. What axis are you looking to move the mesh along though? What i do, is have a plane i pick against. That gives me a flat surface. You simple make it invisible with EntityAlpha 0. But you need to make it pickable with: EntityPickMode plane,2 You'll also need to rotate the plane to where you need it to be, to pick against. |
| ||
Small example to demonstrate. You will probably need to take an offset value, from the click, as the moving the mesh to the mouse's co-ords tends to snap the mesh to it's centre. If you run this, you'll know what i mean: Notice the dark blue plane, that the code is picking against, to get the co-ords. Graphics3D 800,600 SetBuffer BackBuffer() Global camera = CreateCamera() PositionEntity camera,0,0,-15 Global player = CreateCone() EntityPickMode player,2 Global pick_plane = CreatePlane() EntityColor pick_plane,0,0,128 EntityPickMode pick_plane,2 EntityAlpha pick_plane,0.3 RotateEntity pick_plane,-90,0,0 Global mode = 0 ; 0 = nothing picked ; 1 = mouse currently being held down While Not KeyHit(1) If MouseDown(1) If mode = 0 Then CameraPick(camera,MouseX(),MouseY()) If PickedEntity() = player Then EntityPickMode player,0 mode = 1 End If ElseIf mode = 1 Then If KeyDown(29) Then CameraPick(camera,MouseX(),MouseY()) PositionEntity player,PickedX(),PickedY(),PickedZ() End If End If ElseIf MouseDown(1) = False If mode = 1 Then mode = 0 EntityPickMode player,2 End If End If UpdateWorld RenderWorld Text 0,0,mode Text 0,10,"x = "+PickedX()+" y = "+PickedY()+" z = "+PickedZ() Flip Wend End |
| ||
ok. how do i make it so when im not holding down control, it allows u to move it in 3d? like instead of up,down,left,right, it moves it left,right,forward, and backward only when control isnt being held? Graphics3D 800,600,0,2 SetBuffer BackBuffer() Global camera = CreateCamera() CameraRange camera,1,1000000000 PositionEntity camera,0,1,-5 Global player = CreateCone() PositionEntity player,0,1,0 EntityPickMode player,2 Global pick_plane = CreatePlane() EntityColor pick_plane,0,0,128 EntityPickMode pick_plane,2 ;EntityAlpha pick_plane,0.3 ;RotateEntity pick_plane,-90,0,0 Global mode = 0 ; 0 = nothing picked ; 1 = mouse currently being held down ; Create a blank image that is 32 pixels wide and 32 high with 10 frames of 32x32 Global gfxStarfield=CreateTexture(2048,1024,0,10) ; loop through each frame of the graphic we just made For t = 0 To 9 ; Set the drawing buffer to the graphic frame so we can write on it SetBuffer TextureBuffer(gfxStarfield,t) ; put 50 stars in the frame at random locations For y = 1 To Rnd(1000000) Plot Rnd(TextureWidth(gfxStarfield)),Rnd(TextureHeight(gfxStarfield)) Next Next SetBuffer BackBuffer() Global cube=CreateCube() ScaleEntity cube,1000000,1000000,1000000 EntityTexture cube,gfxStarfield FlipMesh cube While Not KeyHit(1) MoveEntity camera,0,(KeyDown(44)-KeyDown(45))*1,0 MoveEntity camera,0,0,(KeyDown(200)-KeyDown(208))*1 TurnEntity camera,0,(KeyDown(203)-KeyDown(205))*1,0 If MouseDown(1) If mode = 0 Then CameraPick(camera,MouseX(),MouseY()) If PickedEntity() = player Then EntityPickMode player,0 mode = 1 End If ElseIf mode = 1 Then If KeyDown(29) Then CameraPick(camera,MouseX(),MouseY()) PositionEntity player,PickedX(),PickedY(),PickedZ() End If End If ElseIf MouseDown(1) = False If mode = 1 Then mode = 0 EntityPickMode player,2 End If End If UpdateWorld RenderWorld Text 0,0,mode Text 0,10,"x = "+PickedX()+" y = "+PickedY()+" z = "+PickedZ() Flip Wend End |
| ||
also. yea. sorry about the star field. i wanted to make it huge like space so yea. |
| ||
I'm not sure i follow your request? |
| ||
ok. so instead of using the mouse to move the object up/down/left/right and if ur finger isnt holding down control key, and u have selected the object, then move the object forward instead of up, and backward instead of down :) the control key is just fine :) |
| ||
u know, like ONLY IF u tilt the camera to point down AT the plane and object, it moves it forward, backward, left and right ONLY if ur not holding control, and ur mouse is down. BUT if u hold control and ur NOT tilting, and ur mouse is down, it does what u have it do when holding down control already :) |
| ||
I have no idea what you mean, sorry. In your example, your not moving the object up and down., your moving it forwards/backwards/left/right, along the plane. |
| ||
right. so instead of moving like this: Player = X Plane = Y X X X YXY YXY YYY it moves LITERALLY up into cyber space, instead of forward. u know, like say u were going to jump? like that. but ONLY when the control key is NOT held down. i have a pic that may help |
| ||
heres the pic: ![]() sorry for the delay. now if i were able to draw a straight forward arrow along w/ the up arrow, i would. |
| ||
Ah right. Well, you'd just create another pick plane, and position it along where you want the entity to move. |
| ||
cant i do anything with entitypick, camerapick, or pickx()y, and z? |
| ||
something close to: Graphics3D 800,600,0,2 SetBuffer BackBuffer() Global camera = CreateCamera() CameraRange camera,1,1000000000 PositionEntity camera,0,1,-5 Global player = CreateCone() PositionEntity player,0,1,0 EntityPickMode player,2 Global pick_plane = CreatePlane() EntityColor pick_plane,0,0,128 EntityPickMode pick_plane,2 ;EntityAlpha pick_plane,0.3 ;RotateEntity pick_plane,-90,0,0 Global mode = 0 ; 0 = nothing picked ; 1 = mouse currently being held down Global tilt = 0 ; 0 = camera isnt tilted ; 1 = camera is tilted ; Create a blank image that is 32 pixels wide and 32 high with 10 frames of 32x32 Global gfxStarfield=CreateTexture(2048,1024,0,10) ; loop through each frame of the graphic we just made For t = 0 To 9 ; Set the drawing buffer to the graphic frame so we can write on it SetBuffer TextureBuffer(gfxStarfield,t) ; put 50 stars in the frame at random locations For y = 1 To Rnd(1000000) Plot Rnd(TextureWidth(gfxStarfield)),Rnd(TextureHeight(gfxStarfield)) Next Next SetBuffer BackBuffer() Global cube=CreateCube() ScaleEntity cube,1000000,1000000,1000000 EntityTexture cube,gfxStarfield FlipMesh cube While Not KeyHit(1) If KeyHit(44) tilt = 1 If KeyHit(45) tilt = 0 If tilt = 1 rx# = rx# + .1 ry# = EntityYaw(camera) rz# = EntityRoll(camera) EndIf If(rx# Or ry# Or rz#) < -360 Then rx#=0:ry#=0:rz#=0 If rx# < -30 Then rx# = -30 If rx# > 30 Then rx# = 30 If(ry# Or rz#) > 360 Then rx#=0:ry#=0:rz#=0 If tilt Then RotateEntity camera,rx#,ry#,rz# If Not tilt If rx# = 30 rx# = rx# - .1 EndIf EndIf MoveEntity camera,0,(KeyDown(30)-KeyDown(31))*1,0 MoveEntity camera,0,0,(KeyDown(200)-KeyDown(208))*1 TurnEntity camera,0,(KeyDown(203)-KeyDown(205))*1,0 If MouseDown(1) If mode = 0 Then CameraPick(camera,MouseX(),MouseY()) If PickedEntity() = player Then EntityPickMode player,0 mode = 1 End If ElseIf mode = 1 Then If KeyDown(29) Then If tilt = 1 mode = 1 CameraPick(camera,MouseX(),MouseY()) PositionEntity player,PickedX(),PickedY(),PickedZ() Else If tilt = 0 CameraPick(camera,MouseX(),MouseY()) PositionEntity player,PickedX(),PickedY(),PickedZ() End If End If End If ElseIf MouseDown(1) = False If mode = 1 Then mode = 0 EntityPickMode player,2 End If End If UpdateWorld RenderWorld Text 0,0,mode Text 0,10,"x = "+PickedX()+" y = "+PickedY()+" z = "+PickedZ() Text 0,20,"tilt:"+tilt Text 0,30,"rx:"+rx# Text 0,40,"ry:"+ry# Text 0,50,"rz:"+rz# Flip Wend End also, how would i fix it so that if rx# > 0 and rx# <= 30 and tilt = 0 then rotateentity camera back to original position slowly? |
| ||
i cant figure out why its not subtracting to 0.. |
| ||
DSW...you should really indent your loops and If/Endif. It makes code WAY easier to read. for example: If Not tilt If rx# = 30 rx# = rx# - .1 EndIf EndIf If a = 100 a = 0 EndIf For b = 0 to num array[b] = b Next |
| ||
i cant figure out why its not subtracting to 0.. These lines are the issue. If(rx# Or ry# Or rz#) < -360 Then rx#=0:ry#=0:rz#=0 If(ry# Or rz#) > 360 Then rx#=0:ry#=0:rz#=0 They should be : if rx# <-360 or ry# < -360 or rz# < -360 then rx#=0:ry#=0:rz#=0 if ry# > 360 or rz# > 360 then rx# = 0 : ry# = 0 : rz# = 0 Even then, you are already limiting rx between -30 and 30 with the following lines so rx will never be < -360 : If rx# < -30 Then rx# = -30 If rx# > 30 Then rx# = 30 To simplify all 4 lines you could use .. If Abs( ry# ) > 360 Or Abs( rz# ) > 360 rx# = 0 : ry# = 0 : rz# = 0 If Abs( rx# ) > 30 rx# = Sgn( rx# ) * 30 |
| ||
ok. its still not moving it to 0..If Abs( ry# ) > 360 Or Abs( rz# ) > 360 rx# = 0 : ry# = 0 : rz# = 0 If Abs( rx# ) >= 30 rx# = Sgn( rx# ) * 30 If(ry# Or rz#) > 360 Then rx#=0:ry#=0:rz#=0 If tilt Then RotateEntity camera,rx#,ry#,rz# : Else tilt = 0 If Abs( rx# ) >= 30 If tilt=0 rx#=rx#-.1 EndIf EndIf |
| ||
I have no idea what you are trying to do, please explain explicitly. |
| ||
well. when u hit z key, it activates the tilt variable. which in turn tilts the camera to a certain degree before the camera stops, and tilt becomes 0 again. buts its not working. i used the x key to try to stop it but it didnt work. |