EDIT: I wanna say I’m using Lwjgl 2 and slick, no other libraries
So, I started asking about this back in my “Rendering” Thread. I’ve been messing with this for the last couple of days, but I’m running into little issues, and thought I should ask. I’ve also been spending hours trying to research this, but I keep finding different answers, and just don’t know what’s right for my situation.
I have a player object in my game, and I’m trying to simulate a “camera” that follows the player. Also, when it reaches the end or start of the level, the camera doesn’t follow it (so it doesn’t look in front/behind the level).
I was also told to follow this:
clear the transform (glLoadIdentity)
glTranslatef(-player.x, -player.y)
for each entity (including the player)
push matrix stack (glPushMatrix)
glTranslatef(entity.x, entity.y)
render entity
pop matrix stack (glPopMatrix)
end for
Now the thing is, glTranslate is deprecated, and I don’t know what’s best to use that isn’t deprecated.
I also don’t really get how this all works I guess, even though it was explained before. I’ve tried messing with it a bunch, but still I’ve been told glTranslate isn’t something I should be using.
To be clear, for the player I have a moveLeft and moveRight method that runs when called.
public void moveLeft(float length)
{
direction = 0;
//Safely moves left by the length provided if possible
if(canMove("Left",length) == true)
{
//checks if the user will stay in the position it should and can actually move to where it wants to
if ((this.x - length) >= 350 && (this.x - length) <= 4050)
{
GL11.glTranslatef(length,0,0);
this.x -= length;
}
else if(((this.x - length) >= 0 && (this.x - length) < 350) || ((this.x - length) > 4050 && (this.x - length) <= 4500))
{
this.x -= length;
}
}
}
public void moveRight(float length)
{
direction = 1;
//Safely moves right by the length provided if possible
if(canMove("Right",length) == true)
{
//checks if the user will stay in the position it should and can actually move to where it wants to
if ((this.x + length) >= 350 && (this.x + length) <= 4050)
{
GL11.glTranslatef(-length,0,0);
this.x += length;
}
else if(((this.x + length) > 0 && (this.x + length) < 350) || ((this.x + length) > 4050 && (this.x + length) < 4500))
{
this.x += length;
}
}
}
So if anyone can give it another go explain the best thing to change for me, that would be great. The code above also has a few issues which I can’t seem to find (the “length” messes things up for some reason).
I was told keep the translate to the render code, but for what I want at the start and the end of the level, I don’t know why or how I would do it like that. I guess my question is just what’s the best way to simulate a camera, since I guess OpenGL moves the actual map, and doesn’t have a camera (again things I found when researching this).