Code: Select all
matrix4 mat;
mat.setRotationDegrees(startrot);
btVector3 forwardDir(mat[8],mat[9],mat[10]);
newobjectnode->getBody()->setLinearVelocity(forwardDir*50);
Code: Select all
matrix4 mat;
mat.setRotationDegrees(startrot);
btVector3 forwardDir(mat[8],mat[9],mat[10]);
newobjectnode->getBody()->setLinearVelocity(forwardDir*50);
I know what it does, but I don't understand how it does it. How does multiplying an angle by 50 get a new speed but the same direction? EX: 180 degrees * 2 = 360 degrees = new direction.B_old wrote:Without having experience with Irrlicht, this is how I interpret the code-snippet:
forwardDir is the Vector that holds the direction in which the camera is looking. So this is also the direction in which the ball should fly. You multiply it by 50 to increase the speed.
The matrix is used in order to extract the direction vector of the camera.
Sets the matrix to the rotation, in this case the camera rotation using Euler angles.killsto wrote:Code: Select all
mat.setRotationDegrees(startrot);
Here we take the 3rd basis vector of the matrix. This basis points into the viewing direction of the camera. This is the case since each matrix is in fact a linear equation system composed of 3 linearly independent base vectors ( X-axis, Y-axis and Z-axis ) and the origin of the coordinate frame. This line is the same as transforming the vector (0,0,1) by the matrix mat.Code: Select all
btVector3 forwardDir(mat[8],mat[9],mat[10]);
Now we have the direction the camera looks along. Since we got it from a rotation matrix this is a normalized vector ( hence the length of it equals to 1 unit ). So if we want a push in the direction of forwardDir with 50 unit strength we simply scale this unit vector by 50. The linear velocity is not a direction alone. The magnitude defines the actual velocity along the vector direction.Code: Select all
newobjectnode->getBody()->setLinearVelocity(forwardDir*50);