好吧,其实这个问题是因为我想做一个小玩意的时候想要做一个效果需要用到螺线的一个效果,但是没人分享过,可能太简单了‘,
但是我是菜鸟,所以自己搞了两天,写了一个能实现的代码,有点乱,不过有注释,其实也挺简单的
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.cos(Math.toRadians(circle_degree-degrees

这篇博客记录了作者在Android开发中实现圆柱螺线曲线的过程,由于找不到现成的解决方案,作者通过两天时间自行编写了代码,包括Activity_GL_Cylinder.java, DrawCylineder.java和MyGlSurfaceView.java三个部分。尽管代码可能较为初级,但已实现基本功能,并期望通过改进实现触摸滑动生成螺线的交互效果。"
103730722,9239256,Apache虚拟主机配置教程,"['Apache配置', '服务器管理', 'Web服务器']
1084

被折叠的 条评论
为什么被折叠?



