Skip to content

Commit 822ae7c

Browse files
author
马君
committed
VRDemo完成
1 parent 1824bae commit 822ae7c

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

app/src/main/assets/vr/skysphere.vert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ attribute vec2 aCoordinate;
99
varying vec2 vCoordinate;
1010

1111
void main(){
12-
gl_Position=uProjMatrix*uViewMatrix*uRotateMatrix*uModelMatrix*vec4(aPosition,1);
12+
gl_Position=uProjMatrix*uRotateMatrix*uViewMatrix*uModelMatrix*vec4(aPosition,1);
1313
vCoordinate=aCoordinate;
1414
}

app/src/main/java/edu/wuwang/opengl/vr/SkySphere.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.nio.ByteOrder;
1414
import java.nio.FloatBuffer;
1515
import java.util.ArrayList;
16+
import javax.microedition.khronos.opengles.GL;
1617

1718
/**
1819
* Created by aiya on 2017/5/19.
@@ -21,11 +22,10 @@
2122
public class SkySphere{
2223

2324
private static final float UNIT_SIZE = 1f;// 单位尺寸
24-
private float r = 0.5f; // 球的半径
25+
private float r = 2f; // 球的半径
2526
final int angleSpan = 2;// 将球进行单位切分的角度
2627
int vCount = 0;// 顶点个数,先初始化为0
2728

28-
private float step=2f;
2929
private Resources res;
3030

3131
private int mHProgram;
@@ -78,9 +78,11 @@ public void setSize(int width,int height){
7878
float ratio=(float)width/height;
7979
//设置透视投影
8080
//Matrix.frustumM(mProjectMatrix, 0, -ratio*skyRate, ratio*skyRate, -1*skyRate, 1*skyRate, 1, 200);
81-
MatrixHelper.perspectiveM(mProjectMatrix,0,35,ratio,0.5f,300);
81+
//透视投影矩阵/视锥
82+
MatrixHelper.perspectiveM(mProjectMatrix,0,45,ratio,1f,300);
8283
//设置相机位置
83-
Matrix.setLookAtM(mViewMatrix, 0, 0f, 0.0f, 2f, 0f, 0f,0.0f, 0f,-1.0f, 0.0f);
84+
Matrix.setLookAtM(mViewMatrix, 0, 0f, 0.0f,0.0f, 0.0f, 0.0f,-1.0f, 0f,1.0f, 0.0f);
85+
//模型矩阵
8486
Matrix.setIdentityM(mModelMatrix,0);
8587
//Matrix.scaleM(mModelMatrix,0,2,2,2);
8688
}
@@ -158,44 +160,44 @@ private void calculateAttribute(){
158160
alVertix.add(x1);
159161
alVertix.add(y1);
160162
alVertix.add(z1);
161-
alVertix.add(x3);
162-
alVertix.add(y3);
163-
alVertix.add(z3);
164163
alVertix.add(x0);
165164
alVertix.add(y0);
166165
alVertix.add(z0);
166+
alVertix.add(x3);
167+
alVertix.add(y3);
168+
alVertix.add(z3);
167169

168170
// *****************************************************************
169171
float s0 = hAngle / 360.0f;
170172
float s1 = (hAngle + angleSpan)/360.0f ;
171-
float t0 = 1 - vAngle / 180.0f;
172-
float t1 = 1 - (vAngle + angleSpan) / 180.0f;
173+
float t0 =vAngle / 180.0f;
174+
float t1 = (vAngle + angleSpan) / 180.0f;
173175

174176
textureVertix.add(s1);// x1 y1对应纹理坐标
175177
textureVertix.add(t0);
176-
textureVertix.add(s0);// x3 y3对应纹理坐标
177-
textureVertix.add(t1);
178178
textureVertix.add(s0);// x0 y0对应纹理坐标
179179
textureVertix.add(t0);
180+
textureVertix.add(s0);// x3 y3对应纹理坐标
181+
textureVertix.add(t1);
180182

181183
// *****************************************************************
182184
alVertix.add(x1);
183185
alVertix.add(y1);
184186
alVertix.add(z1);
185-
alVertix.add(x2);
186-
alVertix.add(y2);
187-
alVertix.add(z2);
188187
alVertix.add(x3);
189188
alVertix.add(y3);
190189
alVertix.add(z3);
190+
alVertix.add(x2);
191+
alVertix.add(y2);
192+
alVertix.add(z2);
191193

192194
// *****************************************************************
193195
textureVertix.add(s1);// x1 y1对应纹理坐标
194196
textureVertix.add(t0);
195-
textureVertix.add(s1);// x2 y3对应纹理坐标
196-
textureVertix.add(t1);
197197
textureVertix.add(s0);// x3 y3对应纹理坐标
198198
textureVertix.add(t1);
199+
textureVertix.add(s1);// x2 y3对应纹理坐标
200+
textureVertix.add(t1);
199201
// *****************************************************************
200202
}
201203
}

0 commit comments

Comments
 (0)