I am still having issues figuring this all out, so I am going to post up a bunch of code and hopefully, with a little luck, and a wee bit of magic, somone can figure this out.
ok so I changed the project setup and now the camera seems to be fixed at a point in space instead of following the user.
just to recap, previously I had the glulook at on the projectionmatrix and that rendered everything correctly but did not allow me to incorporate fog which I desperately want to incorporate…
Thanks for your time, this is pretty ugly!
//gl.glEnable(GL10.GL_FOG); I wish!
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glViewport(0, 0, glGraphics.getWidth(), glGraphics.getHeight());
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluPerspective(gl, 67, glGraphics.getWidth()/(float)glGraphics.getHeight(),
1, 100f);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
GLU.gluLookAt(gl, world.user.cam.pos.x,world.user.cam.pos.y, world.user.cam.pos.z,
world.user.cam.lookat.x, world.user.cam.lookat.y, world.user.cam.lookat.z, 0, 1, 0);
//the cameras position is determined by rotating the user look vector 180 degrees, scaling it a bit and then moving it up in the y
//the lookat is just a copy of the users position
// the idea is to create a third person view looking from above and behind the user
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glTranslatef(world.user.pos.x, world.user.pos.y, world.user.pos.z); // translate to the users position which is the same as the cameras lookat
//gl.glRotatef(world.user.look2.angle() + 90, 0, 1, 0); // rotate the 2d plane 90 from the angle of the look so it appears perpendicular to camera
//The batcher.begin binds the texture
//batcher.drawsprite(x,y,width,height,textureRegion) draws a 2d plane at soecified x,y and width height and applies specified texture region
batcher.beginBatch(ffcharacters);
switch(world.user.direction){
case Zombie.DOWN:
batcher.drawSprite(0, 0, 1, 1, userAnimations[0].getKeyFrame(world.user.time, world.user.moving? Animation.ANIMATION_LOOPING:Animation.ANIMATION_NONLOOPING));
break;
case Zombie.LEFT:
batcher.drawSprite(0, 0, 1, 1, userAnimations[1].getKeyFrame(world.user.time, world.user.moving?Animation.ANIMATION_LOOPING:Animation.ANIMATION_NONLOOPING));
break;
case Zombie.RIGHT:
batcher.drawSprite(0, 0, 1, 1, userAnimations[2].getKeyFrame(world.user.time, world.user.moving?Animation.ANIMATION_LOOPING:Animation.ANIMATION_NONLOOPING));
break;
case Zombie.UP:
batcher.drawSprite(0, 0, 1, 1, userAnimations[3].getKeyFrame(world.user.time, world.user.moving?Animation.ANIMATION_LOOPING:Animation.ANIMATION_NONLOOPING));
break;
}
//end batch renders the plane
batcher.endBatch();
gl.glPopMatrix();
//METHODS WITHIN BATCHER CLASS
public void beginBatch(Texture texture){
texture.bind();
numSprites = 0;
bufferIndex = 0;
}
public void endBatch(){
vertices.setVertices(verticesBuffer, 0, bufferIndex);
vertices.bind();
vertices.draw(GL10.GL_TRIANGLES, 0, numSprites * 6);
vertices.unbind();
}
public void drawSprite(float x, float y, float width, float height, TextureRegion region){
float halfWidth = width / 2;
float halfHeight = height /2;
float x1 = x - halfWidth;
float y1 = y - halfHeight;
float x2 = x + halfWidth;
float y2 = y + halfHeight;
verticesBuffer[bufferIndex++] = x1;
verticesBuffer[bufferIndex++] = y1;
verticesBuffer[bufferIndex++] = region.u1;
verticesBuffer[bufferIndex++] = region.v2;
verticesBuffer[bufferIndex++] = x2;
verticesBuffer[bufferIndex++] = y1;
verticesBuffer[bufferIndex++] = region.u2;
verticesBuffer[bufferIndex++] = region.v2;
verticesBuffer[bufferIndex++] = x2;
verticesBuffer[bufferIndex++] = y2;
verticesBuffer[bufferIndex++] = region.u2;
verticesBuffer[bufferIndex++] = region.v1;
verticesBuffer[bufferIndex++] = x1;
verticesBuffer[bufferIndex++] = y2;
verticesBuffer[bufferIndex++] = region.u1;
verticesBuffer[bufferIndex++] = region.v1;
numSprites++;
}