<< Chapter < Page | Chapter >> Page > |
At this point, you should not find any code in Listing 12 that you don't understand. I have explained the code in Listing 12 earlier in this module or in an earlier module, so I won't repeat that explanation here.
End of discussion .
That concludes the discussion of the program named GM01test05 . You will find a complete listing of this program in Listing 29 .
Scaling, translation, and rotation of a point
Three of the most common and important operations that you will encounter in game programming will be to scale, translate, and/or rotate a geometric object.
Since all geometric objects are composed of points that define the vertices, possibly embellished with lines, shading, lighting, etc., if you know how toscale, translate, and/or rotate a point, you also know how to scale, translate, and/or rotate the entire geometric object. You simply apply the requiredoperation to all of the points that comprise the object and you will have applied the operation to the object as a whole.
However, there are some complex issues associated with hiding the back faces of a rotated object, which will be addressed in a future module under thegeneral topic of backface culling . Backface culling is a process by which you prevent 3D objects from appearing to be transparent.
In a future module, we will learn about a mathematical trick commonly known as homogeneous coordinates that can simplify the scaling, translation, and rotation of a point. However, that will have to wait until we have a better grasp of matrix arithmetic.
In a previous module, you learned how to translate a geometric object. In this program, you willlearn how to scale a geometric object. In the next two programs, you will learn how to rotate geometric objects.
The new scaling methods
The additions to the game-math library included the following two methods:
As the names imply, these two methods can be used to scale a point in either 2D or 3D.
The game-math library method named GM01.Point3D.scale
This method is shown in Listing 13 .
Listing 13 . The game-math library method named GM01.Point3D.scale. |
---|
public GM01.Point3D scale(GM01.ColMatrix3D scale){
return new GM01.Point3D(new ColMatrix3D(getData(0) * scale.getData(0),
getData(1) * scale.getData(1),getData(2) * scale.getData(2)));
}//end scale |
This method multiplies each coordinate value of the Point3D object on which the method is called by the corresponding values in an incoming ColMatrix3D object to produce and return a new Point3D object. This makes it possible to scale each coordinate value that defines thelocation in space by a different scale factor.
If a scale factor for a particular coordinate is less than 1.0 but greater than 0.0, the location of the new point will be closer to the origin along thataxis than was the location of the original point. If a scale factor is greater than 1.0, the new point will be further from the origin along that axis.If the scale factor is negative, the location of the new point will be on the other side of the origin along the same axis.
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?