Linepick/camerapick

Blitz3D Forums/Blitz3D Programming/Linepick/camerapick

I’m not sure if this is a bug which is why I’ve not posted in the bug section, yet at least. I’ve been doing some experiments and I’ve noticed that camerapick is much slower than a linepick even though it is over the same distance. I just wondered why this was the case as it’s surely very similar code within Blitz3D.

Remember that camerapick will go as far as the camera range is. Linepick has a distance parameter. Do you mean, if you send a linepick from the cameras co-ords and a camera pick and hit the same object, the camera pick is slower?

I also thought they are about the same in speed. Ross is correct, as soon as you pick "nothing" then it'll be the camera range, that may be a very long range. I usually put an invisible, meshflipped big cube around the camera, so camerapick will hit it instead of scanning until it reaches the horizon.

But if Camerapick is really slower for some reason, that would be strange.

I should have been more specific but I was in a rush. I know there's no range on a camerapick but I am picking things and at the same range so why the diffference?

I know this might sound daft, put have you set a pickmode for the item your picking? The reason i say, is you might think your picking something, but actually going straight through it.

Hmmmm, verrrrrrrrrry strange. lol. Basically, Linepick is extremely slow, compared to camerapick... odd or what?

Graphics3D 800,600
SetBuffer BackBuffer()


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


Global cube = CreateCube()
EntityPickMode cube,2

Global cube1 = CreateCube()
EntityPickMode cube1,2
PositionEntity cube1,2,0,-5



While Not KeyHit(1)

	Cls


	If MouseHit(1) Then
		CameraPick(camera,MouseX(),MouseY())
		If PickedEntity() <> 0 Then
			flag$="picked with camera pick!, time of = "+PickedTime()+" entity = "+PickedEntity()
			EntityColor PickedEntity(),Rnd(0,255),Rnd(0,255),Rnd(0,255)
		Else
			flag$="nothing picked..."
		End If
	ElseIf MouseHit(2) Then
		LinePick(0,0,-20,0,0,20)
		If PickedEntity() <> 0 Then
			flag$="picked with line pick!, time of = "+PickedTime()+" entity = "+PickedEntity()
			EntityColor PickedEntity(),Rnd(0,255),Rnd(0,255),Rnd(0,255)
		Else
			flag$="nothing picked..."
		End If
	End If
	
	UpdateWorld
	RenderWorld
	Text 0,0,flag
	Flip
Wend
End


I've done some more tests. The further you move the camera away, doesn't seem to affect the time much... It seems most of the extra time in linepick, is spent doing something other than picking... very strange...

indeed. is this the same with older versions of blitz too?

An incomplete Documentation and an incomplete test program may cause wrong conclusions...

What is 0.014 vs 0.019? hours? seconds as I believe you think? or millisecs?!
The docs don't tell...

So put
m=MilliSecs()

before the If Mousehit(1) line

and after
Endif
m2=millisecs()-m

plus
Text 0,15,m
Text 0,30,m2

before Flip

I have m2=0 ! Always. What means its less than 1 millisec
So what is it therefore: 0.014 is 14 microsecs ? In this case: Not a big reason to worry about, right?!
And no bug at all! And not extremely slow either.

So try this (1000 Picks and 3000 Rnds each loop!):
Graphics3D 800,600
SetBuffer BackBuffer()


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


Global cube = CreateCube()
EntityPickMode cube,2

Global cube1 = CreateCube()
EntityPickMode cube1,2
PositionEntity cube1,2,0,-5

cursor=CreateImage(20,20)
CameraClsColor camera,60,55,55
While Not KeyHit(1)

	m=MilliSecs()
	MFlag=0
	If MouseHit(1) Then
		For i=1 To 1000
			CameraPick(camera,MouseX(),MouseY())
			If PickedEntity() <> 0 Then
				flag$="picked with camera pick!, time of = "+PickedTime()+" entity = "+PickedEntity()
				EntityColor PickedEntity(),Rnd(0,255),Rnd(0,255),Rnd(0,255)
			Else
				flag$="nothing picked..."
			End If
		Next
		MFlag=1
	ElseIf MouseHit(2) Then
		For i=1 To 1000
			LinePick(0,0,-20,0,0,20)
			If PickedEntity() <> 0 Then
				flag$="picked with line pick!, time of = "+PickedTime()+" entity = "+PickedEntity()
				EntityColor PickedEntity(),Rnd(0,255),Rnd(0,255),Rnd(0,255)
			Else
				flag$="nothing picked..."
			End If
		Next
		MFlag=1
	End If
	m2=MilliSecs()-m
	If MFlag<>0
		lastm2=m2
	EndIf
	
	UpdateWorld
	RenderWorld
	Color 255,255,255
	Text 0,0,flag
	Text 0,15,m
	Text 0,30,m2
	Text 0,45,lastm2
	DrawBlock cursor,MouseX(),MouseY()
	Flip
Wend
End

In other words: If I didn't make a mistake, it picks 100s of entities without you being able to measure it with the millisecs() function...


Oh boy, I dared to do it again... bash me as usual
.

I asked about pickedtime() in the past and while the documentation states that it's the execution time I'm sure someone told me that it actually returns the time (0...1) based on interpolation between the pick starting and end points. e.g. If the entity was picked half way between the start and end point it would return .5.

I may be wrong though but worth considering.

Stevie

Interesting thought Stevie. And no RaGR, your input is very much welcome. Just personal insults aren't ;o) It was just a quick test as i had to rush out. You have a good point stevie. A similar problem arises with AnimTime(). It doesn't return the actual Animation Time, rather the current frame i believe.

[EDIT]
Ok, i've done some more testing. Looks like your stevie and RaGR. Thanks for that :o)

Yep, Stevie is correct about PickedTime() - it has nothing to do with the actual time the pick took to execute.

What a stupid error, and command name to use...

Yeah, I remember PickedTime had me scratching my head when I first tried using it. It's clear that whoever wrote the docs for the command didn't understand how it works, either. :/

Actually, I think I've only ever used the command once. You can (I think) use it to calculate the distance from the start of the pick to the picked point with PickedTime() * pick_length.