TouchOSC

Next generation modular control surface
TouchOSC Manual

Script · Objects · Vectors


TouchOSC provides 2,3 and 4 component vector types as Vec2 Vec3 Vec4 objects.



Fields

 

vec2.x
vec3.x
vec4.x

The x component of the vector.

 

vec2.y
vec3.y
vec4.y

The y component of the vector.

 

vec3.z
vec4.z

The z component of the vector.

 

vec4.w

The w component of the vector.

 


Constructor Functions

 

function Vec2()                                -- [1]
function Vec2(vec2)                            -- [2]
function Vec2(number)                          -- [3]
function Vec2(number, number)                  -- [4]

function Vec3()                                -- [1]
function Vec3(vec3)                            -- [2]
function Vec3(number)                          -- [3]
function Vec3(number, number, number)          -- [4]

function Vec4()                                -- [1]
function Vec4(vec4)                            -- [2]
function Vec4(number)                          -- [3]
function Vec4(number, number, number, number)  -- [4]

Returns a new vector object with

  1. all components initialized with 0.0.
  2. all components copied from another vector object.
  3. all components initialized with number.
  4. each component initialized with the numbers provided.

 


Functions

 

function length()


-- example
local v = Vec2(1,0)
local l = v:length()
print(l)
> 1

Returns the length of the vector

 

function normalize()


-- example
local v = Vec2(1,1)
local n = v:normalize()

Returns a new vector that is the normalized vector

 


Operators

 

-- multiplication
vector * vector
vector * number

-- division
vector / vector
vector / number

-- addition
vector + vector
vector + number

-- subtraction
vector - vector
vector - number

All operators operate component-wise and return a new vector object.

 


Cookie Policy

We use cookies to deliver website content. By continuing without changing your preferences, you agree to our use of cookies.