• Properly Sizing and Centering a Model in a DModelPanel
    5 replies, posted
Hey, I'm making a hud that requires I render the player's world model onto the hud. I'm having some trouble ensuring that I get a consistent look with all or most weapons. I would really appreciate any help anyone can give me here. [code] local modelPanel = LocalPlayer().modelPanel if not modelPanel then modelPanel = vgui.Create( "DModelPanel" ) LocalPlayer().modelPanel = modelPanel end local x = ScrW() - 300 local y = ScrH() - 280 modelPanel:SetSize( 500, 500 ) modelPanel:SetFOV( 110 ) modelPanel:SetPos( x, y ) modelPanel:SetModel( LocalPlayer():GetActiveWeapon():GetWeaponWorldModel() ) modelPanel:SetColor( Color( 0, 255, 0 ) ) function modelPanel:LayoutEntity( Entity ) return end local PrevMins, PrevMaxs = modelPanel.Entity:GetRenderBounds() modelPanel:SetCamPos(PrevMins:Distance(PrevMaxs) * Vector(0.75, 0.75, 0.5)) modelPanel:SetLookAt((PrevMaxs + PrevMins)/2) [/code] I'm pretty sure there was code somewhere to center anything in a DModelPanel like this but I just can't find it on the wiki anymore. Here's what it currently looks like [quote] [img]http://i.imgur.com/1EvqqPD.jpg[/img] [img]http://i.imgur.com/WV0HHoK.jpg[/img] [img]http://i.imgur.com/yO0rJ0W.jpg[/img] [img]http://i.imgur.com/rXBbt1W.jpg[/img] [/quote] and here's what the overall goal is (ignoring aspect ratio differences): [img]http://i.imgur.com/DT0q2tV.png[/img]
You'll probably have to play around with the CamPos, LookAt and FOV for each weapon and then store those values on the SWEP. You could use a DAdjustableModelPanel just to get the values quickly and then tweak them from there, though bear in mind DAdjustableModelPanel's rotation is gimbal-locked somehow. Trying to generate it automatically won't get very satisfying results since every model is different -- half of them don't even point in the same direction.
Yeah, remember that those icons are created manually for some reason
[QUOTE=gonzalolog;52455527]Yeah, remember that those icons are created manually for some reason[/QUOTE] Well, in this case they were made manually for 2002 reasons - but I know what you mean I'm very sure that there was code to center models arbitrarily in a view somewhere on the wiki but I can't find it now Also, if it's not possible how are spawn icons generated for custom models?
[QUOTE=a1steaksa;52455543]Well, in this case they were made manually for 2002 reasons - but I know what you mean I'm very sure that there was code to center models arbitrarily in a view somewhere on the wiki but I can't find it now Also, if it's not possible how are spawn icons generated for custom models?[/QUOTE] Spawn icons just try to fit the entire model in-frame. They don't care about how good it looks, what angle you're seeing it from or which way it's pointing.
You can always try use the position of it, instead of rotating using RenderBounds (as I tried renderbounds and it wouldnt let me resize it) But with this code, your model can be resized. [CODE] modelPanel:SetSize( 500, 500 ) modelPanel:SetFOV( 110 ) // To zoom in modelPanel:SetPos( 50, 50 ) modelPanel:SetModel( LocalPlayer():GetActiveWeapon():GetWeaponWorldModel() ) modelPanel:SetColor( Color( 0, 255, 0 ) ) function modelPanel:LayoutEntity( Entity ) return end local eyepos = modelPanel.Entity:GetPos() eyepos:Add( Vector( 0, 25, 25 ) ) // Play with me to rotate local PrevMins, PrevMaxs = modelPanel.Entity:GetRenderBounds() modelPanel:SetCamPos(eyepos-Vector(0,0,25)) // Play with me to rotate modelPanel:SetLookAt((PrevMaxs + PrevMins)/2)[/CODE]
Sorry, you need to Log In to post a reply to this thread.