Results 1 to 2 of 2

Thread: Help with basic camera functionality

  1. #1

    Help with basic camera functionality

    I'm currently trying to adopt the "Hello Arrow" sample code from the 3d programming for iphone book and instead of having the arrow rotate to always point up when the phone is turned, i want to essentially move the camera when a swipe is detected. (in essense, when the user swipes across the screen, the camera and its target will move by detltaX and detlaY). I figured this would be a good start to learning opengl ES 2.0 comming from just a regular opengl background. Currently, after loading the program, the arrow just dissapears.

    The original sample code can be found here:

    I ended up adding vector and matrix classes/headers to handle any math that may be needed and used the matrix class's lookat() function. these classes can be found as part of this sample project:

    after that i just added the swipe detection to the and added the variables m_currentx, m_currenty to RenderingEngine2.cpp to track the camera location and the functions

    Code :
    void RenderingEngine2::OnMove(float movementX, float movementY)
        m_currentx += movementX/320;  //x scale
        m_currenty += movementY/480; // y scale
    void RenderingEngine2::ApplyMove() const
       GLfloat distance = 10;
       vec3 eye = vec3(m_currentx, m_currenty, distance);
       vec3 target = vec3(m_currentx, m_currenty, 0);
       vec3 up = vec3(0,1,0);
       mat4 look = Matrix4<float>::LootAt(eye, target, up);
       GLint modelviewUniform = glGetUniform(m_simpleProgram, "Modelview");
       glUniformMatrix4fv(modelviewUniform, 1, 0, look.Pointer());

    in the render function, applyrotation was replaced with applymove and the coordinates of the arrow were edited to include the z axis (all set to zero). currentx and currenty were also intialized to zero.

    and just to make sure that there is nothig wrong with the math, the resulting matrix from lookat is

    [1, 0, ~0, ~0,
    0, 1, 0, ~0,
    ~0, ~0, ~0, ~0,
    ~0, ~0, ~0, 1]

    which if i interpret this right means that x and y stay the same and z goes to zero, which sounds about right to me.

    if anyone can share with me any insight as to why my code isn't working right i'd really appreciate it. Thanks.

  2. #2
    Junior Member
    Join Date
    Sep 2010

    Re: Help with basic camera functionality

    My iPhone game demo does this. Download it here. viewtopic.php?f=9&t=3140

Similar Threads

  1. [Camera] Can't make the camera move appropriately
    By onion_bread in forum OpenGL ES
    Replies: 0
    Last Post: 12-01-2011, 06:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean