WillJBD
08-04-2012, 11:38 PM
I have a archer shooting a arrow. When the archer shoots i need the "camera" to follow the arrow, as to keep the arrow dead center while every thing else translates.
basically follow the arrow.
My code does this to a point, but the arrow somehow gains on the transformation. I don't know how this happens as I set the transformation to position itself where the arrow is positioned.
public void Render(GL10 gl, float deltaTime) {
/************************************************** ************************
* This is where you draw the screen, called every auto Loop pass
* ************************************************** **********************/
//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
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();
gl.glLoadIdentity();
float camX = (float) ((l2rArrow.startX - l2rArrow.PosX));
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
*================================================= ================================================== ====*/
// draw translated things
/**================================================ ================================================== =====
* gl.glPopMatrix(); were done go back to normal
*================================================= ================================================== ====*/
if (hasTranslated){
gl.glPopMatrix();
}
}
as i said, the screen follows the arrow, but the arrow seems to gain on the edge of the screen until it runs off it.
basically follow the arrow.
My code does this to a point, but the arrow somehow gains on the transformation. I don't know how this happens as I set the transformation to position itself where the arrow is positioned.
public void Render(GL10 gl, float deltaTime) {
/************************************************** ************************
* This is where you draw the screen, called every auto Loop pass
* ************************************************** **********************/
//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
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();
gl.glLoadIdentity();
float camX = (float) ((l2rArrow.startX - l2rArrow.PosX));
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
*================================================= ================================================== ====*/
// draw translated things
/**================================================ ================================================== =====
* gl.glPopMatrix(); were done go back to normal
*================================================= ================================================== ====*/
if (hasTranslated){
gl.glPopMatrix();
}
}
as i said, the screen follows the arrow, but the arrow seems to gain on the edge of the screen until it runs off it.