Retrieving vertex coordinates

For questions about using Classic.

Post » Sun Jan 22, 2012 3:00 pm

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
Image
B
17
S
5
G
1
Posts: 122
Reputation: 1,930

Post » Sun Jan 22, 2012 7:08 pm

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.
Image ImageImage
B
166
S
49
G
154
Posts: 8,096
Reputation: 100,213

Post » Sun Jan 22, 2012 7:41 pm

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.
Image
B
17
S
5
G
1
Posts: 122
Reputation: 1,930

Post » Sun Jan 22, 2012 8:11 pm

I would think you would be better off trying to use the color filter, rather than a shader.
Image ImageImage
B
166
S
49
G
154
Posts: 8,096
Reputation: 100,213

Post » Sun Jan 22, 2012 8:54 pm

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.
B
89
S
30
G
94
Posts: 5,152
Reputation: 62,940

Post » Sun Jan 22, 2012 9:40 pm

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
Image
B
17
S
5
G
1
Posts: 122
Reputation: 1,930


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: WhosWho and 4 guests