android opengl es 控制 贴图旋转
来源:互联网 发布:嘉实多机油网络代理商 编辑:程序博客网 时间:2024/06/06 04:09
android opengl es 控制 贴图旋转
摘要:控制贴图旋转有很多种方式,通过片段着色语言或者顶点着色语言可以达到控制贴图旋转的目的,本文讲述一种更简单的控制方式,通过控制顶多坐标控制贴图旋转。
1. 顶点坐标
正常情况下顶点坐标如下所示
private float[] mVerticesData ={ -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f,-1.0f, 1.0f, 0.0f,1.0f, 1.0f, 0.0f};
通过上述可以正常显示一个正的图片,然后我们通过控制角度去改变顶点坐标的值对应的就可以更改旋转角度。
2. 设置角度
public void setAngle(float angle) { float map_width = 480f; float map_height = 480f;//贴图宽高 float play_width = 1080f;//glviewport 设置的宽高 float play_height = 1080f; float input_center_x = 540; float input_center_y = 540;//移动位置,中心点再正中间 float dst_x = (input_center_x - play_width / 2) ; float dst_y = (play_height / 2 - input_center_y); float x1 = 0,y1 = 0; float x2 = 0,y2 = 0; float x3 = 0,y3 = 0; float x4 = 0,y4 = 0; float cos_angle = (float) Math.cos((double)angle); float sin_angle = (float) Math.sin((double)angle); x1 = ((-map_width/2) * cos_angle) + ((-map_height/2) * sin_angle); y1 = ((-map_height/2) * cos_angle) - (-(map_width/2) * sin_angle); x2 = ((map_width/2) * cos_angle) + ((-map_height/2) * sin_angle); y2 = ((-map_height/2) * cos_angle) - ((map_width/2) * sin_angle); x3 = ((-map_width/2) * cos_angle) + ((map_height/2) * sin_angle); y3 = ((map_height/2) * cos_angle) - ((-map_width/2) * sin_angle); x4 = ((map_width/2) * cos_angle) + ((map_height/2) * sin_angle); y4 = ((map_height/2) * cos_angle) - ((map_width/2) * sin_angle);mVerticesData[0] = ((dst_x + x1) / (play_width/2));mVerticesData[1] = ((dst_y + y1) / (play_height/2));mVerticesData[3] = ((dst_x + x2) / (play_width/2));mVerticesData[4] = ((dst_y+ y2) / (play_height/2)); mVerticesData[6] = ((dst_x + x3) / (play_width/2));mVerticesData[7] = ((dst_y + y3) / (play_height/2));mVerticesData[9] = ((dst_x + x4) / (play_width/2));mVerticesData[10] = ((dst_y+ y4) / (play_height/2)); mVertices = ByteBuffer.allocateDirect ( mVerticesData.length * 4 ) .order ( ByteOrder.nativeOrder() ).asFloatBuffer(); mVertices.put ( mVerticesData ).position ( 0 ); }
算出对应坐标,即可完成旋转贴图阅读全文
0 0
- android opengl es 控制 贴图旋转
- android opengl es 3d 贴图 旋转立方体demo
- openGL ES JNI贴图 平移 旋转 缩放
- Android OpenGL ES 旋转glRotatef
- android opengl es 纹理贴图资料
- Android Opengl ES 2.0 纹理贴图
- OpenGL ES纹理贴图
- OpenGL ES纹理贴图
- OpenGL ES纹理贴图
- OpenGL ES 纹理贴图
- android opengl es 三角形、正方形自动旋转
- Android OpenGL ES 绘图 -- 缩放、平移、旋转
- Android OpenGL es 纹理坐标设定与贴图规则
- Android OpenGL es 纹理坐标设定与贴图规则
- Android OpenGL es 纹理坐标设定与贴图规则
- Android OpenGL es 纹理坐标设定与贴图规则
- Android OpenGL es 纹理坐标设定与贴图规则
- Android OpenGL es 3D Rubik Cube 多纹理贴图
- Moveit和OMPL的使用
- 数据结构 C语言版 第一章笔记 基本概念和术语
- QML之Column垂直定位器
- 菜鸟看源码之ArrayList
- BZOJ 1502 计算几何+自适应Simpson积分 解题报告
- android opengl es 控制 贴图旋转
- Android【Service组件】【基本概念及使用】
- leetcode171题解
- TCP通信
- WAMPServer3.0.4自定义网站根目录
- 基于TI C6000的TCP/IP协议栈的研究与实现
- Mapped Statements collection does not contain value
- MyBatis和Hibernate的优缺点对比。
- Centos7安装JDK