noobs & PointEntity

BlitzMax Forums/MiniB3D Module/noobs & PointEntity

MaximilianPs(Posted 2008) [#1]
it's a bit complex to explane it but i'll try.

i've a series of 5 planets placed in line
actually those are defined as object, and are an array.
i've placed the camera a bit distant to see all planets, but i wish that on the mouse click the camera zoom on the picked entity.

to made this i've made a function "CameraMover"
Function CamMover:Int(cam:TCamera, X:Int , Y:Int , Z:Int,target:TEntity, Speed:Int=5) 
	'================== X =========================================================
	Local vX:Int, vY:Int, vZ:Int
	PointEntity(cam, target)
	If EntityX(cam) < X Then
		vX= X - EntityX(Cam) 
		If vX => speed Then
			PositionEntity (cam , EntityX(Cam) + speed , EntityY(Cam) , EntityZ(Cam) )
		End If
	Else	
		vX = EntityX(Cam) - X
		If vX => speed Then
			PositionEntity (cam , EntityX(Cam) - speed , EntityY(Cam) , EntityZ(Cam) )
		End If
	End If
	'================== Y =========================================================
	If EntityY(cam) < Y Then
		vY = Y - EntityY(Cam) 
		If vY => speed Then
			PositionEntity (cam , EntityX(Cam), EntityY(Cam) + speed , EntityZ(Cam) )
		End If
	Else	
		vY = EntityY(Cam) - Y
		If vY => speed Then
			PositionEntity (cam , EntityX(Cam), EntityY(Cam) - speed , EntityZ(Cam) )
		End If
	End If
	'================== Z =========================================================
	If EntityZ(cam) < Z Then
		vZ = Z - EntityZ(Cam) 
		If vZ => speed Then
			PositionEntity(cam , EntityX(Cam), EntityY(Cam) , EntityZ(Cam) + speed )
		End If
	Else	
		vZ = EntityZ(Cam) - Z
		If vZ => speed Then
			PositionEntity (cam , EntityX(Cam), EntityY(Cam) , EntityZ(Cam) - speed)
		End If
	End If
	DebugLog "vx:"+ vX +" vY:"+ vY +" xZ:"+ vZ
	If vX <= speed And vY <= speed And vZ <= speed Then
		Return 1
	Else
		Return 0
	End If
End Function

the function will return 1 when meet the destination.
It will be placed on the main loop, so the user will see the camera movement and will fly through the solar system.

i've to say also that i've declared a properties mesh on the object planets so i can reach it when i need, just like in this case.

Type tPlanet 
	Field ID:Int
	Field Name:String

	Field posX:Int
	Field posY:Int
	Field posZ:Int
	
	Field mass:Int					'planet size
	Field mesh:TEntity
        ...


and then the main code, inside the loop there is a check
if the user click on a planet moveCamera will be = 1 and then ...
If moveCamera = 1 Then
	If camMover(cam , camDest.X, camDest.Y , camDest.Z, Planet[Int(EntityName(entityPickata) )].mesh , 20) = 1 Then MoveCamera = 0
End If


but the problem is with PointEntity 'cause i get a Null object error.
Unhandled Exception:Attempt to access field or method of Null object

i hate this error <_<'


simonh(Posted 2008) [#2]
Either your camera or object doesn't exist when you call PointEntity.


MaximilianPs(Posted 2008) [#3]
camera as been created out of the main cycle and
same is for the planets, I've made it just to avoid that kind of problems :-\


MaximilianPs(Posted 2008) [#4]
'====================================================== 3D Setup ====	
Graphics3D 1000 , 800 , 32 , 0
'Dither True
AntiAlias True
'====================================================== Light =======
	Local light:TLight = CreateLight(2)
	LightRange light , 200000
	AmbientLight 10,10,10
'====================================================== Camera ======
	Global cam:TCamera = CreateCamera() 
	'CameraFogMode cam,1
	'CameraFogRange cam,0,1000
	'========== CAM =============
	Local camX:Int  =  -1800 	'\___ all'alngolo 45°
	Local camY:Int  =	2500		'/
	Local camZ:Int  =	4150
	Local pitch:Int =	  21
	Local yaw:Int   =	-130
	Local roll:Int  =	   0
	Local zoom:Float  =    1.0
	Local mode:Int  =    1
	Local modeDesc:String = "Perspective"

	Local cam_range:Int = 500000
	
	PositionEntity cam , camX , camY , camZ
	RotateEntity cam , pitch , yaw , roll
	CameraRange cam,1,cam_range
	CameraProjMode cam , mode

	Global moveCamera:Int = 0	  	' this is for the camera movement
	Global camDest:tDest			' this is an object to save the coords for the 
	camDest = New tDest				' camera destination... 


	usrSys.drawSystem(usr.SystemID) 	' this generate the planets, by reading a database

'======================================================= CICLO PRINCIPALE ==============
	
While Not KeyDown(KEY_ESCAPE)		
'	keyReset() 
	
	RenderWorld
	
	Local entityPickata:tEntity = PickedEntity()
	If(entityPickata <> Null) 
		If MouseHit(1) Then
			moveCamera = 1
			camDest.X = EntityX(entityPickata, True)
			camDest.Y = EntityY(entityPickata, True)
			camDest.Z = EntityZ(entityPickata, True)
			camDest.Name = Pianeta[Int(EntityName(entityPickata) )].name
		End If
	End If

	If moveCamera = 1 Then
		If camMover(cam , camDest.X, camDest.Y , camDest.Z, Pianeta[Int(EntityName(entityPickata) )].mesh , 20) = 1 Then MoveCamera = 0
	End If
Wend
End 


ok here is, in short words what the maincode are
the drawSystem have a method that will create the 5 planets


klepto2(Posted 2008) [#5]
In this code you never call a CameraPick, so EntityPickata is always Null.

Maybe this code helps you (its a bit buggy due to fast production) ;)




MaximilianPs(Posted 2008) [#6]
oh that's good thx alot :)