Can you use your computer to entertain yourself, especially with one or another video game. Do you want to know the "magic" that is behind a simple Bowling game?, probably think in reformulating your reviews about small details that you see in commercial games, especially when you see work that may exist after details as small as a simple pine of Bowling
The first thing is to know our work environment. In this case I'll use C , but the version of Borland (with their C Builder 6.0) in conjunction with OpenGL.
To not bore you with configurations, what they need for the project is the environment of Borland and the next component of OpenGL:
To install the component, you must copy to the Borland folder and set the correct path to the folder "OpenGLAPPanel" where it was decompressed "directories" of the project.
Something interesting that I will try to keep in the course of this small project, will be to keep actual measurements (if possible). A unit in OpenGL then will be an inch of real life, and so the whole scene and its components will be designed to real scale. Following this essence of reality, will attempt to do everything through accurate equations of descriptions absolute and ideal, as for example outline curves to the pines and the channel of the track, equation of the launch applying effects (spin), pulling force and other features.
A noteworthy point is that in the code and the game interface will try to use English as a language base, so objects retain names such as Bowling, Bowling Pin and other similar in order to avoid mistakes in the names not Anglo-Saxon.
Design and classes
It is necessary to organize our work and better, doing a class diagram. In particular, my idea is that there is a generic class for all figures and each particular implementation of each inherit it.
In a nutshell, a pine tree, ball, game track and full salon will be simply figures and when I tell you an action (move, rotate, draw, among other actions) does not interest me actually to figure I'm referring:
At base, the figures will be made through equations in order to maintain a visual integrity in different situations. It has the ability to be able to generate high definition or low definition to speed up the display objects when there is an approach (e.g. to the user track pines). Through a parameter we could generate a low-resolution pine easily:
One of the most interesting parts is the work that I applied to the pine. You must first consider the standard measures of a pine tree:
Then drawing the outline of the image, tweaking the potential failures added in the perspective of photography pine:
Using the silhouette and a properly configured screen capture program to recognize the characters of the graphic editing program interface, captured the coordinates of all around at regular intervals, trying to obviate catch in the flat spots:
So, I get a text file with all the coordinates of the outline of the silhouette. Anyway, it is still necessary to adjust the data what is relatively simple in a form of either calculation.
To simplify the task of finding the outline, I will make a sort of combination of bezier curves by means of two end points, where modifying nodes of each end curve shall be defined by a point in common, that is of a traditional bezier curve, I will join points that modify each edge, calculating by Lagrange interpolation polynomial.
Thus our initial contour disintegrates into a set of simple and bounded curves, in fact the three together can see something of the outline to the graficarlas (which chart easily in) Scilab):
Points of the curves shown in the images we directly serve to calculate the equations that are as follows (in order from left to right, in the outline):
Clearly in the program, the contour is defined by a function that executed the three previous equations by means of conditions (where the unknown solution is the same) and returning zero for values outside the scope of the real pine.
Now just use this outline and make a solid of revolution. The secret now is to rotate the points and as if it were a Riemann sum, use only pieces of the outline. Rotation must be done manually, using the methods of the Point3d structure rotate a point (a texture using the rotation of OpenGL directly, not is can create because you cannot modify the transformation matrix for OpenGL with glRotated between glBegin and glEnd instructions). In this way the only way was adding t:System.Windows.media.Media3D.Point3D rotation as you can see in the above class diagram.
Ball and track
The ball was created simply with glutSolidSphere of the GLUT library. It has much more science.
Now, in a way similar to pine, the basis for creating the game track is a special contour, this time of extrusion form and not as solid of revolution. According to some measures we have that the Board is thus:
The sides measure some centimeters more than the ball. In this situation the contour, before interpolation parabolas that will generate the same, thus arises:
With these data it is easy to find the two formulas that they will generate the lateral contours for the track:
The release of the ball
In bowling, archery has a peculiarity. Since the friction of the ball is relatively negligible at the beginning of the track (mainly by the force that leads and track oil) produces an effect almost always in the final stretch of the route.
So then we have a shot as the effect applied to the ball, from a top view, with the end of the track in the area of point one:
Thus, we can break features shot in a series of parameters that alter these trajectories. Valid intervals of variables will be defined to clarify things:
The pulling force: Modify the initial speed shall be implemented that a constant friction. Modifies the height of point two of the trajectory.
Effect of shot: Modify the horizontal position of the point in the curve of the path one.
The initial position: Modifies the position of the three nodes in the path. Consider that the track has 106 cm width, in this case the variable represents the position from the Center.
Start address of the shot: Modifies the position of the node one and two of the career, also, there is a directly proportional relationship between the two new positions of the nodes.
After all these settings you can create an equation of the trajectory.
Since it is almost impossible to simulate a phenomenon to perfection in nature, the solution in this instance is to implement a simplified algorithm for the shot:
First of all, the initial velocity of the shot is defined by a constant, which is slightly reduced in each iteration of the game (60 frames per second) update cycle:
This simulated kinetic friction is mitigated by the strength of shot, which modifies the speed of the ball in an extremely intuitive way, by attaching itself to the above expression:
Now, the effect of the shot (spin) only affects the final path of the ball. The impact produced on the trajectory is a modification of its position in the horizontal plane that conforms to:
Thus, while closer to the pines is the ball in his career, more effect will have, as you can see in real shots of the game.
The initial position of the shot is clear, modifies only the horizontal position in an initial instance and does not apply.
The initial direction of the pull modifies the angle of shot in a way that is also unquestionable output:
Collision of the ball with the pines
For collisions, used another strand of process, represented by another "timer" that is usually dormant. At the time that a collision with a pine of Bowling is detected, the initial angle of collision is recorded and the program continues to work normally:
The initial collision verification is simple. Set Euclidean space, checking only is based on the distance between points centers the ball with each of the pines (Euclidean distance), such as recall of basic calculus courses is not more than:
Now, we have clear when he played the ball to a pine tree, however: where what I play?
This calculation is also quite simple:
Now, How would they collide among them?
Collisions have always been an important topic in computer graphics and physical simulations. In fact to simulate a completely real shock would be practically impossible. From an English point of view, we have the positions of the pines. Numbered as they are positioned by my algorithm:
Thus, it is curious that we can reduce the problem to a much more manageable scope:
Then, we will only handle a multiple and possibly chained collision when the angle that the ball hit the green pine generates an angle that produces one of red pines falling (which in turn could generate the same effect later).
Clearly this model of collisions is vague and it was only implemented as well for a time issue. The idea is to offer readers an overall idea about the idea after a collision and not exactly a solution.
With basic forms an idea of the atmosphere, can be however if you want to provide an experience surround it is necessary to Polish the details and the best way of doing this is through the incorporation of textures.
First is required to extract textures and better than from a real place of games such as Bowling of the Mall Curicó Center:
Then, and by way of documentation I ejemplificaré the way in which you were getting textures of high quality without misaligned edges or problems to repeat them:
1) In this case we will create the texture for the track. We start with the original picture captured from a top view of the track:
2) To create a light texture, we will choose a segment with fewer details and imperfections:
3) We prepare the image for the final part, the same must be adjusted with a width and height identical (in this case 128 pixels) and their characteristics as symmetrical as possible:
4) With an "Offset" filter we can enhance our segment:
The idea is to imitate the function of repetition in mosaic that will make OpenGL, to soften the edges of the texture before applying it to the game. The result is always an excellent texture, with which even painting Freehand will get a good result:
Code and executable
There is a problem with the normal of the figures by which the game may be incorrectly on your computer, depending on your graphics accelerator.
Fix it at this point is long and tedious, and considering that my teams do not appear the problem not I plan to correct it.
Source (Borland C Builder 6.0)
Resources (images, spreadsheets, diagrams used):
The Simulator screenshots:
Binary (executable and required libraries):
The program performs correctly, although it missed some functionality to achieve a playable product, in general is, in my opinion fairly complete and I hope to be useful for anyone who tries to create your project related to computer graphics.
One interesting thing is the Bowling in action:
By not basing my non-working code, nor my duties in canned and copied formulas, it is easily understandable as it is exclusive for this Simulator.