Android应用开发揭秘的第28个程序12_4_Gfopengl3D修改版和高仿版的源码注释

//3D3维立体图形

//Gfopengl3DActivity.java

package pak.gfopengl3D;


import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.Renderer;
import android.os.Bundle;

public class Gfopengl3DActivity extends Activity
{
 Renderer render = new GLRender();
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);

  GLSurfaceView glView = new GLSurfaceView(this);
  
  glView.setRenderer(render);
  setContentView(glView);
 }
}

 

 

//GLRender.java

package pak.gfopengl3D;

import java.nio.IntBuffer;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLSurfaceView.Renderer;

public class GLRender implements Renderer
{
 
 float rotateTri, rotateQuad;
 
  int one = 0x10000;
  
  private IntBuffer colorBufferForQuad = IntBuffer.wrap(new int[]{
    
     0,one,0,one,
     0,one,0,one,
     0,one,0,one,
     0,one,0,one,
    
     one, one/2, 0, one,
     one, one/2, 0, one,
     one, one/2, 0, one,
     one, one/2, 0, one,
    
     one,0,0,one,
     one,0,0,one,
     one,0,0,one,
     one,0,0,one,
    
     one,one,0,one,
     one,one,0,one,
     one,one,0,one,
     one,one,0,one,
    
     0,0,one,one,
     0,0,one,one,
     0,0,one,one,
     0,0,one,one,
    
     one,0,one,one,
     one,0,one,one,
     one,0,one,one,
     one,0,one,one,
  });
  
   private IntBuffer colorBuffer = IntBuffer.wrap(new int[]{
    //tri 4 face
     one,0,0,one,
     0,one,0,one,
     0,0,one,one, 
    
     one,0,0,one,
     0,one,0,one,
     0,0,one,one,
    
     one,0,0,one,
     0,one,0,one,
     0,0,one,one,
    
     one,0,0,one,
     0,one,0,one,
     0,0,one,one,
   });
  
  
   private IntBuffer triggerBuffer = IntBuffer.wrap(new int[]{
    0,one,0,
    -one,-one,0,
    one,-one,one,
    
    0,one,0,
    one,-one,one,
    one,-one,-one,
    
    0,one,0,
    one,-one,-one,
    -one,-one,0,
    //-one,-one,-one,
    
    //0,one,0,
    //-one,-one,-one,
    //-one,-one,one
    -one,-one,0,
    one,-one,one,
    one,-one,-one,
   });
   private IntBuffer quaterBuffer = IntBuffer.wrap(new int[]{
     one,one,-one,
     -one,one,-one,
     one,one,one,
     -one,one,one,
     
     one,-one,one,
     -one,-one,one,
     one,-one,-one,
     -one,-one,-one,
     
     one,one,one,
     -one,one,one,
     one,-one,one,
     -one,-one,one,
     
     one,-one,-one,
     -one,-one,-one,
     one,one,-one,
     -one,one,-one,
     
     -one,one,one,
     -one,one,-one,
     -one,-one,one,
     -one,-one,-one,
     
     one, one, -one,
     one, one, one,
     one, -one, -one,
     one, -one, one,
   });
 @Override
 public void onDrawFrame(GL10 gl)
 {
  // 清除屏幕和深度缓存
  gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  // 重置当前的模型观察矩阵
  gl.glLoadIdentity();


  // 左移 1.5 单位,并移入屏幕 6.0
  gl.glTranslatef(-1.5f, 0.0f, -6.0f);
   //设置旋转
  if (rotateTri < 360)
   gl.glRotatef(rotateTri, 0.0f, 1.0f, 0.0f);
  else
  {
   gl.glRotatef(rotateTri, 1.0f, 0.0f, 0.0f);
   if (rotateTri > 720)
    rotateTri = 0;
  }
  
  //设置定点数组
  gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  //设置颜色数组
  gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
  
  gl.glColorPointer(4, GL10.GL_FIXED, 0, colorBuffer);
  // 设置三角形顶点
  gl.glVertexPointer(3, GL10.GL_FIXED, 0, triggerBuffer);
  //绘制三角锥
     for(int i=0; i<4; i++)
     {
      gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, i*3, 3);
     }
  
