2 Cameras and Drawing lines

Blitz3D Forums/Blitz3D Beginners Area/2 Cameras and Drawing lines

Jamie(Posted 2004) [#1]
I wondered if it was possible to draw lines on to seperate cameras and have them show up on the display. I played around with using sprites as a HUD in my game, but they jumped around too much. So I would like to use line method on on camera that is fixed on the horizon and use lines on the second camera that shows everything that would follow the roll of the camera..

Any help would be greatly appreciated

Thanks

Jamie


Rob Farley(Posted 2004) [#2]
The way you use 2 cameras is:

Have the cameras a decent way apart, set your hud camera to no cls and set the camera range to bugger all.

hide hudcam
show camera
renderworld
show hudcam
hide camera
renderworld

The alternative to this is hide all your entities when rendering the hud cam then showing them all again, personally I think this is way too much like hard work.

Not sure what you're getting at with "I would like to use line method on camera" care to expand on that a touch?


Jamie(Posted 2004) [#3]
I am drawing a hud for a combat sim and it needs to be rendered in 2 parts. 1 that truns with the main camera (plane's view) and one that stays level with the horizon. Below is a mock up of how the 2 pieces fit together:

_ _
| ___ ___ |
| ___ ___ |
| _ _ _ _ |
| _ _ _ _ |
_| |_

The 2 outside lines follow the plane's camera and the lines on the inside need to stay even with the terrain asn the plan rolls. Again I tried using a sprite for the inside piece but it jumps around. So since I use line method to create the outside piece, I wondered if I could do that for the internal on also.


Thanks,

Jamie


Rob Farley(Posted 2004) [#4]
Explain Jumps around.

Are you just talking about how to get a line match the rotation of the cameraroll?

If that's the case:

x=graphicswidth()/2
y=graphicsheight()/2
line x+(sin(entityroll(camera)+180)*50),y+(cos(entityroll(camera)+180)*50),x+(sin(entityroll(camera))*50),y+(cos(entityroll(camera))*50)

That's totally untested so it probably won't work...


Rhyolite(Posted 2004) [#5]
As to your question about 2D lines, if I understand correctly, you can draw 2D commands 'on top' off your 3D world after you have rendered it. These 2D lines will be drawn to 2D screen co-ordinats NOT 3D world coordinates.

Renderworld() <-- Draw 3D stuff
Draw2DHud <-- Draw 2D stuff over the top
Flip <-- Display both 3D and 2D on screen

However, not sure this is best method of drawing an aircraft HUD - just answering, hopefully, a bit of your question. Drawing 2D can be slow and lower your FPS (but probably insignificant for a simple HUD). Also, I think using a quad (or maybe a sprite) would work better for a HUD as you were originaly trying to implement.

Rhy Out


GfK(Posted 2004) [#6]
I played around with using sprites as a HUD in my game, but they jumped around too much.
This happens when you position the sprites too close to the camera. You'll get the same effect even if you use two cameras.

Move the sprites further away and scale them up accordingly to solve the problem. I usually have them 180-200 units from the camera.

However, it *is* a good idea to render the HUD with a different camera. If you haven't done that and you ever need to use CameraZoom etc, you've had it, because zooming will affect the HUD as well.


Jamie(Posted 2004) [#7]
Thanks for all of the replies! I modified the code that Rob posted and everything seems to work as desired.

Gfk: I tried moving the sprite further away and modifying its scale, but it still occurs. I am using this in a LARGE project that I discussed yesterday with Rob. It is a combat simulator that has a mesh-based infinite terrain system, etc. Because of the specs for the application my camera range is somewhat large. I have worked to reduce it greatly and have gotten it to a realistic range now. I wondered if the speed I am traveling and the number of polys & surfaces I am rendering and the camera range, etc have anything to do with it. I cut my code and made a quick smaple app and it works like a champ all the time, but with the parameters of the combat sim, it jumps around too much.

Again, Thanks to All!

Jamie


GfK(Posted 2004) [#8]
Odd.

Have you parented all the HUD elements/sprites to the camera, or are you repositioning the whole thing manually?

hide hudcam
show camera
renderworld
show hudcam
hide camera
renderworld
That really isn't necessary. As long as the main camera was created before the HUD camera, you can render the whole lot in one go.