好吧,其实这个问题是因为我想做一个小玩意的时候想要做一个效果需要用到螺线的一个效果,但是没人分享过,可能太简单了‘,
但是我是菜鸟,所以自己搞了两天,写了一个能实现的代码,有点乱,不过有注释,其实也挺简单的
Activity_GL_Cylinder.java代码
package wyf.lgz;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class Activity_GL_Cylinder extends Activity {
private MyGLSurfaceView mGLSurfaceView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mGLSurfaceView = new MyGLSurfaceView(this);
setContentView(mGLSurfaceView);
mGLSurfaceView.setFocusableInTouchMode(true);//设置为可触控
mGLSurfaceView.requestFocus();//获取焦点
}
@Override
protected void onResume() {
super.onResume();
mGLSurfaceView.onResume();
}
@Override
protected void onPause() {
super.onPause();
mGLSurfaceView.onPause();
}
}
DrawCylineder.java代码
package wyf.lgz;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.lang.Math;
import javax.microedition.khronos.opengles.GL10;
public class DrawCylinder
{
private FloatBuffer myVertexBuffer;//顶点坐标缓冲
int vCount;//顶点数量
float length;//圆柱长度 10f
float circle_radius;//圆截环半径 2f
float degreespan; //圆截环每一份的度数大小 20f
int col;//圆柱块数 5f
public float mAngleX;
public float mAngleY;
public float mAngleZ;
private float x1=0f;//直线上端点
private float y1=0f;
private float z1=0f;
private float x4=0f;//直线下端点
private float y4=0f;
private float z4=0f;
public DrawCylinder(float length,float circle_radius,float degreespan,int col)
{
this.circle_radius=circle_radius;
this.length=length;
this.col=col;
this.degreespan=degreespan;
float collength=2.0f;//圆柱每块所占的长度
ArrayList<Float> val=new ArrayList<Float>();//顶点存放列表
// for(float circle_degree=360.0f;circle_degree>0.0f;circle_degree-=degreespan)//循环行
// {//控制点数
// for(int j=0;j<col;j++)//循环列,控制块数
// {
// x1 =(float)(j*collength-length/2);
// y1=(float) (circle_radius*Math.sin(Math.toRadians(circle_degree)));
// z1=(float) (circle_radius*Math.cos(Math.toRadians(circle_degree)));
//
// float x2 =(float)(j*collength-length/2);
// float y2=(float) (circle_radius*Math.sin(Math.toRadians(circle_degree-degreespan)));
// float z2=(float) (circle_radius*Math.