Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
ftl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Maintenance on Friday 28.3. at 13:00. ETA 60 - 90 minutes.
Show more breadcrumbs
Nicolas Pope
ftl
Commits
11a557c9
Commit
11a557c9
authored
5 years ago
by
Nicolas Pope
Browse files
Options
Downloads
Patches
Plain Diff
Improved camera controls
parent
20f8504f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
applications/gui/src/main.cpp
+61
-13
61 additions, 13 deletions
applications/gui/src/main.cpp
with
61 additions
and
13 deletions
applications/gui/src/main.cpp
+
61
−
13
View file @
11a557c9
...
@@ -219,6 +219,17 @@ namespace {
...
@@ -219,6 +219,17 @@ namespace {
}
}
static
Eigen
::
Affine3f
create_rotation_matrix
(
float
ax
,
float
ay
,
float
az
)
{
Eigen
::
Affine3f
rx
=
Eigen
::
Affine3f
(
Eigen
::
AngleAxisf
(
ax
,
Eigen
::
Vector3f
(
1
,
0
,
0
)));
Eigen
::
Affine3f
ry
=
Eigen
::
Affine3f
(
Eigen
::
AngleAxisf
(
ay
,
Eigen
::
Vector3f
(
0
,
1
,
0
)));
Eigen
::
Affine3f
rz
=
Eigen
::
Affine3f
(
Eigen
::
AngleAxisf
(
az
,
Eigen
::
Vector3f
(
0
,
0
,
1
)));
return
ry
*
rz
*
rx
;
}
class
FTLApplication
:
public
nanogui
::
Screen
{
class
FTLApplication
:
public
nanogui
::
Screen
{
public:
public:
explicit
FTLApplication
(
ftl
::
Configurable
*
root
,
ftl
::
net
::
Universe
*
net
,
ftl
::
ctrl
::
Master
*
controller
)
:
nanogui
::
Screen
(
Eigen
::
Vector2i
(
1024
,
768
),
"FT-Lab GUI"
)
{
explicit
FTLApplication
(
ftl
::
Configurable
*
root
,
ftl
::
net
::
Universe
*
net
,
ftl
::
ctrl
::
Master
*
controller
)
:
nanogui
::
Screen
(
Eigen
::
Vector2i
(
1024
,
768
),
"FT-Lab GUI"
)
{
...
@@ -230,9 +241,9 @@ class FTLApplication : public nanogui::Screen {
...
@@ -230,9 +241,9 @@ class FTLApplication : public nanogui::Screen {
//src_ = nullptr;
//src_ = nullptr;
eye_
=
Eigen
::
Vector3f
(
0.0
f
,
0.0
f
,
0.0
f
);
eye_
=
Eigen
::
Vector3f
(
0.0
f
,
0.0
f
,
0.0
f
);
centre
_
=
Eigen
::
Vector3f
(
0.0
f
,
0.0
f
,
-
4
.0
f
);
orientation
_
=
Eigen
::
Vector3f
(
0.0
f
,
0.0
f
,
0
.0
f
);
up_
=
Eigen
::
Vector3f
(
0
,
1.0
f
,
0
);
up_
=
Eigen
::
Vector3f
(
0
,
1.0
f
,
0
);
lookPoint_
=
Eigen
::
Vector3f
(
0.0
f
,
0.0
f
,
-
4.0
f
);
//
lookPoint_ = Eigen::Vector3f(0.0f,0.0f,-4.0f);
lerpSpeed_
=
0.4
f
;
lerpSpeed_
=
0.4
f
;
depth_
=
false
;
depth_
=
false
;
ftime_
=
(
float
)
glfwGetTime
();
ftime_
=
(
float
)
glfwGetTime
();
...
@@ -262,6 +273,18 @@ class FTLApplication : public nanogui::Screen {
...
@@ -262,6 +273,18 @@ class FTLApplication : public nanogui::Screen {
mShader
.
free
();
mShader
.
free
();
}
}
bool
mouseMotionEvent
(
const
Eigen
::
Vector2i
&
p
,
const
Eigen
::
Vector2i
&
rel
,
int
button
,
int
modifiers
)
{
if
(
Screen
::
mouseMotionEvent
(
p
,
rel
,
button
,
modifiers
))
{
return
true
;
}
else
{
if
(
button
==
1
)
{
orientation_
[
0
]
+=
((
float
)
rel
[
1
]
*
0.2
f
*
delta_
);
//orientation_[2] += std::cos(orientation_[1])*((float)rel[1] * 0.2f * delta_);
orientation_
[
1
]
-=
(
float
)
rel
[
0
]
*
0.2
f
*
delta_
;
}
}
}
bool
mouseButtonEvent
(
const
nanogui
::
Vector2i
&
p
,
int
button
,
bool
down
,
int
modifiers
)
{
bool
mouseButtonEvent
(
const
nanogui
::
Vector2i
&
p
,
int
button
,
bool
down
,
int
modifiers
)
{
if
(
Screen
::
mouseButtonEvent
(
p
,
button
,
down
,
modifiers
))
{
if
(
Screen
::
mouseButtonEvent
(
p
,
button
,
down
,
modifiers
))
{
return
true
;
return
true
;
...
@@ -288,7 +311,7 @@ class FTLApplication : public nanogui::Screen {
...
@@ -288,7 +311,7 @@ class FTLApplication : public nanogui::Screen {
camPos
*=
-
1.0
f
;
camPos
*=
-
1.0
f
;
Eigen
::
Vector4f
worldPos
=
src_
->
getPose
()
*
camPos
;
Eigen
::
Vector4f
worldPos
=
src_
->
getPose
()
*
camPos
;
lookPoint_
=
Eigen
::
Vector3f
(
worldPos
[
0
],
worldPos
[
1
],
worldPos
[
2
]);
//
lookPoint_ = Eigen::Vector3f(worldPos[0],worldPos[1],worldPos[2]);
LOG
(
INFO
)
<<
"Depth at click = "
<<
-
camPos
[
2
];
LOG
(
INFO
)
<<
"Depth at click = "
<<
-
camPos
[
2
];
return
true
;
return
true
;
}
}
...
@@ -297,18 +320,34 @@ class FTLApplication : public nanogui::Screen {
...
@@ -297,18 +320,34 @@ class FTLApplication : public nanogui::Screen {
}
}
bool
keyboardEvent
(
int
key
,
int
scancode
,
int
action
,
int
modifiers
)
{
bool
keyboardEvent
(
int
key
,
int
scancode
,
int
action
,
int
modifiers
)
{
using
namespace
Eigen
;
if
(
Screen
::
keyboardEvent
(
key
,
scancode
,
action
,
modifiers
))
{
if
(
Screen
::
keyboardEvent
(
key
,
scancode
,
action
,
modifiers
))
{
return
true
;
return
true
;
}
else
{
}
else
{
LOG
(
INFO
)
<<
"Key press "
<<
key
<<
" - "
<<
action
;
LOG
(
INFO
)
<<
"Key press "
<<
key
<<
" - "
<<
action
;
if
(
key
==
263
||
key
==
262
)
{
if
(
key
==
263
||
key
==
262
)
{
// TODO Should rotate around lookAt object, but requires correct depth
float
scalar
=
(
key
==
263
)
?
-
0.1
f
:
0.1
f
;
Eigen
::
Quaternion
<
float
>
q
;
q
=
Eigen
::
AngleAxis
<
float
>
((
key
==
262
)
?
0.01
f
:
-
0.01
f
,
up_
);
Eigen
::
Affine3f
r
=
create_rotation_matrix
(
orientation_
[
0
],
orientation_
[
1
],
orientation_
[
2
]);
eye_
=
(
q
*
(
eye_
-
centre_
))
+
centre_
;
Vector4f
neye
=
r
.
matrix
()
*
Vector4f
(
scalar
,
0.0
,
0.0
,
1.0
);
eye_
[
0
]
+=
neye
[
0
];
eye_
[
1
]
+=
neye
[
1
];
eye_
[
2
]
+=
neye
[
2
];
return
true
;
return
true
;
}
else
if
(
key
==
264
||
key
==
265
)
{
}
else
if
(
key
==
264
||
key
==
265
)
{
float
scalar
=
(
key
==
264
)
?
0.99
f
:
1.01
f
;
float
scalar
=
(
key
==
264
)
?
-
0.1
f
:
0.1
f
;
eye_
=
((
eye_
-
centre_
)
*
scalar
)
+
centre_
;
Eigen
::
Affine3f
r
=
create_rotation_matrix
(
orientation_
[
0
],
orientation_
[
1
],
orientation_
[
2
]);
Vector4f
neye
=
r
.
matrix
()
*
Vector4f
(
0.0
,
0.0
,
scalar
,
1.0
);
eye_
[
0
]
+=
neye
[
0
];
eye_
[
1
]
+=
neye
[
1
];
eye_
[
2
]
+=
neye
[
2
];
return
true
;
}
else
if
(
key
==
266
||
key
==
267
)
{
float
scalar
=
(
key
==
266
)
?
-
0.1
f
:
0.1
f
;
Eigen
::
Affine3f
r
=
create_rotation_matrix
(
orientation_
[
0
],
orientation_
[
1
],
orientation_
[
2
]);
Vector4f
neye
=
r
.
matrix
()
*
Vector4f
(
0.0
,
scalar
,
0.0
,
1.0
);
eye_
[
0
]
+=
neye
[
0
];
eye_
[
1
]
+=
neye
[
1
];
eye_
[
2
]
+=
neye
[
2
];
return
true
;
return
true
;
}
else
if
(
action
==
1
&&
key
==
'H'
)
{
}
else
if
(
action
==
1
&&
key
==
'H'
)
{
swindow_
->
setVisible
(
!
swindow_
->
visible
());
swindow_
->
setVisible
(
!
swindow_
->
visible
());
...
@@ -327,13 +366,21 @@ class FTLApplication : public nanogui::Screen {
...
@@ -327,13 +366,21 @@ class FTLApplication : public nanogui::Screen {
imageSize
=
{
0
,
0
};
imageSize
=
{
0
,
0
};
float
now
=
(
float
)
glfwGetTime
();
float
now
=
(
float
)
glfwGetTime
();
float
delta
=
now
-
ftime_
;
delta
_
=
now
-
ftime_
;
ftime_
=
now
;
ftime_
=
now
;
if
(
src_
)
{
if
(
src_
)
{
cv
::
Mat
rgb
,
depth
;
cv
::
Mat
rgb
,
depth
;
centre_
+=
(
lookPoint_
-
centre_
)
*
(
lerpSpeed_
*
delta
);
//centre_ += (lookPoint_ - centre_) * (lerpSpeed_ * delta);
Eigen
::
Matrix4f
viewPose
=
lookAt
<
float
>
(
eye_
,
centre_
,
up_
).
inverse
();
//Eigen::Matrix4f viewPose = lookAt<float>(eye_,centre_,up_).inverse();
Eigen
::
Affine3f
r
=
create_rotation_matrix
(
orientation_
[
0
],
orientation_
[
1
],
orientation_
[
2
]);
Eigen
::
Translation3f
trans
(
eye_
);
Eigen
::
Affine3f
t
(
trans
);
Eigen
::
Matrix4f
viewPose
=
(
t
*
r
).
matrix
();
//Eigen::Matrix4f viewPose = t.matrix();
//viewPose *= r.matrix();
src_
->
setPose
(
viewPose
);
src_
->
setPose
(
viewPose
);
src_
->
grab
();
src_
->
grab
();
...
@@ -416,12 +463,13 @@ class FTLApplication : public nanogui::Screen {
...
@@ -416,12 +463,13 @@ class FTLApplication : public nanogui::Screen {
//Source *src_;
//Source *src_;
GLTexture
texture_
;
GLTexture
texture_
;
Eigen
::
Vector3f
eye_
;
Eigen
::
Vector3f
eye_
;
Eigen
::
Vector3f
centre
_
;
Eigen
::
Vector3f
orientation
_
;
Eigen
::
Vector3f
up_
;
Eigen
::
Vector3f
up_
;
Eigen
::
Vector3f
lookPoint_
;
//
Eigen::Vector3f lookPoint_;
float
lerpSpeed_
;
float
lerpSpeed_
;
bool
depth_
;
bool
depth_
;
float
ftime_
;
float
ftime_
;
float
delta_
;
Eigen
::
Vector2f
imageSize
;
Eigen
::
Vector2f
imageSize
;
};
};
...
...
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