PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Question about camera

Hi.

A little question about camera in edgelib:

if in OnNextFrame I translate a player model (E3DSurface object) to:
Code:
player.Translate(x, y, z);


and call:
Code:
display->WorldTranslate(player.getX(), player.getY(), player.getZ()-5000)



isn't the camera supposed to be following the player model? or am I using the wrong function?
Do you guys even check this board anymore ? :?
Hi PocketPlay,

Your code seems fine, although I'm missing the Reset and WorldReset calls from your sample. Are you calling the reset functions before translating?
Hi.


I call the following in OnNextFrame():
Code:

player.Update();
display->Perspective3D(display->GetWidth(), display->GetHeight());
display->WorldReset();
display->WorldTranslate(0, 0, player.getZ() - 5000);


player is an object of a class I derived from E3DSurface.
and yeah, I do call Reset() for him as well.
Code:
class Model: public E3DSurface
...
...

Code:

....
....
void Model::Update() {

Reset();
Rotate(0, angle, 0);
Translate(x, y, z);


}
...
...


well, here's what I don't understand about camera in Edgelib: if it's being translated according to player's position, why does my player model move on screen but the camera doesn't?
Hi PocketPlay,

When translating the world, reverse the x, y and z parameters. Then it should work correctly.

If it still doesn't work, change the order of the translate and rotate calls.
okay,

Code:

display->WorldTranslate( 0, 0, -( player.get(2) - 5000) );


if I do that the model is just upside down and it's the same. the model moves but the camera doesn't.

I did try changing the order of translate/rotate calls. I also tried calling only translates, without rotating anything.
allright, it works now.

I have one question left though - why do I have to reverse parameters? does it have something to do with OpenGL (ES) or Edgelib itself?
PocketPlay wrote:allright, it works now.

I have one question left though - why do I have to reverse parameters? does it have something to do with OpenGL (ES) or Edgelib itself?


IIRC (long time since I did some 3D stuff) it's not openGL or Edgelib issue but a "3D issue":
You're not moving the camera, but moving the entire world while the camera is always stuck at 0,0,0
so I should call WorldTranslate
( 0, 0, 5000-player.getZ() )
instead of
( 0, 0, player.getZ()-5000) )

because of the z axis orientation?
Hi PocketPlay,

You should call it like this:
Translate(0, 0, -player.getZ() - 5000);

The player position is inverted and the camera is placed 5000 units behind the player.
yeah, allright. thanks.

I also have one more question: when I call

display->Perspective3D(display->GetWidth(), display->GetHeight(), 512, 0, 2000);

isn't the camera supposed to move at y = 2000 in the World coordinates? seems like it's always located at y = 0, even if I change those offset params.
the reason I'm asking is because I 'm trying to render two models: player and floor. and for some reason, when I move the floor along Y axis sometimes it disappears.

could that be because the model is out of the camera view?
Hi PocketPlay,

The offset parameters to Perspective3D are for transforming the frustum and don't relate to world coordinates. In most cases you should use the default parameters for those.

It could be possible that the floor disappears if you're looking at the bottom of it, and not from the top. This happens when backface culling is enabled (polygons will only be viewed from the frontside and not from the backside).
that sounds very plausible.

is there any way I can disable this in Edgelib?
Hi,

You can disable backface culling by calling glDisable(GL_CULL_FACE). You can also create 2 planes, one for each side and let them use the same coordinates ('attach' them to each other).
allright, thanks.