Retrieving vertex coordinates

This forum is currently in read-only mode.
  • Hi there,

    for some reason, I get 0 when retrieving vertex coordinates from a distortion map.

    Here's the deal:

    System: Start of layout

    -> Sprite: Set distort map size to 2, 2

    And then for testing:

    + System: Always (every tick)

    -> Text: Set text to str(Sprite.VertexX(1, 1))

    Resulting in 0. Writing the vertex coord to a global variable makes no difference, neither does VertexY or VertexZ.

    What could that mean (apart from the routine being broken)?

    Cheers,

    the Colonel

  • It depends on the map, relative or absolute, and how much is displaced.

    It doesn't get a x, or y, and there are 4 vertices per row/column.

  • I see.

    That is why

    sqrt((Sprite.VertexX(0, 0) - Light.X)^2 + (Sprite.VertexY(0,0) - Light.Y)^2 + (Sprite.VertexZ(0,0) - Light.ZElevation)^2)

    returns crap if nothing is displaced yet.

    That means in order to get the absolute coordinates of a given vertex, you have to revolve it let's say around the sprite's hot spot and translate the vertex coordinates, amiright?

    The reason for all this madness is that I'm trying if it's possible to code a per vertex shader, which would enable basic lighting techniques for displaced 3d sprites.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I would think you would be better off trying to use the color filter, rather than a shader.

  • Sprite.VertexX(1, 1) returns the displacement of the point from it's normal grid position, so if the point is unmoved it will be zero. If the point is moved then it returns the displacement relative to the size of the sprite. So if the sprite is 128x128 and you set the relative displacement of (1,1) to -128,0 then then Sprite.VertexX(1, 1) would return -1.

    To calculate the absolute position of any vertex at (column, row) use the following:

    X:

    ((Sprite.VertexX(column, row)+column/Sprite.MeshCols)*Sprite.Width+Sprite.Left

    Y:

    (Sprite.VertexY(column, row)+row/Sprite.MeshRows)*Sprite.Height+Sprite.Top)

    http://dl.dropbox.com/u/5426011/examples%208/absoluteVertex.cap

    Note:

    the above expressions do not work if the sprite is rotated.

  • Cheerio! That was exactly what I needed, thx R0J0Hound! :)

    newt: Yep, it's going to be the distort map's color filter.

    Thanks

    the Colonel

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)