Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Chase Camera Code

  1. #1

    Chase Camera Code

    Hi Everyone

    I have a little question (as always ).

    I'm trying to implement a chase camera (a very basic one). I figured out the best way was to translate back a bit from the origin and render my model, that was the easy part.

    The hard part is figuring out how to rotate the world in such a way that it looks right. I'm using ODE so I get the Position and Rotation of my "object" using
    [pascal]
    ShipPos := dBodyGetPosition(Ship.Body);
    ShipRot := dBodyGetRotation(Ship.Body);
    [/pascal]

    Where ShipPos is a vector 3 and ShipRot is a 4x4 matrix.

    My problem is I want to positon my camera using gluLookAt, so I need to calcuate the View and Up vectors from the information I get from ODE.

    At this point my brain went to a walk. . Anyone have any suggestion on where to start?

    Cheers

    Dean
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  2. #2

    Chase Camera Code

    View is the third row and up is second row, or if ODE matrices are mathematically correct, then that would be columns instead of rows.

  3. #3

    Chase Camera Code

    I'll give that a go

    Thanks
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  4. #4

    Chase Camera Code

    That worked a treat.

    BTW the ODE matrix seems to be in columns not rows.
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  5. #5
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Chase Camera Code

    Quote Originally Posted by technomage
    That worked a treat.
    Ah... another proud PGD member... HELPED!
    Jason McMillen
    Pascal Game Development
    Co-Founder





  6. #6

    Chase Camera Code

    ODE using righthanded matrices?!? weird.. :?
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  7. #7

    Chase Camera Code

    OK, after a bit more testing it kinda worked, but not fully (rolling works OK, but pitching up or down just looked weird).

    So my comment about the matirx being in columns might not be right, I'll do a bit more testing a let you all know.
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  8. #8

    Chase Camera Code

    Since here camera is of the same orientation as the object this only works if camera is always directly behind the object (cameraPos = ObjectPos ?¢_" something * objectView)
    Edit: maybe you?¢_Tre not giving gluLookAt what it wants: Center = CamraPos + ObjectView. Can't seem to come up with a proper way to compute Up with any camera position at the moment, I'll try to do this later

  9. #9

    Chase Camera Code

    Hi guys

    I thought I'd post some more code.

    There is what I'm doing.

    Firstly I render the world after setting the camera to the position of the object and using the values from the ShipRot matrix to set the view and up vectors

    Then I render the actual object from behind.
    [pascal]
    glPushMatrix;
    ShipPos := dBodyGetPosition(Ship.Body); // get position of ODE body
    ShipRot := dBodyGetRotation(Ship.Body); // get rotation of ODE body
    // set the camera
    UserCam.PositionCamera(ShipPos[0], ShipPos[1], ShipPos[2],
    ShipRot[8],ShipRot[9],ShipRot[10],
    ShipRot[4],ShipRot[5],ShipRot[6]);
    // call gluLookAt
    UserCam.Look;
    // render world
    glPopMatrix;
    glPushMatrix;
    // set teh camerato be behind the object
    UserCam.PositionCamera(0,10,-100,0,0,0,0,1,0);
    // call gluLookAt
    UserCam.Look;
    // render player object
    glPopMatrix;
    [/pascal]

    This works for rolling left and right, but not for pitching up or down.
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  10. #10

    Chase Camera Code

    if PositionCamera uses data directlly for gluLookAt, then like I said it sould be
    UserCam.PositionCamera(ShipPos[0], ShipPos[1], ShipPos[2],
    ShipPos[0] + ShipRot[8], ShipPos[1] + ShipRot[9], ShipPos[2] +ShipRot[10],
    ShipRot[4],ShipRot[5],ShipRot[6]);


    And for any camera position
    CamView = ObjectPos - CamPos;
    CamRight = CrossProduct((0,1,0), CamView);
    CamTop = CrossProduct(CamRight, CamView);

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •