android绘制一个圆柱的螺线曲线

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

好吧,其实这个问题是因为我想做一个小玩意的时候想要做一个效果需要用到螺线的一个效果,但是没人分享过,可能太简单了‘,

但是我是菜鸟,所以自己搞了两天,写了一个能实现的代码,有点乱,不过有注释,其实也挺简单的

 

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.
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值