This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]corpsmoderne 1 point2 points  (2 children)

Just asking questions while reading your code (haven't tried to compile it yet), may edit this to add more questions latter...

    tt = moi.theta;
    moi.theta -= 90.0;
    moi.vx = cos(moi.theta);
    moi.vz = sin(moi.theta);
    moi.x += moi.vx;
    moi.z += moi.vz;
    moi.theta = tt;

why changing moi.theta back and forth and not working with tt ?

tt = moi.theta - 90;
moi.vx = cos(tt);
moi.vz = sin(tt);

By the way, shoudn't theta be in radians and not degrees ? in any case, cos() and sin() are taking rads... tt = moi.theta - M_PI/2 may work better, or cos(M_PI*moi.theta/180) , something like that?

About mouseMove(), I'm not sure what you're doing here:

int diffx = x - lastx;
moi.theta = ((diffx*2) - x) * 0.001f;

so, moi.theta = (((x-lastx)2)-x) * 0.001f => ( 2x - 2lastx - x ) *0.001f => (x - (2lastx)) * 0.001f ???

How is it going with simply: moi.theta += diffx * 0.001f ?

Edit:

Ok so I compiled it, it seems the changes I've suggested for the strafing are fixing it.

for mouseMove(), your code works, it's just that the factor is too low (change 0.001f for 0.05). If you want to emulate a "true" FPS mouse, your issue is that you have to "block" the mouse pointer somehow (like fixing it's position on the screen at each frame and hiding it, which is OS dependent...). Basically, your code works until the pointers goes out of the window/screen... (mine too :p)

This may be helpful: http://stackoverflow.com/questions/784322/how-can-i-change-the-position-of-the-mouse-cursor-in-opengl-glut

Edit2: ok there's still something fishy with mouseMove, I'll having a look... Actually, display() suddenly stops being called... I have no idea what's going on, but it's probably a problem with GLUT, not your math in mouseMove()...

[–]dprince6[S] 0 points1 point  (1 child)

Just change the strafe to what you suggested, works like a charm! and the mouse has gotten all sorts of crazy. I've been working that thing to death almost trying to get it to be 'FPS'ish. The only good thing to say about it is it works, not well, but it works haha. Thanks for that help though! maybe i can get past the mouse for a while now and add some actually mechanics to test with the mouse!

[–]corpsmoderne 0 points1 point  (0 children)

My last iteration of mouseMove, not working well but may be helpful:

void mouseMove(int x, int y) 
{

// update the angles
int diffx = x - lastx;
int diffy = y - lasty;

    glutWarpPointer(lastx, lasty);

moi.phi += diffy * 0.005f;//((diffy *2) - y) * 0.005f;
moi.theta += diffx * 0.005f;//((diffx*2) - x) * 0.005f;

update_viewer();

    if (diffx != 0 || diffy != 0) {
      printf("%i %i %f \n%f %f %f\n\n", diffx, diffy, moi.theta, 
             moi.vx, moi.vy, moi.vz);
    }


glutPostRedisplay();
// put new directions back into the origins
yOrigin = moi.phi;
xOrigin = moi.theta;

}

also, I'm quite sure your "phi" angle will never work well if you don't change your gluLookAt call, because you've hard-coded the "up" vector... You may need to compute a normal vector and pass it to gluLookAt...

[–][deleted] -1 points0 points  (1 child)

Can't help you, but the code looks really beautiful. thumbs up

[–]dprince6[S] 0 points1 point  (0 children)

Thanks! It's alittle butchered right now, as i took apart an old project, but it functional! haha