One of the problems I have is that this makes using variable arrays rather difficult. This would be needed for example to bring a ripple in water or create a "sinusoid" line. I used the FloatBuffer.wrap() call to work around this, but I wonder if there are any side-effects that might prohibit me to work this way ? On my HTC Magic it works fine, and I have attached a project which shows how to do it here.
Any comments from the graphics Gurus ?
Using java Syntax Highlighting
- private void initVertices()
- {
- int[] lineCoords =
- {
- -ONE * 3, ONE / 10 + 4 * ONE, 0, -ONE * 3, -ONE / 10 + 4 * ONE, 0, ONE * 3, ONE / 10, 0, ONE * 3, -ONE / 10, 0
- };
- lineCoordsBuffer = makeIntBuffer(lineCoords);
- float[] lineCoordsF =
- {
- 0.0f, 0.01f, 0, 0.0f, -0.01f, 0, 0.0f, 0.01f, -300, 0.0f, -0.01f, -300
- };
- lineCoordsFBuffer = makeFloatBuffer(lineCoordsF);
- for (int x = 0; x < FLAG_LEN; x++)
- {
- flagCoords[x * 3] = x / 100.0f;
- flagCoords[x * 3 + 1] = 0;
- flagCoords[x * 3 + 2] = 0;
- }
- flagCoords[1] = 1.0f;
- flagCoordsBuffer = FloatBuffer.wrap(flagCoords);
- }
- @Override
- public void onDrawFrame(GL10 gl)
- {
- gl.glEnable(GL10.GL_DITHER);
- gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
- gl.glMatrixMode(GL10.GL_MODELVIEW);
- gl.glLoadIdentity();
- drawBeam(gl);
- drawSinoid(gl);
- }
- private void drawSinoid(GL10 gl)
- {
- gl.glShadeModel(GL10.GL_FLAT);
- gl.glColor4f(1.0f, 1.0f, 0.2f, 1.0f);
- gl.glVertexPointer(3, GL10.GL_FLOAT, 0, flagCoordsBuffer);
- gl.glPushMatrix();
- gl.glTranslatef(-010f, 0, -35.0f);
- gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, FLAG_LEN);
- gl.glPopMatrix();
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
The actual code which changes the values in the arrays:
Using java Syntax Highlighting
- public void setSensorValues(float[] values)
- {
- float newVal, oldVal, diff;
- for (int x = 0; x < 3; x++)
- {
- newVal = values[x] * -2.0f;
- oldVal = this.sensorValues[x];
- diff = newVal - oldVal;
- this.sensorValues[x] = oldVal + diff / 3.0f;
- }
- for (int counter = FLAG_LEN - 2; counter >= 0; counter--)
- {
- flagCoords[counter * 3 + 4] = flagCoords[counter * 3 + 1] * 0.998f;
- }
- flagCoords[1] = (float) (Math.sin(System.currentTimeMillis() / 1000.0) * 8.0f);
- }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
I know that this code uses an indirect NIO buffer, but would it hurt ?




