Difference between revisions of "Vector/Vector3"

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Undo revision 44192 by AlexTMjugador (talk))
m (Restructure)
Line 1: Line 1:
__NOTOC__
 
 
[[Category:Incomplete]]
 
[[Category:Incomplete]]
 
The '''vector3''' class represents a three-dimensional [[vector]].
 
The '''vector3''' class represents a three-dimensional [[vector]].
  
===Methods===
+
==Methods==
*[[Vector3.create|create]]
+
===create===
*[[Vector3.cross|cross]]
+
This is default constructor for the Vector3 class and returns a Vector3 object.
*[[Vector3.dot|dot]]
 
*[[Vector3.normalize|normalize]]
 
  
*[[Vector3.getX|getX]]
+
====Syntax====
*[[Vector3.getY|getY]]
+
<syntaxhighlight lang="lua">vector3 Vector3 ( float x = 0, float y = 0, float z = 0 )</syntaxhighlight>
*[[Vector3.getZ|getZ]]
 
*[[Vector3.getNormalized|getNormalized]]
 
*[[Vector3.getSquaredLength|getSquaredLength]]
 
*[[Vector3.getLength|getLength]]
 
  
*[[Vector3.setX|setX]]
+
* '''x''', '''y''' and '''z''': coordinates for the vector. If not specified, they default to 0.
*[[Vector3.setY|setY]]
+
* Instead of these three coordinates, a single Vector3 object may be inserted to clone it.
*[[Vector3.setZ|setZ]]
+
 
 +
====Example====
 +
This example sorts all players in a nice line on the center of the map.
 +
<section name="Shared" class="both" show="true">
 +
<syntaxhighlight lang="lua">
 +
local players = getElementsByType("player")
 +
local newPlayerPosition = Vector3(-#players - 1, 0, 10) -- Initialize the position vector for the first player in the list
 +
for _, player in ipairs(players) do
 +
    -- Move each player 1 unit forward in X from the previous one
 +
    newPlayerPosition.x = newPlayerPosition.x + 1
 +
    setElementPosition(player, newPlayerPosition)
 +
end
 +
</syntaxhighlight>
 +
</section>
 +
 
 +
===cross===
 +
===dot===
 +
===normalize===
 +
 
 +
===getX and setX===
 +
===getY and setY===
 +
===getZ and setZ===
 +
===getNormalized===
 +
===getSquaredLength===
 +
===getLength===
  
 
[[ru:Vector/Vector3]]
 
[[ru:Vector/Vector3]]

Revision as of 21:35, 2 February 2015

The vector3 class represents a three-dimensional vector.

Methods

create

This is default constructor for the Vector3 class and returns a Vector3 object.

Syntax

vector3 Vector3 ( float x = 0, float y = 0, float z = 0 )
  • x, y and z: coordinates for the vector. If not specified, they default to 0.
  • Instead of these three coordinates, a single Vector3 object may be inserted to clone it.

Example

This example sorts all players in a nice line on the center of the map.

Click to collapse [-]
Shared
local players = getElementsByType("player")
local newPlayerPosition = Vector3(-#players - 1, 0, 10) -- Initialize the position vector for the first player in the list
for _, player in ipairs(players) do
    -- Move each player 1 unit forward in X from the previous one
    newPlayerPosition.x = newPlayerPosition.x + 1
    setElementPosition(player, newPlayerPosition)
end

cross

dot

normalize

getX and setX

getY and setY

getZ and setZ

getNormalized

getSquaredLength

getLength