Skip to content

Commit

Permalink
Add jngl::Rect::drawBoundingBox
Browse files Browse the repository at this point in the history
  • Loading branch information
jhasse committed Nov 30, 2024
1 parent 511aa1b commit 13fe217
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
30 changes: 30 additions & 0 deletions src/jngl/Rect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2024 Jan Niklas Hasse <[email protected]>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
#include "Rect.hpp"

#include "Rgba.hpp"
#include "shapes.hpp"

namespace jngl {

double Rect::getX() const {
return pos.x;
}

double Rect::getY() const {
return pos.y;
}

double Rect::getWidth() const {
return size.x;
}

double Rect::getHeight() const {
return size.y;
}

void Rect::drawBoundingBox(Mat3 modelview) const {
jngl::drawRect(modelview.translate(pos), size, 0xff0000aa_rgba);
}

} // namespace jngl
14 changes: 9 additions & 5 deletions src/jngl/Rect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
/// @file
#pragma once

#include "Mat3.hpp"
#include "Vec2.hpp"

namespace jngl {

/// Simple struct for a rectangle, can be use with jngl::contains
struct Rect {
double getX() const { return pos.x; }
double getY() const { return pos.y; }
double getWidth() const { return size.x; }
double getHeight() const { return size.y; }
double getX() const;
double getY() const;
double getWidth() const;
double getHeight() const;

/// Draws a red box around the rectangle
void drawBoundingBox(Mat3 modelview) const;

Vec2 pos;
Vec2 size;
Vec2 size;
};

} // namespace jngl

0 comments on commit 13fe217

Please sign in to comment.