Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vectors, Angle caching #142

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions entities/entities/ix_item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ if (SERVER) then
end
end

local min, max = Vector(-8, -8, -8), Vector(8, 8, 8)

function ENT:SetItem(itemID)
local itemTable = ix.item.instances[itemID]

Expand All @@ -90,8 +92,6 @@ if (SERVER) then
local physObj = self:GetPhysicsObject()

if (!IsValid(physObj)) then
local min, max = Vector(-8, -8, -8), Vector(8, 8, 8)

self:PhysicsInitBox(min, max)
self:SetCollisionBounds(min, max)
end
Expand Down
4 changes: 2 additions & 2 deletions entities/entities/ix_money.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ function ENT:SetupDataTables()
self:NetworkVar("Int", 0, "Amount")
end

local min, max = Vector(-8, -8, -8), Vector(8, 8, 8)

if (SERVER) then
function ENT:Initialize()
self:SetModel("models/props_lab/box01a.mdl")
Expand All @@ -24,8 +26,6 @@ if (SERVER) then
physObj:EnableMotion(true)
physObj:Wake()
else
local min, max = Vector(-8, -8, -8), Vector(8, 8, 8)

self:PhysicsInitBox(min, max)
self:SetCollisionBounds(min, max)
end
Expand Down
4 changes: 3 additions & 1 deletion entities/weapons/ix_hands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ function SWEP:PrimaryAttack()
end)
end

local viewPunchAngle = Angle(-1.3, 1.8, 0)

function SWEP:SecondaryAttack()
if (!IsFirstTimePredicted()) then
return
Expand Down Expand Up @@ -451,7 +453,7 @@ function SWEP:SecondaryAttack()
return
end

self.Owner:ViewPunch(Angle(-1.3, 1.8, 0))
self.Owner:ViewPunch(viewPunchAngle)
self.Owner:EmitSound("physics/wood/wood_crate_impact_hard"..math.random(2, 3)..".wav")
self.Owner:SetAnimation(PLAYER_ATTACK1)

Expand Down
4 changes: 3 additions & 1 deletion gamemode/core/derma/cl_character.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ end
function PANEL:OnUndim()
end

local vectorScale = Vector(1, 1, 0.0001)

