Move some cubes and save to file !?

Blitz3D Forums/Blitz3D Programming/Move some cubes and save to file !?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

hi !

I want to move some cubes and save the coordinates to a file - but somehow it doesn't work.

; ---------------------- 

Graphics3D 640,480 
SetBuffer BackBuffer() 

Global camera=CreateCamera() 
PositionEntity camera,0,0,-20 

light=CreateLight() 
RotateEntity light,0,0,90 
; GLOBAL --------------------------------------------------------------------------------------
Global centercone
Global moinsel

Global x#
Global y#
Global z#
;_______________________________________________________________________________________________

Type kubus

Field x
Field y
Field Z
Field Rot
Field Blau
Field Gruen
Field alpha#
End Type

Loadposition()


;Handle-----------------------------------------------------------------------------------------
centercone =CreatePivot() 
TurnEntity centercone,0,0,0
HideEntity centercone

LRcone=CreateCone (16,True,centercone)
TurnEntity LRcone,90,0,0
EntityColor LRcone,0,0,255
PositionEntity LRcone,0,0,4
EntityAlpha LRcone,.8
ScaleEntity LRcone,.5,.5,.5

UDcone=CreateCone (16,True,centercone)
TurnEntity UDcone,0,0,0
EntityColor UDcone,255,0,0
PositionEntity UDcone,0,4,0
EntityAlpha UDcone,.8
ScaleEntity UDcone,.5,.5,.5


FBcone=CreateCone (16,True,centercone)
TurnEntity FBcone,0,0,-90
EntityColor FBcone,0,255,0
PositionEntity FBcone,4,0,0
EntityAlpha FBcone,.8
ScaleEntity FBcone,.5,.5,.5
;------------------------------------------------------------------------------------------------MAINLOOP===========================

While Not KeyDown( 1 ) ;----------------------------------------------------------- Esc to end


cammode()

	If MouseHit(1)=True Then Anwahl()							;-----------------------------Left MouseButton to select cube

Moveit()


	If KeyHit(59)=True Then SavePosition()						;------------------------------Press F1 to save

RenderWorld 

;Display ----------------------- Show Coordinates
If moinsel<>0 
Text 0,40,"X: "+EntityX(moinsel)
Text 0,60,"Y: "+EntityY(moinsel)
Text 0,80,"Z: "+EntityZ(moinsel)

EndIf
;--------------------------------

Flip 

Wend 

End
;--------------------------------------------------------------------------------------------------MAINLOOP=========================

Function Cammode();---------------------------------------------------------------------- Cameramovement Keypad

If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0 
If KeyDown( 203 )=True Then TurnEntity camera,0,1,0 
If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.05 
If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.05 

End Function
;--------------------------------------------------------------------------------------------------
Function SavePosition()
	
cfgfile=WriteFile("Supergrabber.dat")
		
	
For moin.kubus=Each kubus
	
	
		WriteFloat(cfgfile, moin\x#)
		WriteFloat(cfgfile, moin\y#)
		WriteFloat(cfgfile, moin\z#)
	
Next	
	
	CloseFile(cfgfile)


End Function

Function Loadposition()
	If FileType("Supergrabber.dat")=1 Then ;-------------------------------------------------------- Check if file exist
	
	cfgfile=ReadFile("Supergrabber.dat")   ;-------------------------------------------------------- Load File	
	For a = 1 To 10
	moin.kubus = New kubus
	moin\x=ReadFloat(cfgfile)
	moin\y=ReadFloat(cfgfile)
	moin\z=ReadFloat(cfgfile)
	

	
	moin\Rot=Rnd(0,255)						;------------------------------------------------------- Random Color and alpha
	moin\Blau=Rnd(0,255)
	moin\Gruen=Rnd(0,255)
	moin\alpha#=Rnd(0.2,1)
	Wuerfel= CreateCube ()
		PositionEntity Wuerfel,moin\x,moin\y,moin\z
		EntityColor Wuerfel,moin\Rot,moin\Gruen,moin\Blau
		EntityAlpha Wuerfel,moin\alpha#
		EntityPickMode Wuerfel,3

	Next

	
		CloseFile(cfgfile)
	
	Else								  ;-------------------------------------------------------- If no such File - create random cubes
	
	For a = 1 To 10

	moin.kubus = New kubus

	moin\x=Rnd(-10,10)
	moin\y=Rnd(-10,10)
	moin\z=Rnd(-10,10)
	moin\Rot=Rnd(0,255)					   ;------------------------------------------------------- Random Color and alpha
	moin\Blau=Rnd(0,255)
	moin\Gruen=Rnd(0,255)
	moin\alpha#=Rnd(0.2,1)
	wuerfel= CreateCube ()
		PositionEntity Wuerfel,moin\x,moin\y,moin\z
		EntityColor Wuerfel,moin\Rot,moin\Gruen,moin\Blau
		EntityAlpha Wuerfel,moin\alpha#
		EntityPickMode Wuerfel,3
	Next
EndIf

End Function


Function anwahl()
	moinsel=	CameraPick(camera,MouseX(),MouseY())
	;------------------------------------------------------------------------------ Displays the handle, if a cube is select
	If PickedEntity()<>0 Then 
	
	
		PositionEntity centercone,EntityX(moinsel),EntityY(moinsel),EntityZ(moinsel)
		ShowEntity centercone
	Else HideEntity centercone
	EndIf
	

End Function

Function  moveit()


	If PickedEntity()<>0 ;Then 
	;------------------------------------------------------------------------------- Numpad to move cube
	If KeyDown(72)=True Then TranslateEntity moinsel,0,0,.5			
	If KeyDown(80)=True Then TranslateEntity moinsel,0,0,-.5
	If KeyDown(75)=True Then TranslateEntity moinsel,-.5,0,0
	If KeyDown(77)=True Then TranslateEntity moinsel,.5,0,0
	If KeyDown(78)=True Then TranslateEntity moinsel,0,.5,0
	;------------------------------------------------------------------------------- +/- = Up/Down
	If KeyDown(74)=True Then TranslateEntity moinsel,0,-.5,0
	If KeyDown(76)=True Then TurnEntity moinsel,0,.5,0
	;------------------------------------------------------------------------------- Numpad 5 to rotate cube
	If KeyDown(199)=True Then RotateEntity moinsel,0,0,0		
			
	;------------------------------------------------------------------------------- Position the handle 		
		PositionEntity centercone,EntityX(moinsel),EntityY(moinsel),EntityZ(moinsel)
		ShowEntity centercone


	EndIf 
	
	
End Function

.