jGL
Loading...
Searching...
No Matches
shape.h
Go to the documentation of this file.
1#ifndef SHAPE_H
2#define SHAPE_H
3
4#include <jGL/primitive.h>
5#include <jGL/orthoCam.h>
6
7namespace jGL
8{
13 class Shape
14 {
15
16 public:
17
19 : transform(nullptr), colour(nullptr)
20 {}
21
22 Shape(const Transform * tra, const glm::vec4 * c)
23 : transform(tra), colour(c)
24 {}
25
27 const glm::vec4 * colour;
28
35 {
37 {
38 {
39 glm::vec2(-0.5, -0.5),
40 glm::vec2(-0.5, 0.5),
41 glm::vec2(0.5, 0.5),
42 glm::vec2(0.5, -0.5)
43 }
44 };
45
46 float ct = std::cos(transform->theta); float st = std::sin(transform->theta);
47 glm::mat2 rot(ct, -st, st, ct);
48 glm::vec2 pos(transform->x, transform->y);
49 glm::vec2 scale(transform->scaleX, transform->scaleY);
50
51
52 for (uint8_t i = 0; i < wbb.vertices.size(); i++)
53 {
54 wbb.vertices[i] = rot*(wbb.vertices[i]*scale)+pos;
55 }
56
57 return wbb;
58 }
59
67 {
70 glm::vec2 pos;
71 for (uint8_t i = 0; i < wbb.vertices.size(); i++)
72 {
73 pos = camera.worldToScreen(wbb.vertices[i].x, wbb.vertices[i].y);
74 sbb.vertices[i].x = uint16_t(pos.x);
75 sbb.vertices[i].y = uint16_t(pos.y);
76 }
77 return sbb;
78 }
79
80 };
81}
82
83#endif /* SHAPE_H */
An orthographic camera for 2D.
Definition orthoCam.h:21
glm::vec2 worldToScreen(float x, float y) const
Convert world position to screen coordinate.
Definition orthoCam.h:76
A drawable shape.
Definition shape.h:14
const Transform * transform
Definition shape.h:26
WorldBoundingBox getWorldBoundingBox() const
Get the WorldBoundingBox of the Shape.
Definition shape.h:34
ScreenBoundingBox getScreenBoundingBox(const OrthoCam &camera)
Get the ScreenBoundingBox of the Shape.
Definition shape.h:66
Shape()
Definition shape.h:18
Shape(const Transform *tra, const glm::vec4 *c)
Definition shape.h:22
const glm::vec4 * colour
Definition shape.h:27
A world space bounding box.
Definition primitive.h:173
A drawable graphic.
Definition id.h:10
A bounding box template.
Definition primitive.h:128
std::array< glm::tvec2< T >, 4 > vertices
Vertices of bounding box.
Definition primitive.h:141
Position, rotation, and scale.
Definition primitive.h:44
double scaleY
Definition primitive.h:62
double theta
Definition primitive.h:60
double y
Definition primitive.h:59
double scaleX
Definition primitive.h:61
double x
Definition primitive.h:58