-
Notifications
You must be signed in to change notification settings - Fork 0
/
NdkView.java
executable file
·135 lines (111 loc) · 4.47 KB
/
NdkView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* NDKmol - Molecular Viewer on Android NDK
(C) Copyright 2011 - 2012, biochem_fan
This file is part of NDKmol.
NDKmol is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package jp.sfjp.webglmol.NDKmol;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView;
import android.opengl.GLU;
public class NdkView implements GLSurfaceView.Renderer {
public float objX, objY, objZ;
public float cameraZ, slabNear, slabFar, FOV = 20, maxD; // FIXME: FOV changing is not supported on JNI side.
public Quaternion rotationQ;
public boolean isMoving = false;
public int width, height;
// See View.hpp for these constants
public int proteinMode = 0;
public int hetatmMode = 2;
public int nucleicAcidMode = 0;
public boolean showSidechain = false;
public boolean showUnitcell = false;
public boolean showSolvents = false;
public boolean doNotSmoothen = false;
public boolean symopHetatms = true;
public int symmetryMode = 0;
public int colorMode = 0;
public boolean fogEnabled = false;
private static native void nativeGLInit();
private static native void nativeGLResize(int w, int h);
private static native void nativeGLRender();
private static native void nativeLoadProtein(String path);
private static native void nativeLoadSDF(String path);
private static native void buildScene(int proteinMode, int hetatmMode, int symmetryMode, int colorMode, boolean showSidechain,
boolean showUnitcell, int nucleicAcidMode, boolean showSolvents,
boolean doNotSmoothen, boolean symopHetatms);
public static native float[] nativeAdjustZoom(int symmetryMode);
public NdkView() {
resetCamera();
}
public void resetCamera() {
float [] parms = nativeAdjustZoom(symmetryMode);
objX = parms[0]; objY = parms[1]; objZ = parms[2];
cameraZ = parms[3]; slabNear = parms[4]; slabFar = parms[5];
maxD = parms[6];
rotationQ = new Quaternion(1, 0, 0, 0);
}
public void prepareScene() {
buildScene(proteinMode, hetatmMode, symmetryMode, colorMode, showSidechain, showUnitcell,
nucleicAcidMode, showSolvents, doNotSmoothen, symopHetatms);
}
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT|GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
float cameraNear = -cameraZ + slabNear;
if (cameraNear < 1) cameraNear = 1;
float cameraFar = -cameraZ + slabFar;
if (cameraNear + 1 > cameraFar) cameraFar = cameraNear + 1;
GLU.gluPerspective(gl, FOV, (float) width / height, cameraNear, cameraFar);
if (fogEnabled) {
gl.glEnable(GL10.GL_FOG);
gl.glFogf(GL10.GL_FOG_MODE, GL10.GL_LINEAR); // EXP, EXP2 is not supported?
gl.glFogfv(GL10.GL_FOG_COLOR, new float[] {0, 0, 0, 1}, 0);
gl.glFogf(GL10.GL_FOG_DENSITY, 0.3f);
// gl.glHint(GL10.GL_FOG_HINT, GL10.GL_DONT_CARE);
gl.glFogf(GL10.GL_FOG_START, cameraNear * 0.3f + cameraFar * 0.7f);
gl.glFogf(GL10.GL_FOG_END, cameraFar);
} else {
gl.glDisable(GL10.GL_FOG);
}
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, cameraZ);
Vector3 axis = rotationQ.getAxis();
gl.glRotatef(180 * rotationQ.getAngle() / (float)Math.PI, axis.x, axis.y, axis.z);
gl.glTranslatef(objX, objY, objZ);
nativeGLRender();
if (fogEnabled) gl.glDisable(GL10.GL_FOG);
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
width = w; height = h;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluPerspective(gl, 20, (float)width / height, 1, 800);
nativeGLResize(w, h);
}
public void onSurfaceCreated(GL10 gl, EGLConfig arg1) {
nativeGLInit();
gl.glDisable(GL10.GL_FOG);
}
public void loadPDB(String path) {
nativeLoadProtein(path);
prepareScene();
resetCamera();
}
public void loadSDF(String path) {
nativeLoadSDF(path);
prepareScene();
resetCamera();
}
}