Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
masterarbeit-kai
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Philipp Adolf
masterarbeit-kai
Commits
9c55c1f0
Commit
9c55c1f0
authored
Jul 06, 2017
by
Adrian Hoppe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vr anbindung
parent
2895ae6b
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
127 additions
and
35 deletions
+127
-35
KinectTutorial3.vcxproj
3_PointCloud/KinectTutorial3.vcxproj
+1
-1
SteamTracking.cpp
3_PointCloud/SteamTracking.cpp
+58
-8
SteamTracking.h
3_PointCloud/SteamTracking.h
+13
-3
main.cpp
3_PointCloud/main.cpp
+52
-23
main.h
3_PointCloud/main.h
+3
-0
No files found.
3_PointCloud/KinectTutorial3.vcxproj
View file @
9c55c1f0
...
...
@@ -54,7 +54,7 @@
<WarningLevel>
Level3
</WarningLevel>
<DebugInformationFormat>
ProgramDatabase
</DebugInformationFormat>
<Optimization>
Disabled
</Optimization>
<AdditionalIncludeDirectories>
H:\Repositories\MasterArbeit\3_PointCloud\glm;D:\Dropbox\Studium\MasterArbeit\3_PointCloud\
glm;..\openvr\headers;glew-2.0.0-win32\glew-2.0.0\include;freeglut-MSVC-3.0.0-2.mp\freeglut\include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>
glm;..\openvr\headers;glew-2.0.0-win32\glew-2.0.0\include;freeglut-MSVC-3.0.0-2.mp\freeglut\include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<TargetMachine>
MachineX86
</TargetMachine>
...
...
3_PointCloud/SteamTracking.cpp
View file @
9c55c1f0
...
...
@@ -17,11 +17,18 @@ std::string SteamTracking::getDeviceTypeAsString(vr::ETrackedDeviceClass device_
return
type
;
}
glm
::
mat
3
x4
*
SteamTracking
::
convertMatrix
(
vr
::
HmdMatrix34_t
in
)
glm
::
mat
4
x4
*
SteamTracking
::
convertMatrix
(
vr
::
HmdMatrix34_t
in
)
{
return
new
glm
::
mat3x4
(
in
.
m
[
0
][
0
],
in
.
m
[
0
][
1
],
in
.
m
[
0
][
2
],
in
.
m
[
0
][
3
],
/*
return new glm::mat4x4( in.m[0][0], in.m[0][1], in.m[0][2], in.m[0][3],
in.m[1][0], in.m[1][1], in.m[1][2], in.m[1][3],
in
.
m
[
2
][
0
],
in
.
m
[
2
][
1
],
in
.
m
[
2
][
2
],
in
.
m
[
2
][
3
]
);
in.m[2][0], in.m[2][1], in.m[2][2], in.m[2][3],
0.0F, 0.0F, 0.0F, 1.0F);
*/
return
new
glm
::
mat4x4
(
in
.
m
[
0
][
0
],
in
.
m
[
1
][
0
],
in
.
m
[
2
][
0
],
0.0
F
,
in
.
m
[
0
][
1
],
in
.
m
[
1
][
1
],
in
.
m
[
2
][
1
],
0.0
F
,
in
.
m
[
0
][
2
],
in
.
m
[
1
][
2
],
in
.
m
[
2
][
2
],
0.0
F
,
in
.
m
[
0
][
3
],
in
.
m
[
1
][
3
],
in
.
m
[
2
][
3
],
1.0
F
);
}
...
...
@@ -77,6 +84,15 @@ void SteamTracking::printVRDevices() {
}
}
void
SteamTracking
::
processEvents
()
{
vr
::
VREvent_t
event
;
while
(
vr_system_
->
PollNextEvent
(
&
event
,
sizeof
(
event
)))
{
processEvent
(
event
);
}
}
void
SteamTracking
::
printMatrix
(
const
vr
::
HmdMatrix34_t
&
htm
)
{
...
...
@@ -93,18 +109,52 @@ void SteamTracking::printMatrix(const vr::HmdMatrix34_t &htm)
}
}
glm
::
mat3x4
*
SteamTracking
::
getTransformationForDevice
(
int
nDevice
)
void
SteamTracking
::
processEvent
(
vr
::
VREvent_t
event
)
{
switch
(
event
.
eventType
)
{
case
vr
:
:
VREvent_TrackedDeviceActivated
:
if
(
debugEvents
)
printf
(
"Device %u attached.
\n
"
,
event
.
trackedDeviceIndex
);
break
;
case
vr
:
:
VREvent_TrackedDeviceDeactivated
:
if
(
debugEvents
)
printf
(
"Device %u detached.
\n
"
,
event
.
trackedDeviceIndex
);
break
;
case
vr
:
:
VREvent_TrackedDeviceUpdated
:
if
(
debugEvents
)
printf
(
"Device %u updated.
\n
"
,
event
.
trackedDeviceIndex
);
break
;
case
vr
:
:
VREvent_ButtonPress
:
if
(
onButtonPress
)
onButtonPress
(
event
);
if
(
debugEvents
)
printf
(
"Device %u Button pressed %u.
\n
"
,
event
.
trackedDeviceIndex
,
event
.
data
.
controller
.
button
);
break
;
case
vr
:
:
VREvent_ButtonUnpress
:
if
(
debugEvents
)
printf
(
"Device %u Button unpressed %u.
\n
"
,
event
.
trackedDeviceIndex
,
event
.
data
.
controller
.
button
);
break
;
case
vr
:
:
VREvent_ButtonTouch
:
if
(
debugEvents
)
printf
(
"Device %u Button touched %u.
\n
"
,
event
.
trackedDeviceIndex
,
event
.
data
.
controller
.
button
);
break
;
case
vr
:
:
VREvent_ButtonUntouch
:
if
(
debugEvents
)
printf
(
"Device %u Button untouched %u.
\n
"
,
event
.
trackedDeviceIndex
,
event
.
data
.
controller
.
button
);
break
;
default
:
if
(
debugEvents
)
printf
(
"Event: %u
\n
"
,
event
.
eventType
);
break
;
}
}
glm
::
mat4x4
*
SteamTracking
::
getTransformationForDevice
(
int
nDevice
)
{
if
(
!
vr_system_
)
{
return
new
glm
::
mat3x4
();
if
(
debug
)
std
::
cout
<<
" NO VR System "
;
return
new
glm
::
mat4x4
();
}
vr_system_
->
GetDeviceToAbsoluteTrackingPose
(
vr
::
TrackingUniverseRawAndUncalibrated
,
0
,
tracked_device_poses_
,
vr
::
k_unMaxTrackedDeviceCount
);
if
(
!
tracked_device_poses_
[
nDevice
].
bPoseIsValid
)
{
if
(
debug
)
std
::
cout
<<
" Device "
<<
nDevice
<<
"Po
i
s is Invalid"
;
return
new
glm
::
mat
3
x4
();
if
(
debug
)
std
::
cout
<<
" Device "
<<
nDevice
<<
"Pos is Invalid"
;
return
new
glm
::
mat
4
x4
();
}
vr
::
ETrackedDeviceClass
device_class
=
vr_system_
->
GetTrackedDeviceClass
(
nDevice
);
...
...
@@ -112,7 +162,7 @@ glm::mat3x4* SteamTracking::getTransformationForDevice(int nDevice)
if
(
device_class
==
vr
::
TrackedDeviceClass_Invalid
)
{
if
(
debug
)
std
::
cout
<<
" Device "
<<
nDevice
<<
"ist Invalid"
;
return
new
glm
::
mat
3
x4
();
return
new
glm
::
mat
4
x4
();
}
vr
::
HmdMatrix34_t
htm
=
tracked_device_poses_
[
nDevice
].
mDeviceToAbsoluteTracking
;
...
...
3_PointCloud/SteamTracking.h
View file @
9c55c1f0
...
...
@@ -3,7 +3,7 @@
#include <sstream>
#include <openvr.h>
#include <glm/mat
3
x4.hpp>
#include <glm/mat
4
x4.hpp>
class
SteamTracking
...
...
@@ -15,18 +15,28 @@ private:
std
::
string
getDeviceTypeAsString
(
vr
::
ETrackedDeviceClass
device_class
);
glm
::
mat
3
x4
*
convertMatrix
(
vr
::
HmdMatrix34_t
in
);
glm
::
mat
4
x4
*
convertMatrix
(
vr
::
HmdMatrix34_t
in
);
void
printMatrix
(
const
vr
::
HmdMatrix34_t
&
htm
);
void
processEvent
(
vr
::
VREvent_t
evnt
);
public
:
bool
debug
=
false
;
bool
debugEvents
=
false
;
SteamTracking
();
~
SteamTracking
();
void
printVRDevices
();
void
processEvents
();
glm
::
mat4x4
*
getTransformationForDevice
(
int
nDevice
);
glm
::
mat3x4
*
getTransformationForDevice
(
int
nDevice
)
;
void
(
*
onButtonPress
)(
vr
::
VREvent_t
)
=
nullptr
;
};
3_PointCloud/main.cpp
View file @
9c55c1f0
...
...
@@ -12,9 +12,10 @@
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
#include <glm/vec3.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <Kinect.h>
...
...
@@ -22,8 +23,8 @@
GLuint
vboId
;
GLuint
cboId
;
GLuint
vboId
Arrow
;
GLuint
cboId
Arrow
;
GLuint
vboId
Export
;
GLuint
cboId
Export
;
float
arrowPoints
[]
=
{
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
};
...
...
@@ -47,7 +48,7 @@ IMultiSourceFrameReader* reader; // Kinect data source
ICoordinateMapper
*
mapper
;
// Converts between depth, color, and 3d coordinates
SteamTracking
*
steamTracking
=
nullptr
;
glm
::
mat
3
x4
*
currentControlerPos
=
nullptr
;
glm
::
mat
4
x4
*
currentControlerPos
=
nullptr
;
static
bool
writeFile
=
false
;
static
bool
captureFrame
=
false
;
...
...
@@ -182,7 +183,7 @@ void getKinectData(bool writeFrameInVector) {
IMultiSourceFrame
*
frame
=
NULL
;
if
(
SUCCEEDED
(
reader
->
AcquireLatestFrame
(
&
frame
)))
{
delete
currentControlerPos
;
currentControlerPos
=
steamTracking
->
getTransformationForDevice
(
0
);
currentControlerPos
=
steamTracking
->
getTransformationForDevice
(
1
);
getDepthData
(
frame
);
getRgbData
(
frame
,
writeFrameInVector
);
...
...
@@ -233,15 +234,19 @@ void writePointCloud() {
void
rotateCamera
()
{
static
double
angle
=
0.
;
static
double
radius
=
4
.
;
static
double
radius
=
20
.
;
double
x
=
radius
*
sin
(
angle
);
double
z
=
radius
*
(
1
-
cos
(
angle
))
-
radius
/
2
;
//gluLookAt(0, 0, 0, 0, 5, 0, 0, 1, 0);
gluLookAt
(
x
,
0
,
z
,
0
,
0
,
radius
/
2
,
0
,
1
,
0
);
//angle += 0.002;
}
void
drawKinectData
()
{
if
(
steamTracking
)
steamTracking
->
processEvents
();
getKinectData
(
captureFrame
);
...
...
@@ -253,12 +258,23 @@ void drawKinectData() {
points
.
reserve
(
points
.
size
()
+
width
*
height
);
colors
.
reserve
(
colors
.
size
()
+
width
*
height
*
3
);
for
(
int
i
=
0
;
i
<
snapshotPoints
.
size
();
i
++
)
{
points
.
push_back
(
/*currentControlerPos */
snapshotPoints
[
i
]
);
for
(
unsigned
int
i
=
0
;
i
<
snapshotPoints
.
size
();
i
++
)
{
points
.
push_back
(
*
currentControlerPos
*
glm
::
vec4
(
snapshotPoints
[
i
],
1.0
f
)
);
colors
.
push_back
(
snapshotColors
[
i
*
3
]);
colors
.
push_back
(
snapshotColors
[
i
*
3
+
1
]);
colors
.
push_back
(
snapshotColors
[
i
*
3
+
2
]);
}
/*
glBindBuffer(GL_ARRAY_BUFFER, vboIdExport);
glBufferData(GL_ARRAY_BUFFER, points.size() * sizeof(glm::vec3), &points[0], GL_DYNAMIC_DRAW);
glUnmapBuffer(GL_ARRAY_BUFFER);
glBindBuffer(GL_ARRAY_BUFFER, cboIdExport);
glBufferData(GL_ARRAY_BUFFER, colors.size() * sizeof(GLfloat), &colors[0], GL_DYNAMIC_DRAW);
glUnmapBuffer(GL_ARRAY_BUFFER);*/
}
captureFrame
=
false
;
...
...
@@ -269,9 +285,9 @@ void drawKinectData() {
glMatrixMode
(
GL_MODELVIEW
);
glLoadIdentity
();
rotateCamera
();
if
(
currentControlerPos
)
glMultMatrixf
(
glm
::
value_ptr
(
*
currentControlerPos
));
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
glEnableClientState
(
GL_VERTEX_ARRAY
);
...
...
@@ -287,7 +303,7 @@ void drawKinectData() {
glDrawArrays
(
GL_POINTS
,
0
,
width
*
height
);
glPushMatrix
();
float
scale
=
1.0
/
10
;
float
scale
=
1.0
f
/
10
;
glScalef
(
scale
,
scale
,
scale
);
//drawArrow();
...
...
@@ -304,11 +320,11 @@ void keyPressed(unsigned char key, int x, int y)
{
switch
(
key
)
{
case
'a'
:
std
::
cout
<<
"Caturing Frame"
<<
std
::
endl
;
std
::
cout
<<
"Caturing Frame
Keyboard
"
<<
std
::
endl
;
captureFrame
=
true
;
break
;
case
's'
:
std
::
cout
<<
"writing File"
<<
std
::
endl
;
std
::
cout
<<
"writing File"
<<
std
::
endl
;
writeFile
=
true
;
break
;
default:
...
...
@@ -319,20 +335,31 @@ void keyPressed(unsigned char key, int x, int y)
instantly */
}
void
captureNextFrame
(
vr
::
VREvent_t
event
)
{
if
(
event
.
trackedDeviceIndex
==
1
&&
event
.
data
.
controller
.
button
==
33
)
{
std
::
cout
<<
"Caturing Frame controler Button"
<<
std
::
endl
;
captureFrame
=
true
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
std
::
cout
<<
"Starting Kinect VR Point Cloud creator"
;
if
(
!
init
(
argc
,
argv
))
return
1
;
if
(
!
initKinect
())
return
1
;
if
(
!
initVR
())
{
shutdownVR
();
}
steamTracking
=
new
SteamTracking
();
steamTracking
->
printVRDevices
();
steamTracking
->
onButtonPress
=
captureNextFrame
;
// OpenGL setup
...
...
@@ -347,18 +374,17 @@ int main(int argc, char* argv[]) {
float
*
fdest2
=
(
float
*
)
framePositions
;
for
(
int
j
=
0
;
j
<
height
;
j
++
)
{
for
(
int
i
=
0
;
i
<
width
;
i
++
)
{
*
fdest
++
=
1.0
*
i
/
width
;
*
fdest
++
=
1.0
*
j
/
height
;
*
fdest
++
=
1.0
f
*
i
/
width
;
*
fdest
++
=
1.0
f
*
j
/
height
;
*
fdest
++
=
1
;
snapshotPoints
.
push_back
(
glm
::
vec3
(
1.0
*
i
/
width
,
1.0
*
j
/
height
,
0
));
snapshotColors
.
push_back
(
1.0
*
i
/
width
*
255
);
snapshotColors
.
push_back
(
1.0
*
j
/
height
*
255
);
snapshotColors
.
push_back
(
(
unsigned
char
)
1.0
*
i
/
width
*
255
);
snapshotColors
.
push_back
(
(
unsigned
char
)
1.0
*
j
/
height
*
255
);
snapshotColors
.
push_back
(
0
);
*
fdest2
++
=
1.0
*
i
/
width
;
*
fdest2
++
=
1.0
*
j
/
height
;;
*
fdest2
++
=
1.0
f
*
i
/
width
;
*
fdest2
++
=
1.0
f
*
j
/
height
;;
*
fdest2
++
=
0
;
}
...
...
@@ -388,7 +414,6 @@ int main(int argc, char* argv[]) {
// Main loop
atexit
(
close
);
execute
();
//drawKinectData();
...
...
@@ -399,3 +424,7 @@ int main(int argc, char* argv[]) {
void
close
()
{
delete
steamTracking
;
}
void
drawGround
()
{
}
3_PointCloud/main.h
View file @
9c55c1f0
#pragma once
#include <openvr.h>
const
int
width
=
512
;
const
int
height
=
424
;
const
int
colorwidth
=
1920
;
...
...
@@ -6,8 +7,10 @@ const int colorheight = 1080;
void
drawKinectData
();
void
keyPressed
(
unsigned
char
key
,
int
x
,
int
y
);
void
captureNextFrame
(
vr
::
VREvent_t
event
);
void
writePointCloud
();
void
close
();
void
drawGround
();
struct
pntsHeader
{
...
...
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