Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
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 1442 times)
0 Members and 1 Guest are viewing this topic.
Offline roland
« Posted 2012-01-24 06: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)

Thanks,
roland
Offline lhkbob

JGO Knight


Medals: 32



« Reply #1 - Posted 2012-01-24 06: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 07: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 08: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 08: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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (17 views)
2014-07-30 21:08:39

Riven (23 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (43 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43
java-gaming.org 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‑gaming.org
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!