Creating a selection box rectangle in Blitz3D?

Blitz3D Forums/Blitz3D Programming/Creating a selection box rectangle in Blitz3D?

Kozmi(Posted 2008) [#1]
Hi everyone,

Was just wondering if anybody would happen to know a good way to write a routine or function that will let a user use thier mouse to click in any given area and drag the mouse while the left mouse button is held down and create a selection rectangle box to a given size buy draging the mouse until' the user lets go of the left mouse button which would then create a rectangle. I already did a search here in the code archive and here on the forums.. But the only thing I found was written for the use of BlitzMax only!! Any help would be very much appreciated. Thank's everybody in advance for your kind help! :)


markcw(Posted 2008) [#2]
Did you see this?

http://www.blitzbasic.com/Community/posts.php?topic=57611

Ross C posted:

Graphics3D 800,600
SetBuffer BackBuffer()


Global camera = CreateCamera()
PositionEntity camera,0,5,-10
RotateEntity camera,45,0,0

Global light = CreateLight()

Global plane = CreatePlane()
PositionEntity plane,0,-0.5,0
EntityColor plane,100,255,100
EntityPickMode plane,2

Global sx = 0
Global sy = 0

Global st_x# = 0
Global st_z# = 0
Global fin_x# = 0
Global fin_z# = 0
Global mouse_down = 0

Type entity
	Field mesh
	Field selected
End Type

e.entity = New entity
e\mesh = CreateCube()
EntityColor e\mesh,0,100,0
e\selected = 0
PositionEntity e\mesh,3,0,3

e.entity = New entity
e\mesh = CreateCube()
EntityColor e\mesh,0,100,0
e\selected = 0
PositionEntity e\mesh,3,0,-3



While Not KeyHit(1)


	If MouseDown(1) Then
		If mouse_down = 0 Then
			mouse_down = 1
			CameraPick(camera,MouseX(),MouseY())
			st_x = PickedX()
			st_z = PickedZ()
			DebugLog("setting - "+st_x+","+st_z)
			sx = MouseX()
			sy = MouseY()
		End If
	Else
		If mouse_down = 1 Then
			CameraPick(camera,MouseX(),MouseY())
			fin_x = PickedX()
			fin_z = PickedZ()
			If fin_x < st_x Then
				temp# = st_x
				st_x = fin_x
				fin_x = temp
			End If
			If fin_z < st_z Then
				temp# = st_z
				st_z = fin_z
				fin_z = temp
			End If
			mouse_down = 0
			select_entity()
		End If
	End If
	
	UpdateWorld
	RenderWorld
	draw_bounding_box()
	Rect MouseX(),MouseY(),2,2
	Text 0,0,st_x+" , "+st_z
	Flip
Wend
End

Function draw_bounding_box()

	If mouse_down = 1 Then
		temp_sx = sx
		temp_sy = sy
		temp_fx = MouseX()
		temp_fy = MouseY()
			If temp_fx < temp_sx Then
				temp# = temp_sx
				temp_sx = temp_fx
				temp_fx = temp
			End If
			If temp_fy < temp_sy Then
				temp# = temp_sy
				temp_sy = temp_fy
				temp_fy = temp
			End If
		Rect temp_sx,temp_sy,temp_fx-temp_sx,temp_fy-temp_sy,0
	End If

End Function

Function select_entity()

	For e.entity = Each entity
		If EntityX(e\mesh) > st_x And EntityX(e\mesh) < fin_x Then
			If EntityZ(e\mesh) > st_z And EntityZ(e\mesh) < fin_z Then
				e\selected = 1
				EntityColor e\mesh,0,255,0
				DebugLog("selected!")
			Else
				e\selected = 0
				EntityColor e\mesh,0,100,0
			End If
		Else
			e\selected = 0
			EntityColor e\mesh,0,100,0
		End If
	Next
	
End Function



Kozmi(Posted 2008) [#3]
Hey thank's alot for your kind help markcw... You have just helped me out on this in a big way!! very much appreciated very much so!!:)


markcw(Posted 2008) [#4]
Hi jackzip8, glad to help, but you should probably thank Ross C, he's very helpful on this forum, has been since I can remember!