Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
qpong
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Armin Co
qpong
Commits
a47b39e3
Commit
a47b39e3
authored
5 years ago
by
Armin Co
Browse files
Options
Downloads
Patches
Plain Diff
Steering improvements.
parent
2234755a
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Particle.cpp
+55
-8
55 additions, 8 deletions
src/Particle.cpp
src/Particle.hpp
+8
-4
8 additions, 4 deletions
src/Particle.hpp
src/QWindow.cpp
+6
-6
6 additions, 6 deletions
src/QWindow.cpp
with
69 additions
and
18 deletions
src/Particle.cpp
+
55
−
8
View file @
a47b39e3
...
...
@@ -114,8 +114,8 @@ Particle::Particle(ParticleImage *momentum, ParticleImage *position, ParticleIma
,
m_obstacleImage
{
obstacles
}
,
m_ready
{
false
}
{
m_players
.
insert
(
std
::
make_pair
(
Player
s
::
One
,
Player
{
-
0.7
,
0.0
}));
m_players
.
insert
(
std
::
make_pair
(
Player
s
::
Two
,
Player
{
0.7
,
0.0
}));
m_players
.
insert
(
std
::
make_pair
(
Player
::
One
,
Velocity
{
-
0.7
,
0.0
}));
m_players
.
insert
(
std
::
make_pair
(
Player
::
Two
,
Velocity
{
0.7
,
0.0
}));
fftw_init_threads
();
...
...
@@ -145,6 +145,7 @@ bool Particle::notReady()
void
Particle
::
propagate
()
{
updatePlayers
();
constexpr
double
dt
=
0.1
;
for
(
unsigned
iy
=
0
;
iy
<
QPong
::
arrayHeight
;
iy
++
)
{
...
...
@@ -153,8 +154,8 @@ void Particle::propagate()
for
(
unsigned
long
ix
=
0
;
ix
<
QPong
::
arrayWidth
;
ix
++
)
{
double
x
=
xAt
(
ix
);
double
E
=
obstaclePotential
(
x
,
y
,
m_players
[
Player
s
::
One
].
x
,
m_players
[
Player
s
::
One
].
y
);
double
E2
=
obstaclePotential
(
x
,
y
,
m_players
[
Player
s
::
Two
].
x
,
m_players
[
Player
s
::
Two
].
y
);
double
E
=
obstaclePotential
(
x
,
y
,
m_players
[
Player
::
One
].
x
,
m_players
[
Player
::
One
].
y
);
double
E2
=
obstaclePotential
(
x
,
y
,
m_players
[
Player
::
Two
].
x
,
m_players
[
Player
::
Two
].
y
);
double
E3
=
sqr
(
y
)
*
sqr
(
y
)
*
sqr
(
y
)
*
0.001
;
int
index
=
QPong
::
arrayWidth
*
iy
+
ix
;
std
::
complex
<
double
>
tmp
=
m_psi
[
index
]
*
exp
(
-
Ci
*
dt
/
hbar
*
(
E
+
E2
+
E3
));
...
...
@@ -220,17 +221,63 @@ void Particle::updateMomentumImage()
}
}
void
Particle
::
updateObstacle
(
Players
player
,
Move
direction
)
constexpr
double
speedStepSize
=
0.0005
;
void
Particle
::
updateObstacle
(
Player
player
,
Move
direction
)
{
constexpr
double
stepSize
=
0.05
;
constexpr
double
addSpped
=
17
;
switch
(
direction
)
{
case
Move
::
Up
:
m_players
[
player
].
y
-=
stepSize
;
m_players
[
player
].
v
y
-=
s
peedS
tepSize
*
addSpped
;
break
;
case
Move
::
Down
:
m_players
[
player
].
y
+=
stepSize
;
m_players
[
player
].
v
y
+=
s
peedS
tepSize
*
addSpped
;
break
;
}
constexpr
double
maxSpeedScale
=
42
;
if
(
m_players
[
player
].
vy
>
speedStepSize
*
maxSpeedScale
)
{
m_players
[
player
].
vy
=
speedStepSize
*
maxSpeedScale
;
}
if
(
m_players
[
player
].
vy
<
-
speedStepSize
*
maxSpeedScale
)
{
m_players
[
player
].
vy
=
-
speedStepSize
*
maxSpeedScale
;
}
}
void
Particle
::
updatePlayers
()
{
constexpr
double
negativeAccelScale
=
1.5
;
for
(
auto
p
:
m_players
)
{
m_players
[
p
.
first
].
y
+=
m_players
[
p
.
first
].
vy
;
if
(
m_players
[
p
.
first
].
vy
>
0.0
)
{
m_players
[
p
.
first
].
vy
-=
speedStepSize
*
negativeAccelScale
;
}
if
(
m_players
[
p
.
first
].
vy
<
0.0
)
{
m_players
[
p
.
first
].
vy
+=
speedStepSize
*
negativeAccelScale
;
}
if
(
m_players
[
p
.
first
].
vy
<
speedStepSize
*
negativeAccelScale
&&
m_players
[
p
.
first
].
vy
>
-
speedStepSize
*
negativeAccelScale
)
{
m_players
[
p
.
first
].
vy
=
0.0
;
}
constexpr
double
maxY
=
1
;
if
(
m_players
[
p
.
first
].
y
>
maxY
)
{
m_players
[
p
.
first
].
y
=
maxY
;
}
if
(
m_players
[
p
.
first
].
y
<
-
maxY
)
{
m_players
[
p
.
first
].
y
=
-
maxY
;
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/Particle.hpp
+
8
−
4
View file @
a47b39e3
...
...
@@ -16,7 +16,7 @@
#include
"ParticleImage.hpp"
enum
class
Player
s
enum
class
Player
{
One
,
Two
...
...
@@ -28,10 +28,12 @@ enum class Move
Down
};
struct
Player
struct
Velocity
{
double
x
;
double
y
;
double
vx
=
0
;
double
vy
=
0
;
};
class
Particle
...
...
@@ -54,7 +56,7 @@ public:
/// @param player
/// @param direction
///
void
updateObstacle
(
Player
s
player
,
Move
direction
);
void
updateObstacle
(
Player
player
,
Move
direction
);
/// @brief Check if everything is initialised.
///
...
...
@@ -66,7 +68,7 @@ private:
fftw_plan
m_planBackward
;
bool
m_ready
;
std
::
map
<
Player
s
,
Player
>
m_players
;
std
::
map
<
Player
,
Velocity
>
m_players
;
ParticleImage
*
m_bufPositionRepresentation
;
ParticleImage
*
m_bufMomentumRepresentation
;
...
...
@@ -75,6 +77,8 @@ private:
/// @brief Update the array at the ArrayCanvas
///
void
updateMomentumImage
();
void
updatePlayers
();
};
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/QWindow.cpp
+
6
−
6
View file @
a47b39e3
...
...
@@ -54,8 +54,8 @@ QWindow::QWindow()
m_vBox
.
pack_start
(
m_fpsBox
,
Gtk
::
PACK_SHRINK
);
m_hBox
.
pack_start
(
m_positionArea
);
m_hBox
.
pack_start
(
m_momentumArea
);
m_hBox
.
pack_start
(
m_positionArea
,
Gtk
::
PACK_EXPAND_WIDGET
);
m_hBox
.
pack_start
(
m_momentumArea
)
,
Gtk
::
PACK_EXPAND_WIDGET
;
m_vBox
.
pack_start
(
m_hBox
);
m_label
.
set_margin_top
(
5
);
...
...
@@ -112,22 +112,22 @@ bool QWindow::onKeyPress(GdkEventKey* event)
constexpr
int
q
=
113
;
if
(
event
->
keyval
==
q
)
{
m_particle
->
updateObstacle
(
Player
s
::
One
,
Move
::
Up
);
m_particle
->
updateObstacle
(
Player
::
One
,
Move
::
Up
);
}
constexpr
int
a
=
97
;
if
(
event
->
keyval
==
a
)
{
m_particle
->
updateObstacle
(
Player
s
::
One
,
Move
::
Down
);
m_particle
->
updateObstacle
(
Player
::
One
,
Move
::
Down
);
}
constexpr
int
ue
=
252
;
if
(
event
->
keyval
==
ue
)
{
m_particle
->
updateObstacle
(
Player
s
::
Two
,
Move
::
Up
);
m_particle
->
updateObstacle
(
Player
::
Two
,
Move
::
Up
);
}
constexpr
int
oe
=
246
;
if
(
event
->
keyval
==
oe
)
{
m_particle
->
updateObstacle
(
Player
s
::
Two
,
Move
::
Down
);
m_particle
->
updateObstacle
(
Player
::
Two
,
Move
::
Down
);
}
return
true
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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