Other ways to establish the point of view
In Chapter 1, we talked about establishing the point of view by calling a single function, fg_3Dpov(). The problem with this function is it uses a concept called "Euler angles". That is, it processes 3 angles at the same time. It works, but it does not give you very much in the way of flexibility. There are better, more precise ways to establish a point of view.
The fg_3Dlookat() function accepts 6 parameters. The first 3 are the x,y,z coordinates of the absolute position of the viewpoint. The next 3 are the x,y,z coordinates of a point you want to look at. This is an excellent way to establish a position and rotation in 3D space.
If you have moved around in 3D space, and you want to know your current position and direction of view, you can call fg_3Dgetpov(). This function returns 6 values. The first 3 values are the x,y,z position of the viewpoint. The next 3 values are the x,y,z coordinates of a unit vector in the direction of the rotation. To get a position and rotation, and then later set the same position and rotation, you can do this:
You can change the position of your point of view without changing the rotation by calling fg_3Dmove(). Similarly, you can change the position of an object by calling fg_3Dmoveobject(). These are both absolute moves. That is, you need to know the exact x,y,z position you want to move to.
What if you just want to move forward a bit, without knowing exactly where you want to move to? Is there an easier way to do it? Yes, there is. You can try these functions for relative viewpoint moves:
fg_3Dmoveforward()There are similar functions for moving objects:
fg_3Dmoveforwardobject()Each of these functions expects you to pass a single value, which is the amount of the move. The units of this value will depend on how you have designed your 3D space, as described in Chapter 1. Note that you can move in other directions too. You can move backwards by calling fg_3Dmoveforward() and passing a negative value too it. Similarly, passing a negative value to fg_3Dmoveright() or fg_3Dmoveup will cause you to move left or down.
Rotation is perhaps one of the hardest concepts for 3D programmers to understand. The mathematics of the 3D rotation matrix are explained here. Fortunately, you don't really need to know this stuff. We have taken care of the details of rotation for you in Fastgraph. To rotate your view or an object, all you need to do is call a few simple functions.
Here are some suggestions.
For an absolute rotations without moving the viewpoint or the object, call fg_3Daxisangle() or fg_3Daxisangleobject(). These functions allow you to specify an axis in terms of x, y and z, (a vector passing through the origin), and an angle by which to rotate. This representation will give you any arbitrary rotation without changing the position of the camera or the object.
For relative rotations, try these for the viewpoint:
fg_3Droll()and try these similar functions for objects:
fg_3Drollobject()Note that fg_3Drotateright() will rotate either to the right or the left. Just pass a negative value if you want to rotate to the left. Similarly, fg_3Drotateup() will rotate down if you pass a negative value. The fg_3Droll() function rolls around the current z axis, or "Out" vector, which faces directly out from the screen. Calling this function will cause the screen to rotate about a point in its exact center.
Using absolute and relative functions for moving and rotating your viewpoint and your objects gives you powerful capabilities. A complete set of these functions will allow you to write your own great 3D games.
Chapter 1 | Chapter 2 | Chapter 3
Chapter 4 | Chapter 5 | Chapter 6 | Chapter 7
Appendix 1 | Appendix 2 | Appendix 3
Fastgraph Home Page