OpenGL仿作橡皮筋技术
来源:互联网 发布:mac 显示绝对路径 编辑:程序博客网 时间:2024/05/02 12:06
算是精仿吧,毕竟不一样,少了第二次点鼠标左键确认绘图,这个可以加上的:
#include <iostream>#include <windows.h>#include <GL/glut.h>using namespace std ;#pragma comment(lib, "glut32.lib") int flag =0;int flagagain=0;POINT start,down; void init(void){ glClearColor(0.0, 0.0, 0.0, 0.0) ; glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0) ;}void display(void) { glClear(GL_COLOR_BUFFER_BIT) ; if(flag) {glColor3f(1.0, 1.0, 1.0) ;glBegin(GL_LINES);GLfloat oldx = start.x*1.00/400;GLfloat oldy = start.y*1.00/400;GLfloat newx = down.x*1.00/400;GLfloat newy = down.y*1.00/400;glVertex2f(oldx,oldy);glVertex2f(newx,newy);glutSwapBuffers(); } glEnd() ; glFlush() ;}void motion(int x, int y) {if(!flag){start.x = x;start.y = 400-y;}down.x = x;down.y = 400-y;}void mouse(int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON) { if (state == GLUT_DOWN) { glutMotionFunc(motion);//获得start flag=1; } } } int main(int argc, char **argv){ glutInit(&argc, argv) ; glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(400, 400) ; glutCreateWindow("I love OpenGl") ; init() ; glutDisplayFunc(display) ; glutMouseFunc(mouse); glutPassiveMotionFunc(motion); glutIdleFunc(display); glutMainLoop(); return 0 ;}
//喏 空心圆
#include <iostream>#include <windows.h>#include <GL/glut.h>#include<math.h>using namespace std ;#define pi 3.1415926535843721#pragma comment(lib, "glut32.lib") int flag =0;int flagagain=0;int n;POINT start,down; float GetLength(POINT start,POINT down){return sqrt((start.x*1.00/400-down.x*1.00/400)*(start.x*1.00/400-down.x*1.00/400)+(start.y*1.00/400-down.y*1.00/400)*(start.y*1.00/400-down.y*1.00/400));}void init(void){ glClearColor(0.0, 0.0, 0.0, 0.0) ; glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0) ;}void display(void) { glClear(GL_COLOR_BUFFER_BIT) ; if(flag) {glColor3f(1.0, 1.0, 1.0) ;glBegin(GL_LINES);GLfloat oldx = start.x*1.00/400;GLfloat oldy = start.y*1.00/400;GLfloat newx = down.x*1.00/400;GLfloat newy = down.y*1.00/400;glVertex2f(oldx,oldy);glVertex2f(newx,newy);glEnd();glBegin(GL_LINE_STRIP); glColor3f(1.0, 1.0, 1.0) ;n = 100;float R = GetLength(start,down);//半径cout<<R<<endl;//输出半径for (int i = 0; i < n; i++){glVertex2f(R*sin(2 * pi / n*i)+oldx, R*cos(2 * pi / n*i)+oldy);//平移到 以原来鼠标 左 键 为原点}glEnd();glutSwapBuffers(); } glEnd() ; glFlush() ;}void motion(int x, int y) {if(!flag){start.x = x;start.y = 400-y;}down.x = x;down.y = 400-y;}void mouse(int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON) { if (state == GLUT_DOWN) { glutMotionFunc(motion);//获得start flag=1; } } } int main(int argc, char **argv){ glutInit(&argc, argv) ; glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(400, 400) ; glutCreateWindow("I love OpenGl") ; init() ; glutDisplayFunc(display) ; glutMouseFunc(mouse); glutPassiveMotionFunc(motion); glutIdleFunc(display); glutMainLoop(); return 0 ;}
0 0
- OpenGL仿作橡皮筋技术
- OpenGL 橡皮筋技术
- OpenGL橡皮筋技术与拾取技术的实现
- openGL下的”橡皮筋“技术(多边形绘制)
- Android--仿橡皮筋效果
- 橡皮筋技术画直线
- 橡皮筋技术的实现
- VC++ MFC橡皮筋技术
- 用OpenGL实现折线和矩形的橡皮筋绘制技术(可完全脱离鼠标)
- mfc橡皮筋技术哦亲~
- C# GDI+ 橡皮筋技术(转)
- MFC橡皮筋矩形框技术
- 橡皮筋
- 橡皮筋
- 仿作4399 经验总结
- 4399 仿作经验
- 利用橡皮筋技术实现的画图
- VC橡皮筋绘图技术的实现
- python 随机库学习
- 网络流24题题目列表
- 怎么理解js的原型对象
- 快速访问Android开发文档
- C语言 宏定义
- OpenGL仿作橡皮筋技术
- JavaScript[12.24]
- willMoveToParentViewController和didMoveToParentViewController
- mjpg-streamer详解2
- mysql修改root密码及root密码忘记的解决办法
- 我的2016--收获的一年
- (4.2.9.1)OrmLite整合SqlCipher
- 关于国产项目Apache Kylin 发展历程及背后的那些事
- 控制摄像机一直看物体的正方,并且相距一定距离