Hello, GLua Community.
I decided to have 3D transitions on 2D surface.
I spent many hours and sleepless nights to make it.
Last Result
There's some functions like EyePos(), EyeAngles() that helps me.
function cam.Create3D2D3D2D(posx,posy,sizex,sizey,scope,add,panel,filter,overridesize,angle,scale)
if panel then posx,posy = panel:GetPos() if !overridesize then sizex,sizey = panel:GetSize() end end
cam.Start3D(EyePos(),Angle()+(angle or Angle()),90,posx,posy,sizex,sizey)
cam.Start3D2D(EyePos()+
Vector(3.01,
math.floor((ScrW()/2-(sizex/2)))*(0.01975),
math.floor((ScrH()/2-(sizey/2)))*(0.0198)
) + (add or Vector()),
Angle(0,-90,90),0.0164+scale)
if filter then if filter != -1 then render.PushFilterMag(filter) end else render.PushFilterMag(TEXFILTER.NONE) end
if filter then if filter != -1 then render.PushFilterMin(filter) end else render.PushFilterMin(TEXFILTER.NONE) end
scope()
if filter != -1 then render.PopFilterMin() end
if filter != -1 then render.PopFilterMag() end
cam.End3D2D()
cam.End3D()
end
This function is using crazy constants and I need to set them manually for needed result.
posx,posy,sizex,sizey set size and pos of 3D Camera.
scope - render function, there i write draw.RoundedBox ,etc.
add - Additional Vector for correct position
panel - is a fast config for posx, posy, sizex and sizey
filter - is TEXFILTER
overridesize - undo useing panels size
angle - Additional Angle for rotating in 3D Env
scale - 3D2D Scale Add
As you can see, to make it work without manual iterruption is imposible there
For now i unserstand that math.floor((ScrW()/2-(sizex/2)))*(0.01975) and math.floor((ScrH()/2-(sizey/2)))*(0.0198) is wrong constants there.
What's wrong?
This
Position of 3D Camera changes viewpoint and 3D2D is moving out
____
I want to solve the issue together with community and share it there.
Thanks.
I think something similar happens if you use cam.PushModelMatrix in a panel paint function. One way around it is to manually draw the panel in HUDPaint or something similar. surface.DisableClipping may also be needed if you experience vertices disappearing.
Have you looked into using cam.PushModelMatrix()? it should be a lot easier than doing all of this math. Assuming all you want to do is rotate and skew in 2d.
I know about PushModelMatrix.
It will only rotate it, i need to move it on derma
matrix:Translate(0,0,forward_back) cam.PushModelMatrix(matrix) ?
However forward and back doesn't make sense in an orthographic perspective.
@CapsAdmin , So, it possible to create this by Matrix?
I made this by my cam.Create3D2D3D2D function:
Yes that should be possible. But I think I've missunderstood a little bit and I'm just talking about another way to achieve this.
But as I said, the issue is probably caused by drawing from within a panel. It may be possible to reverse though.
...Could the solution be this easy?
Check lua/vgui/dmodelpanel.lua they use a 3D space in the 2D render hook of the panel. Then they draw a model. The only difference is that they draw a model, and you're drawing 3D2D.
I noticed one major difference in your code from the dmodelpanel:
function PANEL:Paint( w, h )
if ( !IsValid( self.Entity ) ) then return end
local x, y = self:LocalToScreen( 0, 0 )
self:LayoutEntity( self.Entity )
local ang = self.aLookAngle
if ( !ang ) then
ang = ( self.vLookatPos - self.vCamPos ):Angle()
end
cam.Start3D( self.vCamPos, ang, self.fFOV, x, y, w, h, 5, self.FarZ )
render.SuppressEngineLighting( true )
render.SetLightingOrigin( self.Entity:GetPos() )
render.ResetModelLighting( self.colAmbientLight.r / 255, self.colAmbientLight.g / 255, self.colAmbientLight.b / 255 )
render.SetColorModulation( self.colColor.r / 255, self.colColor.g / 255, self.colColor.b / 255 )
render.SetBlend( ( self:GetAlpha() / 255 ) * ( self.colColor.a / 255 ) )
for i = 0, 6 do
local col = self.DirectionalLight[ i ]
if ( col ) then
render.SetModelLighting( i, col.r / 255, col.g / 255, col.b / 255 )
end
end
self:DrawModel()
render.SuppressEngineLighting( false )
cam.End3D()
self.LastPaint = RealTime()
end
They don't use EyePos or EyeAng. They use a static number which isn't relative to the player and which is set manually. And this makes sense, since the player isn't in this custom 3D space (which is what you create with cam.Start3D).
Try setting the the camera at some position in space, then use `ang = ( 3d2dOriginPos - vCamPos ):Angle()` to make the camera point at the 3d2d you're about to render. Then render the 3d2d.
Also CapsAdmin was right when he used `local x,y = self:LocalToScreen( 0, 0 )` instead of `local x,y = self:GetPos()`, since cam.Start3D is relative to the screen's corner, not the panel's position. DModelPanel will also create a scissor rect around the bounds of the panel before rendering so it doesn't flow out of the panel's bounds.
This code is actially set scale, when i try to do moving of 2d surfaces
Try this: use a dmodelpanel and copy the only:DrawModel function. Then where it draws a model, also draw some 3d2d.
That'll help us see if it's a cam library thing or if it's something we're doing wrong.
@Bobblehead , the result almost the same. However now it angle strictly to screen
Try rendering in a cam.Start2D() to a RenderTarget and then using render.DrawQuadEasy() to draw that.
I don't know the actual using of RenderTarget. I don't know where I need to find Itexture for him and how it helps me
local texture = GetRenderTarget("3d2d",512,512,false)
function DrawRT() --call this in our 3d render space.
render.PushRenderTarget(texture)
cam.Start2D()
Draw2D()
cam.End2D()
render.PopRenderTarget()
end
function Draw2D() --draw our 2d stuff
draw.RoundedBox(0,0,0,200,100,Color(0,0,0))
draw.SimpleText("This Is 2D In 3D on 2D","DermaDefault",100,50,Color(255,255,0),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
end
Well, I can't find the working numbers. Can you give an example?
Sorry, you need to Log In to post a reply to this thread.