rotation problem on Opengl
I have been trying to make a point rotate around another point in Opengl es for android. It works but in a particular way. As the rotation gets bigger (i.e close to 90°) the point gets further away from the centre of rotation.Eventually the point rotates around the centre of rotation in an elliptical orbit however I want it to rotate in a circular fashion. anyone knows how I could be able to do this? thank you
package org.example.pointtest;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import javax.microedition.khronos.opengles.GL10;
public class LegRoot
{
public FloatBuffer hipVertexBuffer;
float[]hip={1.75f,-2.75f,0.0f};//0 hip
float[]knee={1.75f,-6.75f,0.0f};//1 knee
float[]ankle={1.75f,-10.75f,0.0f};//2 ankle
public float distance2D(float[]origin,float[]extremity)
{
float a=extremity[0]-origin[0];
float b=extremity[1]-origin[1];
float c=extremity[2]-origin[2];
float[] d={a,b,c};
return d[1];
}
public LegRoot()
{
float []hippoint=
{
1.75f,-2.75f,0.0f
};//0 hip
ByteBuffer vbb = ByteBuffer.allocateDirect(1*3*4);
vbb.order(ByteOrder.nativeOrder());
hipVertexBuffer=vbb.asFloatBuffer();
hipVertexBuffer.put(hippoint);
hipVertexBuffer.position(0);
}
public void hip(GL10 gl)
{
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0,hipVertexBuffer);// root joint transformation matrix(supposition)
gl.glPushMatrix();
gl.glColor4f(1f, 0f, 0f, 1f);
gl.glRotatef(0f, 0, 0, 1);
gl.glTranslatef(0f,0f, 0);
gl.glDrawArrays(GL10.GL_POINTS, 0, 1);
gl.glPopMatrix();
}
public void knee(GL10 gl)
{
gl.glPushMatrix();
gl.glTranslatef(-hip[0], -hip[1], 0);
gl.glRotatef(0f, 0, 0, 1);
gl.glTranslatef(hip[0], hip[1], 0);
gl.glTranslatef(0,distance2D(hip,knee), 0);
hip(gl);
gl.glPopMatrix();
}
public void ankle(GL10 gl)
{
gl.glPushMatrix();
gl.glTranslatef(-knee[0], -knee[1], 0);
gl.glRotatef(90f, 0, 0, 1);
gl.glTranslatef(knee[0], knee[1], 0);
gl.glTranslatef(0, distance2D(knee, ankle), 0);
knee(gl);
gl.glPopMatrix(开发者_如何学C);
}
}
Just to have an answer here I copied my comment.
You probably have a glScale in your Matrix. You could try to load the identity matrix before drawing to ensure there is no scale involved. But this would remove all other transformations you did before.
Also note: When you have a non square display and don't take in account the aspect ratio of your display this will also look like scaled.
For your second problem: Can you post the rotate statement you mean? And maybe it is better to open a new question for a new problem.
精彩评论