当前位置:操作系统 > 安卓/Android >>

android 3D-纹理------球的纹理

 

看了几天3D这些天才弄懂些画图,现在弄这个纹理烦得很,半懂半不懂的,这个例子是我到网站下载的,感觉不错,先给大家看看,下期我再和大家讨论讨论。

<span style="font-family:FangSong_GB2312;"></span><div><img style="width: 331px; height: 305px;" src="file:///D:\Users\nate\AppData\Roaming\Tencent\Users\397319689\QQ\WinTemp\RichOle\EUJB][9W]%TQK]_]43IED}2.jpg" width="299" height="30" alt="" /></div> 

 

package wyf.sj; 

 

import android.app.Activity; 

import android.os.Bundle; 

import android.widget.CompoundButton; 

import android.widget.LinearLayout; 

import android.widget.ToggleButton; 

import android.widget.CompoundButton.OnCheckedChangeListener; 

 

public class Sample6_2 extends Activity { 

    /** Called when the activity is first created. */ 

 MySurfaceView mGLSurfaceView; 

    @Override 

    public void onCreate(Bundle savedInstanceState) { 

        super.onCreate(savedInstanceState); 

        setContentView(R.layout.main); 

        mGLSurfaceView = new MySurfaceView(this); 

        mGLSurfaceView.requestFocus();//获取焦点 

        mGLSurfaceView.setFocusableInTouchMode(true);//设置为可触控 

         

        LinearLayout ll=(LinearLayout)findViewById(R.id.main_liner);  

        ll.addView(mGLSurfaceView); 

         

        ToggleButton tb=(ToggleButton)this.findViewById(R.id.ToggleButton01); 

        tb.setOnCheckedChangeListener( 

            new OnCheckedChangeListener() 

            { 

     @Override 

     public void onCheckedChanged(CompoundButton buttonView,boolean isChecked)  

     { 

      mGLSurfaceView.setSmoothFlag(!mGLSurfaceView.isSmoothFlag()); 

<pre class="html" name="code">package wyf.sj; 

 

import java.io.IOException; 

import java.io.InputStream; 

 

import javax.microedition.khronos.egl.EGLConfig; 

import javax.microedition.khronos.opengles.GL10; 

 

import android.content.Context; 

import android.graphics.Bitmap; 

import android.graphics.BitmapFactory; 

import android.opengl.GLSurfaceView; 

import android.opengl.GLUtils; 

import android.view.MotionEvent; 

 

public class MySurfaceView extends GLSurfaceView { 

 

    private final float TOUCH_SCALE_FACTOR = 180.0f/320;//角度缩放比例 

    private SceneRenderer mRenderer;//场景渲染器 

    private float mPreviousY;//上次的触控位置Y坐标 

    private float mPreviousX;//上次的触控位置Y坐标 

    private boolean smoothFlag=true;//是否进行平滑着色 

    private int lightAngleGreen=0;//绿光灯的当前角度 

    private int lightAngleRed=90;//红光灯的当前角度 

     

    int textureId;//纹理名称ID 

 

public MySurfaceView(Context context) { 

    super(context); 

    mRenderer = new SceneRenderer();    //创建场景渲染器 

    setRenderer(mRenderer);             //设置渲染器      

    setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);//设置渲染模式为主动渲染    

 

 @Override  

 public boolean onTouchEvent(MotionEvent e) { 

        float y = e.getY(); 

        float x = e.getX(); 

        switch (e.getAction()) { 

        case MotionEvent.ACTION_MOVE: 

            float dy = y - mPreviousY;//计算触控笔Y位移 

            float dx = x - mPreviousX;//计算触控笔Y位移 

            mRenderer.ball.mAngleX += dy * TOUCH_SCALE_FACTOR;//设置沿x轴旋转角度 

            mRenderer.ball.mAngleZ += dx * TOUCH_SCALE_FACTOR;//设置沿z轴旋转角度 

            requestRender();//重绘画面 

        } 

        mPreviousY = y;//记录触控笔位置 

        mPreviousX = x;//记录触控笔位置 

        return true; 

    } 

 

    public void setSmoothFlag(boolean smoothFlag) { 

        this.smoothFlag = smoothFlag; 

    } 

 

    public boolean isSmoothFlag() { 

        return smoothFlag; 

    } 

 

 

private class SceneRenderer implements GLSurfaceView.Renderer  

{    

    Ball ball; 

     

    public SceneRenderer() 

    { 

        //开启一个线程自动旋转球体 

        new Thread() 

        { 

          public void run() 

          { 

            try 

            { 

              Thread.sleep(1000);//休息1000ms再开始绘制 

            } 

            catch(Exception e) 

            { 

        &n

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,