-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.make sky box translation with user touch event
- Loading branch information
1 parent
1dfc7c4
commit 6f9324f
Showing
16 changed files
with
236 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
app/src/main/java/com/example/albertsnow/myapplication/objects/SkyBox.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.example.albertsnow.myapplication.objects; | ||
|
||
import android.opengl.GLES20; | ||
|
||
import com.example.albertsnow.myapplication.data.VertexArray; | ||
import com.example.albertsnow.myapplication.programs.SkyBoxShaderProgram; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
/** | ||
* Created by albertsnow on 7/7/17. | ||
*/ | ||
|
||
public class SkyBox { | ||
private static final int POSITION_COMPONENT_COUNT = 3; | ||
private final VertexArray vertexArray; | ||
private final ByteBuffer indexArray; | ||
|
||
public SkyBox() { | ||
//create a unit cube. | ||
vertexArray = new VertexArray(new float[] { | ||
-1, 1, 1, // (0) Top-left near | ||
1, 1, 1, // (1) Top-right near | ||
-1, -1, 1, // (2) Bottom-left near | ||
1, -1, 1, // (3) Bottom-right near | ||
-1, 1, -1, // (4) Top-left far | ||
1, 1, -1, // (5) Top-right far | ||
-1, -1, -1, // (6) Bottom-left far | ||
1, -1, -1, // (7) Bottom-right far | ||
}); | ||
|
||
indexArray = ByteBuffer.allocate(6 * 6) | ||
.put(new byte[] { | ||
// Front | ||
1, 3, 0, | ||
0, 3, 2, | ||
|
||
// Back | ||
4, 6, 5, | ||
5, 6, 7, | ||
|
||
// Left | ||
0, 2, 4, | ||
4, 2, 6, | ||
|
||
// Right | ||
5, 7, 1, | ||
1, 7, 3, | ||
|
||
// Top | ||
5, 1, 4, | ||
4, 1, 0, | ||
|
||
// Bottom | ||
6, 2, 7, | ||
7, 2, 3 | ||
}); | ||
indexArray.position(0); | ||
} | ||
|
||
public void bindData(SkyBoxShaderProgram skyBoxShaderProgram) { | ||
vertexArray.setVertexAttribPointer(0, | ||
skyBoxShaderProgram.getPositionAttributeLocation(), | ||
POSITION_COMPONENT_COUNT, 0); | ||
} | ||
|
||
public void draw() { | ||
GLES20.glDrawElements(GLES20.GL_TRIANGLES, 36, GLES20.GL_UNSIGNED_BYTE, indexArray); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/example/albertsnow/myapplication/programs/SkyBoxShaderProgram.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.example.albertsnow.myapplication.programs; | ||
|
||
import android.opengl.GLES20; | ||
|
||
import com.example.albertsnow.myapplication.MyApplication; | ||
import com.example.albertsnow.myapplication.R; | ||
|
||
/** | ||
* Created by albertsnow on 7/7/17. | ||
*/ | ||
|
||
public class SkyBoxShaderProgram extends ShaderProgram { | ||
|
||
private final int uMatrixLocation; | ||
private final int uTextureUnitLocation; | ||
private final int aPositionLocation; | ||
|
||
|
||
public SkyBoxShaderProgram() { | ||
super(MyApplication.getApplication() | ||
, R.raw.skybox_vertex_shader, R.raw.skybox_fragment_shader); | ||
|
||
uMatrixLocation = GLES20.glGetUniformLocation(program, U_MATRIX); | ||
uTextureUnitLocation = GLES20.glGetUniformLocation(program, U_TEXTURE_UNIT); | ||
aPositionLocation = GLES20.glGetAttribLocation(program, A_POSITION); | ||
} | ||
|
||
public void setUniforms(float[] matrix, int textureId) { | ||
GLES20.glUniformMatrix4fv(uMatrixLocation, 1, false, matrix, 0); | ||
|
||
GLES20.glActiveTexture(GLES20.GL_TEXTURE0); | ||
GLES20.glBindTexture(GLES20.GL_TEXTURE_CUBE_MAP, textureId); | ||
GLES20.glUniform1i(uTextureUnitLocation, 0); | ||
} | ||
|
||
public int getPositionAttributeLocation() { | ||
return aPositionLocation; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
precision mediump float; | ||
|
||
uniform samplerCube u_TextureUnit; | ||
varying vec3 v_Position; | ||
|
||
void main() | ||
{ | ||
gl_FragColor = textureCube(u_TextureUnit, v_Position); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
uniform mat4 u_Matrix; | ||
attribute vec3 a_Position; | ||
varying vec3 v_Position; | ||
|
||
void main() | ||
{ | ||
v_Position = a_Position; | ||
v_Position.z = -v_Position.z; | ||
|
||
gl_Position = u_Matrix * vec4(a_Position, 1.0); | ||
gl_Position = gl_Position.xyww; | ||
} |