Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bbguimaraes
college
Commits
8e7a235c
Commit
8e7a235c
authored
Jul 17, 2016
by
bbguimaraes
Browse files
sms: isolated code for updating forces
parent
ef75f42a
Changes
3
Hide whitespace changes
Inline
Side-by-side
sms/sms/include/display.h
View file @
8e7a235c
...
...
@@ -37,6 +37,9 @@ class Display : public QGLWidget {
void
set_draw_grid
(
bool
d
)
{
this
->
m_draw_grid
=
d
;}
void
set_draw_axes
(
bool
d
)
{
this
->
m_draw_axes
=
d
;}
const
Mass
*
selected
()
const
{
return
this
->
m_selected
;}
Vector
selected_force
()
const
{
return
this
->
m_selected_force
;}
public
slots
:
void
update_systems
();
...
...
@@ -59,6 +62,7 @@ class Display : public QGLWidget {
std
::
vector
<
Simulation
*>
m_simulations
;
Mass
*
m_selected
;
Vector
m_selected_force
;
Camera
m_camera
;
GLuint
m_texture
;
GLUquadric
*
m_quadric
;
...
...
sms/sms/src/display.cpp
View file @
8e7a235c
...
...
@@ -88,7 +88,7 @@ void Display::select(Vector click, bool rate_limit) {
glMatrixMode
(
GL_MODELVIEW
);
glLoadIdentity
();
Rendering
::
set_camera
(
this
->
m_camera
);
Mass
*
selected
=
nullptr
;
this
->
m_
selected
=
nullptr
;
for
(
auto
simulation
:
this
->
m_simulations
)
for
(
auto
system
:
*
simulation
->
systems
())
{
glRenderMode
(
GL_SELECT
);
...
...
@@ -97,13 +97,12 @@ void Display::select(Vector click, bool rate_limit) {
Rendering
::
draw_masses
(
system
,
GL_SELECT
,
this
->
m_quadric
,
this
->
m_selected
);
if
(
glRenderMode
(
GL_RENDER
)
!=
0
)
{
selected
=
&
(
*
system
->
masses
())[
select_buffer
[
3
]];
this
->
m_
selected
=
&
(
*
system
->
masses
())[
select_buffer
[
3
]];
break
;
}
}
glMatrixMode
(
GL_PROJECTION
);
glPopMatrix
();
this
->
m_selected
=
selected
;
}
/*slot*/
...
...
@@ -185,7 +184,7 @@ void Display::mousePressEvent(QMouseEvent * event) {
void
Display
::
mouseReleaseEvent
(
QMouseEvent
*
event
)
{
if
(
event
->
button
()
==
Qt
::
LeftButton
&&
this
->
m_selected
)
this
->
m_selected
->
set
_force
(
Vector
()
)
;
this
->
m_selected_force
=
Vector
();
}
void
Display
::
mouseMoveEvent
(
QMouseEvent
*
event
)
{
...
...
@@ -206,7 +205,7 @@ void Display::mouseMoveEvent(QMouseEvent * event) {
else
if
(
this
->
m_selected
)
{
auto
move
=
(
this
->
m_click_position
-
position
)
/
this
->
m_camera
.
distance
();
this
->
m_selected
->
set
_force
(
Vector
(
-
move
.
x
(),
move
.
y
())
)
;
this
->
m_selected_force
=
Vector
(
-
move
.
x
(),
move
.
y
());
}
}
this
->
m_last_position
=
position
;
...
...
sms/sms/src/main.cpp
View file @
8e7a235c
...
...
@@ -18,7 +18,8 @@ void init_sm_system3(SpringMassSystem * system, unsigned int side);
GLuint
load_texture
(
const
std
::
string
&
filename
);
void
move_system
(
SpringMassSystem
*
system
,
Vector
v
);
void
update_simulations
(
std
::
vector
<
Simulation
>
*
simulations
);
void
update_simulations
(
std
::
vector
<
Simulation
>
*
simulations
,
Display
*
display
);
int
main
(
int
argc
,
char
**
argv
)
{
const
double
UPDATE_RATE
=
1.0
f
/
3000.0
f
;
...
...
@@ -38,7 +39,9 @@ int main(int argc, char ** argv) {
QTimer
timer
;
QObject
::
connect
(
&
timer
,
&
QTimer
::
timeout
,
[
&
simulations
](){
update_simulations
(
&
simulations
);});
[
&
simulations
,
&
display
]()
{
update_simulations
(
&
simulations
,
&
display
);
});
QObject
::
connect
(
&
timer
,
&
QTimer
::
timeout
,
&
display
,
&
Display
::
updateGL
);
...
...
@@ -46,9 +49,19 @@ int main(int argc, char ** argv) {
return
app
.
exec
();
}
void
update_simulations
(
std
::
vector
<
Simulation
>
*
simulations
)
{
for
(
auto
&
simulation
:
*
simulations
)
void
update_simulations
(
std
::
vector
<
Simulation
>
*
simulations
,
Display
*
display
)
{
const
auto
F
=
Vector
();
for
(
auto
&
simulation
:
*
simulations
)
{
for
(
auto
system
:
*
simulation
.
systems
())
for
(
auto
&
mass
:
*
system
->
masses
())
{
auto
f
=
F
;
if
(
&
mass
==
display
->
selected
())
f
=
f
+
display
->
selected_force
();
mass
.
set_force
(
f
);
}
simulation
.
update
();
}
}
void
init_simulations
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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