java - Change Vertex massive in Renderer class from MainActivity onTouchEvent -
i newbie in android developement , thi question, how can change vertex massive inside class "mainrenderer" inside class "ship" mainactivity ontouchevent?
here code: mainactivity.java:
package com.example.galaga2d; import android.opengl.glsurfaceview; import android.os.bundle; import android.app.activity; import android.view.motionevent; import android.view.window; import android.view.windowmanager; import android.widget.toast; public class mainactivity extends activity { //private boolean istouch = false; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // Убираем тайтл приложения, тобишь делаем его fullscreen requestwindowfeature(window.feature_no_title); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); // Создаём новый surface и устанавливаем mainrenderer glsurfaceview view = new glsurfaceview(this); view.setrenderer(new mainrenderer()); view.setrendermode(glsurfaceview.rendermode_when_dirty); setcontentview(view); } @override public boolean ontouchevent(motionevent event) { int x = (int) event.getx(); int y = (int) event.gety(); int upx = (int) event.getx(); int upy = (int) event.gety(); int downx = (int) event.getx(); int downy = (int) event.gety(); int eventaction = event.getaction(); switch (eventaction) { case motionevent.action_down: toast.maketext(this, "ВНИЗ "+"x: "+x+" y: "+y, toast.length_short).show(); break; case motionevent.action_move: toast.maketext(this, "ДВИЖЕНИЕ "+"x: "+x+" y: "+y, toast.length_short).show(); break; case motionevent.action_up: toast.maketext(this, "ВВЕРХ "+"x: "+x+" y: "+y, toast.length_short).show(); break; } return true; } }
and mainrenderer.java:
package com.example.galaga2d; import java.nio.bytebuffer; import java.nio.floatbuffer; import java.nio.byteorder; import javax.microedition.khronos.egl.eglconfig; import javax.microedition.khronos.opengles.gl10; import android.opengl.glsurfaceview.renderer; public class mainrenderer implements renderer { public int playersize = 0; private ship playership = new ship(); private astedoid enemyastedoid = new astedoid(); @override public void onsurfacecreated(gl10 gl, eglconfig config) { gl.glclearcolor(1.0f, 0.0f, 0.0f, 1.0f); } @override public void ondrawframe(gl10 gl) { gl.glclear(gl10.gl_color_buffer_bit | gl10.gl_depth_buffer_bit); playership.draw(gl); enemyastedoid.draw(gl); } @override public void onsurfacechanged(gl10 gl, int width, int height) { gl.glviewport(0, 0, width, height); gl.glmatrixmode(gl10.gl_projection); gl.glloadidentity(); gl.glorthof(0, width, height, 0, 1, -1); gl.glmatrixmode(gl10.gl_modelview); } // -------------------------------------------------------------------------------- class ship { public int health = 100; public int life = 3; public floatbuffer shipvertexbuffer; public float shipverticles[] = { 5, 5, // лево низ 5, 10, // лево вверх 10, 5, // право низ 10, 10 // право вверх }; public ship() { bytebuffer bb = bytebuffer.allocatedirect(36); bb.order(byteorder.nativeorder()); shipvertexbuffer = bb.asfloatbuffer(); shipvertexbuffer.put(shipverticles); shipvertexbuffer.position(0); } public void draw(gl10 gl) { gl.glcolor4f(0.0f, 1.0f, 0.0f, 1.0f); gl.glvertexpointer(2, gl10.gl_float, 0, shipvertexbuffer); gl.gldrawarrays(gl10.gl_triangle_strip, 0, 4); } } class astedoid { public int health = 100; public int life = 3; public floatbuffer asteroidcolorbuffer; public floatbuffer asteroidvertexbuffer; public float asteroidverticles[] = { 25, 25, // лево низ 25, 30, // лево вверх 30, 25, // право низ 30, 30 // право вверх }; public astedoid() { bytebuffer bb = bytebuffer.allocatedirect(36); bb.order(byteorder.nativeorder()); asteroidvertexbuffer = bb.asfloatbuffer(); asteroidvertexbuffer.put(asteroidverticles); asteroidvertexbuffer.position(0); } public void draw(gl10 gl) { gl.glcolor4f(0.0f, 0.0f, 1.0f, 1.0f); gl.glvertexpointer(2, gl10.gl_float, 0, asteroidvertexbuffer); gl.gldrawarrays(gl10.gl_triangle_strip, 0, 4); } } // -------------------------------------------------------------------------------- }
i want this, create variable "objectsize" , give value 5 in main activity ontouchevent on "case motionevent.action_down", example:
case motionevent.action_down: objectsize = 5; break;
than want use variable change size of drawing object in mainrenderer in class ship, example:
public float shipverticles[] = { 5*objectsize , 5*objectsize, 5*objectsize, 10*objectsize, 10*objectsize, 5*objectsize, 10*objectsize, 10*objectsize };
how can this? thx!
Comments
Post a Comment