Archived

This topic is now archived and is closed to further replies.

HELP with Camera Movement

This topic is 6576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This board is so buggy tonight...
Anyhow, I tried that code and it seems to work OK. Things I would check or might break it are:

1) if PLAYER->movement.x and PLAYER->movement.z are not floating point, the 0.5 result assigned to them would round to zero.

2) It might be better to make delta a float of seconds passed instead of a long int. More precision and less chance of rounding errors.

3) I always explicitly cast things just to be sure of what's going on, so instead of z=c * delta/1000; z = c * (((float) delta) / 1000.0F). In this case I think it actually worked right the first way, but I had to check

4) Make sure the angle is correct, and not already converted to radians.

If none of this stuff pans out, the bug is most likely somewhere else (like in the code that actually updates the 3d camera) Or an invalid input to this function. If you could explain exactly how the camera is moving wrong, that might help.

Hope this helped (:
-ns

Share this post


Link to post
Share on other sites
What are you using to physically place the camera? You might have the right coordinates creating the wrong matrix.

I know you're an OpenGL dude, are you using gluLookAt()?

And unrelated, you might want to use a #define or function to calculate degrees to radians. It'll be slower but a little more accurate. (I still can't get sin/cos of 90 deg. to return an even 1 and 0)

[This message has been edited by logistix (edited December 10, 1999).]

Share this post


Link to post
Share on other sites
I wrote a terrain rendering engine that loads a height field and a texture. Now a Camera/Player can ... ,well should walk over this surface. I use the code below to calculate the movement of the Camera for every frame. The surface is displayed right but the camera moves totally wrong. Can anyone help me?

when LRangle is zero the Camera is looking in -z direction

long int delta ; // := time that passed since last frame in ms

const double DEGtoRAD=0.017453292; // PI/180

if(move forward)
{
double c=cos(PLAYER->LRangle * DEGtoRAD)
,s=sin(PLAYER->LRangle * DEGtoRAD);

PLAYER->movement.x=s * delta/1000;
PLAYER->movement.z=c * delta/1000;

PLAYER->position+ = PLAYER->movement;
}
if(move back)
{
double c=cos(PLAYER->LRangle * DEGtoRAD)
,s=sin(PLAYER->LRangle * DEGtoRAD);

PLAYER->movement.x=-s * delta/1000;
PLAYER->movement.z=-c * delta/1000;

PLAYER->position+ = PLAYER->movement;
}

Share this post


Link to post
Share on other sites
Thanks Thanks Thanks Thanks !!
I nearly went mad, but it finally works. Nightshade you were right the code above is ok.I tested it again and again . Now I know that the error is somewhere else. I usually was calculating the height of the camera after it received a new position. So I set // in front of it and the walking routine worked fine . And finally I found the bug in the height calculation method , but there's still something wrong with it. The Camera is jumping up and down as if it walks over a ground with many holes and stairs.
I hope you can help me again.

void objekt::Camera()
{
glRotatef(HRangle,1,0,0);
glRotatef(LRangle,0,1,0);

glTranslatef(-position.x,-(position.y+1),-position.z);
// I am not sure about this anymore, here must be the second error
}

float objekt::hoehe(xyz &point)
{
int x,z; // next lower grid point
float deltax,deltaz; // distance along x and z axis to the next lower grid point
float ux,vz; // height difference between two grid points in x and z direction

x = (int)point.x;
deltax = point.x-x;

z = (int)point.z;
deltaz = point.z-z;

if(deltax+deltaz<1.0F) // example 1
{
ux = (surface[ z *width + x+1] - surface[z*width + x])*deltax;
vz = (surface[(z+1)*width + x ] - surface[z*width + x])*deltaz;
}
else // example 2 - I think here is something wrong
{
x++; // Position of P
z++;
deltax--; // new deltax and deltaz
deltaz--;
ux = (surface[ z *width + x-1] - surface[z*width + x])*deltax;
vz = (surface[(z-1)*width + x ] - surface[z*width + x])*deltaz;
}

punkt.y=surface[z*width + x] + ux + vz;

return point.y;
}

example 1
P-------o-------
|###|##/|######/ deltaz
|---*##/#|#####/#
|####/##|####/# *:=position of example 1
|###/###|###/## P:=next lower grid point of *
|##/####|##/### o:=grid point
|#/#####|#/####
|/######|/#####
o-------Z----
deltax

example 2 deltax+deltaz > 1
o-------o-------
|######/|######/
|#####/#|#####/ +:=position of example 2
|####/##|####/ P:=next grid point of +
|###/#+-|###/# o:=grid point
|##/##|#|##/##
|#/###|#|#/### deltaz
|/####|#|/####
o-------P----
deltax

# := empty space - ignore this

[This message has been edited by TheMummy (edited December 14, 1999).]

[This message has been edited by TheMummy (edited December 14, 1999).]

[This message has been edited by TheMummy (edited December 14, 1999).]

Share this post


Link to post
Share on other sites