I have setup an orthographic camera, and i am calling the below method within a class that holds a planar quad node. Its purpose is to set the uv on the node so that only a source rectangle from the texture will map into the quad.
Here is how it is used:
Code: Select all
MyQuadNode.setTextureAndUV( "myTexture.png", rect<s32>(0,0,100,100) ) ;
It should be simple enough, and in fact works great with tex rect coordinates starting at (0,0) as above.
It does not work anymore if i pass, say,
Code: Select all
MyQuadNode.setTextureAndUV( "myTexture.png", rect<s32>(10,10,100,100) ) ;
Here is the source code for the uv method:
Code: Select all
void MyQuadNode::setTextureAndUV( const video::ITexture* texture, const RenderMan::rect<s32>& sourceTexRect )
{
dimension2du texsize = texture->getSize() ;
dimension2df uvScaleFactor( sourceTexRect.getWidth()/texsize.Width, sourceTexRect.getHeight()/texsize.Height ) ;
position2d rectCenter = sourceTexRect.getCenter();
vector2df translation0 = vector2df( (1.f*rectCenter.X)/texsize.Width, (1.f*rectCenter.Y)/texsize.Height )/vector2df( uvScaleFactor.Width, uvScaleFactor.Height ) ;
vector2df translation = translation0 - vector2df(0.5f, 0.5f);
getMaterial().setTexture(0, texture );
getMaterial().getTextureMatrix( 0 ).buildTextureTransform( 0*DEGTORAD64,
vector2df(0.f, 0.f),
translation ,
uvScaleFactor );
}Thanks for any suggestion.