  /* 渲染正方体 */
  // 重置当前的模型观察矩阵
     gl.glLoadIdentity();
    
     // 左移 1.5 单位,并移入屏幕 6.0
     gl.glTranslatef(1.5f, 0.0f, -6.0f);
    
     //设置旋转
  if (rotateQuad > -360)
   gl.glRotatef(rotateQuad, 1.0f, 0.0f, 0.0f);
  else
  {
   gl.glRotatef(rotateQuad, 0.0f, 1.0f, 0.0f);
   if (rotateQuad < -720)
    rotateQuad = 0;
  }
  
     //gl.glRotatef(rotateQuad, 1.0f, 0.0f, 0.0f);
    
     //设置和绘制正方形
     gl.glColorPointer(4, GL10.GL_FIXED, 0, colorBufferForQuad);
     gl.glVertexPointer(3, GL10.GL_FIXED, 0, quaterBuffer);

     for(int i=0; i<6; i++)
     {
      gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, i*4, 4);
     }
    
     //绘制正方形结束
     gl.glFinish();

     //取消顶点数组
     gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
     gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
    
     //改变旋转的角度
     rotateTri += 5f;
     rotateQuad -= 5f;
 }

 @Override
 public void onSurfaceChanged(GL10 gl, int width, int height)
 {
  // TODO Auto-generated method stub
  float ratio = (float) width / height;
  //设置OpenGL场景的大小
  gl.glViewport(0, 0, width, height);
  //设置投影矩阵
  gl.glMatrixMode(GL10.GL_PROJECTION);
  //重置投影矩阵
  gl.glLoadIdentity();
  // 设置视口的大小
  gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
  // 选择模型观察矩阵
  gl.glMatrixMode(GL10.GL_MODELVIEW); 
  // 重置模型观察矩阵
  gl.glLoadIdentity(); 
 }

 @Override
 public void onSurfaceCreated(GL10 gl, EGLConfig config)
 {
  // 启用阴影平滑
  gl.glShadeModel(GL10.GL_SMOOTH);
  
  // 黑色背景
  gl.glClearColor(0, 0, 0, 0);
  
  // 设置深度缓存
  gl.glClearDepthf(1.0f);       
  // 启用深度测试
  gl.glEnable(GL10.GL_DEPTH_TEST);      
  // 所作深度测试的类型
  gl.glDepthFunc(GL10.GL_LEQUAL);       
  
  // 告诉系统对透视进行修正
  gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
 }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
phpyun人才招聘系统小程序前端码for_v4.61可兼容授权和VIP。这意味着该前端码可以与phpyun人才招聘系统的4.61本中的授权和VIP进行兼容。 phpyun人才招聘系统小程序前端码是一种用于构建人才招聘小程序的代码库。通过与phpyun人才招聘系统的授权和VIP进行兼容,用户可以在小程序中使用这些功能。授权和VIP通常包含更多的功能和特性,以提供更好的用户体验和更强大的招聘功能。 使用phpyun人才招聘系统小程序前端码,用户可以自定义小程序的外观和交互方式,以满足不同需求。该码提供了一套模板和组件,用户可以根据自己的需求进行修改和定制。同时,该码还提供了与phpyun人才招聘系统后端的API接口,以实现与后端的数据交互和功能调用。 通过兼容授权和VIP,该前端码能够充分发挥phpyun人才招聘系统的功能优势,为用户提供更多选择和灵活性。不论是在招聘企业还是求职者方面,用户都可以使用这个前端码来构建一个功能丰富、易于使用的人才招聘小程序。 总结一下,phpyun人才招聘系统小程序前端码for_v4.61可兼容授权和VIP,意味着用户可以使用这个码来构建一个与phpyun人才招聘系统4.61本的授权和VIP兼容的人才招聘小程序。该码提供了丰富的功能和灵活的定制选项,可以满足不同用户的需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值