RU/Matrix: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (translate methods)
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
__NOTOC__
Матрицы — одна из самых мощных возможностей [[OOP|ООП]] в MTA. Матрицы были и раньше с функцией [[getElementMatrix]], но мы получали ужасную для работы таблицу. Теперь, с новым классом Matrix, мы можем создавать и волшебно манипулировать матрицами.
[[Category:Incomplete]]
__TOC__
Класс матриц был внедрен в 1.4
==Методы==
 
=== Методы ===
*[[Matrix.create|create]]
*[[Matrix.create|create]]
*[[Matrix.transformPosition|transformPosition]]
*[[Matrix.transformPosition|transformPosition]]
Line 19: Line 17:
*[[Matrix.setRight|setRight]]
*[[Matrix.setRight|setRight]]
*[[Matrix.setUp|setUp]]
*[[Matrix.setUp|setUp]]
==Использование матриц==
Предположим, вы хотите созать мусорное ведро - объект 1337 - в двух еденицах впереди игрока. Вы не хотите вручную работать с тригонометрией и запутанными таблицами. Вы просто хотите получить позицию в двух еденицах впереди игрока, учитывая его вращение. Вам понадобятся только эти функции '''[[Matrix.getForward]]'''. '''[[Matrix.getPosition]]''' и '''[[getElementMatrix]]'''.  Это просто:
<syntaxhighlight lang="lua">
Object ( 1337, player.matrix.position + player.matrix.forward * 2 )
</syntaxhighlight>
== Why not stick to the good ol' tables? ==
Say you'd like to get find the position underneath a vehicle. This is the position at any rotation. So if it was upside down, the Z value would be higher than the vehicle Z value. If the vehicle was the right way round, the Z value for underneath car would be less than the Z value for the car.
<syntaxhighlight lang="lua">
--
-- Вместо:
--
local matrix = getElementMatrix(vehicle)
local offX = 0 * matrix[1][1] + 0 * matrix[2][1] - 1 * matrix[3][1] + matrix[4][1]
local offY = 0 * matrix[1][2] + 0 * matrix[2][2] - 1 * matrix[3][2] + matrix[4][2]
local offZ = 0 * matrix[1][3] + 0 * matrix[2][3] - 1 * matrix[3][3] + matrix[4][3]
local pX, pY, pZ = getElementPosition(vehicle)
local positionBelow = {offX-pX, offY-pY, offZ-pZ}
--
-- Вы можете просто сделать так:
--
local positionBelow = vehicle.position - vehicle.matrix.up
</syntaxhighlight>


[[en:Matrix]]
[[en:Matrix]]

Latest revision as of 00:09, 30 November 2014

Матрицы — одна из самых мощных возможностей ООП в MTA. Матрицы были и раньше с функцией getElementMatrix, но мы получали ужасную для работы таблицу. Теперь, с новым классом Matrix, мы можем создавать и волшебно манипулировать матрицами.

Методы

Использование матриц

Предположим, вы хотите созать мусорное ведро - объект 1337 - в двух еденицах впереди игрока. Вы не хотите вручную работать с тригонометрией и запутанными таблицами. Вы просто хотите получить позицию в двух еденицах впереди игрока, учитывая его вращение. Вам понадобятся только эти функции Matrix.getForward. Matrix.getPosition и getElementMatrix. Это просто:

Object ( 1337, player.matrix.position + player.matrix.forward * 2 )

Why not stick to the good ol' tables?

Say you'd like to get find the position underneath a vehicle. This is the position at any rotation. So if it was upside down, the Z value would be higher than the vehicle Z value. If the vehicle was the right way round, the Z value for underneath car would be less than the Z value for the car.

--
-- Вместо:
--
local matrix = getElementMatrix(vehicle)
local offX = 0 * matrix[1][1] + 0 * matrix[2][1] - 1 * matrix[3][1] + matrix[4][1]
local offY = 0 * matrix[1][2] + 0 * matrix[2][2] - 1 * matrix[3][2] + matrix[4][2]
local offZ = 0 * matrix[1][3] + 0 * matrix[2][3] - 1 * matrix[3][3] + matrix[4][3]

local pX, pY, pZ = getElementPosition(vehicle)
local positionBelow = {offX-pX, offY-pY, offZ-pZ}

--
-- Вы можете просто сделать так:
--
local positionBelow = vehicle.position - vehicle.matrix.up