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

Originally posted by Tony798:
[b]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[/b]

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