3D Scrolling

Started by
5 comments, last by andfol 12 years, 1 month ago
Can anybody point me in the direction for beginners tutorials on 3D scrolling. I have a window created for OpenGL also have a player that moves no collision detection yet. I would be grateful for any feedback.
Advertisement
You probably already have the values you need to change in order to "scroll" your camera around. You may have used the GluLookAt() -method, so just change the position and rotation values in the method call. :)
I am not quite sure what you mean Manabreak don't have a camera class as such and I not too familiar with GluLookAt() method.
Sorry for not making myself clear, I didn't literally mean a camera class, but instead the "view" you get on your screen. Do you use the GluLookAt() method? If you do, it has several parameters, the first three ones are the position, the next three are the "target" position and the last three are the "up" vector. By changing the first three, you can change the view position. They're all in the good old X, Y, Z -order, so by changing the first number, you can pan the screen sideways, and so on.
Hi Manabreak,

Hope you pick up this post, I tried using the GluLookAt() function like you suggested above:

gluLookAt(g_Player1.getPosX()+g_Player2.getPosX(),g_Player1.getPosY()+g_Player2.getPosY(),g_Player1.getPosZ()+g_Player2.getPosZ(),0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);

I know this code is a bit messy, I have used my player objects to call the getPos variables. When I compile it it seems to work player2 moves across the screen as if scrolling although I have no movement on it, but player1 that does move according to keypresses just rotates around the screen and a primitive triangle I have drawn moves with it. Do you have a fix would be grateful.
I think the problem is how you use the player positions. I think you're trying to get the midpoint between the players, right? Then you should do something like this:

float camX = (g_Player1.getPosX() + g_Player2.getPosX()) / 2;
float camY = (g_Player1.getPosY() + g_Player2.getPosY()) / 2;
float camZ = (g_Player1.getPosZ() + g_Player2.getPosZ()) / 2;

gluLookAt(camX, camY, camZ, 0f, 0f, 0f, 0f, 1f, 0f);


This isn't tested code, just something I threw out of my head. Hopefully it is what you're trying to do. :)
Hi Manabreak,

Sorry its been so long what you suggested above worked it moves the player in and out keeping perspective but I was wondering is it possible to move the static objects in the scene so they appear to be moving past the moving players. I hope you are still following this I know its been a long time anyway I would be grateful for your feedback.

Thanks andfol.

This topic is closed to new replies.

Advertisement