Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Moving an object depending on it's normal

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2000
    Posts
    3

    Moving an object depending on it's normal

    Hi,

    I've been trying to do the following for quite a while without success (I'm sure it's easy but I'm not that familiar with any of the techniques involved). Basically I have a rectangle :

    po = -1,1,0
    p1 = -1,-1,0
    p2 = 1,-1,0
    p3 = 1,1,0

    and I would like to move it around in the XZ plane. The left and right keys rotate to polygon about y at it's origin and the up and down keys move the object along it's normal. I've tried many approaches but all of them have failed. I'm sure this is something very easy and standard but I'm new at this and it's doing my head in !
    Thanks
    Tony

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2000
    Location
    Hannover, Germany
    Posts
    12

    Re: Moving an object depending on it's normal

    Originally posted by Tony798:
    Hi,

    I've been trying to do the following for quite a while without success (I'm sure it's easy but I'm not that familiar with any of the techniques involved). Basically I have a rectangle :

    po = -1,1,0
    p1 = -1,-1,0
    p2 = 1,-1,0
    p3 = 1,1,0

    and I would like to move it around in the XZ plane. The left and right keys rotate to polygon about y at it's origin and the up and down keys move the object along it's normal. I've tried many approaches but all of them have failed. I'm sure this is something very easy and standard but I'm new at this and it's doing my head in !
    Thanks
    Tony
    You have to store the position, direction and orientation of your object:

    ...
    float pos[3] = {0.0, 0.0, 0.0};
    float dir[3] = {0.0, 0.0, 1.0};//your normal's initial state
    float angY = 0.0;

    //newAng is absolute
    updateDir(float newAng, float *out)
    {
    float p[]={0.0,0.0,0.1};
    float cosa = cos(newAng);
    float sina = sin(newAng);

    out[0] = p[0]*cosa+p[2]*sina;
    out[1] = p[1];
    out[2] = -p[0]*sina+p[2]*cosa;
    }

    updatePos(float speed, float *dir, float *pos)
    {
    pos[0] = pos[0] + speed*dir[0];
    pos[1] = pos[1];// only XZ - Plane
    pos[2] = pos[2] + speed*dir[2];
    }

    void Run(void)
    {
    getInput();
    updateDir(...);
    updatePos(...);
    render();
    }

    .... i hope it works for you ....
    adios dariusz

Posting Permissions

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