Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
1566 Разработка библиотеки конечно элементного моделирования процессов пластического формоизменения материалов
MeshDraws
Commits
a3c807f0
Commit
a3c807f0
authored
10 months ago
by
Миколаенко Вадим Витальевич
Browse files
Options
Download
Patches
Plain Diff
Fixed working with SFML
parent
4965b05b
master
mesh3d
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/main.cpp
+37
-59
source/main.cpp
with
37 additions
and
59 deletions
+37
-59
source/main.cpp
+
37
−
59
View file @
a3c807f0
#include
<iostream>
#include
<Mesh2d.h>
#include
<SFML/Graphics.hpp>
#include
<SFML/Window.hpp>
#include
"vector"
#include
"Mesh2d.h"
#include
"cmath"
#include
"windows.h"
#include
<SFML/Audio.hpp>
#include
<vector>
#include
<iostream>
#include
<array>
#include
<numeric>
#include
"algorithm"
#include
"array"
using
namespace
std
;
bool
Triang
(
std
::
vector
<
double
>&
FrX
,
std
::
vector
<
double
>&
FrY
,
std
::
vector
<
double
>&
W
,
std
::
vector
<
ELEMENT
>&
Elements
,
std
::
vector
<
double
>&
MeshX
,
std
::
vector
<
double
>&
MeshY
,
double
mesh_edge_length_param
);
int
main
()
{
int
main
()
{
sf
::
Clock
clock
;
auto
t1
=
clock
.
getElapsedTime
().
asSeconds
(),
t2
=
t1
;
sf
::
RenderWindow
window
(
sf
::
VideoMode
(
800
,
600
),
"My window"
);
vector
<
array
<
sf
::
Vertex
,
2
>>
lines
;
int
scale
=
4
,
delta
=
70
;
std
::
vector
<
double
>
FrX
=
{
20
,
60
,
60
,
20
};
std
::
vector
<
double
>
FrY
=
{
20
,
20
,
60
,
60
};
std
::
vector
<
std
::
array
<
sf
::
Vertex
,
2
>>
lines
;
for
(
int
el
=
0
;
el
<
FrX
.
size
();
el
++
){
FrX
[
el
]
=
FrX
[
el
]
*
scale
;
}
for
(
int
el
=
0
;
el
<
FrY
.
size
();
el
++
){
FrY
[
el
]
=
FrY
[
el
]
*
scale
;
}
std
::
vector
<
double
>
W
;
int
frame_node_count
=
FrX
.
size
();
W
.
resize
(
frame_node_count
,
-
1
);
std
::
vector
<
double
>
MeshX
;
std
::
vector
<
double
>
MeshY
;
std
::
vector
<
double
>
FrX
=
{
0
,
40
,
40
,
0
},
FrY
=
{
0
,
0
,
40
,
40
},
W
(
FrX
.
size
(),
-
1
);
std
::
vector
<
double
>
MeshX
,
MeshY
;
std
::
vector
<
ELEMENT
>
Elements
;
sf
::
Vertex
line
[
2
];
t1
=
clock
.
getElapsedTime
().
asSeconds
();
Triang
(
FrX
,
FrY
,
W
,
Elements
,
MeshX
,
MeshY
,
5
*
scale
);
Triang
(
FrX
,
FrY
,
W
,
Elements
,
MeshX
,
MeshY
,
5
);
t2
=
clock
.
getElapsedTime
().
asSeconds
();
std
::
cout
<<
"Time elapsed: "
<<
t2
-
t1
<<
std
::
endl
;
// run the program as long as the window is open
while
(
window
.
isOpen
())
{
for
(
auto
el
:
Elements
)
{
line
[
0
]
=
sf
::
Vertex
(
sf
::
Vector2f
(
MeshX
[
el
.
i
],
MeshY
[
el
.
i
]));
line
[
1
]
=
sf
::
Vertex
(
sf
::
Vector2f
(
MeshX
[
el
.
j
],
MeshY
[
el
.
j
]));
window
.
draw
(
line
,
2
,
sf
::
Lines
);
line
[
0
]
=
sf
::
Vertex
(
sf
::
Vector2f
(
MeshX
[
el
.
i
],
MeshY
[
el
.
i
]));
line
[
1
]
=
sf
::
Vertex
(
sf
::
Vector2f
(
MeshX
[
el
.
k
],
MeshY
[
el
.
k
]));
window
.
draw
(
line
,
2
,
sf
::
Lines
);
line
[
0
]
=
sf
::
Vertex
(
sf
::
Vector2f
(
MeshX
[
el
.
j
],
MeshY
[
el
.
j
]));
line
[
1
]
=
sf
::
Vertex
(
sf
::
Vector2f
(
MeshX
[
el
.
k
],
MeshY
[
el
.
k
]));
window
.
draw
(
line
,
2
,
sf
::
Lines
);
// Sleep(20);
window
.
display
();
}
// check all the window's events that were triggered since the last iteration of the loop
const
float
x_max
=
*
std
::
max_element
(
FrX
.
begin
(),
FrX
.
end
());
const
float
y_max
=
*
std
::
max_element
(
FrY
.
begin
(),
FrY
.
end
());
sf
::
View
view
(
sf
::
FloatRect
({
0.0
f
,
0.0
f
},
{
x_max
,
y_max
}));
view
.
zoom
(
1.1
);
window
.
setView
(
view
);
size_t
count
=
0
;
clock
.
restart
();
sf
::
ConvexShape
triagnle
{
3
};
triagnle
.
setFillColor
(
sf
::
Color
{
55
,
55
,
55
});
triagnle
.
setOutlineThickness
(
-
0.1
);
triagnle
.
setOutlineColor
(
sf
::
Color
::
White
);
while
(
window
.
isOpen
()){
sf
::
Event
event
;
while
(
window
.
pollEvent
(
event
))
{
// "close requested" event: we close the window
if
(
event
.
type
==
sf
::
Event
::
Closed
)
window
.
close
();
if
(
clock
.
getElapsedTime
().
asSeconds
()
>
0.1
)
{
count
=
std
::
min
(
count
+
1
,
Elements
.
size
());
clock
.
restart
();
}
window
.
display
();
window
.
clear
();
for
(
size_t
i
=
0
;
i
<
count
;
++
i
)
{
triagnle
.
setPoint
(
0
,
sf
::
Vector2f
{
(
float
)
MeshX
[
Elements
[
i
].
i
],
(
float
)
MeshY
[
Elements
[
i
].
i
]});
triagnle
.
setPoint
(
1
,
sf
::
Vector2f
{
(
float
)
MeshX
[
Elements
[
i
].
j
],
(
float
)
MeshY
[
Elements
[
i
].
j
]
});
triagnle
.
setPoint
(
2
,
sf
::
Vector2f
{
(
float
)
MeshX
[
Elements
[
i
].
k
],
(
float
)
MeshY
[
Elements
[
i
].
k
]
});
window
.
draw
(
triagnle
);
}
window
.
display
();
}
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
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!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets