Howdy, Stranger!

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

In this Discussion

Tracking direction of movement

edited December 2012 in Examples Posts: 22

I am still playing around and am questioning whether I am going about this in the simplest fashion. I've created a triangle mesh and am able to update the vertices to move it across the screen. Firstly, is this the best way to create movement? Secondly, how would I determine the direction/heading? I'm assuming I would have to do some vector calculations, but is there another way?

setup()
    triangle.vertices = {vec2(0,0),vec2(80,40),vec2(0,80)}

draw()
    triangle:draw()
    i = i + 1

    v3 = triangle:vertex(i%3+1)
    v2 = vec2(v3.x, v3.y) 

    i2 = v2 + vec2(3,3)  
    triangle:vertex(i%3+1, i2)

Lastly, why does the mesh:vertex() method return a vec3? Is it necessary to change it to a vec2 as I have?
Thanks much!
Still having fun,
Mark

Tagged:

Comments

  • Jmv38Jmv38 Mod
    edited December 2012 Posts: 3,295

    1- movement: mesh are the fastest way to draw many things. If all these things are stable relative to one another, the best way for movement is to use global commands: translate(), rotate(), scale(). If these things have independant movements then you can only move them by mesh:vertex().
    2- direction: depends on what you want to do...?
    3- mesh vec3: the vertex of the mesh are vec(3), for 3d, but codea add some cool way to init them if you work in 2d only: you can set them as vec2, codea adds the missing z coordinate ( 0?). I would suggest you to keep your position in a vec2 table, and pass them to the mesh when they change, rather that reading the mesh vec3 value after it has been set. It takes more memory, but will be much simpler if you are not familiar with vectors.
    Also: the first elements of the mesh are drawn first, it is important if opacity come into play.

Sign In or Register to comment.