C#openGL多个对象分开旋转 [英] C# openGL multiple objects rotate seperatly

查看:149
本文介绍了C#openGL多个对象分开旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

这次...我在一个视口或屏幕上绘制多个对象时遇到问题.我想在屏幕上绘制多个对象,然后从中选择(从1到10或使用制表符或任何其他键盘),然后旋转它们.

我设法画了两个物体.

查看图片: http://postimage.org/image/kjjxmyky5/ [

Hello again guys!

This time...i have a problem drawing multiple objects on one viewport or screen. I would like to draw more then one object on the screen and then choose from them (from number 1 to 10 or using tab or any other keyboard) and then rotate them.

I''ve managed to draw two objects..

See picture: http://postimage.org/image/kjjxmyky5/[^]

But when i want to rotate one object he will go out of shape, because i dont call this function:

Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);



查看图片:
http://postimage.org/image/kmtwn8g97/ [



See picture: http://postimage.org/image/kmtwn8g97/[^]

If i DO call it, then the other object dissapears. I''ve tried to use pushMatrix and popMatrix functions, but as it seems i do not understand them quite good if the solution can be made with them.

I seek help, how to have more objects on screen and using rotate and translate functions seperatly on them, while one is rotating or moving, the others stay, where the are.

Can anyone help me? Thnx

推荐答案

应用旋转后,当前模型视图矩阵将随旋转而改变.
因此,第二次旋转将应用于已经旋转的模型视图矩阵.

用转换(旋转,平移,缩放)绘制对象后,必须将其重置.
否则,下一个变换将应用于应用变换的矩阵.
它将提供意外的对象绘图.

After applying a rotation, current model view matrix will changed with the rotation.
Therefore the second rotation will be applied on the already rotated model view matrix.

After drawing an object with a transformation(rotation,translation,scaling) you have to reset it.
Otherwise next transformation will applied on the transformation applied matrix.
It will provide unexpected object drawing.

glClearColor( 0.5,0.5,0.5,0.5 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glMatrixMode(GL_MODELVIEW_MATRIX);
// Save current matrix
glPushMatrix();

// Apply rotation for first object.
glRotatef( 15,0, 0, 1 ); // Here model view matrix rotated.

// Draw first object with rotation. Object1

// Reset matrix to old state. Therefore rotation on model view matrix is reset.
glPopMatrix();


// Save matrix.
glPushMatrix();

// Apply new rotation for second object.
glRotatef( 45,0, 0, 1 );

// Draw next object with new rotation. Object2

// Reset matrix to old state.
glPopMatrix();

// display


这篇关于C#openGL多个对象分开旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