diff --git a/lua/pac3/core2/client/components/bounding_box.lua b/lua/pac3/core2/client/components/bounding_box.lua index b46cbaea..57e0428a 100644 --- a/lua/pac3/core2/client/components/bounding_box.lua +++ b/lua/pac3/core2/client/components/bounding_box.lua @@ -157,7 +157,7 @@ function META:GetWorldMin() local scale = self.entity.transform:GetScaleMatrix() local tr = Matrix() - tr:SetTranslation((min - self:GetCenter()) * scale:GetScale()) + tr:SetTranslation((min + self:GetCenter()) * scale:GetScale() * self.entity.transform:GetLocalScale()) tr = tr * m return tr:GetTranslation() @@ -170,11 +170,9 @@ function META:GetWorldMax() local scale = self.entity.transform:GetScaleMatrix() local tr = Matrix() - tr:SetTranslation((max - self:GetCenter()) * scale:GetScale()) + tr:SetTranslation((max + self:GetCenter()) * scale:GetScale() * self.entity.transform:GetLocalScale()) tr = tr * m - --print(utility.TransformVector(m, max + scale:GetTranslation() * m:GetScale()), tr:GetTranslation()) - return tr:GetTranslation() end diff --git a/lua/pac3/core2/client/components/gizmo.lua b/lua/pac3/core2/client/components/gizmo.lua index 27f98043..332751a3 100644 --- a/lua/pac3/core2/client/components/gizmo.lua +++ b/lua/pac3/core2/client/components/gizmo.lua @@ -31,7 +31,7 @@ local function create_grab(self, mdl, pos, on_grab, on_grab2) ent:SetIgnoreZ(true) ent:RemoveComponent("gizmo") ent:SetModel(mdl) - ent:SetPosition( pos) + ent:SetPosition(pos) ent:SetMaterial(white_mat) ent:SetAlpha(1) ent:SetIgnoreParentScale(true) @@ -85,7 +85,7 @@ function META:SetupViewTranslation() ent:SetColor(YELLOW) ent:AddEvent("Update", function() - ent:SetLocalScale(Vector(1,1,1) * 0.03 * self:GetDistanceScaler()) + ent:SetLocalScale(Vector(1,1,1) * 0.006 * self:GetDistanceScaler()) ent:SetWorldPosition(self.entity:GetWorldCenter()) end) end @@ -101,7 +101,7 @@ function META:StartGrab(axis, center) self.grab_matrix = self.entity.transform:GetWorldMatrix() * Matrix() self.grab_matrix:SetScale(Vector(1,1,1)) - + center = center or self.grab_matrix:GetTranslation() self.center_pos = util.IntersectRayWithPlane( @@ -129,6 +129,119 @@ function META:GetGrabPlanePosition(axis, center) return plane_pos end + +local function draw_notches( zoom, level, x, y, w, h, range, value, min, max ) + local size = level * zoom + if ( size < 5 ) then return end + if ( size > w * 2 ) then return end + + local alpha = 255 + + if ( size < 150 ) then alpha = alpha * ( ( size - 2 ) / 140 ) end + if ( size > ( w * 2 ) - 100 ) then alpha = alpha * ( 1 - ( ( size - ( w - 50 ) ) / 50 ) ) end + + local halfw = w * 0.5 + local span = math.ceil( w / size ) + local realmid = x + w * 0.5 - ( value * zoom ) + local mid = x + w * 0.5 - math.fmod( value * zoom, size ) + local top = h * 0.4 + local nh = h - top + + local frame_min = math.floor( realmid + min * zoom ) + local frame_width = math.ceil( range * zoom ) + local targetW = math.min( w - math.max( 0, frame_min - x ), frame_width - math.max( 0, x - frame_min ) ) + + surface.SetDrawColor( 0, 0, 0, alpha ) + surface.DrawRect( math.max( x, frame_min ), y + top, targetW, 2 ) + + surface.SetFont( "DermaDefault" ) + + for n = -span, span, 1 do + + local nx = mid + n * size + + if ( nx > x + w || nx < x ) then continue end + + local dist = 1 - ( math.abs( halfw - nx + x ) / w ) + + local val = ( nx - realmid ) / zoom + + if ( val <= min + 0.001 ) then continue end + if ( val >= max - 0.001 ) then continue end + + surface.SetDrawColor( 0, 0, 0, alpha * dist ) + surface.SetTextColor( 0, 0, 0, alpha * dist ) + + surface.DrawRect( nx, y + top, 2, nh ) + + local tw, th = surface.GetTextSize( val ) + + surface.SetTextPos( nx - ( tw * 0.5 ), y + top - th ) + surface.DrawText( val ) + + end + + surface.SetDrawColor( 0, 0, 0, alpha ) + surface.SetTextColor( 0, 0, 0, alpha ) + + -- + -- Draw the last one. + -- + local nx = realmid + max * zoom + if ( nx < x + w ) then + surface.DrawRect( nx, y + top, 3, nh ) + + local val = max + local tw, th = surface.GetTextSize( val ) + + surface.SetTextPos( nx - ( tw * 0.5 ), y + top - th ) + surface.DrawText( val ) + end + + -- + -- Draw the first + -- + local nx = realmid + min * zoom + if ( nx > x ) then + surface.DrawRect( nx, y + top, 3, nh ) + + local val = min + local tw, th = surface.GetTextSize( val ) + + surface.SetTextPos( nx - ( tw * 0.5 ), y + top - th ) + surface.DrawText( val ) + end + + +end + +local UnderMaterial = Material( "gui/numberscratch_under.png" ) +local CoverMaterial = Material( "gui/numberscratch_cover.png" ) + +local function draw_ruler(x,y,w,h, value, min, max, zoom) + -- Background + -- + surface.SetMaterial( UnderMaterial ) + surface.SetDrawColor( 255, 255, 255, 255 ) + surface.DrawTexturedRect( x, y, w, h ) + + --local min = -1000 + --local max = 1000 + local range = max - min + ---local value = 1.5 -- float value + + --local zoom = 2 + local decimals = 4 + + for i = 1, 4 do + draw_notches(zoom, 10 ^ i, x, y, w, h, range, value, min, max ) + end + + for i = 0, decimals do + draw_notches(zoom, 1 / 10 ^ i, x, y, w, h, range, value, min, max ) + end +end + function META:SetupTranslation() local dist = 8 local thickness = 1.5 @@ -167,12 +280,73 @@ function META:SetupTranslation() visual:SetIgnoreZ(true) visual:RemoveComponent("gizmo") visual:RemoveComponent("input") + visual.model.Render3D = function() + local center = self.entity:GetWorldCenter() + visual:SetWorldPosition(center) + local world = ent.transform:GetMatrix() + local scale = world:GetScale() + world:SetScale(Vector(1,1,1)) + world:Rotate(Angle(0,90,0)) + world:Rotate(Angle(-90,0,0)) + + world:Translate(Vector(0,0,0)) + + + local val + + if axis == "GetRight" then + val = -self.entity:GetPosition().y + elseif axis == "GetUp" then + val = -self.entity:GetPosition().z + elseif axis == "GetForward" then + val = -self.entity:GetPosition().x + end + + cam.Start3D2D(world:GetTranslation(), world:GetAngles(), scale:Length()) + cam.IgnoreZ(true) + draw_ruler(-256,-64 - 20,512,64, val, -32000, 32000, (1/(center - pac999.camera.GetViewMatrix():GetTranslation()):Length()) * 320 ) + cam.IgnoreZ(false) + cam.End3D2D() + + cam.Start2D() + local x, y = -256, 128 + local pos = world:GetTranslation():ToScreen() + x = pos.x + 25 + y = pos.y + 25 + local w, h = 512, 64 + local decimals = 3 + local value = val + -- + -- Text Value + -- + local str = tostring(val) + + + if ( decimals == 0 ) then + str = Format( "%i", value ) + else + str = Format( "%." .. decimals .. "f", value ) + end + + + str = string.Comma( str ) + surface.SetFont( "DermaLarge" ) + local tw, th = surface.GetTextSize( str ) + + draw.RoundedBoxEx( 8, x, y, tw*1.5, th*1.5, Color( 0, 186, 255, 255 ), true, true, true, true ) + + surface.SetTextColor( 255, 255, 255, 255 ) + surface.SetTextPos( x + tw * 0.25, y + th * 0.25 ) + surface.DrawText( str ) + cam.End2D() + + + end visual:SetModel("models/hunter/blocks/cube025x025x025.mdl") visual:SetMaterial(white_mat) visual:SetColor(color_white) visual:SetAlpha(1) - visual:SetLocalScale(Vector(thickness/25,thickness/25,32000)) - visual:SetWorldPosition(self.entity:GetWorldCenter()) + --visual:SetLocalScale(Vector(thickness/25,thickness/25,32000)) local a if axis == "GetRight" then @@ -201,13 +375,8 @@ function META:SetupTranslation() local function update(ent, dir) local m = self:GetDistanceScaler() - local box_pos = self.entity:NearestPoint(self.entity:GetWorldCenter() + dir * 1000 * m) - - if not box_pos then return end - - ent:SetLocalScale(Vector(1,1,1.25) * m * 0.02) - - ent:SetWorldPosition(box_pos + (box_pos - self.entity:GetWorldCenter()):GetNormalized() * m * 2) + ent:SetLocalScale(Vector(1,1,2) * m * 0.0025) + ent:SetWorldPosition(self.entity:GetWorldCenter() + dir * m * 0.75) ent.transform:GetWorldMatrix() end @@ -240,6 +409,16 @@ function META:SetupTranslation() update(ent, m[axis2](m)*-1) end) + --[[ + local beam = pac999.scene.AddNode(ent) + beam:SetModel("models/mechanics/wheels/wheel_speed_72.mdl") + beam:SetLocalScale(Vector(0.3,0.3,50)) + + beam:SetIgnoreZ(true) + beam:RemoveComponent("gizmo") + beam:RemoveComponent("input") + beam:SetColor(gizmo_color) + beam:SetMaterial(white_mat)]] end return ent @@ -251,7 +430,10 @@ function META:SetupTranslation() end function META:SetupRotation() - local disc = "models/hunter/tubes/tube4x4x025d.mdl" + local disc = "models/props_lab/teleportring.mdl" + local disc = "models/props_phx/construct/glass/glass_curve360x2.mdl" + local disc = "models/squad/sf_tubes/sf_tube1x180.mdl" + local disc = "models/hunter/tubes/tube2x2x05.mdl" local dist = dist*0.5/1.25 local visual_size = 0.28 local scale = 0.25 @@ -326,7 +508,6 @@ function META:SetupRotation() end local function add_grabbable(axis, axis2, gizmo_color, fixup_callback) - local disc = "models/props_phx/construct/glass/glass_curve360x2.mdl" local m = self.entity:GetWorldMatrix() local dir = m[axis2](m) * dist @@ -337,11 +518,11 @@ function META:SetupRotation() --ent:SetWorldPosition(self.entity:NearestPoint(wpos + dir) + dir) if axis == "GetRight" then - ent:SetAngles(Angle(45,180,90)) + ent:SetAngles(Angle(90,180,90)) elseif axis == "GetUp" then - ent:SetAngles(Angle(0,90 -45,0)) + ent:SetAngles(Angle(0,0,0)) elseif axis == "GetForward" then - ent:SetAngles(Angle(90 +45,90,90)) + ent:SetAngles(Angle(90,90,90)) end ent:SetColor(gizmo_color) @@ -349,10 +530,10 @@ function META:SetupRotation() ent:AddEvent("Update", function() local s = self.entity:GetScaleMatrix():GetScale() local l = math.max(s.x, s.y, s.z)/3 - + local m = self:GetDistanceScaler() - - ent:SetLocalScale(Vector(1,1,0.0125) * 0.2 * (m ^ 0.5)) + + ent:SetLocalScale(Vector(1,1,0.15) * m * 0.015) ent:SetWorldPosition(self.entity:GetWorldCenter()) end) end @@ -444,6 +625,8 @@ function META:SetupScale() else self.entity.transform:SetCageSizeMin(cage_min_start + (dir * dist)) end + + render.DrawWireframeBox( self.entity:GetWorldCenter(), self.entity:GetWorldAngles(), self.entity:GetMin(), self.entity:GetMax(), Color(255, 204, 51, 255), true ) end end end @@ -456,6 +639,7 @@ function META:SetupScale() if not box_pos then return end ent:SetWorldPosition(box_pos) + ent:SetLocalScale(Vector(1,1,1) * 0.006 * self:GetDistanceScaler()) ent.transform:GetWorldMatrix() end diff --git a/lua/pac3/core2/client/components/transform.lua b/lua/pac3/core2/client/components/transform.lua index d4deb16a..82c753d7 100644 --- a/lua/pac3/core2/client/components/transform.lua +++ b/lua/pac3/core2/client/components/transform.lua @@ -205,11 +205,16 @@ do tr:Translate(-self:GetCageMin()) end + + local part = self.PACPart + if part:IsValid() then + tr:Scale(part.Scale * part.Size) + end + self.ScaleMatrix = tr end function META:GetScaleMatrix() - if not self.ScaleMatrix then self:InvalidateScaleMatrix() end @@ -244,9 +249,9 @@ end function META:GetMatrix() local part = self.PACPart - + if part:IsValid() then - return part:GetWorldMatrix() + return part:GetWorldMatrix() end @@ -275,6 +280,17 @@ function META:GetMatrix() return self.cached_matrix end +function META:GetTRMatrix() + local part = self.PACPart + if part:IsValid() then + local m = Matrix() + m:SetTranslation(part.Position) + m:SetAngles(part.Angles) + return m + end + return self.TRMatrix +end + function META:BuildTRMatrix() local tr = self:GetTRMatrix() * Matrix() @@ -312,7 +328,7 @@ function META:UpdatePACMatrix(m) if not m then local lmat = self:GetScaleMatrix() - + pace.mctrl.OnScale(part, self:GetScaleMatrix():GetScale()) lmat = lmat*Matrix() lmat:SetScale(Vector(1,1,1)) @@ -323,21 +339,21 @@ function META:UpdatePACMatrix(m) return end - local lmat = part:GetBoneMatrix():GetInverse() * m + local lmat = part:GetBoneMatrix():GetInverse() * m pace.mctrl.OnMove(part, lmat:GetTranslation()) pace.mctrl.OnRotate(part, lmat:GetAngles()) - + part.WorldMatrix = nil part:GetWorldMatrix() - + return true end function META:SetWorldMatrix(m) if self:UpdatePACMatrix(m) then return end - + local lm = m:GetInverse() * self:GetMatrix() self:SetTRMatrix(self:GetTRMatrix() * lm:GetInverse())