明确了项目目录的结构,但是结构什么的也太"抽象"了。
本篇开始上代码!
模型的绘制-
前几天的学习中,live2d的绘制有了一些了解了,在Android端使用OpenGL ES绘制模型时需要Surface绘制和Renderer渲染,那么切入点就为GLSurfaceView和Renderer。
在SampleApp1中的sample包下LAppView和LAppRenderer就分别饰演的这两个角色
LAppRenderer implements GLSurfaceView.Renderer LAppView extends GLSurfaceView
渲染器类LAppRenderer -
LAppRenderer 类实现了Renderer接口,实现了onSurfaceCreated、onSurfaceChanged、onDrawFrame方法
@Override public void onSurfaceCreated(GL10 context, EGLConfig arg1) { setupBackground(context); } //设置背景图片 private void setupBackground(GL10 context) { try { InputStream in = FileManager.open(LAppDefine.BACK_IMAGE_NAME); bg=new SimpleImage(context,in); bg.setDrawRect( LAppDefine.VIEW_LOGICAL_MAX_LEFT, LAppDefine.VIEW_LOGICAL_MAX_RIGHT, LAppDefine.VIEW_LOGICAL_MAX_BOTTOM, LAppDefine.VIEW_LOGICAL_MAX_TOP); bg.setUVRect(0.0f,1.0f,0.0f,1.0f); } catch (IOException e) { e.printStackTrace(); } }
onSurfaceCreated()作为surface被创建后需要做的处理,但是这里只加载了背景图片
在onDrawFrame()方法中有很多的OpenGL绘制时的配置,由于LAppLive2DManager和Utils的存在很多操作都不在这里实现了,这里还是很明显的绘制出了background和models,方法还是熟悉的方法,只是藏了起来
if(bg!=null){ gl.glPushMatrix() ; { float SCALE_X = 0.25f ; float SCALE_Y = 0.1f ; gl.glTranslatef( -SCALE_X * accelX , SCALE_Y * accelY , 0 ) ; bg.draw(gl); } gl.glPopMatrix() ; } for(int i=0;i<delegate.getModelNum();i++) { LAppModel model = delegate.getModel(i); if(model.isInitialized() && ! model.isUpdating()) { model.update(); model.draw(gl); } }