|
尊敬的您,如果通过搜索引擎来到本站,可能你所要找的资讯已不在首页显示,请点击页面上方对应的分类导航按钮以找到您所搜索的资讯,或者您也可以点击搜索引擎提供的快照功能,以方便您对资讯的获取。
Contacts:
. Google doneykoo # gmail # com . MSN doneykoo # hotmail # com
. Tecent QQ 1245 98760 . Twitter doneykoo |
Shares:
. http://doneykoo.ycool.com/ . http://www.google.com/reader/shared/doneykoo/
. http://renren.com/profile.do?id=54944 . http://www.blogjava.net/doneykoo/
. http://www.douban.com/people/33802118/ . http://ouditian.com/index_old.htm
|

|
How to: Convert Between Various String Types Basically: http://msdn.microsoft.com/en-us/library/ms235631%28VS.80%29.aspx However, if you are working under Unicode charsets, note this: CStringA is the ANSI form of CString, and CStringW is the UNICODE form. So long as UNICODE is defined, CString is typedefined as CStringW. Else, CString is CStringA. so try this example to convert // given variables
CString wszStr;
char szStr[250];
// char array to CString
wszStr = CString(szStr);
// CString to char array
strcpy( szStr, CStringA(wszStr) );
|
常用喷技术范例。五毛必备。
A:这鸡蛋真难吃。
B:隔壁家那鸭蛋更难吃,你咋不说呢?
A:这鸡蛋真难吃。
B:有本事你下个好吃的蛋来。
A:这鸡蛋真难吃。
B:下蛋的是一只勤劳勇敢善良正直的鸡。
A:这鸡蛋真难吃。
B:比前年的蛋已经进步很多了。
A:这鸡蛋真难吃。
B:你就是吃这鸡蛋长大的,你有什么权力说这蛋不好吃?
A:这鸡蛋真难吃。
B:你这么说是什么居心什么目的?
A:这鸡蛋真难吃。
B:嫌难吃就别吃,滚去吃隔壁的鸭蛋吧。
A:这鸡蛋真难吃。
B:隔壁的鸡给了你多少钱?
A:这鸡蛋真难吃。
B:再难吃也是自己家的鸡下的蛋,凭这个就不能说难吃。
A:这鸡蛋真难吃。
B:隔壁家的鸡蛋是伪鸡蛋。
A:这鸡蛋真难吃。
B:没有XXX,你连这鸡蛋都吃不上。
A:这鸡蛋真难吃。
B:你这样说不利于稳定,不和谐。
A:这鸡蛋真难吃。
B:要对咱们家的鸡有耐心,它一定会下出更好吃的蛋。
A:这鸡蛋真难吃。
B:隔壁家也吃过这样的鸡蛋,这是初级阶段。
A:这鸡蛋真难吃。
B:很多家都是因为吃隔壁的鸭蛋而导致家庭成员冲突,生活水平下降最终解体。
A:这鸡蛋真难吃。
B:你太偏激了
A:这鸡蛋真难吃。
B:你怎么能这样说呢,你看把鸡窝整理得这么干净,鸡蛋才会好吃啦。
A:这鸡蛋真难吃。
B:你不要乱看一些东西,要看一些正面的,人家说鸡蛋难吃都是假的,都是谣言,你看CCAV就知道鸡蛋其实还是好吃的。
A:这鸡蛋真难吃
B:慢慢的就会变得好吃了,想想以前都没有鸡蛋吃呢,要么就是小鸡蛋,这已经很不错了,你知足吧。
|
========DoNeY's Notes of <Addison Wesley - OpenGL Programming Guide 2nd Edition> doneykoo.ycool.com========
Viewing Transformations
A viewing transformation changes the position and orientation of the viewpoint.
Use one or more modeling transformation commands (that is, glTranslate*() and glRotate*() ). You can think of the effect of these transformations as moving the camera position or as moving all the objects in the world, relative to a stationary camera.
Use the Utility Library routine gluLookAt() to define a line of sight.
This routine encapsulates a series of rotation and translation commands.
Create your own utility routine that encapsulates rotations and translations. Some applications, for example, you may want to specify the roll, pitch, and heading rotation angles of a plane in flight.
Using glTranslate*() and glRotate*()
Since the viewpoint is initially located at the origin and since objects are often easily constructed there as well, in general you have some transformation so that the object can be viewed.
Note that, as shown in the figure, the camera initially points down the negative z-axis.

Figure 3-9 : Object and Viewpoint at the Origin
In the simplest case, you can move the viewpoint backward, away from the objects.
This has the same effect as moving the object forward, or away from the viewpoint.
Remember that by default forward is down the negative z-axis.
glTranslatef( 0.0, 0.0, -5.0 );
This routine moves the objects in the scene -5 units along the z-axis. It is equivalent to moving the camera +5 units along the z-axis.

