Speedy radar?

Blitz3D Forums/Blitz3D Programming/Speedy radar?

MadJack(Posted 2006) [#1]
So what's the general consensus on the best way to do radar?

I'm writing a tank game. I put together a radar routine (about a year ago) that uses line drawing (to a texture) for bullets and pre-rotated images for plotting tanks. There could be up to 50 or more plots within range at any one time. Needless to say, it's too slow.

So how are you all doing it?

I'm considering setting up a separate camera, creating temp meshes to represent tanks/bullets, taking a render and copying the render to a radar mesh. Seems like a lot of mucking around, but if I have a pre-made pool of plot shapes, it could be quite fast. Anyone else doing it this way?


Andy(Posted 2006) [#2]
Don't erase the texture, but instead update one or two objects each FPS.


Andy


Stevie G(Posted 2006) [#3]
Use a second camera, with a small viewport ... far away from the scene and have a proxy mesh (cubes ) for each tank & object which is parented to a pivot directly below the camera. Then just render this scene from above & copyrect to your texture.

Each time a tank moves ... move it's proxy by the same and that's about it.

Should be faster than writepixel etc...

Stevie


MadJack(Posted 2006) [#4]
Andy

Hmm - there'll be a fair number of plots and it's quite crucial that the radar show realtime info... If only B3d was quicker at drawing/copying images etc.. (and a rendertotexture option would be very useful)

StevieG
Yeah - I'll have to go with this approach. It won't be quite as simple as single boxes as I'll also have to display turrets, but same principle.

Thanks for the replies.


octothorpe(Posted 2006) [#5]
How about teeny-tiny quads on a single surface on your HUD - each quad representing one radar "blip"? I would imagine this would be faster than both drawing on textures and doing a second render.


Sir Gak(Posted 2006) [#6]
You can do a little 2D superimposed over the corner of your 3D scene. The images can just be simply DrawImage images or Rect command objects (unless you need the little radar map to be alpha-transparent) put on the scene AFTER you do your Renderworld command (slap the 2D stuff on the screen after all the 3D stuff is rendered).


MadJack(Posted 2006) [#7]
octothorpe

'How about teeny-tiny quads on a single surface on your HUD'

Aye - although a 2nd render cam has the advantage of being unaffected by changes to your main cam (e.g. camerarange, fog, geometry intersecting the view, etc...)

Sir Gak
DrawImage is simply too slow - mixing 2d/3d is never a good idea in terms of maintaining framerate.


Stevie G(Posted 2006) [#8]
This IS Tanks Universal we're talking about isn't it?

It'd be faster to use Octothorpes method.

No reason why you still can't use a second camerarender for the whole hud display which is outwith the play area. Depending on how you do it, it pmay not even be necessary to copyrect to a texturebuffer.

Stevie


MadJack(Posted 2006) [#9]
Stevie G
'This IS Tank Universal we're talking about isn't it?'


It is indeed.

I'm already using Sswift's GUIcode (I have SpriteCandy but can't stomach the work that'd be required to drop that in) so it makes sense to use that. I just wanted to see what ideas people had re radars.

(By the way, I'm on my way to releasing a 2 level playtest demo in the next few months)


RifRaf(Posted 2009) [#10]
Here I go ressurecting old posts again :) Madjack , what method did you end up using. Im at that point with TinyTanks. I was just going to use Sprite cany and superimpose imageobects onto the scene based on unit placements.


MadJack(Posted 2009) [#11]
RR

I wanted to be able to plot contacts + areas of influence onto a circular radar area and have them clip automatically.

In the end, I set up simple flat shapes + radar camera at a large distance from the level geometry. Whenever I updated an actor, I also updated the relative position/rotation of each corresponding 'radar plot object'. By moving the radar camera closer/further away, I can adjust the radar 'zoom' factor.

Three times each second I did a renderworld (radar camera)/copyrect to a 256x256 texture mapped onto a disc placed in front (upper left) of my main camera. Bit fiddly getting that all aligned etc..

Couple of things - I used Toms dx7test.dll for its rendertotexture ability. However I also included a safe mode that used blitz's native copyrect. Now that I'm using Xors, I can use its in-built rendertotexture function.

(If my radar had been square, I expect I could have saved some fps by doing a straight render viewport to screen).


Kryzon(Posted 2009) [#12]
Hey MadJack, could you show me a sample of how are you using the dx7test to utilize Render-To-Texture?


MadJack(Posted 2009) [#13]
Kryzon

Sorry - just looking at the code, I remember I chucked dx7test due to it conflicting with older ATI cards and causing BSODS. ATI 1550 cards in particular, so I've just used the vanilla blitz copyrect command in the end.

If I get the chance, I'll look up an earlier build though (at work at present)

	If TEX_RADAR = 0 Or FLAG_CUTSCENE <> 0 Then Return
	
	SetBuffer BackBuffer()
	CameraProjMode CAMERA,0;TURN OFF MAIN CAM
	CameraProjMode GUI_Camera,0
	CameraProjMode CAMERA_RADAR,1;TURN ON RADAR CAM
	
	RenderWorld
	CopyRect 0,0,256,256,0,0,BackBuffer(),TextureBuffer(TEX_RADAR)

	;SET ZOOM BY WHETHER IN TANK/ON FOOT
	If OBJ_DATA(GROUP_PLAYER,MEMBER_PLAYER,26) = 7;IN TANK
		CameraZoom     CAMERA_RADAR, 1.2
	Else
		CameraZoom     CAMERA_RADAR, 2.4;HALVE THE VIEW
	EndIf



Kryzon(Posted 2009) [#14]
Sure.

So far I haven't saw how one would use dx7test to accomplish Render-To-Texture, so if you have a sample for that, I'd appreciate.

Bye.


BLaBZ(Posted 2009) [#15]
another idea for radar....

Either a good idea or a really bad one...

Parent a camera above your player/main object

Use CameraProject to see/find the location of things to the camera

draw things as rec/images to camera..

How do you think that would work speed wise?


BLaBZ(Posted 2009) [#16]
Quick Mock up of the idea....

The "radar" camera is turned off, so its not rendering, but its still able to notice whether or not it's seeing objects

I'm on a pretty crap computer(@work) framerate doesn't seem to change with or without this radar effect, between 44 and 37 FPS

Graphics3D 800,600,16,2
SetBuffer BackBuffer()

;;keep track of frames per second
Global fpscount, fpstime,fps1
SeedRnd MilliSecs()

;;player camera
cam1 = CreateCamera()
PositionEntity cam1,0,4,-10
;;a light!
light1 = CreateLight()


;;player character
Global sphere1 = CreateSphere()
PointEntity cam1,sphere1
EntityParent cam1,sphere1

;;the radar
Global cam2 = CreateCamera()
PositionEntity cam2,0,10,0
PointEntity cam2,sphere1
CameraViewport cam2,10,10,110,110
EntityParent cam2,sphere1
;;Hide camera so we don't render objects in radar
CameraProjMode cam2,0

;;ground
Global plane1 = CreateGround( 100,100 )
PositionEntity plane1,0,-5,0


;;our balls
Type ball
	Field mesh
End Type 

;;lets make 300 of them
For x = 0 To 300
	aball.ball = New ball
	aball\mesh = CreateSphere()
	ScaleEntity aball\mesh,0.6,0.6,0.6
	PositionEntity aball\mesh,Rnd(-100,100),0,Rnd(-100,100)
Next





While Not KeyHit(1)

Movement()

UpdateWorld
RenderWorld

FPS()
RadarEffect()

Flip 0
Cls


Wend

;;simple controls
Function Movement()
	If KeyDown(203) Then MoveEntity sphere1,-1,0,0
	If KeyDown(205) Then MoveEntity sphere1,1,0,0
	If KeyDown(200) Then MoveEntity sphere1,0,0,1
	If KeyDown(208) Then MoveEntity sphere1,0,0,-1
End Function

;;make a ground
Function CreateGround( x,z )
	ground = CreateMesh()	
	mesh = CreateSurface(ground)
	AddVertex(mesh,-x,0,z,0,1);;top left
	AddVertex(mesh,x,0,z,1,1);;top right
	AddVertex(mesh,-x,0,-z,0,0);;bottom left
	AddVertex(mesh,x,0,-z,1,0);;bottom right
	AddTriangle(mesh,0,1,2)
	AddTriangle(mesh,2,1,3)
	EntityFX ground,1
	EntityColor ground,100,100,150
	Return ground
End Function 

;;keep track of our frames per second
Function FPS()
	fpscount=fpscount+1
	If MilliSecs()>fpstime Then 
		fpstime=MilliSecs()+1000
		fps1=fpscount
		fpscount=0
	EndIf 
	Color 255,255,255
	Text 720,10,"FPS: "+ fps1
End Function

;;draw a rectangle whereever there is a ball
Function RadarEffect()

;;radar color
Color 0,0,100
Rect 10,10,110,110

	For aball.ball = Each ball
		;;if entity can be seen by our invisible camera, draw it to radar
		If EntityInView(aball\mesh,cam2)
			CameraProject cam2,EntityX#(aball\mesh),EntityY#(aball\mesh),EntityZ#(aball\mesh)
			Color 255,0,0	
			Rect ProjectedX#() + 5,ProjectedY#() + 5,10,10
		EndIf
	Next
	
;;create green square to represent player
Color 0,255,0
Rect 60,60,10,10
End Function



Blitzplotter(Posted 2009) [#17]
Very impressive code Kryzon, I tried something along these lines and failed. Can I suggest you submit this to the coding archives - it is an excellent piece of radar code if I say so myself.


Kryzon(Posted 2009) [#18]
Heh, I'm sure you've read the nicks wrong there, blitzplotter. I didn't write any code in this topic.

Bumping my previous question, can anybody out there demonstrate to me how to use Render-To-Texture feature from the Dx7test DLL?


Warner(Posted 2009) [#19]
I never tried it, but maybe this post here?
http://www.blitzbasic.com/Community/posts.php?topic=62050#693566


RifRaf(Posted 2009) [#20]
Thanks, i forgot to update my comments, but ive got a radar working. I just went the spritecandy route and made a radar layer.


Kryzon(Posted 2009) [#21]
Thanks Warner.