Я нарисовал одну линию с вершинами (0.2f, 0.2f, 0.0f) & (-0.2f, -0.2f, 0.0f) в OpenGL. Поскольку z-компонент координат линии отсутствует, это означает, что линия находится в плоскости XY. Теперь я пытаюсь повернуть линию вокруг оси Z, используя функцию glRotatef. В идеале поворот линии должен был бы проходить по кругу (по крайней мере, он должен был выглядеть как круг при повороте на 1 - 360), но почему-то он больше напоминал эллипс, более вытянутый к оси y (я думаю, что быть из-за эффекта глубины). но так как моя линия полностью находится в плоскости XY (так как компонент Z отсутствует в линейных координатах), почему я получаю такой эффект глубины? Я разместил свой код с этим вопросом. Пожалуйста, укажите мне правильное направление?
Файл кода GLSurfaceViewActivity:
package com.mobi.trials.gldemo;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class GLSurfaceViewActivity extends Activity {
SimpleGLSurfaceView glView = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("GLDemo", "In the activity");
glView = new SimpleGLSurfaceView(this);
setContentView(glView);
}
@Override
protected void onPause() {
super.onPause();
glView.onPause();
}
@Override
protected void onResume() {
super.onResume();
glView.onResume();
}
}
Файл кода SimpleGLSurfaceView:
package com.mobi.trials.gldemo;
import android.content.Context;
import android.opengl.GLSurfaceView;
public class SimpleGLSurfaceView extends GLSurfaceView {
public SimpleGLSurfaceView(Context context) {
super(context);
final DrawGLSurfaceCanvasView renderer = new DrawGLSurfaceCanvasView(this);
setFocusable(true);
setFocusableInTouchMode(true);
setRenderer(renderer);
}
}
Файл кода DrawGLSurfaceCanvasView:
package com.mobi.trials.gldemo;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView;
public class DrawGLSurfaceCanvasView implements GLSurfaceView.Renderer {
SimpleLine line;
private float rotationAngle = 0.0f;
float lineVertices[] = { 0.2f, 0.2f, 0f,
-0.2f, -0.2f, 0f };
public DrawGLSurfaceCanvasView(GLSurfaceView view) {
}
@Override
public void onDrawFrame(GL10 gl) {
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glClear(GL10.GL_COLOR_BUFFER_BIT|GL10.GL_DEPTH_BUFFER_BIT);
gl.glRotatef(rotationAngle, 0.0f, 0.0f, 1.0f);
if(rotationAngle <= -360.0f)
{
rotationAngle = 0.0f;
}
rotationAngle -= 1f;
line.draw(gl);
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
line = new SimpleLine(lineVertices);
}
}
Файл кода SimpleLine:
package com.mobi.trials.gldemo;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import javax.microedition.khronos.opengles.GL10;
public class SimpleLine {
float vertices[];
private FloatBuffer vertexBuffer;
public SimpleLine(float[] vertices) {
super();
this.vertices = vertices;
}
public void draw(GL10 gl)
{
ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
vbb.order(ByteOrder.nativeOrder());
vertexBuffer = vbb.asFloatBuffer();
vertexBuffer.put(vertices);
vertexBuffer.position(0);
// Update : Added orthographic projection matrix.
// Update II : Corrected the values of orthgraphic projection matrix.
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glDrawArrays(GL10.GL_LINES, 0, 2);
}
} * * тысяча двадцать-один