opengl 旋转立方体

#include<GL/glut.h>#include<stdio.h>#include<math.h>intoldmx=0;intoldmy=0;intoldmz=0;... #include<GL/glut.h>
#include<stdio.h>
#include<math.h>

int oldmx=0;
int oldmy=0;
int oldmz=0;
int newx=0;
int newy=0;
int newz=0;
int cos_ankle=0;

void Mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN)
oldmx=x,oldmy=y;
}

void onMouseMove(int x,int y)
{
int newx=x,newy=y;
}

void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

cos_ankle=((oldmx*newx+oldmy*newy)/sqrt(((double)oldmx*(double)oldmx+(double)oldmy*(double)oldmy)*((double)newx*(double)newx+(double)newy*(double)newy)));
glRotatef(acos((double)cos_ankle),0,0,10);
glBegin(GL_QUADS);
glColor3f(1.0,0.0,0.0);
//前
glVertex3f(-0.5,-0.5,0.5);
glVertex3f(-0.5,0.5,0.5);
glVertex3f(0.5,0.5,0.5);
glVertex3f(0.5,-0.5,0.5);
//后
glVertex3f(-0.5,-0.5,-0.5);
glVertex3f(-0.5,0.5,-0.5);
glVertex3f(0.5,0.5,-0.5);
glVertex3f(0.5,-0.5,-0.5);
//左
glVertex3f(-0.5,-0.5,-0.5);
glVertex3f(-0.5,0.5,-0.5);
glVertex3f(-0.5,0.5,0.5);
glVertex3f(-0.5,-0.5,0.5);
//右
glVertex3f(0.5,-0.5,0.5);
glVertex3f(0.5,0.5,0.5);
glVertex3f(0.5,0.5,-0.5);
glVertex3f(0.5,-0.5,-0.5);
//上
glVertex3f(-0.5,0.5,0.5);
glVertex3f(-0.5,0.5,-0.5);
glVertex3f(0.5,0.5,-0.5);
glVertex3f(0.5,0.5,0.5);
//下
glVertex3f(-0.5,-0.5,-0.5);
glVertex3f(-0.5,-0.5,0.5);
glVertex3f(0.5,-0.5,0.5);
glVertex3f(0.5,-0.5,-0.5);
glEnd();
glFlush();
}

int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("第一个OpenGL程序");
glutIdleFunc(myDisplay);
glutMouseFunc(Mouse);
glutMotionFunc(onMouseMove);
glutDisplayFunc(&myDisplay);
glutMainLoop();
return 0;
}
展开
 我来答
  • 你的回答被采纳后将获得:
  • 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
matbdhematical
2015-05-09 · TA获得超过350个赞
知道答主
回答量:302
采纳率:0%
帮助的人:82.6万
展开全部
这个东西并不是太难的,你可以: 定义一个矩形区域范围,为实现点击鼠标左键来实现自由移动颜色条的功能 ... 然后你通过这个点的坐标来判断,此点是否在该区域内,如果是的,则自由移动颜色条,否则是立方体的自由旋转...
追问
你好,我写的这个程序能运行,但不显示立方体。你能不能帮我看看那里出问题了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
深圳量子动力
2024-10-21 广告
双目摄像头可找深圳量子动力双目摄像系统可通过无线方式进行面部捕捉,可以满足在家、工作室、直播间、专业动捕棚等多种场景的不同使用人群。支持Metahuman Animator解算,支持升级animator高精度表情方案... 点击进入详情页
本回答由深圳量子动力提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式