0

I am coding a sidescrolling Jump n' Run game in C# using the Open TK Framework. In order to enable a sidescrolling effect, i would add a fixed value to all X coordinates of my Vector3 which is part of an PrimitiveType.Quad. All my platforms, which I build of multiple quads are stored inside a linked list so that i can iterate through it.

My question is, should i add a fixed constat to all coordinates, which would require to iterate my list of platforms

OR

is it preferable to update the objects X component, and then translate it using GL.Translate(x, y, z)?

Which method is better in context of performance? Should i rather translate my camera to the side (which would also require to call a translate function in background as i am concerned)?

public void Move() {// is applied on a platform object

        posX -= 0.015; 

        A.X -= 0.015; // A-H are Vector3
        B.X -= 0.015;
        C.X -= 0.015;
        D.X -= 0.015;
        E.X -= 0.015;
        F.X -= 0.015;
        G.X -= 0.015;
        H.X -= 0.015;        
    }

this.gameObjects.drawObjects(); 
//method that iterates through linked list and draws platform objects

or better only update posX and using the Translate(); method:

GL.LoadIdentity();
GL.Translate(posX, 0.0f, -3.5f); 
user3605638
  • 207
  • 1
  • 5
  • 11

1 Answers1

-1

Definitely go with the GL.Translate() option. This is the reason it is there. Keep the draw coordinates constant and update the coordinate system instead.

If you want performance then create a display list with the drawing primitives, and then to render use GL.Tanslate() and GL.Rotate() and call the list with GL.CallList()

Edit 1

In its simplest form your drawing loop might look like this

for (int i=0; i<objects.Count; i++)
{
    GL.PushMatrix();
    objects[i].Render();
    GL.PopMatrix();
}

public void Render()
{
    GL.Translate(Position);
    GL.Scale(Scale, Scale, Scale);

    ... draw primitives
}
John Alexiou
  • 28,472
  • 11
  • 77
  • 133
  • I am using GL.Translate now. In order to ensure that consecutive calls of GL.Translate(); do not affect each other, i have to apply the translation within GL.PushMatrix(); and GL.PopMatrix();. Is this correct? Sould I Rather use GL.Pop and GL.Push outside my iteration that draws the platforms and set up a Translation chain, so that diffenrent translate calls do not affect each other? – user3605638 May 09 '14 at 22:32
  • I have also always used `GL.PushMatrix()` and `GL.PopMatrix()` so you are doing the right thing. Your scene should follow a tree structure and include a push before each branch starts and a pop when it ends. – John Alexiou May 11 '14 at 07:18