Figure 3-10: Separating the Viewpoint and the Object
Now suppose you want to view the objects from the side. Should you issue a rotate command before or after the translate command?
glTranslatef( 0.0, 0.0, -5.0 );
glRotatef( 90.0, 0.0, 1.0, 0.0 );
If you're having trouble keeping track of the effect of successive matrix multiplications, try using both the fixed and local coordinate system approaches and see whether one makes more sense to you. Note that with the fixed coordinate system, rotations always occur about the grand origin, whereas with the local coordinate system, rotations occur about the origin of the local system. You might also try using the gluLookAt() utility routine described in the next section.
Using the gluLookAt() Utility Routine
Often, programmers construct a scene at the origin or some other convenient location, then they want to look at it from an arbitrary point to get a good view of it.
void gluLookAt( GLdouble eyx, GLdouble eyey, GLdouble eyez,
GLdouble centerx, GLdouble centery, GLdouble centerz,
GLdouble upx, GLdouble upy, GLdouble upz );
Defines a viewing matrix and multiplies it to the right of the current matrix. The desired viewpoint is specified by eyex, eyey, and eyez. The centerx, centery, and centerz arguments specify any point along the desired line of sight, but typically they're some point in the center of the scene being looked at. The upx, upy, and upz arguments indicate which direction is up (that is, the direction from the bottom to the top of the viewing volume).
In the default position, the camera is at the origin, looking down the negative z-axis, and has the positive y-axis as straight up. This is the same as calling
gluLookAt( 0.0, 0.0, 0.0, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0);
The z value of the reference is -100.0, but could be any negative z.
Note that gluLookAt() is part of the Utility Library rather than the basic OpenGL library.
This isn't because it's not useful, but because it encapsulates several basic OpenGL commands - specifically, glTranslate*() and glRotate*().
Note: You can have only one active viewing transformation. You cannot try to combine the effects of two viewing transformations. If you want to change the position of the camera, make sure you call glLoadIdentity() to wipe away the effects of any current viewing transformation.
Advanced
To transform any arbitrary vector so that it's coincident with another arbitrary vector ( for instance, the negative z-axis), you need to do a little mathematics. The axis about which you want to rotate is given by the cross product of the two normalized vectors. The angle of rotation can be calculated from the dot product of the normalized vectors. ( See Appendix E for details)
Creating a Custom Utility Routine
Advanced
For some specialized applications, you might want to define your own transformation routine.
Try this
Suppose you are writing a flight simulator and you'd like to display the world from the point of view of the pilot of a plane.
void pilotView{GLdouble planex, GLdouble planey,
GLdouble planez, GLdouble roll,
GLdouble pitch, GLdouble heading)
{
glRotated(roll, 0.0, 0.0, 1.0);
glRotated(pitch, 0.0, 1.0, 0.0);
glRotated(heading, 1.0, 0.0, 0.0);
glTranslated(-planex, -planey, -planez);
}
Suppose your application involves orbiting the camera around an object that's centered at the origin. In this case, you'd like to specify the viewing transformation by using polar coordinates.
void polarView{GLdouble distance, GLdouble twist,
GLdouble elevation, GLdouble azimuth)
{
glTranslated(0.0, 0.0, -distance);
glRotated(-twist, 0.0, 0.0, 1.0);
glRotated(-elevation, 1.0, 0.0, 0.0);
glRotated(azimuth, 0.0, 0.0, 1.0);
}
|
在人民网看到一句“一语惊坛”,说“掺了三聚氰胺的GDP盛行,谁能保证中国经济不得肾结石?”网友跟帖都说这句话说得好,说得形象生动,也说出了中国经济面临的窘境和悲哀。
关于中国式GDP的计算方法,有位学者曾给我们打过一个比喻:在公路上相向而行的两辆车,如果各行其道,那么他们在此地创造的中国式GDP为零,但如果其 中一辆车突然反道行驶,并与另一辆车发生相撞,按中国式GDP计算方法,生意就来了,首先,两辆车的损坏拉动了汽车修理GDP,又拉动了事故处理GDP, 如果有人受伤或死亡就更好了,因为这又可以直接拉动医院的GDP和火葬场的GDP。
最近江西一栋四星级宾馆刚造了13年就被炸了,有评论 说这一拆一建的过程实际就是打造GDP数字的过程:拆也GDP,建也GDP。我们不难发现,一个地方,引进污染企业,公开排污,盲目生产,他们的产值直接 进了当地的GDP,过后水不能吃了,人不能住了,要铺设管道,引进自来水,这又是GDP,要整体搬迁,躲避污染了,又是GDP,要搞环境治理了,为污染埋 单了,还是拉动GDP,这GDP数字就像是海大的一个筐,不论你怎么瞎折腾,他每年都能增长个八九不离十!
一户人家,先是把自家人身上的血卖了,实现了家庭GDP增长;后来把自己家里的地卖了,又实现了家庭GDP的增长,再后来,再将家里的房子卖了,还是实现了GDP的增长,请问,这样的增长意味着什么?这样的增长又如何面对未来?
许多人都把官员热衷GDP归结于所谓的政绩观念,这实在是滑天下之大稽。难道卖血是政绩?卖地卖家产也是政绩?官员热衷的所谓GDP,说穿了不过是管理无 能的一块遮羞布,是掩盖某些集团进行利益掠夺的一个愰子,一个借口。这样的不分正负,不分黑白,不分得失的GDP,已经为越来越多的百姓所不耻。
我曾在一篇文章中写道:你GDP就是增长百分之一万,好处被少数人少数行业掠夺走了,老百姓只有当房奴孩奴的结果,这样的GDP增长要它何用?反过来,如果人民生活稳定了,生活负担变轻了,社会风气好转了,那GDP就是负值又有什么关系呢?
政府全面退出炒地谋利,严厉打击炒房犯罪
中国房地产市场的严重泡沫,主要是由于政府参予炒买炒卖土地造成的!政府的职能,本应是社会经济运行这个竞赛场上的裁判员;政府的天职,就是为社会经济运 行公平、公正执法。可现在中国的地方政府却无一不在大肆炒买卖炒土地,参预市场利益角逐!一些地方的政府财政高度依赖卖地派生的土地经济,而且买卖土地所 得根本就没有或未能纳入财政预算监管的范畴!这就如同足球场上的裁判同时下场踢球,并同时参预赌球活动欺骗观众博利一样!各级地方政府手里都握有大把的不 受财政预算监管的买卖土地所得的孔方兄,小金库能够取缔得了吗?!腐败能够扼制住吗?!
我国实行的是土地国有的政策。但土地国有并不是地 方政府所有!现在许多地方的政府热衷于卖地搞开发的做法,其法律依据值得商榷!而这种高度依赖炒买炒卖土地的财政,虽然能逞一时之快,却是在毁祖宗基业, 断子孙万代的生路!并且正是政府炒买炒卖土地的做法,导致了中国房地产市场严重的泡沫!政府炒买炒卖土地,以房地产为支柱产业,财政严重依赖卖地,实无异 于饮鸩止渴!
住房是人要生存的必须品之一,是老百姓生存的必须条件!但自房改以来,就不容许企业自建住房了;居民个人合伙集资修建住房, 也是不容许的!政府又很少提供廉租住房,自古华山一条路,可中国的城镇居民要想住房子,就只剩下购买商品房这一条路了!老百姓购买商品房的需求,是逼出来 的!是政府为了土地财政利益,放任甚至纵容奸商炒房,使得绝大多数中国的城镇居民将一生全部押在了一套住房上的!如此做法,迟早是要出问题的,是要出大问 题的!
当官不代表,代表不当官
立法、行政、监督三位一体,如此绝对的权力怎能不产生三公消费九千亿这样的绝对腐败!
减少人大代表职数,实行代表专职化,当官不代表,代表不当官,是落实中华人民共和国宪法“第二条 中华人民共和国的一切权力属于人民。”、第三条第二款“国家行政机关、审判机关、检察机关都由人民代表大会产生,对它负责,受它监督”的根本保证。
中国拥有全世界最为庞大的公务员群体,还有许多不在编制之类的终公务员和事业编制群体,但中国政府的行政效率却低下!
中 国目前还并不富裕,教育、医疗......中国不论办什么事情都差钱,唯独三公消费不差钱!中国的各级地方政府及其职能部门,基本上全都拥有当地最为豪华 的办公设施,还建有大量的以“培训中心”命名的豪华楼堂馆所!尽管各级地方政府都建有大量的豪华办公场所和楼堂馆所,但很多官员还长期在四星级、五星级的 宾馆长期包房消费!很多会议也都要在四考级、五星级的宾馆召开!每年公款吃喝逾3000亿元人民币,国家怎能承受得起!老百姓又怎能承受得起!
中 国拥有世界上最为庞大的公务用车,且相互攀比,你买了奥迪,我就买尼桑!他就会弄来一台陆虎!公务用车配备已经完全失控!其庞大、豪华程度堪为世界之最! 如此庞大、豪华的公务用车,外加还要养上一支十分庞大的专职驾驶员队伍!这些人在私自用车,车辆保养、维修等等方面偷支冒领,外带还要关说人情,干挠政 务!每年超过3000亿元人民币的老百姓血汗就这样被浪费了!
黄山云海,阳朔漓江,避暑胜地,天涯海角,官员们就象候鸟一样,在天上飞来 飞去!但现在,他们已经不满足于在中华大地上飞来飞去的了,就连港澳、新、马、泰都已经无法满足他们的胃口了!于是,什么伦敦、巴黎、悉尼、纽约,全世界 都是他们旅游的目的地!还要去拉斯维加斯寻求一下刺激!公款旅游年逾3000亿元人民币,还使他们得到了将家属移民国外,成则继续为非作歹,败则出逃去当寓公,裸身做官的启示!
PS.
裸体官员(Naked official ;Naked Officials)。
裸体官员,简称裸官,是指配偶和子女非因工作需要均在国(境)外定居或加入外国国籍或取得国(境)外永久居留权的公职人员。
裸体官员是深圳市委市政府2009年11月25日颁布实施的《关于加强党政正职监督的暂行规定》中提出的新概念,目的是加强官员的有效管理和廉政监督,成功阻止国内或某些外派机构的官员腐败犯罪后携巨款潜逃海外、逃避打击。
裸体官员和裸体做官都简称为“裸官”,是词义接近或类似的名词。如原陕西省政协副主席庞家钰,其妻儿早在他大权独揽的时候,于2002年移民加拿大。庞家钰自己在国内当官腐败、将家属移居海外,直至2008年6月被判刑,这种现象被网友称为“裸体做官”,“裸官”迅速成为网络热词。
如何培养孩子良好的行为方式和习惯
孩子们每天的活动都是由无数的彼此关联的行为组成,而个体的行为是在生理心理和社会因素的共同影响下发生的,这些因素包括:孩子的个性与一贯行为方式,行为发生的情境,孩子当时的身心状况,行为、情境与行为动机之间的基本关系,以及孩子的经验等。
因此,对于孩子行为的判断不应该是武断的“对”或“错”。而应该根据行为发生的背景和原因等因素,决定孩子的行为是“适宜”或“不适宜”。教养者对孩子这些 行这的态度和处理方式,都直接会对孩子行为习惯和行为方式的形成产生至关重要的作用,进而会影响孩子一生的成长与发展。
在日常生活中,对于孩子的 不适宜行为,绝大多数教养者都会抱着严肃的态度,并且马上采取及时的措施来制止该行为的再次发生。但是对于孩子所表现出的那些适宜行为,教养者却认为这 是理所应当的,或者是应该自然发生的。因此经常会有家长动辄对于孩子的不适宜行为大发脾气,但同时却对孩子所表现出来的适宜行为熟视无睹。
但是孩子的适宜行为不会自然产生,而不适宜行为的减少,甚至浑水摸鱼也不会导致适宜行为的必然出现。教养者需要不时地对孩子的适宜行为给予反馈,即表扬或奖励,以增加或保持其出现的机率。
这管那管的组织和机构
取消或合并近几年不断涌现的这管那管的组织和机构,这些以“管”自居,以“管”牟利,甚至以“管”胡作非为,制造事端,残害百姓的事件接连发生,不仅没管 好任何事情,倒是越管越乱,大大增加了政府行政成本。实际上这些要管的事情都可以通过提高公民意识和素质一举几得。我是一名教师,我在管理学生方面一贯采 用设立做好事和发现汇报做好事者奖,收到很好的管理效果。班长是为同学服务的,是登记好人好事者,不是管同学的。这样使学生们个个有荣誉感。个个积极进 步。
|
========DoNeY's Notes of <Addison Wesley - OpenGL Programming Guide 2nd Edition> doneykoo.ycool.com========
General-Purpose Transformation Commands
void gMatrixMode()
Specifies whether the modelview, projection, or texture matrix will be modified, using the argument GL_MODELVIEW, GL_PROJECTION, or GL_TEXTURE.
void glLoadIdentity()
Sets the currenly modifiable matrix to (4 x 4) identity matrix.
void glLoadMatrix{fd}(const TYPE *m);
sets the sixteen values of the current matrix to those specified by m.
void glMultMatrix{fd}(const TYPE *m);
multiplies the matrix specified by the sixteen values pointed to by m by the current matrix and stores the result as the current matrix.
Caution: if you're programming in C and you declare a matrix as m[4][4], then the element m[i][j] is in the ith column and jth row of the OpenGL transformation matrix. This is a reverse of the standard C convention in which m[i][j] is in row i and column j.
To avoid this confusion, you should declare your matrices as m[16].
Note: All matrix multiplication with OpenGL occurs as follows:
Suppose the current matrix is C and the matrix specified by glMultMatrix*() or any of the transformation commands is M. After multiplication, the result is always CM.
========DoNeY's Notes of <Addison Wesley - OpenGL Programming Guide 2nd Edition> doneykoo.ycool.com========
Viewing and Modeling Transformations
The first part of this section discusses how to think about transformations; later, specific commands are presented.
Keep in mind that you must call glMatrixMode() with GL_MODELVIEW as its argument prior to performing any modeling or viewing transformations.
Think about Transformations
In general, the order of transformations is critical. If you do transformation A and then transformation B, you almost always get something different than if you do them in the opposite order.
Figure 3-4: Rotating First or Tranlating First
The Order of Specifying a series of transformations
Each successive glMultMatrix*() or transformation command multiplies a new 4x4 matrix M by the current modelview matrix C to yield CM. Finally, vertex v is multiplied by the current modelview matrix - the matrix CM.
This process means that the last transformation command called in your program is actually the first one applied to the vertices: CMv.
Grand, Fixed Coordinate System
Thus, if you like to think in terms of a grand, fixed coordinate system - in which matrix multiplications affect the position, orientation, and scaling of your model - you have to think of the multiplications as occurring in the opposite order from how they appear in the code.
Using a simple example shown here, if you want the object to appear on the axis after the operations, the rotation must occur first, followed by the translation. To do this, you need to reverse the order of operations in the code. So the code looks something like this, where R is the rotation matrix and T is the translation matrix:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMultMatrix(T); // translation
glMultMatrix(R); // rotation
draw_the_object();
Moving a Local Coordinate System
Another way to view matrix multiplications is to forget about a grand, fixed coordinate system in which your model is transform and instead, imagine that a local coordinate system is tied to the object you're drawing. All operations occur relative to this changing coordinate system. With this approach, the matrix multiplications now appear in the natural order in the code.
To see this in the translation-rotation example, begin by visualizing the object with a coordinate system tied to it. The translation operation moves the object and its coordinate system down the x-axis together. Then, the rotation occurs about the origin (now-translated), so the object rotates in place in its position which is seen on the grand axis.
This second approach can be problematic, however, in cases where scaling occurs, and especially so when the scaling is nonuniform (scaling different amounts along the different axes). After uniform scaling, translations move a vertex by a multiple of what they did before, since the coordinate system is stretched. Nonuniform scaling mixed with rotations may make the axes of the local coordinate system nonperpendicular.
Order of Modeling and Viewing
As mentioned earlier, you normally issue viewing transformation commands in your program before any modeling transformations. This way, a vertex in a model is first transformed into the desired orientation and then transformed by the viewing operation. Since the matrix multiplications must be specified in reverse order, the viewing commands need to come first.
Since the commands for performing modeling transformations can be used to perform viewing transformations, modeling transformations are discussed first, even if viewing transformations are actually issued first. This order matches the way many programmers think when planning their code: Often, they write all the code to construct their scene, which involves transformations of position and orientation relative to each other. Next, they decide where the viewpoint to be set and write the viewing transformations accordingly.
========DoNeY's Notes of <Addison Wesley - OpenGL Programming Guide 2nd Edition> doneykoo.ycool.com========
Modeling Transformations
The three OpenGL routines for modeling transformations are glTranslate*(), glRotate*(), and glScale*().
All three commands are equivalent to producing an appropriate translation, rotation, or scaling matrix, and then calling glMultMatrix*() with that matrix as the argument. However, these three routines might be faster than using glMultMatrix*(). OpenGL automatically computes the matrices for you.
Translate
void glTranslate{fd}(TYPE x, TYPE y, TYPE z);
Multiplies the current matrix by a matrix that moves (translates) and object by the given x, y, and z values (or moves the local coordinate system by the same amounts).

