Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Glow
glow-extras
Commits
4a664b55
Commit
4a664b55
authored
May 27, 2019
by
Philip Trettner
Browse files
more 2D graphics
parent
22266479
Changes
1
Hide whitespace changes
Inline
Side-by-side
vector/glow-extras/vector/graphics2D.hh
View file @
4a664b55
...
...
@@ -17,6 +17,7 @@ struct stroke2D
stroke2D
()
=
default
;
stroke2D
(
tg
::
color3
const
&
c
)
:
color
(
c
,
1.0
f
),
width
(
1.0
f
)
{}
stroke2D
(
tg
::
color4
const
&
c
,
float
w
=
1.0
f
)
:
color
(
c
),
width
(
w
)
{}
stroke2D
(
float
r
,
float
g
,
float
b
,
float
a
=
1.0
f
)
:
color
(
r
,
g
,
b
,
a
),
width
(
1.0
f
)
{}
};
struct
fill2D
{
...
...
@@ -25,6 +26,7 @@ struct fill2D
fill2D
()
=
default
;
fill2D
(
tg
::
color4
const
&
c
)
:
color
(
c
)
{}
fill2D
(
tg
::
color3
const
&
c
)
:
color
(
c
)
{}
fill2D
(
float
r
,
float
g
,
float
b
,
float
a
=
1.0
f
)
:
color
(
r
,
g
,
b
,
a
)
{}
};
/// High-level API for writing to images
...
...
@@ -38,6 +40,11 @@ struct fill2D
/// Example:
/// g.draw(tg::pos3{...}, {1, 0, 0}); // 1px red dot
/// g.draw(tg::segment3{...}, {tg::color3::blue, 5.0f}); // 5px blue segment
///
/// TODO:
/// - infinite types like ray and line
/// - vectors
/// - think about customization points
struct
graphics2D
{
explicit
graphics2D
(
image2D
&
img
)
:
img
(
img
)
{}
...
...
@@ -66,6 +73,30 @@ public:
perform_draw
(
stroke
);
}
void
draw
(
tg
::
triangle2
const
&
t
,
stroke2D
const
&
stroke
)
{
img
.
begin_path
();
img
.
move_to
(
t
.
pos0
);
img
.
line_to
(
t
.
pos1
);
img
.
line_to
(
t
.
pos2
);
img
.
line_to
(
t
.
pos0
);
perform_draw
(
stroke
);
}
void
draw
(
tg
::
circle2
const
&
c
,
stroke2D
const
&
stroke
)
{
img
.
begin_path
();
img
.
circle
(
c
.
center
,
c
.
radius
);
perform_draw
(
stroke
);
}
void
draw
(
tg
::
sphere2
const
&
s
,
stroke2D
const
&
stroke
)
{
img
.
begin_path
();
img
.
circle
(
s
.
center
,
s
.
radius
);
perform_draw
(
stroke
);
}
// filling
public:
void
fill
(
tg
::
aabb2
const
&
r
,
fill2D
const
&
fill
)
...
...
@@ -75,6 +106,33 @@ public:
perform_fill
(
fill
);
}
void
fill
(
tg
::
triangle2
const
&
t
,
fill2D
const
&
fill
)
{
img
.
begin_path
();
img
.
move_to
(
t
.
pos0
);
img
.
line_to
(
t
.
pos1
);
img
.
line_to
(
t
.
pos2
);
img
.
line_to
(
t
.
pos0
);
perform_fill
(
fill
);
}
void
fill
(
tg
::
circle2
const
&
c
,
fill2D
const
&
fill
)
{
img
.
begin_path
();
img
.
circle
(
c
.
center
,
c
.
radius
);
perform_fill
(
fill
);
}
void
fill
(
tg
::
sphere2
const
&
s
,
fill2D
const
&
fill
)
{
img
.
begin_path
();
img
.
circle
(
s
.
center
,
s
.
radius
);
perform_fill
(
fill
);
}
public:
image2D_low_level_api
&
low_level_api
()
{
return
img
;
}
private:
void
perform_draw
(
stroke2D
const
&
s
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment