Viewport dimensions

Blitz3D Forums/Blitz3D Programming/Viewport dimensions

_PJ_(Posted 2009) [#1]
Aside from libraries such as Blitz3D Plus etc.

Is there a means of determining if a 2D screen position (specifically the mouse cursor) is with in the boundaries of a particular camera's screen viewport?

Of course, I should know what MY viewport settings are, but I'm in the process of working on something for the Code archives which will hopefully be more generic.
Otherwise, I supposer I could just have some cnstants that need to be input by the user.


Guy Fawkes(Posted 2009) [#2]
idk.. try:

omx = nomx

nomx = mouse_x

mouse_x  = MouseX()

omy = nomy

nomy = mouse_y

mouse_y  = MouseY()

function screen(camera)

x# = projectedx(camera)-mouse_x
y# = projectedy(camera)-mouse_y

end function



Stevie G(Posted 2009) [#3]
You can't use cameraproject here so the above is nonsense!

As you're talking about purely 2d coords you have no option but to store the coords of the viewports as you create them and use a rectsoverlap to see which one is being selected. See below for example.

Graphics3D 800,600,32,1

Type CamT
	Field Camera
	Field x, y
	Field sx, sy
End Type

Global Cam1 = CAMERAcreate( 0,0,400,300 ) : CameraClsColor Cam1, 200,50,50
Global Cam2 = CAMERAcreate( 400,0,400,300 ) : CameraClsColor Cam2, 50,50,200
Global Cam3 = CAMERAcreate( 0,300,400,300 ) : CameraClsColor Cam3, 50,200,50
Global Cam4 = CAMERAcreate( 400,300,400,300 ) : CameraClsColor Cam4, 150,150,0

While Not KeyHit(1)

	ThisCamera = CAMERAselected( MouseX(), MouseY() )
	RenderWorld()
	
	Text MouseX(), MouseY(), "X", 1, 1
	Text 0,0, ThisCamera
	
	Flip
	
Wend

;=============================================================
;=============================================================
;=============================================================
	
Function CAMERAcreate( x, y, sx, sy )

	c.CamT = New CamT
	c\Camera = CreateCamera()
	CameraViewport c\Camera, x , y , sx , sy
	c\x = x
	c\y = y
	c\sx = sx
	c\sy = sy

	Return c\Camera	
	
End Function

;=============================================================
;=============================================================
;=============================================================

Function CAMERAselected( x, y )

	Found = 0

	For c.CamT = Each CamT

		If RectsOverlap( x, y, 1, 1, c\x, c\y, c\sx, c\sy )
			Found = c\Camera
		EndIf
		
	Next	
	
	Return Found

End Function



_PJ_(Posted 2009) [#4]
Yup, purely 2D, Stevie. Thanks for working on that.

I was afraid it wouldn't be possible, although I do feel it's quite strange in a way. Surely Blitz and its render must know and remember the dimensions of the viewport!

Oh well. As I said, it's no big deal for an individual, but in trying to create a generiic function for anyone to use, I guess I need to ensure the user gives the viewport dimensions in a Global or passed in as a parameter.

I never considered RectOverlap, though - Is that likely to be faster than, say checking individually X or Y < > dimensions?