好的,这是代码。我要它执行的操作是将屏幕转换为跟随对象l2rArrow。可以,但是l2rArrow仍然在屏幕上飞舞。即使我将转换设置为l2rArrow的x,y,当应该将l2rArrow置于死点时,l2rArrow最终仍会在屏幕外运行。
当我将camX乘以25时,似乎会稍微好一些,但只会一点点。箭头仍然飞离屏幕。
public void Render(GL10 gl, float deltaTime) {
//Log.d("Game", "Render");
gl.glViewport(0, 0, Screen.SCREEN_WIDTH, Screen.SCREEN_HEIGHT);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(0, Screen.WIDTH_SCALE, 0, Screen.HEIGHT_SCALE, 1, -1);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL10.GL_TEXTURE_2D);
MeshRect mRect; // this holds all of our rectangles
// draw the sky/backdrop************************************************************
texture.bind(gl, Texture.TEXTURE_SKY1);
mRect = new MeshRect(Sky.getMyRect());
mRect.Draw(GL10.GL_TRIANGLES, gl);
//draw clouds***********************************************************************
clouds.Update();
Vector<Cloud> vClouds = clouds.getClouds();
for (int i = 0; i < vClouds.size(); i++){
vClouds.get(i).Update(deltaTime);
texture.bind(gl, Texture.TEXTURE_CLOUDS1);
mRect = new MeshRect(vClouds.get(i).getMyRect());
mRect.Draw(GL10.GL_TRIANGLES, gl);
if (vClouds.get(i).hasRunCourse()){
clouds.RemoveCloud(vClouds.get(i).getID());
}
}
// draw arrows and applied power ups***********************************************************************
boolean hasTranslated = false;
if (!l2rArrow.isFired) {
gl.glPushMatrix(); //save our state
gl.glTranslatef(l2rArrow.GetToOriginX, l2rArrow.GetToOriginY, 0f); // translate to origin 0,0,0
gl.glRotatef(LBow.getAngle(), 0f, 0f, 1f); //rotate
gl.glTranslatef(-l2rArrow.GetToOriginX, -l2rArrow.GetToOriginY, 0f); // translate to where we want to draw it
texture.bind(gl, Texture.TEXTURE_L2RARROW);
mRect = new MeshRect(l2rArrow.getMyRect());
mRect.Draw(GL10.GL_TRIANGLES, gl);
gl.glPopMatrix(); //return to saved state
} else {
l2rArrow.Update(deltaTime);
texture.bind(gl, Texture.TEXTURE_L2RARROW);
mRect = new MeshRect(l2rArrow.getMyRect());
mRect.Draw(GL10.GL_TRIANGLES, gl);
hasTranslated = true;
gl.glPushMatrix();
float camX = (float) ((l2rArrow.startX - l2rArrow.PosX));
camX = camX * 25;
float camY = (float) ((l2rArrow.startY - l2rArrow.PosY));
if (camY > 0) { camY = 0;}
gl.glTranslatef(camX, camY,0f);
if (l2rArrow.hasCollided) {
//run collision code for detecting a hit and ending turn
}
}
/**=======================================================================================================
* Everything between here should be effected by translate | | gl.gltranslatef(x,y,z) x = Xoffset
*=======================================================================================================*/
/**=======================================================================================================
* gl.glPopMatrix(); back to origin
*=======================================================================================================*/
if (hasTranslated){
gl.glPopMatrix();
}
//finish drawing other non translated
}
最佳答案
我没有为gl.glLoadIdentity()
看到GL_MODELVIEW
。您确定要从单位矩阵开始Modelview吗?如果没有,翻译将继续与前一帧连接。我也没有看到gl.glMatrixMode
调用切换到GL_MODELVIEW
,在这种情况下,所有矩阵变换都将进入投影矩阵。