- 8,934
- 11,700
Описание: возвращает 2д координаты всех углов модели по айди модели машины/скина и хендлу ( простое использование функции getModelDemensions() ).
Код:
Пример использования:
Код:
Lua:
function getCarModelCornersIn2d(id, handle)
local x1, y1, z1, x2, y2, z2 = getModelDimensions(id)
local t = {
[1] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x1 , y1 * -1.1, z1))},
[2] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x1 * -1.0 , y1 * -1.1, z1))},
[3] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x1 * -1.0 , y1 , z1))},
[4] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x1 , y1 , z1))},
[5] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x2 * -1.0 , y2 , z2))},
[6] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x2 * -1.0 , y2 * -0.9, z2))},
[7] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x2 , y2 * -0.9, z2))},
[8] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x2 , y2 , z2))},
}
return t
end
Lua:
function getCharModelCornersIn2d(id, handle)
local x1, y1, z1, x2, y2, z2 = getModelDimensions(id)
local t = {
[1] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x1 , y1 * -1.1, z1))}, -- {x = x1, y = y1 * -1.0, z = z1},
[2] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x1 * -1.0 , y1 * -1.1, z1))}, -- {x = x1 * -1.0, y = y1 * -1.0, z = z1},
[3] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x1 * -1.0 , y1 , z1))}, -- {x = x1 * -1.0, y = y1, z = z1},
[4] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x1 , y1 , z1))}, -- {x = x1, y = y1, z = z1},
[5] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x2 * -1.0 , y2 , z2))}, -- {x = x2 * -1.0, y = 0, z = 0},
[6] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x2 * -1.0 , y2 * -0.9, z2))}, -- {x = x2 * -1.0, y = y2 * -1.0, z = z2},
[7] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x2 , y2 * -0.9, z2))}, -- {x = x2, y = y2 * -1.0, z = z2},
[8] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x2 , y2 , z2))}, -- {x = x2, y = y2, z = z2},
}
return t
end
Lua:
local font = renderCreateFont('Tahoma', 10, 4)
function main()
while not isSampAvailable() do wait(0) end
while true do
wait(0)
if isCharInAnyCar(PLAYER_PED) then
local c = getCarModelCornersIn2d(getCarModel(storeCarCharIsInNoSave(PLAYER_PED)), storeCarCharIsInNoSave(PLAYER_PED))
for i = 1, #c do
renderDrawPolygon(c[i][1] - 2, c[i][2] - 2, 10, 10, 10, 0, 0xFFff004d)
renderFontDrawText(font, 'Corner #'..i, c[i][1], c[i][2], 0xFFFFFFFF, 0x90000000)
end
renderDrawLine(c[1][1], c[1][2], c[2][1], c[2][2],2, 0xFFff004d)
renderDrawLine(c[2][1], c[2][2], c[3][1], c[3][2],2, 0xFFff004d)
renderDrawLine(c[3][1], c[3][2], c[4][1], c[4][2],2, 0xFFff004d)
renderDrawLine(c[4][1], c[4][2], c[1][1], c[1][2],2, 0xFFff004d)
renderDrawLine(c[5][1], c[5][2], c[6][1], c[6][2],2, 0xFFff004d)
renderDrawLine(c[6][1], c[6][2], c[7][1], c[7][2],2, 0xFFff004d)
renderDrawLine(c[7][1], c[7][2], c[8][1], c[8][2],2, 0xFFff004d)
renderDrawLine(c[8][1], c[8][2], c[5][1], c[5][2],2, 0xFFff004d)
renderDrawLine(c[1][1], c[1][2], c[5][1], c[5][2],2, 0xFFff004d)
renderDrawLine(c[2][1], c[2][2], c[8][1], c[8][2],2, 0xFFff004d)
renderDrawLine(c[3][1], c[3][2], c[7][1], c[7][2],2, 0xFFff004d)
renderDrawLine(c[4][1], c[4][2], c[6][1], c[6][2],2, 0xFFff004d)
end
end
end
function getCarModelCornersIn2d(id, handle)
local x1, y1, z1, x2, y2, z2 = getModelDimensions(id)
local t = {
[1] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x1 , y1 * -1.1, z1))},
[2] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x1 * -1.0 , y1 * -1.1, z1))},
[3] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x1 * -1.0 , y1 , z1))},
[4] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x1 , y1 , z1))},
[5] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x2 * -1.0 , y2 , z2))},
[6] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x2 * -1.0 , y2 * -0.9, z2))},
[7] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x2 , y2 * -0.9, z2))},
[8] = {convert3DCoordsToScreen(getOffsetFromCarInWorldCoords(handle, x2 , y2 , z2))},
}
return t
end
Lua:
local font = renderCreateFont('Tahoma', 10, 4)
function main()
while not isSampAvailable() do wait(0) end
while true do
wait(0)
local c = getCharModelCornersIn2d(getCharModel(PLAYER_PED), PLAYER_PED)
for i = 1, #c do
renderDrawPolygon(c[i][1] - 2, c[i][2] - 2, 10, 10, 10, 0, 0xFFff004d)
renderFontDrawText(font, 'Corner #'..i, c[i][1], c[i][2], 0xFFFFFFFF, 0x90000000)
end
renderDrawLine(c[1][1], c[1][2], c[2][1], c[2][2],2, 0xFFff004d)
renderDrawLine(c[2][1], c[2][2], c[3][1], c[3][2],2, 0xFFff004d)
renderDrawLine(c[3][1], c[3][2], c[4][1], c[4][2],2, 0xFFff004d)
renderDrawLine(c[4][1], c[4][2], c[1][1], c[1][2],2, 0xFFff004d)
renderDrawLine(c[5][1], c[5][2], c[6][1], c[6][2],2, 0xFFff004d)
renderDrawLine(c[6][1], c[6][2], c[7][1], c[7][2],2, 0xFFff004d)
renderDrawLine(c[7][1], c[7][2], c[8][1], c[8][2],2, 0xFFff004d)
renderDrawLine(c[8][1], c[8][2], c[5][1], c[5][2],2, 0xFFff004d)
renderDrawLine(c[1][1], c[1][2], c[5][1], c[5][2],2, 0xFFff004d)
renderDrawLine(c[2][1], c[2][2], c[8][1], c[8][2],2, 0xFFff004d)
renderDrawLine(c[3][1], c[3][2], c[7][1], c[7][2],2, 0xFFff004d)
renderDrawLine(c[4][1], c[4][2], c[6][1], c[6][2],2, 0xFFff004d)
end
end
function getCharModelCornersIn2d(id, handle)
local x1, y1, z1, x2, y2, z2 = getModelDimensions(id)
local t = {
[1] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x1 , y1 * -1.1, z1))}, -- {x = x1, y = y1 * -1.0, z = z1},
[2] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x1 * -1.0 , y1 * -1.1, z1))}, -- {x = x1 * -1.0, y = y1 * -1.0, z = z1},
[3] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x1 * -1.0 , y1 , z1))}, -- {x = x1 * -1.0, y = y1, z = z1},
[4] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x1 , y1 , z1))}, -- {x = x1, y = y1, z = z1},
[5] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x2 * -1.0 , y2 , z2))}, -- {x = x2 * -1.0, y = 0, z = 0},
[6] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x2 * -1.0 , y2 * -0.9, z2))}, -- {x = x2 * -1.0, y = y2 * -1.0, z = z2},
[7] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x2 , y2 * -0.9, z2))}, -- {x = x2, y = y2 * -1.0, z = z2},
[8] = {convert3DCoordsToScreen(getOffsetFromCharInWorldCoords(handle, x2 , y2 , z2))}, -- {x = x2, y = y2, z = z2},
}
return t
end