Vector/Vector3: Difference between revisions
Jump to navigation
Jump to search
m (Undo revision 44192 by AlexTMjugador (talk)) |
m (Restructure) |
||
Line 1: | Line 1: | ||
[[Category:Incomplete]] | [[Category:Incomplete]] | ||
The '''vector3''' class represents a three-dimensional [[vector]]. | The '''vector3''' class represents a three-dimensional [[vector]]. | ||
=== | ==Methods== | ||
===create=== | |||
This is default constructor for the Vector3 class and returns a Vector3 object. | |||
====Syntax==== | |||
<syntaxhighlight lang="lua">vector3 Vector3 ( float x = 0, float y = 0, float z = 0 )</syntaxhighlight> | |||
* | * '''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. | |||
<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 [-]
Sharedlocal 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