korogui

03-11-2003, 06:39 PM

Hello. I'm having a big problem trying to make a car rotate, the big problem, is cause the car apears to be stuck in the center 'world-axis' (0,0,0). So, I saw a code that rotates and moves a camera around the world just the way I need... But i dont understood how it works... So, if anyone can post a code for a newbie like me...

(I just wanna make a car that runs in the scene)

Here's the code that 'rotates the camera around it's own center' or something like this http://www.opengl.org/discussion_boards/ubb/wink.gif ohhh! and sorry for the poor english! hehehe!

void CCamera::RotateView(float angle, float x, float y, float z)

{

CVector3 vNewView;

CVector3 vView;

vView.x = m_vView.x - m_vPosition.x; // This gets the direction of the X

vView.y = m_vView.y - m_vPosition.y; // This gets the direction of the Y

vView.z = m_vView.z - m_vPosition.z; // This gets the direction of the Z

float cosTheta = (float)cos(angle);

float sinTheta = (float)sin(angle);

vNewView.x = (cosTheta + (1 - cosTheta) * x * x) * vView.x;

vNewView.x += ((1 - cosTheta) * x * y - z * sinTheta) * vView.y;

vNewView.x += ((1 - cosTheta) * x * z + y * sinTheta) * vView.z;

vNewView.y = ((1 - cosTheta) * x * y + z * sinTheta) * vView.x;

vNewView.y += (cosTheta + (1 - cosTheta) * y * y) * vView.y;

vNewView.y += ((1 - cosTheta) * y * z - x * sinTheta) * vView.z;

vNewView.z = ((1 - cosTheta) * x * z - y * sinTheta) * vView.x;

vNewView.z += ((1 - cosTheta) * y * z + x * sinTheta) * vView.y;

vNewView.z += (cosTheta + (1 - cosTheta) * z * z) * vView.z;

m_vView.x = m_vPosition.x + vNewView.x;

m_vView.y = m_vPosition.y + vNewView.y;

m_vView.z = m_vPosition.z + vNewView.z;

}

(I just wanna make a car that runs in the scene)

Here's the code that 'rotates the camera around it's own center' or something like this http://www.opengl.org/discussion_boards/ubb/wink.gif ohhh! and sorry for the poor english! hehehe!

void CCamera::RotateView(float angle, float x, float y, float z)

{

CVector3 vNewView;

CVector3 vView;

vView.x = m_vView.x - m_vPosition.x; // This gets the direction of the X

vView.y = m_vView.y - m_vPosition.y; // This gets the direction of the Y

vView.z = m_vView.z - m_vPosition.z; // This gets the direction of the Z

float cosTheta = (float)cos(angle);

float sinTheta = (float)sin(angle);

vNewView.x = (cosTheta + (1 - cosTheta) * x * x) * vView.x;

vNewView.x += ((1 - cosTheta) * x * y - z * sinTheta) * vView.y;

vNewView.x += ((1 - cosTheta) * x * z + y * sinTheta) * vView.z;

vNewView.y = ((1 - cosTheta) * x * y + z * sinTheta) * vView.x;

vNewView.y += (cosTheta + (1 - cosTheta) * y * y) * vView.y;

vNewView.y += ((1 - cosTheta) * y * z - x * sinTheta) * vView.z;

vNewView.z = ((1 - cosTheta) * x * z - y * sinTheta) * vView.x;

vNewView.z += ((1 - cosTheta) * y * z + x * sinTheta) * vView.y;

vNewView.z += (cosTheta + (1 - cosTheta) * z * z) * vView.z;

m_vView.x = m_vPosition.x + vNewView.x;

m_vView.y = m_vPosition.y + vNewView.y;

m_vView.z = m_vPosition.z + vNewView.z;

}