Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (710)
Games in Android Showcase (212)
games submitted by our members
Games in WIP (784)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Texture coordinates on different sized triangles  (Read 1987 times)
0 Members and 1 Guest are viewing this topic.
Offline roland
« Posted 2012-01-24 05:35:02 »

Hi, I would like a texture to look the same on all triangles, no matter what size, how skinny/stretched they are.
How can I do this with u,v coordinates?

[Edit] I also need the texture to repeat (so < 0 and > 1 coordinates are ok)

Offline lhkbob

JGO Knight

Medals: 32

« Reply #1 - Posted 2012-01-24 05:44:02 »

Do you mean same size when projected onto the screen or when in 3D space?

You would assign your largest triangles UV coordinates so that the maximum vertex of the triangle has coordinates referencing the maximum edge of the texture.  Then you compare a triangles dimensions to with the largest and scale its UVs by the same ratio.  This will only have a subset of the image on the smaller textures.  I'm not entirely sure of the math, I'm sleepy, but it would create a reasonable effect.

Another alternative is to have your smallest triangles map the entire image, and then use a UV wrapping mode so that the image is repeated or mirrored.  The UVs for your larger triangles will then be scaled up by the ratio of their dimension increase (i.e. the opposite of above, where you would scale down).

Offline roland
« Reply #2 - Posted 2012-01-24 06:30:15 »

thanks for the reply, lhkbob.

Edit: sorry, my program was working,  I was just using the wrong texture coordinates.

Thanks again  Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lhkbob

JGO Knight

Medals: 32

« Reply #3 - Posted 2012-01-24 07:11:48 »

That picture helps a lot, I misunderstood your question.  I thought you wanted the same image to be shown within each triangle.

What the picture looks like is that each triangle is accessing a different part of a single image, you just want the picture data to not be stretched and skewed.  If this is the right interpretation, you can fix it pretty easily by imagining how the triangles lie on the image.  Since they are 2D (I think so in your case since you said it was 2D world), this is pretty easy.

Your UV coordinates for every triangle share the same coordinate space, and you consider the origin to be the bottom left of the image.  Then you determine where each triangle's 3 vertices would lie within the image and use those values from 0 to 1 (where 1 is the far edge, either top or right).

If you're in 3D, it's much the same logic but you have to figure out some way to unwrap your 3D set of triangles to all lie flat within the image plane.  Since you're 2D, everything is already unwrapped for you.

Offline roland
« Reply #4 - Posted 2012-01-24 07:20:56 »

Thanks, that's a better way to do it. Then you don't have to loop through all the vertices to find the largest  Smiley
Even though my problem turned out to be my own fault I think this might come in handy sometime.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

numerical (56 views)
2017-02-21 07:32:16

numerical (55 views)
2017-02-21 07:31:46

theagentd (161 views)
2017-02-18 13:42:33

theagentd (164 views)
2017-02-18 13:35:16

h.pernpeintner (1327 views)
2017-01-24 22:39:11

h.pernpeintner (1315 views)
2017-01-24 22:38:32

Galdo (1875 views)
2017-01-12 13:44:09

Archive (1967 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2506 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2307 views)
2016-12-15 21:50:57
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!