Cameras in lua?

Is there any place I can actually learn about how the cam library and how to actually put it to use? Ive checked out the tutorials on the Gmod Wiki, and done a bit of googleing, but it seems like there aren’t any actual tutorials to put this to work. It’d be much more useful to play with em firsthand…


It depends on what you mean by cam / cameras… The Start3D2D basically allows you to project from x dimension plane onto a y dimension plane. You can also easily convert from 3D to 2D by simply using a Vector and adding :ToScreen( ) to it ( it’ll return x, y ).

If you want to control the player camera, look at CalcView as Tolee says. I have a few examples but I’m curious… What is the end goal / what are you trying to do so we can better understand which way you’re swaying…

Probably something like a thirdperson feature, or moving shots of the map that aren’t from the player’s perspective in a gamemode, or something of the sort. I think that what I’m trying to do would be Calcview like Tolee said, and the cam library would be more useful for stuff like… I dunno, making a television broadcast system or something? Am I right?

Moving the player’s view ( thirdperson, etc ) is done inside CalcView. You could even use it to make the player’s view come from another thing.

The purpose the cam library is to enter a different rendering state from the one you are in - DModelPanel uses a 3d camera to render a 3d model inside a 2d control. The labels above most items in Stranded / DarkRP are done by creating a 2d camera to render 2d objects inside a 3d space, which is why 3D2D requires a position, normal, and scale.

To do something like a television or projector, where the player is seeing something that is happening elsewhere in the map, but from their own perspective, would be a combination of a render target and render.RenderView( camdata ). You’d set the render target to render to, open a viewport, and then call render.RenderView ( and then be a good citizen and end the viewport and revert the rendertarget ).