Está en la página 1de 10

Facilitador: Cesar Zenet Lopez Cruz

INGENIERÍA EN SISTEMAS
COMPUTACIONALES

Graficación.

ESTUDIANTE:

LAVADORES MIS ANGEL ADOLFO

Esferas Botando.

YUCATÁN. 04/Diciembre/2023
COMENTARIOS:

Durante la realización de este trabajo, tuve la oportunidad de practicar mis habilidades de


programación y aplicar conceptos aprendidos en mi carrera de ingeniería de sistemas
computacionales. El objetivo de dibujar y hacer rebotar las esferas en un entorno gráfico fue un
desafío interesante que me permitió explorar el uso de la biblioteca SharpGL y aprender sobre el
manejo de elementos gráficos en Windows Forms.

Aunque me enfrenté a la dificultad de generar un solo método para manejar las dos esferas, pude
resolverlo creando métodos separados para cada una y llamándolos en el bucle principal del
programa. Esto me permitió actualizar el estado y dibujar las esferas de forma independiente.

El proceso de hacer que las esferas reboten fue emocionante y me permitió experimentar con el
movimiento y las colisiones. Ajustar los parámetros de velocidad, dirección y aceleración de las
esferas me ayudó a comprender mejor los conceptos físicos relacionados con el movimiento y el
rebote.

En general, esta experiencia fue enriquecedora y me permitió aplicar mis conocimientos de


programación en un contexto práctico y divertido.
Capturas.
Código Fuente.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SharpGL;

namespace CLASE_20_Y_21
{
public partial class Form1 : Form
{

float mRadioBola = 1f;


float mX = 10;
float mY = 20;
float mVX = 0.45f;
float mVY = 0.45f;
float mAY = 0.2f;
int mDireccion = 1;
bool mFin = false;
double mK = 0.1;
Color Micolor = Color.Red;

float mRadioBola2 = 1f;


float mX2 = 45;
float mY2 = 20;
float mVX2 = -0.45f;
float mVY2 = 0.45f;
float mAY2 = 0.2f;
int mDireccion2 = 1;
bool mFin2 = false;
double mK2 = 0.1;
Color Micolor2 = Color.Blue;

static Random rand = new Random();

public Form1()
{
InitializeComponent();

SharpGL.OpenGL gl = this.openGLCtrl1.OpenGL;
float[] light_ambient = { 0.2f, 0.2f, 0.2f, 1.0f };
float[] light_diffuse = { 1, 0, 1, 0, 1, 0, 1, 0 };
float[] light_specular = { 1, 0, 1, 0, 1, 0, 1, 0 };
float[] light_position = { 5.5f, 0.0f, 1.5f, 1.0f };
gl.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
float[] mat_specular = { 1.0f, 1.0f, 1.0f, 1.1f };
float[] mat_shininess = { 50 };
gl.Material(OpenGL.FRONT, OpenGL.SPECULAR, mat_specular);

gl.Light(OpenGL.LIGHT0, OpenGL.AMBIENT, light_ambient);


gl.Enable(OpenGL.LIGHTING);
gl.Enable(OpenGL.LIGHT0);
gl.Enable(OpenGL.DEPTH_TEST);
}

public Color NuevoColor()


{

int r = (int)(rand.Next(1, 255));


int g = (int)(rand.Next(1, 255));
int b = (int)(rand.Next(1, 255));
return System.Drawing.Color.FromArgb(r, g, b);

}
//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public void actualizarEstado()
{

if (mFin == true)
{
mX = 10;
mY = 20;
mFin = false;
Micolor = NuevoColor();
return;
}

mX += (float)mVX;

if (mDireccion == 1)
{
mY -= (float)mVY;

if (mY < mRadioBola * 2)


{
mY = 0;
mDireccion = 2;
double delta = (double)mVY * mK;
double newVY = mVY - (delta + 0.01);

if (delta < 0.1)


{
mFin = true;
}
mVY = (float)newVY;
}
else
{

mVY += mAY;
}
}
else
{
if (mDireccion == 2)
{

mY += (float)mVY;
mVY -= mAY;
if (mVY < 0)
{
mVY = 0;
mDireccion = 1;
}
}
}
}

public void dibujarse(SharpGL.OpenGL gl)


{
SharpGL.SceneGraph.Quadrics.Sphere Esfera = new SharpGL.SceneGraph.Quadrics.Sphere();
Esfera.Create(gl);
Esfera.Slices = 20;
Esfera.Stacks = 16;
Esfera.Radius = mRadioBola;
Esfera.Material.Diffuse = Micolor;
//Esfera.QuadricDrawStyle = SharpGL.SceneGraph.Quadrics.Quadric.DrawStyle.Fill;
gl.Color(Micolor.R / 255.0, Micolor.G / 255.0, Micolor.B / 255.0);
Vertex EsferaPos = new Vertex(mX, mY, 0.0f);
Esfera.Translate = EsferaPos; Esfera.Draw(gl);
}

//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''
public void actualizarEstado2()
{

if (mFin2 == true)
{
mX2 = 45;
mY2 = 20;
mFin2 = false;
Micolor2 = NuevoColor();
return;
}

mX2 += (float)mVX2;
if (mDireccion2 == 1)
{
mY2 -= (float)mVY2;

if (mY2 < mRadioBola2 * 2)


{
mY2 = 0;
mDireccion2 = 2;
double delta2 = (double)mVY2 * mK2;
double newVY2 = mVY2 - (delta2 + 0.01);

if (delta2 < 0.1)


{
mFin2 = true;
}
mVY2 = (float)newVY2;
}
else
{

mVY2 += mAY2;
}
}
else
{
if (mDireccion2 == 2)
{

mY2 += (float)mVY2;
mVY2 -= mAY2;
if (mVY2 < 0)
{
mVY2 = 0;
mDireccion2 = 1;
}
}
}
}

public void dibujarse2(SharpGL.OpenGL gl)


{
SharpGL.SceneGraph.Quadrics.Sphere Esfera = new SharpGL.SceneGraph.Quadrics.Sphere();
Esfera.Create(gl);
Esfera.Slices = 20;
Esfera.Stacks = 16;
Esfera.Radius = mRadioBola2;
Esfera.Material.Emission = Micolor;
//Esfera.QuadricDrawStyle = SharpGL.SceneGraph.Quadrics.Quadric.DrawStyle.Fill;
gl.Color(Micolor2.R / 255.0, Micolor2.G / 255.0, Micolor2.B / 255.0);
Vertex EsferaPos = new Vertex(mX2, mY2, 0.0f);
Esfera.Translate = EsferaPos; Esfera.Draw(gl);
}
//''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''

private void openGLCtrl1_OpenGLDraw(object sender, PaintEventArgs e)


{
SharpGL.OpenGL gl = this.openGLCtrl1.OpenGL;
gl.Clear(OpenGL.COLOR_BUFFER_BIT | OpenGL.DEPTH_BUFFER_BIT);
gl.LoadIdentity();
gl.Translate(-28.0f, -10.0f, -30.0f);
dibujarse(gl);
dibujarse2(gl);
actualizarEstado();
actualizarEstado2();
}

}
}

También podría gustarte