IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> [android] [OpenGLES 1.1] (想不出名字) -> 正文阅读

[移动开发][android] [OpenGLES 1.1] (想不出名字)

标题

OpenGLES 1.x相比于OpenGLES 2.x和3.x,不用写着色器,方便许多,今天闲着没事,就写几个类
不过貌似有点问题,难道是我使用方式不对???
这个先留着当模板,寒假写个OpenGLES 3.x的

代码

Camera.java

package com.Diamond.gl10try;

import android.opengl.*;
import android.renderscript.Float3;
import android.opengl.Matrix;
import android.opengl.GLES11;
import android.renderscript.Matrix4f;
import android.util.Log;

public class Camera {
    private Float3 m_eye;
	private Float3 m_center;
	private Float3 m_up;
	
	public Camera() {
		m_eye = new Float3();
		m_center = new Float3(0.0f,0.0f,-1.0f);
		m_up = new Float3(0.0f,1.0f,0.0f);
	}
	public Camera(Float3 eye,Float3 center,Float3 up) {
		m_eye = eye;
		m_center = center;
		m_up = up;
	}
	
	public Camera setEye(Float3 value) {
		m_eye = value;
		return this;
	}
	public Camera setCenter(Float3 value) {
		m_center = value;
		return this;
	}
	public Camera setUp(Float3 value) {
		m_up = value;
		return this;
	}
	
	public Float3 getEye() {
		return m_eye;
	}
	public Float3 getCenter() {
		return m_center;
	}
	public Float3 getUp() {
		return m_up;
	}
	
	public Camera forward(float l) {
		m_eye.z = m_eye.z + l;
		return this;
	}
	public Camera back(float l) {
		return forward(-l);
	}
	public Camera up(float l) {
		m_eye.y = m_eye.y + l;
		return this;
	}
	public Camera down(float l) {
		return up(-l);
	}
	public Camera left(float l) {
		m_eye.x = m_eye.x + l;
		return this;
	}
	public Camera right(float l) {
		return left(-l);
	}
	
	public static Matrix4f getProjection(float fovy,float aspect,float near,float far) {
		Matrix4f matrix = new Matrix4f();
		matrix.loadIdentity();
		matrix.loadPerspective(fovy,aspect,near,far);
		return matrix;
	}
	public Matrix4f getView() {
		float[] matrix = new float[16];
		Matrix.setLookAtM(matrix,0,m_eye.x,m_eye.y,m_eye.z,m_center.x,m_center.y,m_center.z,m_up.x,m_up.y,m_up.z);
		return new Matrix4f(matrix);
	}
	public Camera updateCamera() {
		Matrix4f matrix = this.getProjection(120.0f,0.5f,0.1f,100.0f);
		matrix.multiply(getView());
		GLES11.glMatrixMode(GLES11.GL_PROJECTION);
		GLES11.glLoadIdentity();
		GLES11.glMultMatrixf(matrix.getArray(),0);
		return this;
	}
}

Object.java

package com.Diamond.gl10try;

