Separating a line of cubes?

Blitz3D Forums/Blitz3D Programming/Separating a line of cubes?

JA2(Posted 2007) [#1]
Hi everyone, I'm in need of a bit of help...

I have a line of pickable cubes. I want to be able to click any of the cubes and have the others know that the line is broken. For example, say I click cubes 4 and 8, then cubes 1+2+3 will become a separate line, 5+6 will become a separate line, and cubes 9+10 will become a separate line.

The line doesn't have to do anything, just know that it's now separate. Just changing the colours of each cube in a line to match would be great :)

Thanks in advance for any help on this. Here's what I have so far:




Vertigo(Posted 2007) [#2]
If these are built in a chain, why not have two type fields, Previous_cube_state and Next_Cube_state. Point the handle's of the other objects to the prev and next fields. Then do a check for each cube in the chain. Have it check the previous then the next. Have a type field for each, Prev_broken and Next_broke true/false. Checking object x, if object x's next_cube_state's object type field for Broken = true then make the current object's type field broken = true. If that makes sense. If an entire chain never returns a broken =true then globally that chain is still intact.

Hope that helps.
Scott


Stevie G(Posted 2007) [#3]
Like this?

Graphics3D 640,480,0,2
SetBuffer BackBuffer()
SeedRnd MilliSecs()
HidePointer

Global Camera	= CreateCamera()
Global Light	= CreateLight()
Global Plane	= CreatePlane()
Global PlaneTex	= CreateTexture (64,64)

Color 0,0,100
Rect 0,0,64,64
Color 0,0,150
Rect 0,0,32,32
Rect 32,32,32,32
CopyRect 0,0,64,64,0,0,BackBuffer(),TextureBuffer(PlaneTex)

EntityTexture Plane,PlaneTex

Type Cube

	Field X,Y,Z,Mesh,Mark,Picked,Num
	Field Active

End Type

Local CE.Cube,A

For A = 1 To 10

	CE.Cube = New Cube
	CE\Mesh	= CreateCube()
	CE\Mark	= CreateCone()
	CE\X	= -10+A*2
	CE\Y	= 0
	CE\Z	= 15
	CE\Num	= A
	CE\Active = True
	
	PositionEntity CE\Mesh,CE\X,CE\Y,CE\Z
	ScaleEntity CE\Mesh,0.9,0.9,0.9
	EntityColor CE\Mesh,Rnd(100,200),Rnd(100,200),Rnd(100,200)
	EntityPickMode CE\Mesh,2

	PositionEntity CE\Mark,CE\X,CE\Y+2,CE\Z
	RotateEntity CE\Mark,180,0,0
	ScaleEntity CE\Mark,0.2,0.5,0.2
	EntityColor CE\Mark,0,255,0
	
Next


While Not KeyDown (1)

	If MouseHit (1)

		CameraPick (Camera,MouseX(),MouseY())
		
		If PickedEntity() <> 0
		
			For CE.Cube = Each Cube
			
				If PickedEntity() = CE\Mesh
				
					CE\Picked = True
					CE\Active = False
				
				EndIf
			
			Next
		
		EndIf

	EndIf

	For CE.Cube = Each Cube

		If CE\Picked = True
		
			EntityAlpha CE\Mesh,0.1
			EntityAlpha CE\Mark,0.1
		
		Else
		
			EntityAlpha CE\Mesh,1
			EntityAlpha CE\Mesh,1
		
		EndIf
	
	Next
	
	UpdateWorld
	RenderWorld
	
	For CE.Cube = Each Cube
	
		Color 0,0,255
	
		CameraProject Camera,CE\X,CE\Y,CE\Z
		Tx = ProjectedX()
		Ty = ProjectedY()
		
		Text Tx, Ty,CE\Num,True,True
		
		
		Color 0,128,0
		;link active
		If CE\Active
			;last
			l.cube = Before CE
			If l <> Null
				If l\Active 
					CameraProject Camera, l\X, l\Y, l\Z
					Line Tx, Ty, ProjectedX(), ProjectedY()
				EndIf
			EndIf
			;next
			n.cube = After CE 
			If n <> Null
				If n\Active 
					CameraProject Camera, n\X, n\Y, n\Z
					Line Tx, Ty, ProjectedX(), ProjectedY()
				EndIf
			EndIf
		EndIf
	
	Next
	
	Color 255,0,0
	Line MouseX()-10,MouseY(),MouseX()+10,MouseY()
	Line MouseX(),MouseY()-10,MouseX(),MouseY()+10
	
	Flip
	
Wend
End



JA2(Posted 2007) [#4]
Exactly what I wanted. Thanks guys :)