diff --git a/samples/golf/src/golf/GolfStateUI.cpp b/samples/golf/src/golf/GolfStateUI.cpp index b1053e28a..d8add218a 100644 --- a/samples/golf/src/golf/GolfStateUI.cpp +++ b/samples/golf/src/golf/GolfStateUI.cpp @@ -1759,6 +1759,10 @@ void GolfState::buildUI() mapEnt.getComponent().addChild(entity.getComponent()); + auto dbEnt = m_uiScene.createEntity(); + dbEnt.addComponent().setPosition({ 0.f, 0.f, 0.1f }); + dbEnt.addComponent().setPrimitiveType(GL_LINE_STRIP); + //stroke indicator entity = m_uiScene.createEntity(); entity.addComponent().setScale({ 0.f, 0.f }); @@ -1767,7 +1771,7 @@ void GolfState::buildUI() entity.addComponent().active = true; entity.getComponent().setUserData(0.f); entity.getComponent().function = - [&, mapEnt](cro::Entity e, float dt) + [&, mapEnt, dbEnt](cro::Entity e, float dt) mutable { e.getComponent().setPosition(glm::vec3(m_minimapZoom.toMapCoords(m_currentPlayer.position), 0.01f)); e.getComponent().setRotation(m_inputParser.getYaw() + m_minimapZoom.tilt); @@ -1801,11 +1805,16 @@ void GolfState::buildUI() } //4 is the relative size of the sprite to the texture... need to update this if we make sprite scale dynamic - e.getComponent().setScale(glm::vec2(scale, 1.f) * (1.f / mapEnt.getComponent().getScale().x)); + const auto InverseScale = (1.f / mapEnt.getComponent().getScale().x); + e.getComponent().setScale(glm::vec2(scale, 1.f) * InverseScale); auto miniBounds = mapEnt.getComponent().getWorldTransform() * mapEnt.getComponent().getLocalBounds(); - miniBounds = glm::inverse(e.getComponent().getWorldTransform()) * miniBounds; - + auto wt = e.getComponent().getWorldTransform(); + auto q = glm::rotate(cro::Transform::QUAT_IDENTITY, -e.getComponent().getRotation2D(), cro::Transform::Z_AXIS); + + miniBounds = glm::inverse(wt) * miniBounds; + //miniBounds = glm::toMat4(q) * miniBounds; + /*auto miniBounds = mapEnt.getComponent().getLocalBounds(); const auto wScale = mapEnt.getComponent().getWorldScale().x; miniBounds *= wScale; @@ -1813,9 +1822,19 @@ void GolfState::buildUI() miniBounds.bottom -= e.getComponent().getPosition().x * wScale;*/ e.getComponent().setCroppingArea(miniBounds); + + std::vector verts = + { + cro::Vertex2D(glm::vec2(miniBounds.left, miniBounds.bottom), cro::Colour::Magenta), + cro::Vertex2D(glm::vec2(miniBounds.left + miniBounds.width, miniBounds.bottom), cro::Colour::Magenta), + cro::Vertex2D(glm::vec2(miniBounds.left + miniBounds.width, miniBounds.bottom + miniBounds.height), cro::Colour::Magenta), + cro::Vertex2D(glm::vec2(miniBounds.left, miniBounds.bottom + miniBounds.height), cro::Colour::Magenta), + cro::Vertex2D(glm::vec2(miniBounds.left, miniBounds.bottom), cro::Colour::Magenta), + }; + dbEnt.getComponent().setVertexData(verts); }; mapEnt.getComponent().addChild(entity.getComponent()); - + entity.getComponent().addChild(dbEnt.getComponent()); //green close up view