📄 program.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using Tao.FreeGlut;
using Tao.OpenGl;
//programa hecho por jesus hernandez
//itsl
//ing. en sist. compt.
namespace Graficos
{
class Program
{
static double x1, y1, x2, y2;
static void Main(string[] args)
{//inicializar todo esto para tao opengl
Console.WriteLine("introduzca el valor de X1");
x1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("introduzca el valor de Y1");
y1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("introduzca el valor de X2");
x2 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("introduzca el valor de Y2");
y2 = Convert.ToDouble(Console.ReadLine());
Glut.glutInit();
Glut.glutInitDisplayMode(Glut.GLUT_SINGLE | Glut.GLUT_RGB);
Glut.glutInitWindowSize(640, 480);
Glut.glutCreateWindow("**************Algoritmo DDA**************");
//termina inicializacion de componentes tao opengl
//llamamos a la funcion dda
Glut.glutDisplayFunc(dda);
// register the callback functions
//Glut.glutDisplayFunc(new Glut.DisplayCallback(dda));
//***************funciona para desplegar dibujo
//Glut.glutDisplayFunc(Display);
//*******funcion para desplegar dibujo
//'Glut.glutDisplayFunc(New Glut.DisplayCallback(mostrar))
//'init() '; // additional initializations as necessary
Glut.glutMainLoop(); // go into a perpetual loop
}
static void Display()
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
Gl.glColor3f(0.6F, 0.6F, 0.6F);
Gl.glLoadIdentity() ;//''muy importante;
//Gl.glColor3f(.1110f, .10f, 1.0f);
//Gl.glRotated(15D, 0.0, 10.0, 1.0);
//Glut.glutWireSphere(0.5D, 15, 12);
cubo();
//Gl.glFlush()
//Glut.glutSwapBuffers()
}
public static void cubo()
{/*
Gl.glRotated(1, 10, 10, 9);
Glut.glutWireCube(0.9);
Gl.glPointSize(5.0f);
Gl.glColor3f(1.0f, 0.0f, 0.0f);
Gl.glBegin(Gl.GL_POINTS);
Gl.glVertex3d(0, .7, 0);
Gl.glVertex3d(1, -.7, 1);
Gl.glEnd();
Gl.glColor3f(0.0f, 1.0f, 0.0f);
Gl.glTranslated(0, .6666, .1);
Gl.glRotated(15, 10, 20, 10);
Glut.glutWireCube(.3);
Gl.glColor3f(1.0f, 1.0f, 0.0f);
//Gl.glRotated(0, 0, 0, 0);
//Gl.glTranslated(0.6, -.6666, .1);
//Glut.glutWireCube(.3);
Gl.glRotated(23, 10, 20, 10);
Gl.glTranslated(.01, 0, 0);
Glut.glutWireCone(.2, 1, 3, 4);
Glut.glutWireDodecahedron();
*/
Gl.glRotated(40, 30, 30.0, 20.0);
//Glut.glutWireSphere(.4, 20, 16);
Gl.glColor3f(0F, 0.6F, 0.6F);
Glut.glutSolidCube(.9);
Gl.glColor3f(0.1F, 0.2F, 0.1F);
Glut.glutWireCube(.9);
}
public static void dda()
{
//componentes necesarios
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
Gl.glColor3f(0.6F, 0.6F, 0.6F);//poner color a los pixeles
Gl.glLoadIdentity();//''muy importante;
///componentes necesarios
Gl.glPointSize(2.0f);//medida de los puntos
//Gl.glColor3f(0.0f, 1.0f, 0.0f);
//ddaDibujar(.1, .1, 1, 1);
//Gl.glColor3f(1.0f, 0.0f, 1.0f);
//ddaDibujar(.3, .1, .6, .6);
//Gl.glColor3f(1.0f, 0.111f, 1.0f);
//ddaDibujar(-1,-1, .5, 1);
Gl.glBegin(Gl.GL_POINTS);
//dibujando el plano
float z = -1, w = 1, c = 0;
for (int i = 0; i < 200; i++)
{
Gl.glColor3f(w, c, z);
Gl.glVertex2d(z, 0);
Gl.glVertex2d(0, w);
z += .01f;
w -= .01f;
c += .1f;
}
Gl.glEnd();
///pasamos las
Gl.glPointSize(5.0f);
Gl.glColor3f(0.6f, 1.0f, 0.6f);
ddaDibujar(x1, y1, x2, y2);
//Gl.glRotatef(20, 10, 4, 6);
//Glut.glutWireCube(.2);
//Gl.glColor3f(.1f, .1f, .1f);
//Glut.glutSolidCube(.2);
//Glut.glutWireSphere
}
public static void ddaDibujar(double x1,double y1,double x2, double y2)
{
//empieza dda
double xinicial = x1, yinicial = y1, xfinal = x2, yfinal = y2,x,y;
double deltax, deltay, xincremento, yincremento;
double pasos;
deltax = xfinal - xinicial;
deltay = yfinal - yinicial;
if (Math.Abs(deltax) > Math.Abs(deltay))
pasos = Math.Abs(deltax);
else
pasos = Math.Abs(deltay);
xincremento = (deltax / pasos) / 10;
yincremento = (deltay / pasos) / 10;
x = xinicial;
y = yinicial;
Gl.glBegin(Gl.GL_POINTS);
//Gl.glColor3f(1f, 1.0f, .5f);
Gl.glVertex2d(x, y);
for (double k = .1; k <= pasos; k += .1)
{
x = (x + xincremento);
y = (y + yincremento);
Gl.glVertex2d(x, y);
}
Gl.glEnd();
//termina dda
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -