• Orthographic camera?
    4 replies, posted
I'm trying to make a top-view ortographic camera (a-la 90's games, e.g. The Sims), but I'm not having much luck. The wikis (new and old) don't help much. This is the code I have right now, it's completely experimental and just has a bunch of shit I've been throwing at it seeing if it works: [CODE]local function OriginCam() local CamData = {} --CamData.angles = Angle(90,LocalPlayer():EyeAngles().yaw,0) --local pos = LocalPlayer():GetPos()+Vector(2000,2000,2000) CamData.origin = LocalPlayer():GetPos()+Vector(200,200,200) CamData.angles = Angle(45,225,0) --CamData.angles = LocalPlayer():EyeAngles() --CamData.origin = pos --CamData.fov = 90 CamData.ortho = true CamData.znear = 0 CamData.zfar = 5000 CamData.x = 0 CamData.y = 0 CamData.w = ScrW() / 3 CamData.h = ScrH() / 3 pac.SkipRendering(true) render.RenderView(CamData) pac.ForceRendering(true) pac.SkipRendering(false) end hook.Add("HUDPaint", "OriginCam", OriginCam)[/CODE] (The PAC functions are irrelevant, they're just there to keep it working on both the HUD view and the normal view.) The result is plain black no matter what I do. A couple of questions, other than the fix for that: - What are the ortholeft, etc parameters? What should I put in them and what do they do? - A novice question, but how would I get the angles from one point to another? In Expression 2 I recall you can do that simply by subtracting two position vectors but that doesn't seem to be the case in Lua. Thanks in advance for the help.
This one will zoom in/out based on player speed. If you want the speed function to work, you'll need to add a clause for vehicle. If you want the camera to not rotate with the player, remove the LocalPlayer( ):EyeAngles( ).yaw portion [lua]local function TopDownCamera( ) local CamData = {} CamData.angles = Angle( 90, LocalPlayer( ):EyeAngles( ).yaw , 0 ) CamData.origin = LocalPlayer( ):GetPos( ) + Vector( 0, 0, math.Clamp( LocalPlayer( ):GetVelocity( ):Length( ) * 5, 1000, 4500 ) ) CamData.x = 0 CamData.y = 0 CamData.w = ScrW( ) // 5 CamData.h = ScrH( ) // 4 render.RenderView( CamData ) end[/lua] Edit: Tested yours, using CamData.ortho = true makes it black. pac is nil on my client.
I'm not really interested in making the camera zoom with speed, I just want ortographic projection to work. PAC is a server-side addon in a server I'm on, you can omit those lines. .ortho is the bug in question. The wiki defines it as being a proper parameter, but setting it true results in black. Did Garry break something again or are we just missing documentation?
[url]http://wiki.garrysmod.com/page/Classes/ViewData[/url] You're missing a few parameters. You don't have the clipping planes set: [lua] CamData.ortho = true CamData.ortholeft = 0; CamData.orthoright = 150; CamData.orthotop = 0; CamData.orthobottom = 150;[/lua]
[QUOTE=Acecool;41643037][url]http://wiki.garrysmod.com/page/Classes/ViewData[/url] You're missing a few parameters. You don't have the clipping planes set: [lua] CamData.ortho = true CamData.ortholeft = 0; CamData.orthoright = 150; CamData.orthotop = 0; CamData.orthobottom = 150;[/lua][/QUOTE] Aha, I saw those parameters but I couldn't figure out what they needed. This works perfectly, thank you very much.
Sorry, you need to Log In to post a reply to this thread.