Hello Guest

Author Topic: How do I read UV values?  (Read 4244 times)

roid100

  • Newbie
  • *
  • Posts: 6
    • View Profile
How do I read UV values?
« on: March 25, 2013, 09:35:28 am »
Hello,
When I searched the boards, I found this way to calculate the posion of Uvs.

float fX = (sourceTexture.width) * UVs[0].x;
float fY = (sourceTexture.height) * UVs[2].y;
float fX2 = (sourceTexture.width) * UVs[1].x;;
float fY2 = (sourceTexture.height) * UVs[0].y;
float fWidth = fX2 - fX;
float fHeight = -(fY2 - fY);

Almost of all sprite has no problem with this code,
but just some of sprites in the same Collection has got a problem.
They have zero value for 'fWidth'

I attached a JPG.
As you see, some of my sprites has the same value for Uvs[0].x and Uvs[1].x

What is the problem?
How can I read the value of Uvs?

Help me please~~

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How do I read UV values?
« Reply #1 on: March 25, 2013, 01:01:47 pm »
Refer to tk2dClippedSprite.cs - SetGeometry. The orientation of the sprite is explained in there with ascii art diagrams.
Some sprites may be rotated, which is probably why having a problem with it doing it the way you're doing it there.

roid100

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: How do I read UV values?
« Reply #2 on: March 25, 2013, 01:27:17 pm »
Yes!
I've checked it, and it had been rotated.
One more question please.
Is there easy way to check if it is roated or not in script?
If there is, how can I do?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How do I read UV values?
« Reply #3 on: March 25, 2013, 03:16:05 pm »
Yup, that code in tk2dClippedSprite there tells you.

// Prior to tk2d 1.92,
if (sourceTexture.flipped)  // its rotated and flipped (what usually happens in tk2d)

// tk2d 1.92++
if (sourceTexture.flipped != tk2dSpriteCollectionData.FlipMode.None) // if !flipped
// tk2d 1.92 onwards supports other forms of flipping / rotating.