turn model to face direction of movement
Quote: Original post by b3rs3rk
@vincoof: but it's not simpler to compute the angle between the vector at start position and the vector at end position of the model? i'm asking this because i'm trying this way... and works QUITE good o_O
It might work if you use the same "up" vector, but in the general case it may not be the case.
i'm trying this:
start.Normalize();
end.Normalize();
float dot = (start.x * end.x) + (start.z * end.z);
float cs = acos(dot)*180/PI;
glRotate(cs,0,1,0);
i feel like i've missed something :/
start.Normalize();
end.Normalize();
float dot = (start.x * end.x) + (start.z * end.z);
float cs = acos(dot)*180/PI;
glRotate(cs,0,1,0);
i feel like i've missed something :/
errr...the angle after the acos will already be in radians, sorry for that. Otherwise it looks right.
use a matrix loaded with rotation values and transform the model with it...
The world isn't unpredictable. It's CHAOTIC.
Thanks for all the input. I was able to get it to work. Here is what I think I understand about it. It is very similar to the look-at function for the camera, except that things are backwards for the camera...kind of like a mirror image. So you basically do the same thing that you would do when creating the look-at matrix, except the translation values would not be negative, and you would transpose the rotation:
//*****************************************************
// first calculate each axis
axis[Z] = Normalize(look-eye);
axis[X] = Normalize(CrossProduct(axis[Z], up));
axis[Y] = CrossProduct(axis[X], axis[Z]);
// for some reason i have to get the inverse for x-axis
// not sure what i am doing to cause me to have to do this
// but it makes the numbers come out correctly
axis[X] *= -1.0f;
// now fill in the values for the matrix
matrix[0] = axis[X][X]; matrix[1] = axis[X][Y]; matrix[ 2] = axis[X][Z]; matrix[3] = 0.0f;
matrix[4] = axis[Y][X]; matrix[5] = axis[Y][Y]; matrix[ 6] = axis[Y][Z]; matrix[7] = 0.0f;
matrix[8] = axis[Z][X]; matrix[9] = axis[Z][Y]; matrix[10] = axis[Z][Z]; matrix[11] = 0.0f;
matrix[12] = eye[X]; matrix[13] = eye[Y]; matrix[14] = eye[Z]; matrix[15] = 1.0f;
// now set the world matrix (directx)
D3DXMATRIX mat(mmatrix);
direct3DDevice->SetTransform(D3DTS_WORLD, &(D3DMATRIX)mat);
//***********************************************************
I have tested this for quite some time and am pretty conviced that it is correct, although i dont understand why the x-axis comes out backwards causing me to have to multiply it by -1.0.
//*****************************************************
// first calculate each axis
axis[Z] = Normalize(look-eye);
axis[X] = Normalize(CrossProduct(axis[Z], up));
axis[Y] = CrossProduct(axis[X], axis[Z]);
// for some reason i have to get the inverse for x-axis
// not sure what i am doing to cause me to have to do this
// but it makes the numbers come out correctly
axis[X] *= -1.0f;
// now fill in the values for the matrix
matrix[0] = axis[X][X]; matrix[1] = axis[X][Y]; matrix[ 2] = axis[X][Z]; matrix[3] = 0.0f;
matrix[4] = axis[Y][X]; matrix[5] = axis[Y][Y]; matrix[ 6] = axis[Y][Z]; matrix[7] = 0.0f;
matrix[8] = axis[Z][X]; matrix[9] = axis[Z][Y]; matrix[10] = axis[Z][Z]; matrix[11] = 0.0f;
matrix[12] = eye[X]; matrix[13] = eye[Y]; matrix[14] = eye[Z]; matrix[15] = 1.0f;
// now set the world matrix (directx)
D3DXMATRIX mat(mmatrix);
direct3DDevice->SetTransform(D3DTS_WORLD, &(D3DMATRIX)mat);
//***********************************************************
I have tested this for quite some time and am pretty conviced that it is correct, although i dont understand why the x-axis comes out backwards causing me to have to multiply it by -1.0.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement