mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46:03 +01:00
fix(client/zones): convert tables to vectors
Ensure tables (either array or map) set as points, coords, or size are converted into vectors. Includes complementary reformatting.
This commit is contained in:
@@ -289,8 +289,10 @@ local DrawPoly = DrawPoly
|
|||||||
local function debugPoly(self)
|
local function debugPoly(self)
|
||||||
for i = 1, #self.triangles do
|
for i = 1, #self.triangles do
|
||||||
local triangle = self.triangles[i]
|
local triangle = self.triangles[i]
|
||||||
DrawPoly(triangle[1].x, triangle[1].y, triangle[1].z, triangle[2].x, triangle[2].y, triangle[2].z, triangle[3].x, triangle[3].y, triangle[3].z, 255, 42, 24, 100)
|
DrawPoly(triangle[1].x, triangle[1].y, triangle[1].z, triangle[2].x, triangle[2].y, triangle[2].z, triangle[3].x,
|
||||||
DrawPoly(triangle[2].x, triangle[2].y, triangle[2].z, triangle[1].x, triangle[1].y, triangle[1].z, triangle[3].x, triangle[3].y, triangle[3].z, 255, 42, 24, 100)
|
triangle[3].y, triangle[3].z, 255, 42, 24, 100)
|
||||||
|
DrawPoly(triangle[2].x, triangle[2].y, triangle[2].z, triangle[1].x, triangle[1].y, triangle[1].z, triangle[3].x,
|
||||||
|
triangle[3].y, triangle[3].z, 255, 42, 24, 100)
|
||||||
end
|
end
|
||||||
for i = 1, #self.polygon do
|
for i = 1, #self.polygon do
|
||||||
local thickness = vec(0, 0, self.thickness / 2)
|
local thickness = vec(0, 0, self.thickness / 2)
|
||||||
@@ -305,7 +307,8 @@ local function debugPoly(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function debugSphere(self)
|
local function debugSphere(self)
|
||||||
DrawMarker(28, self.coords.x, self.coords.y, self.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, self.radius, self.radius, self.radius, 255, 42, 24, 100, false, false, false, true, false, false, false)
|
DrawMarker(28, self.coords.x, self.coords.y, self.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, self.radius, self.radius,
|
||||||
|
self.radius, 255, 42, 24, 100, false, false, false, true, false, false, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
local glm_polygon_contains = glm.polygon.contains
|
local glm_polygon_contains = glm.polygon.contains
|
||||||
@@ -318,11 +321,34 @@ local function insideSphere(self, coords)
|
|||||||
return #(self.coords - coords) < self.radius
|
return #(self.coords - coords) < self.radius
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function convertToVector(coords)
|
||||||
|
local _type = type(coords)
|
||||||
|
|
||||||
|
if _type ~= 'vector3' then
|
||||||
|
if _type == 'table' then
|
||||||
|
return vec3(coords[1] or coords.x, coords[2] or coords.y, coords[3] or coords.z)
|
||||||
|
end
|
||||||
|
|
||||||
|
error(("expected type 'vector3' or 'table' (received %s)"):format(_type))
|
||||||
|
end
|
||||||
|
|
||||||
|
return coords
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
poly = function(data)
|
poly = function(data)
|
||||||
data.id = #Zones + 1
|
data.id = #Zones + 1
|
||||||
data.thickness = data.thickness or 4
|
data.thickness = data.thickness or 4
|
||||||
data.polygon = glm.polygon.new(data.points)
|
|
||||||
|
local pointN = #data.points
|
||||||
|
local points = table.create(pointN, 0)
|
||||||
|
|
||||||
|
for i = 1, pointN do
|
||||||
|
points[i] = convertToVector(data.points[i])
|
||||||
|
end
|
||||||
|
|
||||||
|
data.polygon = glm.polygon.new(points)
|
||||||
|
|
||||||
data.coords = data.polygon:centroid()
|
data.coords = data.polygon:centroid()
|
||||||
data.remove = removeZone
|
data.remove = removeZone
|
||||||
data.contains = contains
|
data.contains = contains
|
||||||
@@ -338,7 +364,8 @@ return {
|
|||||||
|
|
||||||
box = function(data)
|
box = function(data)
|
||||||
data.id = #Zones + 1
|
data.id = #Zones + 1
|
||||||
data.size = data.size and data.size / 2 or vec3(2)
|
data.coords = convertToVector(data.coords)
|
||||||
|
data.size = data.size and convertToVector(data.size) / 2 or vec3(2)
|
||||||
data.thickness = data.size.z * 2 or 4
|
data.thickness = data.size.z * 2 or 4
|
||||||
data.rotation = quat(data.rotation or 0, vec3(0, 0, 1))
|
data.rotation = quat(data.rotation or 0, vec3(0, 0, 1))
|
||||||
data.polygon = (data.rotation * glm.polygon.new({
|
data.polygon = (data.rotation * glm.polygon.new({
|
||||||
@@ -361,6 +388,7 @@ return {
|
|||||||
|
|
||||||
sphere = function(data)
|
sphere = function(data)
|
||||||
data.id = #Zones + 1
|
data.id = #Zones + 1
|
||||||
|
data.coords = convertToVector(data.coords)
|
||||||
data.radius = (data.radius or 2) + 0.0
|
data.radius = (data.radius or 2) + 0.0
|
||||||
data.remove = removeZone
|
data.remove = removeZone
|
||||||
data.contains = insideSphere
|
data.contains = insideSphere
|
||||||
|
|||||||
Reference in New Issue
Block a user