Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
VR-demos
Commits
14a108c1
Commit
14a108c1
authored
Sep 11, 2017
by
Ruben Jesus Garcia Hernandez
Browse files
Haptic Feedback option (hapticfeedback) to indicate if controller is
touching an atom. Detect and indicate corrupt xyz file.
parent
ff5ae2db
Changes
4
Hide whitespace changes
Inline
Side-by-side
NOMADVRLib/ConfigFile.cpp
View file @
14a108c1
...
@@ -46,6 +46,7 @@ Solid *solid;
...
@@ -46,6 +46,7 @@ Solid *solid;
bool
saveStereo
;
bool
saveStereo
;
int
screenshotdownscaling
;
int
screenshotdownscaling
;
bool
hapticFeedback
;
//markers such as hole positions and electron positions
//markers such as hole positions and electron positions
float
**
markers
;
float
**
markers
;
...
@@ -176,6 +177,7 @@ int loadConfigFile(const char * f)
...
@@ -176,6 +177,7 @@ int loadConfigFile(const char * f)
voxelSize
[
i
]
=-
1
;
voxelSize
[
i
]
=-
1
;
saveStereo
=
false
;
saveStereo
=
false
;
screenshotdownscaling
=
1
;
screenshotdownscaling
=
1
;
hapticFeedback
=
false
;
//
//
FILE
*
F
=
fopen
(
f
,
"r"
);
FILE
*
F
=
fopen
(
f
,
"r"
);
if
(
F
==
0
)
if
(
F
==
0
)
...
@@ -472,6 +474,8 @@ int loadConfigFile(const char * f)
...
@@ -472,6 +474,8 @@ int loadConfigFile(const char * f)
r
=
fscanf
(
F
,
"%d"
,
&
screenshotdownscaling
);
r
=
fscanf
(
F
,
"%d"
,
&
screenshotdownscaling
);
if
(
r
<
1
)
if
(
r
<
1
)
eprintf
(
"Error reading screenshotdownscaling value"
);
eprintf
(
"Error reading screenshotdownscaling value"
);
}
else
if
(
!
strcmp
(
s
,
"hapticfeedback"
))
{
hapticFeedback
=
true
;
}
else
if
(
!
strcmp
(
s
,
"supercell"
))
{
}
else
if
(
!
strcmp
(
s
,
"supercell"
))
{
r
=
fscanf
(
F
,
"%f %f %f"
,
supercell
,
supercell
+
1
,
supercell
+
2
);
r
=
fscanf
(
F
,
"%f %f %f"
,
supercell
,
supercell
+
1
,
supercell
+
2
);
}
else
if
(
!
strcmp
(
s
,
"
\x0d
"
))
{
//discard windows newline (problem in Sebastian Kokott's phone (?!)
}
else
if
(
!
strcmp
(
s
,
"
\x0d
"
))
{
//discard windows newline (problem in Sebastian Kokott's phone (?!)
...
...
NOMADVRLib/ConfigFile.h
View file @
14a108c1
...
@@ -42,6 +42,8 @@ extern Solid *solid;
...
@@ -42,6 +42,8 @@ extern Solid *solid;
extern
bool
saveStereo
;
extern
bool
saveStereo
;
extern
int
screenshotdownscaling
;
extern
int
screenshotdownscaling
;
extern
bool
hapticFeedback
;
//markers such as hole positions and electron positions
//markers such as hole positions and electron positions
extern
float
**
markers
;
extern
float
**
markers
;
extern
float
**
markercolours
;
extern
float
**
markercolours
;
...
...
NOMADVRLib/atoms.cpp
View file @
14a108c1
...
@@ -202,9 +202,10 @@ int findAtom(const char *const s)
...
@@ -202,9 +202,10 @@ int findAtom(const char *const s)
const
char
*
readAtomsXYZErrors
[]
=
{
const
char
*
readAtomsXYZErrors
[]
=
{
"All Ok"
,
//0
"All Ok"
,
//0
"could not open file"
,
//-1
"Could not open file"
,
//-1
"error loading atom type and position line"
,
//-2
"Error loading atom type and position line"
,
//-2
"atom type unknown"
,
//-3
"Atom type unknown"
,
//-3
"Corrupt xyz file"
//-4
};
};
int
readAtomsXYZ
(
const
char
*
const
file
,
int
**
numatoms
,
int
*
timesteps
,
float
***
pos
)
int
readAtomsXYZ
(
const
char
*
const
file
,
int
**
numatoms
,
int
*
timesteps
,
float
***
pos
)
...
@@ -220,10 +221,18 @@ int readAtomsXYZ(const char *const file, int **numatoms, int *timesteps, float *
...
@@ -220,10 +221,18 @@ int readAtomsXYZ(const char *const file, int **numatoms, int *timesteps, float *
return
-
1
;
return
-
1
;
}
}
*
timesteps
=
0
;
*
timesteps
=
0
;
int
blanklines
=
0
;
while
(
!
feof
(
f
))
{
while
(
!
feof
(
f
))
{
r
=
fscanf
(
f
,
"%d"
,
&
mynumatoms
);
r
=
fscanf
(
f
,
"%d"
,
&
mynumatoms
);
if
(
r
<
1
)
if
(
r
<
1
)
{
blanklines
++
;
if
(
blanklines
>
3
)
{
eprintf
(
"Corrupt xyz file %s. Error at %d atoms
\n
"
,
file
,
mynumatoms
);
return
-
4
;
}
continue
;
//there may be a blank line at the end of the file
continue
;
//there may be a blank line at the end of the file
}
blanklines
=
0
;
(
*
timesteps
)
++
;
(
*
timesteps
)
++
;
discardline
(
f
);
discardline
(
f
);
//eprintf ("Getting atoms, mynumatoms=%d",mynumatoms);
//eprintf ("Getting atoms, mynumatoms=%d",mynumatoms);
...
@@ -245,6 +254,7 @@ int readAtomsXYZ(const char *const file, int **numatoms, int *timesteps, float *
...
@@ -245,6 +254,7 @@ int readAtomsXYZ(const char *const file, int **numatoms, int *timesteps, float *
//return -3;
//return -3;
}
}
(
mypos
.
back
())[
4
*
i
+
3
]
=
(
float
)
a
;
(
mypos
.
back
())[
4
*
i
+
3
]
=
(
float
)
a
;
//RGH FIXME, add cloned atoms
}
}
}
}
...
...
OpenVR/TimestepData/hellovr_opengl_main.cpp
View file @
14a108c1
...
@@ -1077,8 +1077,10 @@ void CMainApplication::ProcessVREvent( const vr::VREvent_t & event )
...
@@ -1077,8 +1077,10 @@ void CMainApplication::ProcessVREvent( const vr::VREvent_t & event )
void
CMainApplication
::
HapticFeedback
(){
void
CMainApplication
::
HapticFeedback
(){
HapticFeedback
(
firstdevice
);
if
(
hapticFeedback
)
{
HapticFeedback
(
seconddevice
);
HapticFeedback
(
firstdevice
);
HapticFeedback
(
seconddevice
);
}
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Purpose: Haptic feedback if controller near an atom
// Purpose: Haptic feedback if controller near an atom
...
@@ -1092,19 +1094,53 @@ void CMainApplication::HapticFeedback(int device)
...
@@ -1092,19 +1094,53 @@ void CMainApplication::HapticFeedback(int device)
if
(
dp
.
bPoseIsValid
)
{
if
(
dp
.
bPoseIsValid
)
{
vr
::
HmdMatrix34_t
mat
=
dp
.
mDeviceToAbsoluteTracking
;
vr
::
HmdMatrix34_t
mat
=
dp
.
mDeviceToAbsoluteTracking
;
Vector3
controllerPos
(
mat
.
m
[
0
][
3
],
mat
.
m
[
1
][
3
],
mat
.
m
[
2
][
3
]);
Vector3
controllerPos
(
mat
.
m
[
0
][
3
],
mat
.
m
[
1
][
3
],
mat
.
m
[
2
][
3
]);
for
(
int
i
=
0
;
i
<
numAtoms
[
currentset
];
i
++
)
{
int
atomsInTimestep
;
Vector3
posatom
(
atoms
[
currentset
][
i
*
4
+
0
],
atoms
[
currentset
][
i
*
4
+
1
],
atoms
[
currentset
][
i
*
4
+
2
]);
if
(
currentset
==
0
)
//remember rotation
atomsInTimestep
=
numAtoms
[
0
];
else
atomsInTimestep
=
numAtoms
[
currentset
]
-
numAtoms
[
currentset
-
1
];
for
(
int
i
=
0
;
i
<
atomsInTimestep
;
i
++
)
{
float
atomr
=
atomRadius
(
atoms
[
currentset
][
i
*
4
+
3
]);
//Vector3 posatom(atoms[currentset][i*4+0], atoms[currentset][i*4+1], atoms[currentset][i*4+2]);
Vector3
posatom
(
atoms
[
currentset
][
i
*
4
+
0
],
atoms
[
currentset
][
i
*
4
+
2
],
atoms
[
currentset
][
i
*
4
+
1
]);
//y/z flipped
int
p
[
3
];
for
(
p
[
0
]
=
0
;
p
[
0
]
<
std
::
max
(
1
,
repetitions
[
0
]);(
p
[
0
])
++
)
for
(
p
[
1
]
=
0
;
p
[
1
]
<
std
::
max
(
1
,
repetitions
[
1
]);(
p
[
1
])
++
)
for
(
p
[
2
]
=
0
;
p
[
2
]
<
std
::
max
(
1
,
repetitions
[
2
]);(
p
[
2
])
++
)
{
float
delta
[
3
];
::
GetDisplacement
(
p
,
delta
);
Vector3
iPos
(
delta
[
0
],
delta
[
1
],
delta
[
2
]);
Vector3
up
(
-
UserPosition
.
x
,
-
UserPosition
.
y
,
UserPosition
.
z
);
Vector3
pos
=
posatom
-
up
+
iPos
;
pos
=
Vector3
(
pos
.
x
,
pos
.
y
,
-
pos
.
z
);
float
l
=
(
pos
-
controllerPos
).
length
();
if
(
l
<
atomr
*
atomScaling
)
{
m_pHMD
->
TriggerHapticPulse
(
device
,
0
,
3000
);
return
;
}
}
}
//now cloned atoms
if
(
currentset
==
0
&&
clonedAtoms
)
{
Vector3
up
(
-
UserPosition
.
x
,
-
UserPosition
.
y
,
UserPosition
.
z
);
Vector3
up
(
-
UserPosition
.
x
,
-
UserPosition
.
y
,
UserPosition
.
z
);
Vector3
pos
=
posatom
-
up
;
for
(
int
i
=
0
;
i
<
numClonedAtoms
;
i
++
)
{
pos
.
z
=-
pos
.
z
;
float
atomr
=
atomRadius
(
clonedAtoms
[
currentset
][
i
*
4
+
3
]);
float
l
=
(
pos
-
controllerPos
).
length
();
Vector3
posatom
(
clonedAtoms
[
currentset
][
i
*
4
+
0
],
clonedAtoms
[
currentset
][
i
*
4
+
2
],
clonedAtoms
[
currentset
][
i
*
4
+
1
]);
if
(
l
<
0.2
f
)
{
Vector3
pos
=
posatom
-
up
;
m_pHMD
->
TriggerHapticPulse
(
device
,
0
,
3000
);
pos
.
z
=-
pos
.
z
;
return
;
float
l
=
(
pos
-
controllerPos
).
length
();
if
(
l
<
atomr
*
atomScaling
)
{
m_pHMD
->
TriggerHapticPulse
(
device
,
0
,
3000
);
return
;
}
}
}
}
}
}
}
// pose is valid
}
}
}
}
...
@@ -1378,8 +1414,8 @@ void CMainApplication::SetupScene()
...
@@ -1378,8 +1414,8 @@ void CMainApplication::SetupScene()
{
{
SetupIsosurfaces
();
SetupIsosurfaces
();
SetupAtoms
();
SetupAtoms
();
delete
[]
clonedAtoms
;
//
delete[] clonedAtoms;
//required for haptic feedback
clonedAtoms
=
0
;
//
clonedAtoms=0;
SetupUnitCell
();
SetupUnitCell
();
SetupMarker
();
SetupMarker
();
}
}
...
@@ -2314,6 +2350,7 @@ void CMainApplication::RenderScene(vr::Hmd_Eye nEye)
...
@@ -2314,6 +2350,7 @@ void CMainApplication::RenderScene(vr::Hmd_Eye nEye)
if
(
ISOS
==
0
)
{
if
(
ISOS
==
0
)
{
RenderAtoms
(
nEye
);
RenderAtoms
(
nEye
);
RenderUnitCell
(
nEye
);
RenderUnitCell
(
nEye
);
RenderAllTrackedRenderModels
(
nEye
);
return
;
return
;
}
}
...
...
Write
Preview
Supports
Markdown
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