For reasons that I don't know about myself, I have a sense of familiarity with C + +, there is always want to use C + + to complete programming tasks of the impulse, but I really do not like always in the black box in the console input output, and MFC I temporarily do not know how to operate the mechanism, a large string of already completed documents, Looking dizzy, OpenGL is more suitable for the need, and there is a glut can help in the console to implement a simple form, as a simple use of the full enough, complex use will later say.
I am completely beginner, referring to the "OpenGL tutorial" This document and some references on the network to complete this simple solar system model. (here to thank the creator of this tutorial as well as the share, I feel very good writing, online download, I was from Baidu Library, I also sent a copy to the resources) why is the solar system model? Because I like this, and a lot of people have done this, really do not understand, or there is a code can learn. Gossip is not much to say, first on the effect of a picture:
And then go straight to the start of any project that should be a requirement analysis, the simple requirement is to display a model that looks like the solar system on the screen and looks like it, and it's really going to take a precise solar system model that is time-consuming and laborious and no one is paying for it. Then the design phase, as object-oriented programming, first look for objects, the solar system of the eight planets and the sun itself, in order to look more beautiful point, the orbit will be drawn out, so there are two objects, all objects have to implement a draw method, to draw itself, Design a myobj parent class can facilitate the completion of the drawing work, I think since each track is attributed to a certain star, then the orbit can be used as the private property of the star, this should be a dependency. The class diagram is as follows:
The basic information of astral Aster includes radius radius, Revolution period revolution_solar, rotation period revolution_self, Orbital orbit, and revolution radius distance. The orbital orbit has only one RADIUS attribute. Some of the secondary attributes that are defined in the implementation are not listed in the class diagram.
Have a class diagram, you can enter the coding phase, the first need to configure the development environment, I was using the vs2010, the development of the use of OpenGL, download the address Baidu Google all line, I do not remember the original download address, passed a to the resources. The tutorial says to integrate the development library into VS, but I don't like it so much, it's not necessary to change the entire development environment, as long as you set up a single project, the. dll file is saved to the generated run file, and the. h file is saved to the project folder. Lib files should be able to use relative paths when loading in code, but I'm not sure where the base path is, so I've chosen to set the properties of the project:
Right-click the project name in Solution Explorer, select Properties->linker->general, in additional Librarydirectories inside the Lib file to save the absolute path on it. The load Lib file uses the #pragma comment (lib, file name).
There are many examples in the tutorial, and the knowledge points are very clear, do not repeat. One of the problems I encountered was that in the fifth lesson, when the day-month system was implemented, if you use the parameters in the tutorial, you can not see anything in the window, but if I reduced the parameters to 10 times times, it is normal to display, although I searched some of the coordinates of the transformation of the article, but still do not know why this problem, If the proportional scaling should not have different results. Does OpenGL not accept too large a parameter?
To say a little bit about the Glulookat function, it may be my personal problem, in understanding the function of a little bit of effort, the function has nine parameters, divided into three groups, the first group is about the movement of viewpoints, the point of view is initially in (0,0,0) points, If you do not move the coordinates after the perspective projection transformation, then the drawing of the image will appear in the location of the point of view, similar to someone put things in their eyes, behind the things will not see, of course, you can move the coordinates first, and then draw the object of the solution, But the advantage of Glulookat is that developers do not have to calculate the position of each object, simply through this function can achieve arbitrary angle of observation. It certainly doesn't matter if you only draw on a plane made up of the XYZ axis, but you want to look at the entire system at 45 or 75 degree angles. The position of each object is not a good calculation. The way I understand this function is that the developer first draws the entire system into the coordinate systems and then realizes the change of observation angle through the function, and automatically calculates the relative position of each object by OpenGL. This function must be placed before other coordinates change, and I feel that the order in which it is executed is at the end of the entire system. The above is irresponsible conjecture, without any theoretical support, hereby declare .....
Well, that's a little far. The second group of parameters is the coordinate of the center point of the viewpoint observation, the visual range of the perspective projection itself is a pyramid, and the line of view and center point is the vertical line from the vertex to the bottom.
The third set of parameters represents the positive direction, that is, what the observer is looking at, the tutorial says that the line from the (0,0,0) point to this point determines the positive direction, for example, if set to (0,1,0), similar to the normal viewing screen, (0,-1,0) means that the person is looking at the screen upside down (0,0,- 1) indicates looking down at the keyboard, (0,0,1) to look down from behind the monitor to see the keyboard ...
There are some problems with the lighting and material settings, later on, the whole project has been uploaded to the resources, if necessary, please download.
To say a little bit of things, the first time you set up a project mistakenly selected Windows application, you can change into a console in the Properties->linker->system->subsystem.
Modify the console program's icon to select Add Resource->icon, You can only use the. ico file, if the previous icon, the system will use the small ID value as an icon, you can open resource.h, and then set their own icon ID value to the smallest, open the Resource.h method is: first open the. rc file (select View Code) , and then select Open Document at Include<resource.h>.