![]() |
naev 0.12.6
|
Handles the Lua vector handling bindings. More...
#include "nlua_vec2.h"#include "collision.h"#include "nluadef.h"
Go to the source code of this file.
Functions | |
| static int | vectorL_new (lua_State *L) |
| Creates a new vector. | |
| static int | vectorL_newP (lua_State *L) |
| Creates a new vector using polar coordinates. | |
| static int | vectorL_copy (lua_State *L) |
| Copies a vector. | |
| static int | vectorL_tostring (lua_State *L) |
| Converts a vector to a string. | |
| static int | vectorL_add__ (lua_State *L) |
| static int | vectorL_add (lua_State *L) |
| Adds two vectors or a vector and some cartesian coordinates. | |
| static int | vectorL_sub__ (lua_State *L) |
| static int | vectorL_sub (lua_State *L) |
| Subtracts two vectors or a vector and some cartesian coordinates. | |
| static int | vectorL_mul__ (lua_State *L) |
| static int | vectorL_mul (lua_State *L) |
| Multiplies a vector by a number. | |
| static int | vectorL_div__ (lua_State *L) |
| static int | vectorL_div (lua_State *L) |
| Divides a vector by a number. | |
| static int | vectorL_unm (lua_State *L) |
| static int | vectorL_dot (lua_State *L) |
| Dot product of two vectors. | |
| static int | vectorL_cross (lua_State *L) |
| Cross product of two vectors. | |
| static int | vectorL_get (lua_State *L) |
| Gets the cartesian positions of the vector. | |
| static int | vectorL_polar (lua_State *L) |
| Gets polar coordinates of a vector. | |
| static int | vectorL_set (lua_State *L) |
| Sets the vector by cartesian coordinates. | |
| static int | vectorL_setP (lua_State *L) |
| Sets the vector by polar coordinates. | |
| static int | vectorL_distance (lua_State *L) |
| Gets the distance from the Vec2. | |
| static int | vectorL_distance2 (lua_State *L) |
| Gets the squared distance from the Vec2 (saves a sqrt()) | |
| static int | vectorL_mod (lua_State *L) |
| Gets the modulus of the vector. Lua function parameter: Vec2 v Vector to get modulus of. Lua return parameter: number The modulus of the vector. | |
| static int | vectorL_angle (lua_State *L) |
| Gets the angle of the vector. Lua function parameter: Vec2 v Vector to get angle of. Lua return parameter: number The angle of the vector. | |
| static int | vectorL_normalize (lua_State *L) |
| Normalizes a vector. Lua function parameter: Vec2 v Vector to normalize. Lua function parameter:[opt=1] number n Length to normalize the vector to. Lua return parameter: Vec2 Normalized vector. | |
| static int | vectorL_collideLineLine (lua_State *L) |
| Sees if two line segments collide. | |
| static int | vectorL_collideCircleLine (lua_State *L) |
| Computes the intersection of a line segment and a circle. | |
| int | nlua_loadVector (nlua_env env) |
| Loads the vector metatable. | |
| vec2 * | lua_tovector (lua_State *L, int ind) |
| Represents a 2D vector in Lua. | |
| vec2 * | luaL_checkvector (lua_State *L, int ind) |
| Gets vector at index making sure type is valid. | |
| vec2 * | lua_pushvector (lua_State *L, vec2 vec) |
| Pushes a vector on the stack. | |
| int | lua_isvector (lua_State *L, int ind) |
| Checks to see if ind is a vector. | |
Variables | |
| static const luaL_Reg | vector_methods [] |
Handles the Lua vector handling bindings.
These bindings control the spobs and systems.
Definition in file nlua_vec2.c.
| int lua_isvector | ( | lua_State * | L, |
| int | ind ) |
Checks to see if ind is a vector.
| L | Lua state to check. |
| ind | Index position to check. |
Definition at line 161 of file nlua_vec2.c.
Pushes a vector on the stack.
| L | Lua state to push vector onto. |
| vec | Vector to push. |
Definition at line 145 of file nlua_vec2.c.
| vec2 * lua_tovector | ( | lua_State * | L, |
| int | ind ) |
Represents a 2D vector in Lua.
This module allows you to manipulate 2D vectors. Usage is generally as follows:
To call members of the metatable always use:
Lua module: vec2
Gets vector at index.
| L | Lua state to get vector from. |
| ind | Index position of vector. |
Definition at line 119 of file nlua_vec2.c.
| vec2 * luaL_checkvector | ( | lua_State * | L, |
| int | ind ) |
Gets vector at index making sure type is valid.
| L | Lua state to get vector from. |
| ind | Index position of vector. |
Definition at line 130 of file nlua_vec2.c.
| int nlua_loadVector | ( | nlua_env | env | ) |
Loads the vector metatable.
| env | Environment to load the vector metatable into. |
Definition at line 85 of file nlua_vec2.c.
|
static |
Adds two vectors or a vector and some cartesian coordinates.
If x is a vector it adds both vectors, otherwise it adds cartesian coordinates to the vector.
Lua usage parameter: my_vec = my_vec + your_vec Lua usage parameter: my_vec:add( your_vec ) Lua usage parameter: my_vec:add( 5, 3 )
Lua function parameter: Vector v Vector getting stuff added to. Lua function parameter: number|Vec2 x X coordinate or vector to add to. Lua function parameter: number|nil y Y coordinate or nil to add to. Lua return parameter: Vec2 The result of the vector operation.
| L | Lua State |
Lua function: add
Definition at line 286 of file nlua_vec2.c.
|
static |
Definition at line 318 of file nlua_vec2.c.
|
static |
Gets the angle of the vector. Lua function parameter: Vec2 v Vector to get angle of. Lua return parameter: number The angle of the vector.
| L | Lua State |
Lua function: angle
Definition at line 715 of file nlua_vec2.c.
|
static |
Computes the intersection of a line segment and a circle.
Lua function parameter: Vector center Center of the circle. Lua function parameter: number radius Radius of the circle. Lua function parameter: Vector p1 First point of the line segment. Lua function parameter: Vector p2 Second point of the line segment. Lua return parameter: Vector|nil First point of collision or nil if no collision. Lua return parameter: Vector|nil Second point of collision or nil if single-point collision.
| L | Lua State |
Lua function: collideCircleLine
Definition at line 777 of file nlua_vec2.c.
|
static |
Sees if two line segments collide.
Lua function parameter: Vec2 s1 Start point of the first segment. Lua function parameter: Vec2 e1 End point of the first segment. Lua function parameter: Vec2 s2 Start point of the second segment. Lua function parameter: Vec2 e2 End point of the second segment. Lua return parameter: integer 0 if they don't collide, 1 if they collide on a point, 2 if they are parallel, and 3 if they are coincident.
| L | Lua State |
Lua function: collideLineLine
Definition at line 751 of file nlua_vec2.c.
|
static |
Copies a vector.
Lua function parameter: Vec2 v Vector to copy. Lua return parameter: Vec2 A copy of v.
| L | Lua State |
Lua function: copy
Definition at line 247 of file nlua_vec2.c.
|
static |
Cross product of two vectors.
Lua function parameter: Vec2 a First vector. Lua function parameter: Vec2 b Second vector. Lua return parameter: number The cross product.
| L | Lua State |
Lua function: cross
Definition at line 540 of file nlua_vec2.c.
|
static |
Gets the distance from the Vec2.
Lua usage parameter: my_vec:dist() – Gets length of the vector (distance from origin). Lua usage parameter: my_vec:dist( your_vec ) – Gets distance from both vectors (your_vec - my_vec).
Lua function parameter: Vec2 v Vector to act as origin. Lua function parameter:[opt=vec2.new()] Vec2 v2 Vector to get distance from, uses origin (0,0) if not set. Lua return parameter: number The distance calculated.
| L | Lua State |
Lua function: dist
Definition at line 648 of file nlua_vec2.c.
|
static |
Gets the squared distance from the Vec2 (saves a sqrt())
Lua usage parameter: my_vec:dist2() – Gets squared length of the vector (distance squared from origin). Lua usage parameter: my_vec:dist2( your_vec ) – Gets squared distance from both vectors (your_vec - my_vec)^2.
Lua function parameter: Vec2 v Vector to act as origin. Lua function parameter:[opt=vec2.new()] Vec2 v2 Vector to get squared distance from, uses origin (0,0) if not set. Lua return parameter: number The distance calculated.
| L | Lua State |
Lua function: dist2
Definition at line 679 of file nlua_vec2.c.
|
static |
Divides a vector by a number.
Lua usage parameter: my_vec = my_vec / 3 Lua usage parameter: my_vec:div(3)
Lua function parameter: Vec2 v Vector to divide. Lua function parameter: number mod Amount to divide by. Lua return parameter: Vec2 The result of the vector operation.
| L | Lua State |
Lua function: div
Definition at line 478 of file nlua_vec2.c.
|
static |
Definition at line 493 of file nlua_vec2.c.
|
static |
Dot product of two vectors.
Lua function parameter: Vec2 a First vector. Lua function parameter: Vec2 b Second vector. Lua return parameter: number The dot product.
| L | Lua State |
Lua function: dot
Definition at line 524 of file nlua_vec2.c.
|
static |
Gets the cartesian positions of the vector.
Lua usage parameter: x,y = my_vec:get()
Lua function parameter: Vec2 v Vector to get position of. Lua return parameter: number X position of the vector. Lua return parameter: number Y position of the vector.
| L | Lua State |
Lua function: get
Definition at line 558 of file nlua_vec2.c.
|
static |
Gets the modulus of the vector. Lua function parameter: Vec2 v Vector to get modulus of. Lua return parameter: number The modulus of the vector.
| L | Lua State |
Lua function: mod
Definition at line 702 of file nlua_vec2.c.
|
static |
Multiplies a vector by a number.
Lua usage parameter: my_vec = my_vec * 3 Lua usage parameter: my_vec:mul( 3 )
Lua function parameter: Vec2 v Vector to multiply. Lua function parameter: number mod Amount to multiply by. Lua return parameter: Vec2 The result of the vector operation.
| L | Lua State |
Lua function: mul
Definition at line 427 of file nlua_vec2.c.
|
static |
Definition at line 451 of file nlua_vec2.c.
|
static |
Creates a new vector.
Lua usage parameter: vec2.new( 5, 3 ) – creates a vector at (5,3) Lua usage parameter: vec2.new() – creates a vector at (0,0)
Lua function parameter:[opt=0] number x If set, the X value for the new vector. Lua function parameter:[opt=x] number y If set, the Y value for the new vector. Lua return parameter: Vec2 The new vector.
| L | Lua State |
Lua function: new
Definition at line 188 of file nlua_vec2.c.
|
static |
Creates a new vector using polar coordinates.
Lua usage parameter: vec2.newP( 1000, 90 ) – creates a vector at (0,1000) Lua usage parameter: vec2.newP() – creates a vector at (0,0)
Lua function parameter:[opt=0] number m If set, the modulus for the new vector. Lua function parameter:[opt=0] number a If set, the angle for the new vector, in radians. Lua return parameter: Vec2 The new vector.
| L | Lua State |
Lua function: newP
Definition at line 220 of file nlua_vec2.c.
|
static |
Normalizes a vector. Lua function parameter: Vec2 v Vector to normalize. Lua function parameter:[opt=1] number n Length to normalize the vector to. Lua return parameter: Vec2 Normalized vector.
| L | Lua State |
Lua function: normalize
Definition at line 729 of file nlua_vec2.c.
|
static |
Gets polar coordinates of a vector.
The angle is in radians.
Lua usage parameter: modulus, angle = my_vec:polar()
Lua function parameter: Vec2 v Vector to get polar coordinates of. Lua return parameter: number The modulus of the vector. Lua return parameter: number The angle of the vector.
| L | Lua State |
Lua function: polar
Definition at line 579 of file nlua_vec2.c.
|
static |
Sets the vector by cartesian coordinates.
Lua usage parameter: my_vec:set(5, 3) – my_vec is now (5,3)
Lua function parameter: Vec2 v Vector to set coordinates of. Lua function parameter: number x X coordinate to set. Lua function parameter: number y Y coordinate to set.
| L | Lua State |
Lua function: set
Definition at line 597 of file nlua_vec2.c.
|
static |
Sets the vector by polar coordinates.
Lua usage parameter: my_vec:setP( 1, 90 ) – my_vec is now (0,1)
Lua function parameter: Vec2 v Vector to set coordinates of. Lua function parameter: number m Modulus to set. Lua function parameter: number a Angle to set, in radians.
| L | Lua State |
Lua function: setP
Definition at line 621 of file nlua_vec2.c.
|
static |
Subtracts two vectors or a vector and some cartesian coordinates.
If x is a vector it subtracts both vectors, otherwise it subtracts cartesian coordinates to the vector.
Lua usage parameter: my_vec = my_vec - your_vec Lua usage parameter: my_vec:sub( your_vec ) Lua usage parameter: my_vec:sub( 5, 3 )
Lua function parameter: Vec2 v Vector getting stuff subtracted from. Lua function parameter: number|Vec2 x X coordinate or vector to subtract. Lua function parameter: number|nil y Y coordinate or nil to subtract. Lua return parameter: Vec2 The result of the vector operation.
| L | Lua State |
Lua function: sub
Definition at line 362 of file nlua_vec2.c.
|
static |
Definition at line 389 of file nlua_vec2.c.
|
static |
Converts a vector to a string.
Lua function parameter: Vector v Vector to convert to as string. Lua return parameter: string String version of v.
| L | Lua State |
Lua function: __tostring
Definition at line 261 of file nlua_vec2.c.
|
static |
Definition at line 507 of file nlua_vec2.c.
|
static |
Vector metatable methods.
Definition at line 50 of file nlua_vec2.c.