|
13 | 13 | import java.nio.ByteOrder; |
14 | 14 | import java.nio.FloatBuffer; |
15 | 15 | import java.util.ArrayList; |
| 16 | +import javax.microedition.khronos.opengles.GL; |
16 | 17 |
|
17 | 18 | /** |
18 | 19 | * Created by aiya on 2017/5/19. |
|
21 | 22 | public class SkySphere{ |
22 | 23 |
|
23 | 24 | private static final float UNIT_SIZE = 1f;// 单位尺寸 |
24 | | - private float r = 0.5f; // 球的半径 |
| 25 | + private float r = 2f; // 球的半径 |
25 | 26 | final int angleSpan = 2;// 将球进行单位切分的角度 |
26 | 27 | int vCount = 0;// 顶点个数,先初始化为0 |
27 | 28 |
|
28 | | - private float step=2f; |
29 | 29 | private Resources res; |
30 | 30 |
|
31 | 31 | private int mHProgram; |
@@ -78,9 +78,11 @@ public void setSize(int width,int height){ |
78 | 78 | float ratio=(float)width/height; |
79 | 79 | //设置透视投影 |
80 | 80 | //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); |
82 | 83 | //设置相机位置 |
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 | + //模型矩阵 |
84 | 86 | Matrix.setIdentityM(mModelMatrix,0); |
85 | 87 | //Matrix.scaleM(mModelMatrix,0,2,2,2); |
86 | 88 | } |
@@ -158,44 +160,44 @@ private void calculateAttribute(){ |
158 | 160 | alVertix.add(x1); |
159 | 161 | alVertix.add(y1); |
160 | 162 | alVertix.add(z1); |
161 | | - alVertix.add(x3); |
162 | | - alVertix.add(y3); |
163 | | - alVertix.add(z3); |
164 | 163 | alVertix.add(x0); |
165 | 164 | alVertix.add(y0); |
166 | 165 | alVertix.add(z0); |
| 166 | + alVertix.add(x3); |
| 167 | + alVertix.add(y3); |
| 168 | + alVertix.add(z3); |
167 | 169 |
|
168 | 170 | // ***************************************************************** |
169 | 171 | float s0 = hAngle / 360.0f; |
170 | 172 | 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; |
173 | 175 |
|
174 | 176 | textureVertix.add(s1);// x1 y1对应纹理坐标 |
175 | 177 | textureVertix.add(t0); |
176 | | - textureVertix.add(s0);// x3 y3对应纹理坐标 |
177 | | - textureVertix.add(t1); |
178 | 178 | textureVertix.add(s0);// x0 y0对应纹理坐标 |
179 | 179 | textureVertix.add(t0); |
| 180 | + textureVertix.add(s0);// x3 y3对应纹理坐标 |
| 181 | + textureVertix.add(t1); |
180 | 182 |
|
181 | 183 | // ***************************************************************** |
182 | 184 | alVertix.add(x1); |
183 | 185 | alVertix.add(y1); |
184 | 186 | alVertix.add(z1); |
185 | | - alVertix.add(x2); |
186 | | - alVertix.add(y2); |
187 | | - alVertix.add(z2); |
188 | 187 | alVertix.add(x3); |
189 | 188 | alVertix.add(y3); |
190 | 189 | alVertix.add(z3); |
| 190 | + alVertix.add(x2); |
| 191 | + alVertix.add(y2); |
| 192 | + alVertix.add(z2); |
191 | 193 |
|
192 | 194 | // ***************************************************************** |
193 | 195 | textureVertix.add(s1);// x1 y1对应纹理坐标 |
194 | 196 | textureVertix.add(t0); |
195 | | - textureVertix.add(s1);// x2 y3对应纹理坐标 |
196 | | - textureVertix.add(t1); |
197 | 197 | textureVertix.add(s0);// x3 y3对应纹理坐标 |
198 | 198 | textureVertix.add(t1); |
| 199 | + textureVertix.add(s1);// x2 y3对应纹理坐标 |
| 200 | + textureVertix.add(t1); |
199 | 201 | // ***************************************************************** |
200 | 202 | } |
201 | 203 | } |
|
0 commit comments