Figure 3-5 : Translating an Object
Rotate
void glRotate{fd}(TYPE angle, TYPE x, TYPE y, TYPE z);
Multiplies the current matrix by a matrix that rotates an object (or the local coordinate system) in a counterclockwise direction about the ray from the origin through the point (x, y, z). The angle parameter specifies the angle of rotation in degrees.
The effect of glRotate(45.0, 0.0, 0.0, 1.0), which is a rotation of 45 degrees about the z-axis:

Figure 3-6 : Rotating an Object
Note that an object that lies farther from the axis of rotation is more dramatically rotated ( has a larger orbit) thant an object drawn near the axis.
Scale
void glScale{fd}(TYPE x, TYPE y, TYPE z);
Multiplies the current matrix by a matrix that stretches, shrinks, or reflects an object along the axes. Each x, y, and z coordinate of every point in the object is multiplied by the corresponding argument x, y, or z.
With the local coordinate system approach, the local coordinate axes are streched, shrunk, or reflected by the x, y, and z factors, and the associated object is transformed with them.
Figure 3-7 shows the effect of glScalef( 2.0, -0.5, 1.0)

Figure 3-7 : Scaling and Reflecting an Object
glScale*() is the only one of the three modeling transformations that changes the apparent size of an object: Scaling with values greater than 1.0 stretches an object, and using values less than 1.0 shrinks it. Scaling with a -1.0 value reflects an object across an axis.
In general, you should limit your use of glScale*() to those cases where it is necessary. Using glScale*() decreases the performance of lighting calculations, because the normal vectors have to be renormalized after transformation.
Note: A scale value of zero collapses all object coordinates along that axis to zero. It is usually not a good idea to do this, because such operation cannot be undone. Mathematically speaking, the matrix cannot be inverted, and inverse matrices are required for certain lighting operations.
Sometimes collapsing coordinates does make sense, however; the calculation of shadows on a planar surface is a typical application. ( See shadows in Chapter 14 ) In general, if a coordinate system is to be collapsed, the projection matrix should be used rather than the modelview matrix.
A Modeling Transformation Code Example
A solid wireframe triangle is drawn with no modeling transformation.
The same triangle is drawn again, but with a dashed line stipple and translated.
A triangle is drawn with a long dashed line stipple, with its height ( y-axis) halved and its width ( x-axis) doubled.
A rotated, scaled triangle, made of dotted lines, is drawn.