function PANEL:Paint(width, height)
local amount = self.currentDimAmount
local bShouldScale = self.currentScale != 1
Expand All @@ -69,7 +71,7 @@ function PANEL:Paint(width, height)
-- draw child panels with scaling if needed
if (bShouldScale) then
matrix = Matrix()
matrix:Scale(Vector(1, 1, 0.0001) * self.currentScale)
matrix:Scale(vectorScale * self.currentScale)
matrix:Translate(Vector(
ScrW() * 0.5 - (ScrW() * self.currentScale * 0.5),
ScrH() * 0.5 - (ScrH() * self.currentScale * 0.5),
Expand Down
7 changes: 5 additions & 2 deletions gamemode/core/derma/cl_charload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ local function GetCharacter(self)
return self.character
end

local camPos = Vector(80, 0, 35)
local camAngle = Angle(0, 180, 0)

function PANEL:Init()
self.activeCharacter = ClientsideModel(errorModel)
self.activeCharacter:SetNoDraw(true)
Expand All @@ -45,8 +48,8 @@ function PANEL:Init()
self.shadeY = 0
self.shadeHeight = 0

self.cameraPosition = Vector(80, 0, 35)
self.cameraAngle = Angle(0, 180, 0)
self.cameraPosition = camPos
self.cameraAngle = camAngle
self.lastPaint = 0
end

Expand Down
29 changes: 17 additions & 12 deletions gamemode/core/derma/cl_dev_icon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -437,48 +437,53 @@ function PANEL:BestGuessLayout()
end
end

local vectorX200 = Vector( 200, 0, 0 )

function PANEL:FullFrontalLayout()
local p = self.prev
local ent = p.model:GetEntity()
local pos = ent:GetPos()
local campos = pos + Vector( -200, 0, 0 )
pos:Sub(vectorX200)

ICON_INFO.camPos = campos
ICON_INFO.camPos = pos
ICON_INFO.FOV = 45
ICON_INFO.camAng = (campos * -1):Angle()
ICON_INFO.camAng = (pos * -1):Angle()
end

function PANEL:AboveLayout()
local p = self.prev
local ent = p.model:GetEntity()
local pos = ent:GetPos()
local campos = pos + Vector( 0, 0, 200 )
pos:Add(vectorX200)

ICON_INFO.camPos = campos
ICON_INFO.camPos = pos
ICON_INFO.FOV = 45
ICON_INFO.camAng = (campos * -1):Angle()
ICON_INFO.camAng = (pos * -1):Angle()
end

local vectorY200 = Vector( 0, 200, 0 )

function PANEL:RightLayout()
local p = self.prev
local ent = p.model:GetEntity()
local pos = ent:GetPos()
local campos = pos + Vector( 0, 200, 0 )
pos:Add(vectorY200)

ICON_INFO.camPos = campos
ICON_INFO.camPos = pos
ICON_INFO.FOV = 45
ICON_INFO.camAng = (campos * -1):Angle()
ICON_INFO.camAng = (pos * -1):Angle()
end

local angleYawMinus180 = Angle( 0, -180, 0 )

function PANEL:OriginLayout()
local p = self.prev
local ent = p.model:GetEntity()
local pos = ent:GetPos()
local campos = pos + Vector( 0, 0, 0 )

ICON_INFO.camPos = campos
ICON_INFO.camPos = pos
ICON_INFO.FOV = 45
ICON_INFO.camAng = Angle( 0, -180, 0 )
ICON_INFO.camAng = angleYawMinus180
end


Expand Down
15 changes: 11 additions & 4 deletions gamemode/core/derma/cl_menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ function PANEL:SetCharacterOverview(bValue, length)
end
end

local angleYaw180 = Angle(0, 180, 0)

function PANEL:GetOverviewInfo(origin, angles, fov)
local originAngles = Angle(0, angles.yaw, angles.roll)
local target = LocalPlayer():GetObserverTarget()
Expand All @@ -204,7 +206,7 @@ function PANEL:GetOverviewInfo(origin, angles, fov)
newOrigin = origin - LocalPlayer():OBBCenter() * 0.6 + forward
end

local newAngles = originAngles + Angle(0, 180, 0)
local newAngles = originAngles + angleYaw180
newAngles.pitch = 5
newAngles.roll = 0

Expand Down Expand Up @@ -309,6 +311,9 @@ function PANEL:OnKeyCodePressed(key)
end
end

local vectorZ6 = Vector(0, 0, 6)
local angleM456000 = Angle(-45, 60, 0)

function PANEL:Think()
if (IsValid(self.projectedTexture)) then
local forward = LocalPlayer():GetForward()
Expand All @@ -318,8 +323,8 @@ function PANEL:Think()
right.z = 0

self.projectedTexture:SetBrightness(self.overviewFraction * 4)
self.projectedTexture:SetPos(LocalPlayer():GetPos() + right * 16 - forward * 8 + Vector(0, 0, 6))
self.projectedTexture:SetAngles(forward:Angle() + Angle(-45, 60, 0))
self.projectedTexture:SetPos(LocalPlayer():GetPos() + right * 16 - forward * 8 + vectorZ6)
self.projectedTexture:SetAngles(forward:Angle() + angleM456000)
self.projectedTexture:Update()
end

Expand All @@ -339,6 +344,8 @@ function PANEL:Think()
end
end

local vectorZDiv1000 = Vector(1, 1, 0.0001)

function PANEL:Paint(width, height)
derma.SkinFunc("PaintMenuBackground", self, width, height, self.currentBlur)

Expand All @@ -348,7 +355,7 @@ function PANEL:Paint(width, height)
local currentScale = Lerp(self.currentAlpha / 255, 0.9, 1)
local matrix = Matrix()

matrix:Scale(Vector(1, 1, 0.0001) * currentScale)
matrix:Scale(vectorZDiv1000 * currentScale)
matrix:Translate(Vector(
ScrW() * 0.5 - (ScrW() * currentScale * 0.5),
ScrH() * 0.5 - (ScrH() * currentScale * 0.5),
Expand Down
4 changes: 3 additions & 1 deletion gamemode/core/derma/cl_spawnicon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ function PANEL:Init()
end
end

local vectorZ64 = Vector(0, 0, 64)

function PANEL:SetModel(model, skin, hidden)
BaseClass.SetModel(self, model)

Expand Down Expand Up @@ -58,7 +60,7 @@ function PANEL:SetModel(model, skin, hidden)
end

entity:SetIK(false)
entity:SetEyeTarget(Vector(0, 0, 64))
entity:SetEyeTarget(vectorZ64)
end

function PANEL:SetHidden(hidden)
Expand Down
3 changes: 2 additions & 1 deletion gamemode/core/hooks/cl_hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,15 @@ local vignetteAlphaDelta = 0
local blurGoal = 0
local blurDelta = 0
local hasVignetteMaterial = vignette != "___error"
local vectorZ768 = Vector(0, 0, 768)

timer.Create("ixVignetteChecker", 1, 0, function()
local client = LocalPlayer()

if (IsValid(client)) then
local data = {}
data.start = client:GetPos()
data.endpos = data.start + Vector(0, 0, 768)
data.endpos = data.start + vectorZ768
data.filter = client
local trace = util.TraceLine(data)

Expand Down
6 changes: 3 additions & 3 deletions gamemode/core/hooks/sh_hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ PLAYER_HOLDTYPE_TRANSLATOR["bugbait"] = "normal"

local PLAYER_HOLDTYPE_TRANSLATOR = PLAYER_HOLDTYPE_TRANSLATOR
local HOLDTYPE_TRANSLATOR = HOLDTYPE_TRANSLATOR

local magicVector = Vector(16.5438, -0.1642, -20.5493)
function GM:TranslateActivity(client, act)
local clientInfo = client:GetTable()
local modelClass = clientInfo.ixAnimModelClass or "player"
Expand Down Expand Up @@ -94,7 +94,7 @@ function GM:TranslateActivity(client, act)
local fixVector = clientInfo.ixAnimTable[2]

if (isvector(fixVector)) then
client:SetLocalPos(Vector(16.5438, -0.1642, -20.5493))
client:SetLocalPos(magicVector)
end

if (isstring(act)) then
Expand Down Expand Up @@ -497,7 +497,7 @@ function GM:Move(client, moveData)
if (client:GetNetVar("actEnterAngle")) then
moveData:SetForwardSpeed(0)
moveData:SetSideSpeed(0)
moveData:SetVelocity(Vector(0, 0, 0))
moveData:SetVelocity(vector_origin)
end

if (client:GetMoveType() == MOVETYPE_WALK and moveData:KeyDown(IN_WALK)) then
Expand Down
6 changes: 4 additions & 2 deletions gamemode/core/libs/sh_business.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ if (SERVER) then
end
end)

local vectorZ16 = Vector(0, 0, 16)
local vectorZ05 = Vector(0, 0, 0.5)
net.Receive("ixShipmentUse", function(length, client)
local uniqueID = net.ReadString()
local drop = net.ReadBool()
Expand All @@ -89,7 +91,7 @@ if (SERVER) then
end

if (drop) then
ix.item.Spawn(uniqueID, entity:GetPos() + Vector(0, 0, 16), function(item, itemEntity)
ix.item.Spawn(uniqueID, entity:GetPos() + vectorZ16, function(item, itemEntity)
if (IsValid(client)) then
itemEntity.ixSteamID = client:SteamID()
itemEntity.ixCharID = client:GetCharacter():GetID()
Expand All @@ -108,7 +110,7 @@ if (SERVER) then
entity.items[uniqueID] = entity.items[uniqueID] - 1

if (entity:GetItemCount() < 1) then
entity:GibBreakServer(Vector(0, 0, 0.5))
entity:GibBreakServer(vectorZ05)
entity:Remove()
end
end
Expand Down
2 changes: 1 addition & 1 deletion gamemode/core/meta/sh_item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ if (SERVER) then
-- Spawn the actual item entity.
local entity = ents.Create("ix_item")
entity:Spawn()
entity:SetAngles(angles or Angle(0, 0, 0))
entity:SetAngles(angles or angle_zero)
-- Make the item represent this item.
entity:SetItem(self.id)

Expand Down
13 changes: 9 additions & 4 deletions gamemode/core/sh_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,10 @@ do
local R = debug.getregistry()
local VECTOR = R.Vector
local CrossProduct = VECTOR.Cross
local vecYMinusOne = Vector(0, -1, 0)

function VECTOR:Right(vUp)
if (self[1] == 0 and self[2] == 0) then return Vector(0, -1, 0) end
if (self[1] == 0 and self[2] == 0) then return vecYMinusOne end

if (vUp == nil) then
vUp = vector_up
Expand Down Expand Up @@ -967,6 +968,9 @@ do

local NUM_TANGENTS = 8
local tangents = {0, 1, 0.57735026919, 0.3639702342, 0.267949192431, 0.1763269807, -0.1763269807, -0.267949192431}
local vec16 = Vector(16,16,16)
local mVec16 = -Vector(16,16,16)


function ix.util.FindUseEntity(player, origin, forward)
local tr
Expand Down Expand Up @@ -1002,8 +1006,8 @@ do
tr = util.TraceHull({
start = searchCenter,
endpos = searchCenter + down * 72,
mins = -Vector(16,16,16),
maxs = Vector(16,16,16),
mins = mVec16,
maxs = vec16,
mask = useableContents,
filter = player
})
Expand Down Expand Up @@ -1480,6 +1484,7 @@ do
return entity
end

local vecZ16 = Vector(0, 0, 16)
function playerMeta:SetRagdolled(state, time, getUpGrace)
if (!self:Alive()) then
return
Expand Down Expand Up @@ -1538,7 +1543,7 @@ do

if (self:IsStuck()) then
entity:DropToFloor()
self:SetPos(entity:GetPos() + Vector(0, 0, 16))
self:SetPos(entity:GetPos() + vecZ16)

local positions = ix.util.FindEmptySpace(self, {entity, self})

Expand Down
9 changes: 6 additions & 3 deletions plugins/act/cl_hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ local forwardOffset = 16
local backwardOffset = -32
local heightOffset = Vector(0, 0, 20)
local idleHeightOffset = Vector(0, 0, 6)
local vector0064 = Vector(0, 0, 64)
local mVector444 = Vector(-4, -4, -4)
local vector444 = Vector(4, 4, 4)

function PLUGIN:CalcView(client, origin)
local enterAngle = client:GetNetVar("actEnterAngle")
Expand Down Expand Up @@ -72,10 +75,10 @@ function PLUGIN:CalcView(client, origin)
if (head) then
local position = client:GetBonePosition(head) + forward * offset + height
local data = {
start = (client:GetBonePosition(head) or Vector(0, 0, 64)) + forward * 8,
start = (client:GetBonePosition(head) or vector0064) + forward * 8,
endpos = position + forward * offset,
mins = Vector(-4, -4, -4),
maxs = Vector(4, 4, 4),
mins = mVector444,
maxs = vector444,
filter = client
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/mapscene.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ PLUGIN.description = "Adds areas of the map that are visible during character se
PLUGIN.scenes = PLUGIN.scenes or {}

local x3, y3 = 0, 0
local realOrigin = Vector(0, 0, 0)
local realAngles = Angle(0, 0, 0)
local realOrigin = vector_origin
local realAngles = angle_zero
local view = {}

if (CLIENT) then
Expand Down
Loading