import com.Diamond.gl10try.Vertex;
import android.opengl.*;
import android.renderscript.Float3;
import android.renderscript.Matrix4f;
import android.opengl.GLES11;
import java.nio.FloatBuffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class Object {
	private Float3 m_position;
	private Float3 m_rotate;
	private Float3 m_scale;
	private float[] m_vertices;
	private float[] m_color;
	
	public Object() {
		m_position = new Float3();
		m_rotate = new Float3();
		m_scale = new Float3();
		m_vertices = null;
		m_color = null;
	}
	public Object(float[] ver) {
		m_position = new Float3();
		m_rotate = new Float3();
		m_scale = new Float3();
		m_vertices = ver;
		m_color = null;
	}
	public Object(float[] ver,float[] col) {
		m_position = new Float3();
		m_rotate = new Float3();
		m_scale = new Float3();
		m_vertices = ver;
		m_color = col;
	}
	
	public Object setVertices(float[] ver) {
		m_vertices = ver;
		return this;
	}
	public float[] getVertices() {
		return m_vertices;
	}
	
	public Object setColor(float[] col) {
		m_color = col;
		return this;
	}
	public float[] getColor() {
		return m_color;
	}
	
	public Object translate(Float3 value) {
		m_position = value;
		return this;
	}
	public Object rotate(Float3 value) {
		m_rotate = value;
		return this;
	}
	public Object scale(Float3 value) {
		m_scale = value;
		return this;
	}
	
	public Float3 getTranslate() {
		return m_position;
	}
	public Float3 getRotate() {
		return m_rotate;
	}
	public Float3 getScale() {
		return m_scale;
	}
	
	public Matrix4f getModelView() {
		Matrix4f modelview = new Matrix4f();
		modelview.loadIdentity();
		modelview.translate(m_position.x,m_position.y,m_position.z);
		modelview.rotate(m_rotate.x,1.0f,0.0f,0.0f);
		modelview.rotate(m_rotate.y,0.0f,1.0f,0.0f);
		modelview.rotate(m_rotate.z,0.0f,0.0f,1.0f);
		modelview.scale(m_scale.x,m_scale.y,m_scale.z);
		return modelview;
	}
	public Object setModelView() {
		GLES11.glMatrixMode(GLES11.GL_MODELVIEW);
		GLES11.glLoadIdentity();
		GLES11.glMultMatrixf(getModelView().getArray(),0);
		return this;
	}
	public Object setModelView2() {
		GLES11.glMatrixMode(GLES11.GL_MODELVIEW);
		GLES11.glLoadIdentity();
		GLES11.glTranslatef(m_position.x,m_position.y,m_position.z);
		GLES11.glRotatef(m_rotate.x,1.0f,0.0f,0.0f);
		GLES11.glRotatef(m_rotate.y,0.0f,1.0f,0.0f);
		GLES11.glRotatef(m_rotate.z,0.0f,0.0f,1.0f);
		GLES11.glScalef(m_scale.x,m_scale.y,m_scale.z);
		return this;
	}
	
	public static FloatBuffer getBuffer(float[] array) {
		ByteBuffer bb = ByteBuffer.allocateDirect(array.length * 4);
		bb.order(ByteOrder.nativeOrder());
		FloatBuffer fb = bb.asFloatBuffer();
		fb.put(array);
		fb.position(0);
		return fb;
	}
	public Object enableCilent() {
		GLES11.glEnableClientState(GLES11.GL_VERTEX_ARRAY);
		GLES11.glVertexPointer(3,GLES11.GL_FLOAT,0,this.getBuffer(m_vertices));
		if(m_color != null) {
			GLES11.glEnableClientState(GLES11.GL_COLOR_ARRAY);
			GLES11.glColorPointer(4,GLES11.GL_FLOAT,0,this.getBuffer(m_color));
		}
		return this;
	}
	public Object disableClient() {
		GLES11.glDisableClientState(GLES11.GL_VERTEX_ARRAY);
		GLES11.glDisableClientState(GLES11.GL_VERTEX_ARRAY);
		return this;
	}
}

Vertex.java

package com.Diamond.gl10try;

import android.renderscript.Float3;
import android.renderscript.Float2;

public class Vertex {
    public Float3 position;
	public Float3 normal;
	public Float2 texCoord;
	
	public Vertex() {
		position = new Float3();
		normal = new Float3();
		texCoord = new Float2();
	}
	public Vertex(Float3 pos) {
		position = pos;
		normal = new Float3();
		texCoord = new Float2();
	}
	public Vertex(Float3 pos,Float3 nor) {
		position = pos;
		normal = nor;
		texCoord = new Float2();
	}
	public Vertex(Float3 pos,Float2 tex) {
		position = pos;
		normal = new Float3();
		texCoord = tex;
	}
	public Vertex(Float3 pos,Float3 nor,Float2 tex) {
		position = pos;
		normal = nor;
		texCoord = tex;
	}
}

  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2022-01-03 16:13:34  更:2022-01-03 16:13:53 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 10:47:15-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码