Skip to content

Commit

Permalink
Merge pull request TrenchBroom#4189 from TrenchBroom/4140-sprite-offset
Browse files Browse the repository at this point in the history
4140: Fix sprite alignment
  • Loading branch information
kduske authored Jan 23, 2023
2 parents 3f59b4e + 9673db5 commit a06164e
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 154 deletions.
24 changes: 14 additions & 10 deletions common/src/IO/ImageSpriteParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,24 @@ void ImageSpriteParser::doLoadFrame(
{
const auto w = static_cast<float>(texture->width());
const auto h = static_cast<float>(texture->height());
const auto x = w / 2.0f;
const auto y = h / 2.0f;
const auto x1 = -w / 2.0f;
const auto y1 = -h / 2.0f;
const auto x2 = x1 + w;
const auto y2 = y1 + h;

auto& frame = model.loadFrame(
frameIndex, m_name, vm::bbox3f{vm::vec3f{-x, -y, 0}, vm::vec3f{x, y, 0}});

const auto bboxMin = vm::vec3f{vm::min(x1, x2), vm::min(x1, x2), vm::min(y1, y2)};
const auto bboxMax = vm::vec3f{vm::max(x1, x2), vm::max(x1, x2), vm::max(y1, y2)};
auto& frame = model.loadFrame(frameIndex, m_name, {bboxMin, bboxMax});

const auto triangles = std::vector<Assets::EntityModelVertex>{
Assets::EntityModelVertex{{-x, -y, 0}, {0, 1}},
Assets::EntityModelVertex{{-x, +y, 0}, {0, 0}},
Assets::EntityModelVertex{{+x, +y, 0}, {1, 0}},
Assets::EntityModelVertex{{x1, y1, 0}, {0, 1}},
Assets::EntityModelVertex{{x1, y2, 0}, {0, 0}},
Assets::EntityModelVertex{{x2, y2, 0}, {1, 0}},

Assets::EntityModelVertex{{+x, +y, 0}, {1, 0}},
Assets::EntityModelVertex{{+x, -y, 0}, {1, 1}},
Assets::EntityModelVertex{{-x, -y, 0}, {0, 1}},
Assets::EntityModelVertex{{x2, y2, 0}, {1, 0}},
Assets::EntityModelVertex{{x2, y1, 0}, {1, 1}},
Assets::EntityModelVertex{{x1, y1, 0}, {0, 1}},
};

auto size = Renderer::IndexRangeMap::Size{};
Expand Down
7 changes: 4 additions & 3 deletions common/src/IO/SprParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,13 @@ std::unique_ptr<Assets::EntityModel> SprParser::doInitializeModel(Logger& /* log
const auto w = static_cast<float>(pictureFrame.width);
const auto h = static_cast<float>(pictureFrame.height);
const auto x1 = static_cast<float>(pictureFrame.x);
const auto y1 = -static_cast<float>(pictureFrame.y);
const auto y1 = static_cast<float>(pictureFrame.y) - h;
const auto x2 = x1 + w;
const auto y2 = y1 + h;

auto& modelFrame = model->loadFrame(
i, std::to_string(i), {vm::vec3f{x1, y1, 0}, vm::vec3f{x2, y2, 0}});
const auto bboxMin = vm::vec3f{vm::min(x1, x2), vm::min(x1, x2), vm::min(y1, y2)};
const auto bboxMax = vm::vec3f{vm::max(x1, x2), vm::max(x1, x2), vm::max(y1, y2)};
auto& modelFrame = model->loadFrame(i, std::to_string(i), {bboxMin, bboxMax});

const auto triangles = std::vector<Assets::EntityModelVertex>{
Assets::EntityModelVertex{{x1, y1, 0}, {0, 1}},
Expand Down
Loading

0 comments on commit a06164e

Please sign in to comment.