Figure 3-8 : Modeling Transformation Example
Sample:
glLoadIdentity();
glColor3f(1.0, 1.0, 1.0);
draw_triangle(); /* solid lines */
glEnable(GL_LINE_STIPPLE); /* dashed lines */
glLineStipple(1, 0xF0F0);
glLoadIdentity();
glTranslatef(-20.0, 0.0, 0.0);
draw_triangle();
glLineStipple(1, 0xF00F); /*long dashed lines */
glLoadIdentity();
glScalef(1.5, 0.5, 1.0);
draw_triangle();
glLineStipple(1, 0x8888); /* dotted lines */
glLoadIdentity();
glRotatef (90.0, 0.0, 0.0, 1.0);
draw_triangle ();
glDisable (GL_LINE_STIPPLE);
Another :
GLfloat triangleVertices[] = {
0, 0, 0,
1, 0, 0,
0.5, 1.732/2, 0
};
{
// triangle vertices
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 3*sizeof(GLfloat), triangleVertices);
glPushAttrib(GL_LINE_STIPPLE);
glEnable(GL_LINE_STIPPLE);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// triangles start
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,4,0,3);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(1,1,0);
// triangle 1
glPushMatrix();
glDrawArrays(GL_TRIANGLES, 0, 3);
glPopMatrix();
// triangle 2
glPushMatrix();
glTranslatef(-0.5, 0, 0);
glLineStipple(1, 0x7070);
glDrawArrays(GL_TRIANGLES, 0, 3);
glPopMatrix();
// triangle 3
glPushMatrix();
glTranslatef(-0.5, 1.73/2/4, 0);
glScalef(2, 0.5, 1);
glLineStipple(1, 0xFF00); // line stipple won't be affected by the glScalef()
glDrawArrays(GL_TRIANGLES, 0, 3);
glPopMatrix();
// triangle 4
glPushMatrix();
// I am going to rotate it around the right-down corner of the triangle,
// which was originally (1, 0, 0)
glScalef(-1, 1, 1);
glTranslatef(-1.0, 0.0, 0);
glRotatef(30, 0, 0, 1);
glLineStipple(1, 0xAAAA);
glDrawArrays(GL_TRIANGLES, 0, 3);
glPopMatrix();
// triangles end
glPopMatrix();
glPopAttrib();
}
Note the use of glLoadIdentity() to isolate the effects of modeling transformations; initializing the matrix values prevents successive transformations from having a cumulative effect.
Note: Sometimes, programmers who want a continuously rotating object attempt to achieve this by repeatedly applying a rotation matrix that has small values. The problem with this is that because of round-off errors, the product of thousands of tiny rotations gradually drifts away from the desired value. Instead, you may use an increment angle and issue a new rotation command with the new angle at each update step.
|
========DoNeY's Notes of <Addison Wesley - OpenGL Programming Guide 2nd Edition> doneykoo.ycool.com========
.
Chapter 3
Viewing
Chapter Objectives
- View a geometric model in any orientation by transforming it three-dimensional space
- Control the location in three-dimensional space from which the model is viewed
- Clip undesired parts of the objects that are out of the scene
- Manipulate the matrix stacks that control the model transformation for viewing and project the model onto the screen
- Combine multiple transformations to complex structures in motion, such as a solar system or an articulated robot arm
- Reverse or mimic the operations of geometric processing pipeline
Three computer operations to convert an object's three dimensional coordinates to pixel positions on the screen.
- Transformations, which represented by matrix multiplication, including modeling, viewing and projection operations. Such operations include rotation, translation, scaling, reflecting, orthographic projection and perspective projection.
- Clip the parts of objects outside the window.
- Viewport transformation: a correspondence between three-dimensional coordinates and screen pixels.
========DoNeY's Notes of <Addison Wesley - OpenGL Programming Guide 2nd Edition> doneykoo.ycool.com========
Overview: The Camera Analogy
The steps of transformation process to produce the desired scene for viewing.
- Set up your tripod and pointing the camera at the scene ( viewing projection ).
- Arrange the scene to be photographed into the desired composition ( modeling transformation ).
- Choose a camera lens or adjust the zoom ( projection transformation ).
- Determine how large you want the final photograph to be ( viewport transformation ).
The viewing transformation must precede the modeling transformations in your code.
But you can specify the projection and the viewport transformations at any point before drawing occurs.
A Simple Example: Drawing a Cube
Example 3-1
OpenGL_005
/// <summary>
/// Callback: Draw things for display
/// This callback is called when GLUT need to redisplay the window
/// </summary>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
// clear the matrix
glLoadIdentity();
// viewing transformation
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 );
// modeling transformation
glScalef(1.0, 2.0, 1.0);
glutWireCube(1.0);
glutSwapBuffers();
}
/// <summary>
/// Callback:
/// This callback is called when window is to be reshaped
/// </summary>
void reshape(int w, int h)
{
GLfloat ratio = 1.333;
if ( 1.0*w/h > ratio )
w = 1.0*h*ratio;
else
h = 1.0*w/ratio;
// viewport transformation
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
// change to projection view
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// projection transformation
// glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
gluPerspective(60.0, 1.0, 1.5, 20.0);
// change back to model view
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/// <summary>
/// Callback: handle the mouse events
/// This callback is called when mouse events are detected
/// </summary>
void mouse(int button, int state, int x, int y)
{
}
/// <summary>
/// Do some initialization for app
/// </summary>
void init(void)
{
glClearColor(0.0, 0.0, 0.1, 0.0);
glShadeModel(GL_FLAT);
}
The Viewing Transformation
In this example, before the viewing transformation can be specified, the current matrix is set to the identity matrix with glLoadIdentity().
This step is necessary since most of the transformations commands multiply the current matrix by a pecified matrix and then set the current matrix to be the result. So you need to clear the current matrix by loading it with the identity matrix.
The viewing transformation is specified with gluLookAt().
The arguments for this command indicate where the camera (or eye position) is placed, where it is aimed, and which way is up. The up-vector defines a unique orientation for the camera.
If gluLookAt() was not called, the camera has a default position and orientation.
It is situated at the origin, points down the negative z-axis, and has an up-vector of (0, 1, 0).
void APIENTRY gluLookAt (
GLdouble eyex,
GLdouble eyey,
GLdouble eyez,
GLdouble centerx,
GLdouble centery,
GLdouble centerz,
GLdouble upx,
GLdouble upy,
GLdouble upz);
The Modeling Transformation
You use it to position and orient the model. For example, to rotate, to translate, or to scale it, or perform some combination of these operations.
glScalef() is a model transformation to scale.
For example, with glScalef(1.0, 2.0, 1.0), if one corner of the cube had originally been at (3.0, 3.0, 3.0), then the corner would be drawn at (3.0, 6.0, 3.0) .
Try This
Change the gluLookAt() call in Example 3-1 to the modeling transformation glTranslatef() with parameters (0.0, 0.0, -5.0). The result should look exactly the same.
void APIENTRY glScalef (GLfloat x, GLfloat y, GLfloat z);
The Projection Transformation
Determine what the filed of view or viewing volume is and therefore what objects are inside it and to some extent how they look.
In addition to filed-of-view considerations, the projection transformation determines how objects are projected onto the screen.
Two basic types of projections are provided, along with several corresponding commands for describing relevant parameters.
One type is perspective projection, which matches how you see things in daily life.
Use glFrustum() command to specify the perspective projection.
The other type of projection is orthographic, which maps objects directly onto the screen without affecting their relative size.
Before glFrustum() is called to set the projection transformation, some preparation needs to happen. As shown in reshape() routine in Example 3-1, the command glMatrixMode() is used first with the argument GL_PROJECTION. This indicates that the current matrix specifies the projection transformation. The following transformation calls will affect this projection matrix.
As you can see, after a few lines later, glMatrixMode() is called again, this time with GL_MODELVIEW as the argument. This indicates that succeeding transformations now affect the modelview matrix instead of the projection matrix.
Note that glLoadIdentity() is used to initialize the current projection matrix so that only the specified transformation has effect.
Now glFrustum() can be called, with arguments that define the parameters of the projection transformation.
Try This
Change the glFrustum() call in Example 3-1 to the more commonly used Utility Library routine gluPerspective() with parameters (60.0, 1.0, 1.5, 20.0). Then try different values for fovy and aspect.
void APIENTRY glFrustum (
GLdouble left, GLdouble right,
GLdouble bottom, GLdouble top,
GLdouble zNear, GLdouble zFar);
void APIENTRY gluPerspective (
GLdouble fovy,
GLdouble aspect,
GLdouble zNear,
GLdouble zFar);
The Viewport Transformation
The viewport indicates the shape of the available screen area into which the scene is mapped.
You can think of the viewport transformation as defining the size and location of the final processed photograph.
The arguments to glViewport() describe the origin of the available screen space within the window, and the with and height of the available screen area, all measured in pixels on the screen.
That is why this command needs to be called in reshape() when the window changes its size, the viewport needs to change accordingly.
void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height);
Drawing the Scene
Once all the transformations have been specified, you are ready to draw the scene.
As the scene is drawn, OpenGL transforms each vertex of every object in the scene and projected, clipped, mapped onto the screen.
|
========DoNeY's Notes of <Addison Wesley - OpenGL Programming Guide 2nd Edition> doneykoo.ycool.com========
.
Attribute Groups
glPushAttrib(GLbitfield mask)
glPopAttrib(void)
save or restore attribute groups
Attribute Groups
GL_ACCUM_BUFFER_BIT
GL_ALL_ATTRIB_BIT
GL_COLOR_BUFFER_BIT
GL_CURRENT_BIT
GL_DEPTH_BUFFER_BIT
GL_ENABLE_BIT
GL_EVAL_BIT
GL_FOR_BIT
GL_HINT_BIT
GL_LIGHTING_BIT
GL_LINE_BIT
GL_LIST_BIT
GL_PIXEL_MODE_BIT
GL_POINT_BIT
GL_POLYGON_BIT
GL_POLYGON_STIPPLE_BIT
GL_SCISSOR_BIT
GL_STENCIL_BUFFER_BIT
GL_TEXTURE_BIT
GL_TRANSFORM_BIT
GL_VIEWPORT_BIT
glPushClientAttrib(GLbitfield mask)
glPopClientAttrib(void)
save or restore attribute client groups
Client Attribute Groups
GL_CLIENT_PIXEL_STORE_BIT
GL_CLIENT_VERTEX_ARRAY_BIT
GL_ALL_CLIENT_ATTRIB_BIT
glGetIntegerv() with GL_MAX_ATTRIB_STACK_DEPTH and GL_MAX_CLIENT_ATTRIB_STACK_DEPTH
========DoNeY's Notes of <Addison Wesley - OpenGL Programming Guide 2nd Edition> doneykoo.ycool.com========
Some Hints for Building Polygonal Models of Surfaces
.
Keep polygon orientations consistent.
Make sure that when viewed from outside, all the polygons on the surface are oriented in the same direction (clockwise or counterclockwise). If you use glScale*() to reflect geometry around some axis of symmetry, you might change the orientation with glFrontFace().
When you subdivide a surface, watch out for any nontrianglular polygons.
The three vertices of a triangle are guaranteed to lie on a plane, while any polygonwith four or more vertices might not.
There's always a trade-off between the display speed and the quality of the image.
For high-quality images, it's a good idea to subdivide more on the silhouette edges than in the interior.
Try to avoid T-intersections in your models.
If you're constructing a closed surface, make sure to use exactly the same numbers for coordinates at the beginning and the end of a closed loop.
An Example: Building an Icosahedron
a regular icosahedron composed of twenty faces that span twelve vertices, each face of which is an equilateral triangle.
Culculating Normal Vectors for a Surface
You need to supply the normal vector to the surface.
GLfloat light0_ambient[] =
{0.2, 0.2, 0.2, 1.0};
GLfloat light0_diffuse[] =
{0.0, 0.0, 0.0, 1.0};
GLfloat light1_diffuse[] =
{1.0, 1.0, 1.0, 1.0};
GLfloat light1_position[] =
{0.9, 0.9, -2.0, 0.0};
// value for constructing the icosahedron
#define X .525731112119133606
#define Z .850650808352039932
// vertex data
static GLfloat vdata[12][3] = {
{-X, 0.0, Z}, {X, 0.0, Z}, {-X, 0.0, -Z}, {X, 0.0, -Z},
{0.0, Z, X}, {0.0, Z, -X}, {0.0, -Z, X}, {0.0, -Z, -X},
{Z, X, 0.0}, {-Z, X, 0.0}, {Z, -X, 0.0}, {-Z, -X, 0.0}
};
// index data
static GLuint tindices[20][3] = {
{0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1},
{8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},
{7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6},
{6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11}
};
// normalize a 3fv
void normalize(float v[3]) {
GLfloat d = sqrtf( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] );
if (d == 0.0)
{
return;
}
v[0] /= d;
v[1] /= d;
v[2] /= d;
}
// draw a triangle
void drawTriangle(float v1[3], float v2[3], float v3[3])
{
glBegin(GL_TRIANGLES);
//GLfloat norm[3];
//normcrossprod(v1,v2,norm);
//glNormal3fv(norm);
glNormal3fv(v1);
glVertex3fv(v1);
glNormal3fv(v2);
glVertex3fv(v2);
glNormal3fv(v3);
glVertex3fv(v3);
glEnd();
}
// draw triangles which construct a sphere like object
// recursively divide the triangles so that the sphere becomes smoother
void subdivide(float v1[3], float v2[3], float v3[3], int depth)
{
if (depth < 1) {
// draw the divided triangles
drawTriangle(v1,v2,v3);
return;
}
// divide them
GLfloat v12[3],v23[3],v31[3];
for (int i = 0; i<3; i++) {
v12[i] = v1[i] + v2[i];
v23[i] = v2[i] + v3[i];
v31[i] = v3[i] + v1[i];
}
// normalize so the vertices are on the designed surface of a sphere
// ,just like other vertices, they all have a distance of 1 from the zero point
normalize(v12);
normalize(v23);
normalize(v31);
// recursively calculate and draw
subdivide(v1,v12,v31,depth-1);
subdivide(v2,v23,v12,depth-1);
subdivide(v3,v31,v23,depth-1);
subdivide(v12,v23,v31,depth-1);
}
float rotateAngle = 0.0;
#define SUBDIVIDE
/// <summary>
/// Callback: Draw things for display
/// This callback is called when GLUT need to redisplay the window
/// </summary>
void display(void)
{
int i;
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(rotateAngle, 1, 1, 1 );
glColor3f(0.5, 0.5, 0.5);
for (i=0; i<20; i++) {
subdivide( &vdata[ tindices[i][0] ][0],
&vdata[ tindices[i][1] ][0],
&vdata[ tindices[i][2] ][0], 2 );
}
glPopMatrix();
glutSwapBuffers();
}
|
中文环境下设置GVIM的界面、菜单、提示为英文语言
修改你的_vimrc,通常为类似C:\Program Files\Vim
加入以下语句至末尾
" set the menu & the message to English
set langmenu=en_US
let $LANG = 'en_US'
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
|
Dereference a List of Array Elements
void glDrawElements(GLenum mode, GLsizei count, GLenum type, void *indices);
defines a sequence of geometric primitive which is indicated by indices in an array.
count is the number of elements.
type is one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT.
mode specifies what kind of primitives are constructed, which is one of GL_POLYGON, GL_LINE, GL_TRIANGLE and other modes just like the parameter in glBegin();
do not encapsulate glDrawElements() between glBegin and glEnd
Dereference a Sequence of Array Elements
void glDrawArrays(GLenum mode, GLint first, GLsizei count)
darw a sequence from an array.
========DoNeY's Notes of <Addison Wesley - OpenGL Programming Guide 2nd Edition> doneykoo.ycool.com========
Interleaved Arrays
Advanced
void glInterleavedArrays(GLenum format, GLsizei stride, void *pointer);
initializes the arrays at a time.
format is one of 14 symbolic constants, see table
stride specifies the byte offset between vertices.
if stride is 0, vertices are understood to be tightly packed.
Table 2-5: variables that direct glInterleavedArrays()
format
|
size_c
|
size_v
|
size
|
GL_V2F
|
|
2
|
2f
|
GL_V3F
|
|
3
|
3f
|
GL_C3F_V3F
|
3
|
3
|
6f
|
...
|
|
|
|
Note:
- glInterleavedArrays() only enables and disables corresponding vertex arrays and specifies values for array data.
- It does not render anything.
- So, you must still go on with step 3 to call glArrayElement(), glDrawElements(), or glDrawArrays() to dereference the pointers and render your primitives.
========DoNeY's Notes of <Addison Wesley - OpenGL Programming Guide 2nd Edition> doneykoo.ycool.com========
Sample of using mentioned styles of rendering primitives by vertices and vertex arrays:
1 //******************************************************
2 //
3 // Copyright
4 //
5 // Dong Zhou
6 // doneykoo@gmail.com
7 // http://doneykoo.ycool.com
8 //
9 //******************************************************
10
11 #include <gl\glut.h>
12
13
14 GLfloat vertices[] = {
15 1.0, 1.0, 1.0, 5.0, 5.0,
16 0.9, 0.1, 0.1, 55.0, 5.0,
17 0.1, 0.9, 0.1, 55.0, 55.0,
18 0.3, 0.3, 0.9, 5.0, 55.0,
19 };
20
21 GLfloat vertices2[] = {
22 -16, 18, 0,
23 16, 18, 0,
24 16, 10, 0,
25 -16, 10, 0,
26
27 -4, 10, 0,
28 4, 10, 0,
29 4, 5, 0,
30 -4, 5, 0,
31
32 -20, 5, 0,
33 20, 5, 0,
34 20, -3, 0,
35 -20, -3, 0,
36
37 0, 2, 0,
38 18, -16, 0,
39 13, -21, 0,
40 0, -8, 0,
41
42 0, 2, 0,
43 -18, -16, 0,
44 -13, -21, 0,
45 0, -8, 0,
46 };
47
48 GLfloat interleaved_vertices[] = {
49 1.0, 1.0, 1.0, -55.0, -55.0, 0.0,
50 0.9, 0.1, 0.1, 55.0, -55.0, 0.0,
51 0.1, 0.9, 0.1, 55.0, 55.0, 0.0,
52 0.3, 0.3, 0.9, -55.0, 55.0, 0.0,
53 };
54
55 GLubyte indices[] = {
56 0, 2, 2, 1, 1, 3
57 };
58
59
60 GLfloat matrix1[] = {
61 0.2, 0, 0, 0,
62 0, 0.2, 0, 0,
63 0, 0, 0.2, 0,
64 -50, -50, 0, 1,
65 };
66
67 GLfloat rotateAngle = 0.0;
68
69 /// <summary>
70 /// Callback: Draw things for display
71 /// This callback is called when GLUT need to redisplay the window
72 /// </summary>
73 void display(void)
74 {
75 glClear(GL_COLOR_BUFFER_BIT);
76
77 // ClientState
78 glEnableClientState(GL_COLOR_ARRAY);
79 glEnableClientState(GL_VERTEX_ARRAY);
80 glColorPointer(3, GL_FLOAT, 5*sizeof(GLfloat), vertices);
81 glVertexPointer(2, GL_FLOAT, 5*sizeof(GLfloat), &vertices[3]);
82
83 glLineWidth(3);
84
85 // the basic style
86 glPushMatrix();
87 glMultMatrixf(matrix1); // zoom and offset
88 glBegin(GL_LINE_LOOP);
89 glArrayElement(0);
90 glArrayElement(1);
91 glArrayElement(2);
92 glArrayElement(3);
93 glEnd();
94 glPopMatrix();
95
96
97
98 // glDrawElements - vertex indices
99 glDrawElements(GL_LINES, 6, GL_UNSIGNED_BYTE, indices);
100
101 // ClientState
102 glDisableClientState(GL_COLOR_ARRAY);
103 glVertexPointer(2, GL_FLOAT, 3*sizeof(GLfloat), vertices2);
104
105 glPushMatrix();
106 glRotatef(rotateAngle, 0, 0, 1 );
107 // glDrawArrays - a sequence in vertex array
108 glDrawArrays(GL_QUADS, 0, 20);
109 glPopMatrix();
110
111 // interleaved array
112 glInterleavedArrays(GL_C3F_V3F, 0, interleaved_vertices);
113 glDrawArrays(GL_LINE_LOOP, 0, 4);
114
115 glutSwapBuffers();
116 }
117
118 void idle()
119 {
120 rotateAngle += 0.5;
121
122 glutPostRedisplay();
123 }
124
125 /// <summary>
126 /// Callback:
127 /// This callback is called when window is to be reshaped
128 /// </summary>
129 void reshape(int w, int h)
130 {
131 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
132 //glMatrixMode(GL_PROJECTION);
133 glLoadIdentity();
134 //glOrtho(0,100,0,100,-1,1);
135 glOrtho(-100,100,-100,100,-1,1);
136 }
137
138 /// <summary>
139 /// Callback: handle the mouse events
140 /// This callback is called when mouse events are%
|
|
|
|
|