As usual, I used a sprite sheet found on the internet, that I put in a 1024x1024 image to avoid the potential NPOT problems. The texture can be found here, in case it’s relevant. Don’t judge me, my boss is a cat person.
My problem is that when I apply my texture transform matrix, I can see a bit of the sprite that is directly on top of the one I’m displaying. It’s like the display is offseted vertically by one pixel. As far as I can tell, I computed the matrix correctly, but I may have overlooked something.
Here’s the relevant code. Bear in mind that I snipped some validation and sanitization part to be more concise :
Code: Select all
void TBillboardAnimation::ParseTexture(ITexture * texture, TParseMethod parseMethod, int columnCount, int rowCount)
{
float horizontalRatio; //! horizontal (width) value of a node relative to the texture size
float verticalRatio; //! vertical (height) value of a node relative to the texture size
dimension2du textureSize = texture->getSize();
// Since texture matrices uses vector from 0.0f to 1.0f, we need to find the ratio between the render target and the texture size.
horizontalRatio = (f32)_Size.Width / (f32)textureSize.Width;
verticalRatio = (f32)_Size.Height / (f32)textureSize.Height;
// We loop for the number of matrices we need to parse.
int currentColumn = 0;
int currentRow = 0;
core::vector2df transformVector;
core::matrix4 transformMatrix;
for(int i = 0; i < columnCount*rowCount; i++)
{
// Create a transform vector.
transformVector = core::vector2df((f32)currentColumn * horizontalRatio, (f32)currentRow * verticalRatio);
// Build the actual texture transform matrix from the transform vector.
transformMatrix.buildTextureTransform(0.0f, core::vector2df(0.0f), transformVector, core::vector2df(horizontalRatio, verticalRatio));
// Add the texture and the transformation matrix to the frames' list.
// NOTE : I have a vector of TTransformationMatrix, which is simply a struct compounding an ITexture* with a matrix4. It's used when it's time to render.
AddTransformationMatrix(texture, transformMatrix);
// Handle the parse method
// NOTE : This is so we can have texture atlas that goes horizontally or vertically.
switch(parseMethod)
{
// Parse as Rows. Increment the columns ; once we're done with a row, return to the first column and switch row.
case TParseMethod::ByRows :
{
currentColumn++;
if(currentColumn >= columnCount)
{
currentColumn = 0;
currentRow++;
}
break;
}
// Parse as Columns. Increment the rows ; once we're done with a column, return to the first row and switch column.
case TParseMethod::ByColumns :
{
currentRow++;
if(currentRow >= rowCount)
{
currentRow = 0;
currentColumn++;
}
break;
}
}
}
}
Code: Select all
void TBillboardAnimation::render()
{
if(_TransformationMatrixVector.size() > 0)
{
TTransformationMatrix ttMatrix = _TransformationMatrixVector[GetCurrentFrame()];
setMaterialTexture(0, ttMatrix.texture);
getMaterial(0).setTextureMatrix(0, ttMatrix.matrix);
CBillboardSceneNode::render();
}
}