Jeff Ward Posted January 9, 2017 Report Share Posted January 9, 2017 I'm trying to integrate spriter into my home grown engine that uses a 3D rendering system on the back end. I'm using SpriterPlusPlus and I've overridden SpriterEngine::AtlasFile to render the actual images, but things don't seem to be in the right place. I'm basing my code off this file in the sample: https://github.com/lucidspriter/SpriterPlusPlus/blob/master/example/override/sfmlimagefile.cpp For the time being, everything is essentially being rendered with a unit square centered at 0, 0 (instead of the top left corner at 0, 0). Things I'm not sure about are that initial translation by atlasData.spriteSourcePosition, and the move of the pivot by -0.5. I think putting the top left corner at 0, 0 might solve the pivot problem, but I'm not sure what the spriteSourcePosition translation is doing. Here's the psuedo code for rendering (in AtlasFile::renderSprite) transform = identity() if(atlasData.rotated) { transform = scale(atlasData.frameSize.y, atlasData.frameSize.x) transform *= translate(atlasData.spriteSourcePosition.y, atlasData.spriteSourcePosition.x) transform *= rotateZ(PI / 2) } else { transform = scale(atlasData.frameSize.x, atlasData.frameSize.y) transform *= translate(atlasData.spriteSourcePosition.x, atlasData.spriteSourcePosition.y) } transform *= translate(-(pivot.x - 0.5) * atlasData.sourceSize.x, -(pivot.y - 0.5f) * atlasData.sourceSize.y) transform *= spriteInfo->scale transform *= rotateZ(-spriteInfo->getAngle()) transform *= translate(spriteInfo->getPosition()) Anyone see anything obvious? Quote Link to comment Share on other sites More sharing options...
Jeff Ward Posted January 9, 2017 Author Report Share Posted January 9, 2017 Of course, as soon as I wrote this I figured it out. Key was actualy realizing that I should be using a unit square with the top left at (0, 0), not centered at 0, 0. Other weirdness is rotated versions should use atlasData.spriteSourcePosition.y - atlasData.sourceSize.y, where non-rotated use atlasData.spriteSourcePosition.y unmodified Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.