blackknight467

08-16-2010, 04:58 PM

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: http://examples.oreilly.com/9780596804831/HelloArrow

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:

http://examples.oreilly.com/9780596804831/CrudeBloom/

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

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.

The original sample code can be found here: http://examples.oreilly.com/9780596804831/HelloArrow

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:

http://examples.oreilly.com/9780596804831/CrudeBloom/

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

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.