A little question to lession 10
Hi,
i try to modify the lession 10, so that i can move with the forward key in the direction in which i look (like free fly). I hope somebody can tell me how can i do this ......
Sorry for that newbie question
Oh boy, this is really hard to explain without drawing a picture, but I'll try
.
To accomplish what you're looking for, you need two angles - one angle representing his rotation counterclockwise from the Z axis, and one representing his rotation "tilted up" from the XZ plane. For example, suppose he's facing exactly between the X and Z axes, and say his tilt is 30 degrees above it.
In the lesson 10 code, the player always moves a distance of .05 along the XZ plane:
xpos -= (float)sin(heading*piover180) * 0.05f; // Move On The X-Plane Based On Player Direction
zpos -= (float)cos(heading*piover180) * 0.05f; // Move On The Z-Plane Based On Player Direction
In your code, your player is going to move a distance of .05 along a line 30 degrees above the XZ plane, which means his distance along the XZ plane will be .05 * cos(30 degrees) (because if a triangle's hypotenuse is d, its leg adjacent to that angle is d*cos(angle). So all you have to do is add * cos (tiltangle * piover180) to the end of the above two lines.
His change in Y coordinate will be .05 * sin(30 degrees), in other words, the leg of the triangle *opposite* the angle, so you just add a line like this:
ypos = ypos + .05f * sin (tiltangle).
Hope this makes sense, it's just a simple application of the principle that if a triangle's hypotenuse is d, and one of the angles is a, then the leg adjacent to that angle is d cos a and the opposite it is d sin a.
Good luck!
Love means nothing to a tennis player
[edited by - DalTXColtsFan on October 3, 2003 12:21:23 PM]

To accomplish what you're looking for, you need two angles - one angle representing his rotation counterclockwise from the Z axis, and one representing his rotation "tilted up" from the XZ plane. For example, suppose he's facing exactly between the X and Z axes, and say his tilt is 30 degrees above it.
In the lesson 10 code, the player always moves a distance of .05 along the XZ plane:
xpos -= (float)sin(heading*piover180) * 0.05f; // Move On The X-Plane Based On Player Direction
zpos -= (float)cos(heading*piover180) * 0.05f; // Move On The Z-Plane Based On Player Direction
In your code, your player is going to move a distance of .05 along a line 30 degrees above the XZ plane, which means his distance along the XZ plane will be .05 * cos(30 degrees) (because if a triangle's hypotenuse is d, its leg adjacent to that angle is d*cos(angle). So all you have to do is add * cos (tiltangle * piover180) to the end of the above two lines.
His change in Y coordinate will be .05 * sin(30 degrees), in other words, the leg of the triangle *opposite* the angle, so you just add a line like this:
ypos = ypos + .05f * sin (tiltangle).
Hope this makes sense, it's just a simple application of the principle that if a triangle's hypotenuse is d, and one of the angles is a, then the leg adjacent to that angle is d cos a and the opposite it is d sin a.
Good luck!
Love means nothing to a tennis player
My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)
[edited by - DalTXColtsFan on October 3, 2003 12:21:23 PM]
Love means nothing to a tennis player
My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement