• 大小: 5KB
    文件类型: .cpp
    金币: 1
    下载: 0 次
    发布日期: 2021-05-25
  • 语言: C/C++
  • 标签: Opengl  考试复习  

资源简介

适合初学者,赚点积分,计算机图形学实验课完全自学,不容易啊QAQ

资源截图

代码片段和文件信息

// random.cpp : 定义控制台应用程序的入口点。
//

// random.cpp : 定义控制台应用程序的入口点。
//

#include “stdafx.h“
#include 
#include 

GLfloat theta = 0.0size=20.0xrot=0yrot=300step=0.01R1=0R2R3; // 全局变量
bool updownleftright=true;
#define DEGREES_TO_RADIANS 3.14159/180.0

void Mouse(int btnint stateint xint y)
{
//if (btn==GLUT_LEFT_BUTTON && state == GLUT_DOWN)
}

void MouseMove(int xmoveint ymove)
{
}

//画矩形函数
void drawrect(int xstartint ystartint xendint yend)
{
      glBegin(GL_POLYGON);
         glVertex2i(xstartystart);
     glVertex2i(xstartyend);
     glVertex2i(xendyend);
     glVertex2i(xendystart);
 glVertex2i(xstartystart);
     glEnd();
}


//画三角形函数
void drawtriangle(int xstartint ystartint xendint yend)
{
 glBegin(GL_POLYGON);
         glVertex2i(xstartystart);
     glVertex2i(xendyend);
 glVertex2i(xstartyend);
     glEnd();
}

void circle(float xrot1float yrot1)
{
 glBegin(GL_POLYGON);
     glVertex2f(xrot1+size*sin(theta*DEGREES_TO_RADIANS)yrot1+size*cos(theta*DEGREES_TO_RADIANS));
     glVertex2f(xrot1+size*sin((theta+60)*DEGREES_TO_RADIANS)yrot1+size*cos((theta+60)*DEGREES_TO_RADIANS));
 glVertex2f(xrot1+size*sin((theta+120)*DEGREES_TO_RADIANS)yrot1+size*cos((theta+120)*DEGREES_TO_RADIANS));
     glVertex2f(xrot1+size*sin((theta+180)*DEGREES_TO_RADIANS)yrot1+size*cos((theta+180)*DEGREES_TO_RADIANS));
     glVertex2f(xrot1+size*sin((theta+240)*DEGREES_TO_RADIANS)yrot1+size*cos((theta+240)*DEGREES_TO_RADIANS));
     glVertex2f(xrot1+size*sin((theta+300)*DEGREES_TO_RADIANS)yrot1+size*cos((theta+300)*DEGREES_TO_RADIANS));
   glEnd();
}
void rect(float x1float y1float x2float y2float x3float y3float x4float y4)
{
glBegin(GL_POLYGON);
     glVertex2f(x1y1);
 glVertex2f(x2y2);
 glVertex2f(x3y3);
 glVertex2f(x4y4);
   glEnd();
}


void display()
{
float y1y2xrot1yrot1xrot2yrot2;
int handmove=0;
int flag=0;
y1=yrot-50.0;
getchar();
   y2=yrot-100.0;
   glClear(GL_COLOR_BUFFER_BIT);
   glColor3f (0.0 1.0 0.0);
    rect(xrot-20+R1y2-130xrot-20y2xrot-10y2xrot-10+R1y2-130);

glColor3f (1.0 1.0 1.0);
   drawrect(xrot-30yrot-30xrot+30yrot+30);   
   

   glBegin(GL_POLYGON);
     glVertex2f(xrot-50y1-100);
     glVertex2f(xrot-50y1);
 glVertex2f(xrot+50y1);
     glVertex2f(xrot+50y1-100);
   glEnd();

   //

   glColor3f (1.0 0.0 0.0);
   drawrect(xrot-5-handmoveyrot-130xrot+5-handmoveyrot-60);
   drawrect(xrot-5+handmoveyrot-130xrot+5+handmoveyrot-60);

  glColor3f (0.0 1.0 0.0);
   //drawrect(xrot-20y2-130x

评论

共有 条评论