Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
VR-demos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nomad-lab
VR-demos
Commits
70d13df1
Commit
70d13df1
authored
Nov 06, 2017
by
Ruben Jesus Garcia Hernandez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Android: support spheres. support gamepad.
parent
eb2d0670
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
20 deletions
+94
-20
GoogleCardboardAndroid/NOMADgvrT/src/main/jni/treasure_hunt_jni.cc
...dboardAndroid/NOMADgvrT/src/main/jni/treasure_hunt_jni.cc
+5
-0
GoogleCardboardAndroid/NOMADgvrT/src/main/jni/treasure_hunt_renderer.cc
...dAndroid/NOMADgvrT/src/main/jni/treasure_hunt_renderer.cc
+45
-13
GoogleCardboardAndroid/NOMADgvrT/src/main/jni/treasure_hunt_renderer.h
...rdAndroid/NOMADgvrT/src/main/jni/treasure_hunt_renderer.h
+5
-1
NOMADVRLib/polyhedron.h
NOMADVRLib/polyhedron.h
+39
-6
No files found.
GoogleCardboardAndroid/NOMADgvrT/src/main/jni/treasure_hunt_jni.cc
View file @
70d13df1
...
...
@@ -125,5 +125,10 @@ JNI_METHOD(void, nativeLoadConfigFile)
native
(
native_treasure_hunt
)
->
loadConfigFile
();
}
JNI_METHOD
(
void
,
nativekeyPress
)
(
JNIEnv
*
env
,
jobject
obj
,
jlong
native_treasure_hunt
,
jint
key
)
{
int
k
=
key
;
native
(
native_treasure_hunt
)
->
keyPress
(
k
);
}
}
// extern "C"
GoogleCardboardAndroid/NOMADgvrT/src/main/jni/treasure_hunt_renderer.cc
View file @
70d13df1
...
...
@@ -341,6 +341,40 @@ static float VectorInnerProduct(const std::array<float, 4>& vect1,
}
}
// anonymous namespace
void
TreasureHuntRenderer
::
keyPress
(
int
k
)
{
//X=99, Y=100, A=96, B=97
//UP=19, DOWN=20, LEFT=21, RIGHT=22,
//https://developer.android.com/reference/android/view/KeyEvent.html
switch
(
k
)
{
case
19
:
currentSet
++
;
if
(
currentSet
>
TIMESTEPS
-
1
)
currentSet
=
0
;
break
;
case
20
:
currentSet
--
;
if
(
currentSet
<
0
)
currentSet
=
TIMESTEPS
-
1
;
break
;
case
21
:
currentIso
++
;
if
(
currentIso
>
ISOS
)
currentIso
=
0
;
break
;
case
22
:
currentIso
--
;
if
(
currentIso
<
0
)
currentIso
=
ISOS
;
break
;
case
99
:
animateTimesteps
=!
animateTimesteps
;
break
;
case
96
:
animateMovement
=!
animateMovement
;
}
}
void
TreasureHuntRenderer
::
loadConfigFile
(
void
)
{
if
(
configPath
!=
nullptr
)
...
...
@@ -495,6 +529,7 @@ glGenTextures(2+ZLAYERS, textDepthPeeling);
//isosurfaces
if
(
ISOS
)
{
currentIso
=
ISOS
;
//rgh: FIXME Additive blending for android; do not need most of these textures
//additive blending means white background makes everything white
float
m
=
BACKGROUND
[
0
];
...
...
@@ -668,8 +703,7 @@ void TreasureHuntRenderer::DrawFrame() {
ProcessControllerInput
();
}
// if (animateTimesteps) {
if
(
animateTimesteps
)
{
if
(
animationspeed
>
1
)
currentSet
+=
animationspeed
;
else
{
...
...
@@ -682,7 +716,7 @@ void TreasureHuntRenderer::DrawFrame() {
}
if
(
currentSet
>
TIMESTEPS
-
1
)
currentSet
=
0
;
//
}
}
PrepareFramebuffer
();
gvr
::
Frame
frame
=
swapchain_
->
AcquireFrame
();
...
...
@@ -693,7 +727,7 @@ void TreasureHuntRenderer::DrawFrame() {
head_view_
=
gvr_api_
->
GetHeadSpaceFromStartSpaceRotation
(
target_time
);
if
(
animate
Timesteps
)
{
if
(
animate
Movement
)
{
const
float
speed
=
0.01
;
gvr
::
Mat4f
inv
=
invert
(
head_view_
);
//for (int i=0;i<4;i++)
...
...
@@ -708,8 +742,8 @@ if (animateTimesteps) {
}
LOGD
(
"UT=%f, %f, %f
\n
"
,
UserTranslation
[
0
],
UserTranslation
[
1
],
UserTranslation
[
2
]);
LOGD
(
"MovementSpeed=%f
\n
"
,
movementspeed
);
//
LOGD("UT=%f, %f, %f\n", UserTranslation[0], UserTranslation[1], UserTranslation[2]);
//
LOGD("MovementSpeed=%f\n", movementspeed);
gvr
::
Mat4f
left_eye_matrix
=
gvr_api_
->
GetEyeFromHeadMatrix
(
GVR_LEFT_EYE
);
gvr
::
Mat4f
right_eye_matrix
=
gvr_api_
->
GetEyeFromHeadMatrix
(
GVR_RIGHT_EYE
);
...
...
@@ -853,7 +887,7 @@ if (has_abc) {
}
if
(
ISOS
)
RenderIsos
(
modelview_projection_cube_
,
ISOS
);
RenderIsos
(
modelview_projection_cube_
,
currentIso
);
}
...
...
@@ -1045,8 +1079,7 @@ glBindVertexArray(AtomTVAO[0]);
eprintf
(
"1 Gl error RenderAtomTrajectoriesUnitCell: %d
\n
"
,
e
);
//glUseProgram(UnitCellP);
//glUniformMatrix4fv(m_nUnitCellMatrixLocation, 1, GL_FALSE, matrix);
float
color
[
4
]
=
{
1
,
0
,
0
,
1
};
glUniform4fv
(
UnitCellColourLoc
,
1
,
color
);
glUniform4fv
(
UnitCellColourLoc
,
1
,
atomtrajectorycoluor
);
if
((
e
=
glGetError
())
!=
GL_NO_ERROR
)
eprintf
(
"Gl error after glUniform4fv 2 RenderAtomTrajectoriesUnitCell: %d
\n
"
,
e
);
//glEnableVertexAttribArray(0);
...
...
@@ -1114,9 +1147,8 @@ void TreasureHuntRenderer::RenderUnitCell(const gvr::Mat4f eyeViewProjection)
glUseProgram
(
UnitCellP
);
glUniformMatrix4fv
(
UnitCellMatrixLoc
,
1
,
GL_FALSE
,
t
);
if
((
e
=
glGetError
())
!=
GL_NO_ERROR
)
eprintf
(
"Gl error after glUniform4fv 1 RenderUnitCell: %d
\n
"
,
e
);
float
color
[
4
]
=
{
1
,
1
,
1
,
1
};
glUniform4fv
(
UnitCellColourLoc
,
1
,
color
);
eprintf
(
"Gl error after glUniform4fv 1 RenderUnitCell: %d
\n
"
,
e
);
glUniform4fv
(
UnitCellColourLoc
,
1
,
unitcellcolour
);
if
((
e
=
glGetError
())
!=
GL_NO_ERROR
)
eprintf
(
"Gl error after glUniform4fv 2 RenderUnitCell: %d
\n
"
,
e
);
glBindVertexArray
(
UnitCellVAO
);
...
...
@@ -1142,6 +1174,6 @@ void TreasureHuntRenderer::RenderUnitCell(const gvr::Mat4f eyeViewProjection)
}
void
TreasureHuntRenderer
::
OnTriggerEvent
()
{
animate
Timesteps
=!
animateTimesteps
;
animate
Movement
=!
animateMovement
;
}
GoogleCardboardAndroid/NOMADgvrT/src/main/jni/treasure_hunt_renderer.h
View file @
70d13df1
...
...
@@ -45,6 +45,8 @@ class TreasureHuntRenderer {
TreasureHuntRenderer
(
gvr_context
*
gvr_context
,
std
::
unique_ptr
<
gvr
::
AudioApi
>
gvr_audio_api
);
void
keyPress
(
int
k
);
/**
* Destructor.
*/
...
...
@@ -173,7 +175,9 @@ GLuint BlendVAO=0, BlendBuffer=0, BlendIndices=0;
int
*
numISOIndices
=
nullptr
/*[ISOS*TIMESTEPS]*/
;
int
currentSet
=
0
;
bool
animateTimesteps
=
false
;
bool
animateTimesteps
=
true
;
bool
animateMovement
=
false
;
int
currentIso
;
void
RenderAtoms
(
const
float
*
m
);
void
RenderUnitCell
(
const
gvr
::
Mat4f
eyeViewProjection
);
...
...
NOMADVRLib/polyhedron.h
View file @
70d13df1
...
...
@@ -25,14 +25,16 @@ public:
static
const
float
Verts
[];
};
class
Solid
{
public:
enum
Type
{
Icosahedron
,
Octahedron
,
Tetrahedron
Tetrahedron
,
Sphere
};
Solid
(
Type
t
)
{
Solid
(
Type
t
,
int
SphereFacets
=
15
)
{
switch
(
t
)
{
case
Icosahedron
:
nFaces
=
Icosahedron
::
nFaces
;
...
...
@@ -45,17 +47,48 @@ public:
Faces
=
Octahedron
::
Faces
;
nVerts
=
Octahedron
::
nVerts
;
Verts
=
Octahedron
::
Verts
;
break
;
case
Tetrahedron
:
nFaces
=
Tetrahedron
::
nFaces
;
Faces
=
Tetrahedron
::
Faces
;
nVerts
=
Tetrahedron
::
nVerts
;
Verts
=
Tetrahedron
::
Verts
;
}
}
break
;
case
Sphere
:
//https://stackoverflow.com/questions/23143921/python-program-to-create-sphere-coordinates-not-working
//http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html For the future
nVerts
=
SphereFacets
*
SphereFacets
;
float
*
tVerts
=
new
float
[
nVerts
*
3
];
for
(
int
i
=
0
;
i
<
SphereFacets
;
i
++
)
for
(
int
j
=
0
;
j
<
SphereFacets
;
j
++
)
{
float
t
,
f
;
t
=
i
*
2
*
M_PI
/
(
float
)(
SphereFacets
-
1
);
f
=
j
*
M_PI
/
(
float
)(
SphereFacets
-
1
);
tVerts
[
i
*
SphereFacets
*
3
+
j
*
3
]
=
sin
(
f
)
*
sin
(
t
);
tVerts
[
i
*
SphereFacets
*
3
+
j
*
3
+
1
]
=
sin
(
f
)
*
cos
(
t
);
tVerts
[
i
*
SphereFacets
*
3
+
j
*
3
+
2
]
=
cos
(
f
);
}
nFaces
=
2
*
(
SphereFacets
-
1
)
*
(
SphereFacets
-
1
);
int
*
tFaces
=
new
int
[
3
*
nFaces
];
for
(
int
i
=
0
;
i
<
SphereFacets
-
1
;
i
++
)
for
(
int
j
=
0
;
j
<
SphereFacets
-
1
;
j
++
)
{
tFaces
[
i
*
(
SphereFacets
-
1
)
*
6
+
j
*
6
]
=
i
*
SphereFacets
+
j
;
tFaces
[
i
*
(
SphereFacets
-
1
)
*
6
+
j
*
6
+
1
]
=
((
i
+
1
)
%
SphereFacets
)
*
SphereFacets
+
j
;
tFaces
[
i
*
(
SphereFacets
-
1
)
*
6
+
j
*
6
+
2
]
=
(
i
)
*
SphereFacets
+
(
j
+
1
)
%
SphereFacets
;
tFaces
[
i
*
(
SphereFacets
-
1
)
*
6
+
j
*
6
+
3
]
=
((
i
+
1
)
%
SphereFacets
)
*
SphereFacets
+
j
;
tFaces
[
i
*
(
SphereFacets
-
1
)
*
6
+
j
*
6
+
4
]
=
(
i
)
*
SphereFacets
+
(
j
+
1
)
%
SphereFacets
;
tFaces
[
i
*
(
SphereFacets
-
1
)
*
6
+
j
*
6
+
5
]
=
((
i
+
1
)
%
SphereFacets
)
*
SphereFacets
+
(
j
+
1
)
%
SphereFacets
;
}
Faces
=
tFaces
;
Verts
=
tVerts
;
}
// switch
}
// Solid (constructor)
int
nFaces
;
const
int
*
Faces
;
int
nVerts
;
const
float
*
Verts
;
};
};
// class Solid
#endif // __POLYHEDRON_H
\ No newline at end of file
#endif // __POLYHEDRON_H
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