计算机图形学设计的内容还真是多啊,openGL环境下画图实在太麻烦了
刚刚看了看MFC的东东 只能做出这个最基本的啦 但很多想要完成的东东却无从下手啊
我想问的是如何对"DDA算法生成直线"那项进行操作,不是点击就画图了,比如点完之后可以弹出个对话框 ,可以输入直线启始坐标,然后再生成图,谢谢指点
用C就可以了。呵呵,简单的做了一下,可以参考参考,本方法,不好意思。
/*************************************/
/* name : mo xiaoming */
/* write date: 2006-9-21 */
/*************************************/
#include "stdio.h"
#include "math.h"
#include "graphics.h"
/**************************************************
* the function name: WriteMuem
* select the number to write a line or exit window
* return the select number
**************************************************/
int WriteMuem()
{
int select;
printf("*--------- Enter n -----------------*\n");
printf("* [1].Start Write a Line *\n");
printf("* [0].Exit Window *\n");
printf("*-----------------------------------*\n");
printf("Please Enter n:");
scanf("%d",&select);
return select;
}
/*************************************************************
* the function name : WriteLine
* write a line function
* no return nothing
*************************************************************/
void WriteLine(float x1,float y1,float x2,float y2,int color)
{
float x,y,x3,y3,n,t;
printf("\n\nx1=%f,y1=%f,x2=%f,y2=%f,color=%d\n",x1,y1,x2,y2,color);
x3=x2-x1;
y3=y2-y1;
n=fabs(x3);
t=fabs(y3);
n=(t>n)?t:n;
if(n!=0.0){
x=x3/n;
y=y3/n;
}
x1+=0.5;
y1+=0.5;
x3=(int)x1;
y3=(int)y1;
x2=(int)(x2+0.5);
y2=(int)(y2+0.5);
n=fabs(x3-x2);
t=fabs(y3-y2);
n=(t>n)?t:n;
putpixel((int)x3,(int)y3,(int)color);
/*getch();*/
while(n>0){
x1+=x;
y1+=y;
n--;
putpixel((int)x1,(int)y1,(int)color);
}
}
/*************************************
* the function name:inner
* the inner function
*****************************************/
void inner()
{
float x1=0.0,y1=0.0;
float x2=0.0,y2=0.0;
int n=1,color=1;
while(n!=0){
/*call the function WriteMuem*/
n=WriteMuem();
switch((int)n){
case 1:
printf("Enter x1:"); scanf("%f",&x1);
printf("\nEnter y1:"); scanf("%f",&y1);
printf("\nEnter x2:"); scanf("%f",&x2);
printf("\nEnter y2:"); scanf("%f",&y2);
printf("Select the color:(1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:)");
scanf("%d",&color);
printf("\n\n\n Write Out the line :\n");
/*call the function:WriteLine*/
WriteLine(x1,y1,x2,y2,color);
printf("Press the Enter!\n");
getch();
break;
case 0:exit(0);/*Exit The Window */
default :break;
}
}
}
/*the main function*/
int main(void)
{
int VGA_driver=VGA,VGA_mode=VGAHI; /* create the driver */
clrscr(); /* clear the window */
initgraph(&VGA_driver,&VGA_mode,""); /* initgraph */
inner(); /* call the function inner */
closegraph(); /* closegraph */
return 0;
}