Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

vec2 [ANSWERED]

edited November 2011 in Questions Posts: 3

I've seen references to vec2 to create vectors in some examples. Are there any docs on how to use vec2? I'm curious if it has methods like add(), sub(), mag(), etc.. and functions in a similar way to PVector in Processing. Thanks!

Comments

  • In a similiar vein I see vec3 in the autocomplete but not in the descriptions, is it available?

  • DylanDylan Admin Mod
    Posts: 121

    Hi vince,
    There is documentation for vec2 in the reference.
    You can view it online here
    http://twolivesleft.com/Codea/Reference/#functions/index/graphics

    Or from the browser in Codify

  • SimeonSimeon Admin Mod
    edited November 2011 Posts: 4,847

    vec2 has overloaded operators, unlike Processing's PVector. Here's a quick example:

    -- 
    v1 = vec2(1,0)
    v2 = vec2(1,1)
    v3 = v1 + v2 * 2
    
    print(v3)
    
    -- prints "(3, 2)"
    

    You can call methods on a vec2 instance by using the colon operator, so:

    normv3 = v3:normalize()
    

    See the documentation that Dylan mentioned for the rest of the API.

  • Posts: 3

    Thanks! Just what I was looking for.

Sign In or Register to comment.