Atomic Electronic Operation model
The model transformation and stack knowledge are used in the atomic electronic operation model, the code is as follows:
//MyOpengl.cpp:Defines the entry point for the console application.//#include"stdafx.h"//SimpleGL.cpp:Defines the entry point for the console application.//#include <stdlib.h>#include<GL\glut.h>#include<iostream>using namespacestd;voidRenderscene () {StaticGlfloat Felect =0.0f; Glclear (Gl_color_buffer_bit|gl_depth_buffer_bit); Glmatrixmode (Gl_modelview); Glloadidentity (); Gltranslatef (0.0f,0.0f,-100.0f); glcolor3f (1.0f,0.0f,0.0f); Glutsolidsphere (10.0f, -, -); Glpushmatrix (); glcolor3f (1.0f,1.0f,0.0f); Glrotatef (Felect,0.0f,1.0f,0.0f); Gltranslatef (90.0f,0.0f,0.0f); Glutsolidsphere (6.0f, -, -); Glpopmatrix (); Glpushmatrix (); Glrotatef (45.0f,0.0f,0.0f,1.0f); Glrotatef (Felect,0.0f,1.0f,0.0f); Gltranslatef (-70.0f,0.0f,0.0f); Glutsolidsphere (6.0f, -, -); Glpopmatrix (); Glpushmatrix (); Glrotatef (-45.0f,0.0f,0.0f,1.0f); Glrotatef (Felect,0.0f,1.0f,0.0f); Gltranslatef (0.0f,0.0f,60.0f); Glutsolidsphere (6.0f, the, the); Glpopmatrix (); Felect+=10.0f; if(felect>360.0) Felect=0.0f; Glutswapbuffers ();}voidchangesize (Glsizei w,glsizei h) {if(h==0) H=1; Glfloat Aspectratio= (glfloat) w/(glfloat) H; Glviewport (0,0, w,h); Glmatrixmode (gl_projection); Glloadidentity (); if(w<h) Glortho (-100.0,100.0,-100.0/aspectratio,100.0/aspectratio,200.0,-200.0); ElseGlortho (-100.0*aspectratio,100.0*aspectratio,-100.0,100.0,200.0,-200.0); Glmatrixmode (Gl_modelview); Glloadidentity ();}voidSETUPRC () {Glclearcolor (0.0f,0.0f,0.0f,1.0f); glcolor3f (1.0f,0.0f,0.0f);}voidTimerfunction (intvalue) {Glutpostredisplay (); Gluttimerfunc ( -, Timerfunction,1);}intMainintargcChar*argv[]) {Glutinit (&argc,argv); Glutinitdisplaymode (glut_double|Glut_rgb); Glutinitwindowsize ( -, -); Glutcreatewindow (" Simple"); Glutdisplayfunc (Renderscene); Glutreshapefunc (changesize); Gluttimerfunc ( -, Timerfunction,1); //Glutspecialfunc (Specialkeys);SETUPRC (); Glutmainloop (); return 0;}
First, by running this program, we find that the GLROTATEF (angle,0,0,1) function always uses the current Xoy plane as the rotating plane, see code:
Glrotatef (45.0f,0.0f,0.0f,1.0f);
Glrotatef (felect,0.0f,1.0f,0.0f);
Gltranslatef ( -70.0f,0.0f,0.0f);
Glutsolidsphere (6.0f,25,25);
The first line determines that the rotated plane is a xoz plane after 45 rotations, similar to the second row. It is important to note that in order for electrons to move around atoms from the nucleus, you must first use the GLROTATEF () function and then use the Gltranslatef () function.
Second, using the Glpushmatrix () function causes the matrix x in the current buffer to be saved to the stack, and the matrix in the current buffer is still x. When using the Glpopmatrix () function, the top of the stack can be restored to the buffer while the top of the stack pops up.
Notice that the pairs appear in the code.
Glpopmatrix (); Glpushmatrix ();
This is also a usage, usually the newly-popped matrix is saved into the stack, mainly for the purpose of repeated use in the buffer.
Atomic Electronic Operation model