140 lines
6.4 KiB
C#
140 lines
6.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.Numerics;
|
|
|
|
namespace Bonhomme01
|
|
{
|
|
class Jambe : Rectangle
|
|
{
|
|
private int etapeMarche = 0;
|
|
Rectangle jambeBas, pied;
|
|
public Color Fond
|
|
{
|
|
get
|
|
{
|
|
return base.fond;
|
|
}
|
|
set
|
|
{
|
|
base.fond = jambeBas.fond = pied.fond = value;
|
|
}
|
|
}
|
|
public struct AngleJambe
|
|
{
|
|
public float AngleBassin;
|
|
public float AngleGenou;
|
|
public float AngleCheville;
|
|
public AngleJambe(float angleBassin, float angleGenou, float angleCheville)
|
|
{
|
|
this.AngleBassin = angleBassin;
|
|
this.AngleGenou= angleGenou;
|
|
this.AngleCheville = angleCheville;
|
|
}
|
|
}
|
|
public AngleJambe angleJambe;
|
|
public Jambe(PictureBox hebergeur, Point origine, int Lhorizontal, int Lvertical) : base(hebergeur, origine, Lhorizontal, Lvertical/2)
|
|
{
|
|
|
|
Rectangle me = this;
|
|
angleJambe = new AngleJambe(0, 0, 0);
|
|
base.angleRotation = angleJambe.AngleBassin;
|
|
jambeBas = new Rectangle(hebergeur, Lhorizontal, Lvertical/2, ref me, angleJambe.AngleGenou);
|
|
pied = new Rectangle(hebergeur, Lhorizontal*2, Lvertical/10, ref jambeBas, angleJambe.AngleCheville);
|
|
}
|
|
public Jambe(PictureBox hebergeur, Point origine, int Lhorizontal, int Lvertical, AngleJambe angle) : base(hebergeur, origine, Lhorizontal, Lvertical/2, angle.AngleBassin)
|
|
{
|
|
Rectangle me = this;
|
|
angleJambe = angle;
|
|
jambeBas = new Rectangle(hebergeur, Lhorizontal, Lvertical/2, ref me, angleJambe.AngleGenou);
|
|
pied = new Rectangle(hebergeur, Lhorizontal * 2, Lvertical/10, ref jambeBas, angleJambe.AngleCheville);
|
|
}
|
|
public Jambe(PictureBox hebergeur, Point origine, int Lhorizontal, int Lvertical, AngleJambe angle, Point origineRotation) : base(hebergeur, origine, Lhorizontal, Lvertical/2, angle.AngleBassin, origineRotation)
|
|
{
|
|
Rectangle me = this;
|
|
angleJambe = angle;
|
|
jambeBas = new Rectangle(hebergeur, origine, Lhorizontal, Lvertical/2, angleJambe.AngleGenou, origineRotation);
|
|
pied = new Rectangle(hebergeur, jambeBas.CIG, Lhorizontal * 2, Lvertical/10, angleJambe.AngleCheville, origineRotation);
|
|
}
|
|
public new void Afficher(IntPtr handle)
|
|
{
|
|
base.angleRotation = angleJambe.AngleBassin;
|
|
jambeBas.angleRotation = angleJambe.AngleGenou;
|
|
pied.angleRotation = angleJambe.AngleCheville;
|
|
base.CentrerPointOrigine();
|
|
base.Afficher(handle);
|
|
jambeBas.CentrerPointOrigine();
|
|
jambeBas.Afficher(handle);
|
|
//pied.CentrerPointOrigine();
|
|
pied.Afficher(handle);
|
|
}
|
|
public new void Cacher(IntPtr handle)
|
|
{
|
|
base.angleRotation = angleJambe.AngleBassin;
|
|
jambeBas.angleRotation = angleJambe.AngleGenou;
|
|
pied.angleRotation = angleJambe.AngleCheville;
|
|
|
|
base.Cacher(handle);
|
|
jambeBas.Cacher(handle);
|
|
pied.Cacher(handle);
|
|
}
|
|
public float Genou
|
|
{
|
|
get { return jambeBas.angleRotation; }
|
|
set { jambeBas.angleRotation = angleJambe.AngleGenou = value%360; }
|
|
}
|
|
public float Cheville
|
|
{
|
|
get { return pied.angleRotation; }
|
|
set { pied.angleRotation = angleJambe.AngleCheville =value%360; }
|
|
}
|
|
public void Bouger(int x, int y)
|
|
{
|
|
//Origine = new Point(Origine.X + x, Origine.Y + y);
|
|
// jambeBas.Origine = new Point(jambeBas.Origine.X + x, jambeBas.Origine.Y + y);
|
|
// pied.Origine = new Point(pied.Origine.X + x, pied.Origine.Y + y);
|
|
}
|
|
public void Monter(int x)
|
|
{
|
|
PointComplexe l = new PointComplexe(new PointComplexe(base.CSG, base.CSD).Millieux(), new PointComplexe(jambeBas.CIG, jambeBas.CID).Millieux());//Vecteur entre le haut et le bas du pied
|
|
PointComplexe m = new PointComplexe(new PointComplexe(base.CSG, base.CSD).Millieux(), new PointComplexe(base.CIG, base.CID).Millieux());//Vecteur entre le haut et le bas du pied
|
|
// var a = ((l.ABS - x) * (l.ABS - x));
|
|
int lvertical = (int)m.ABS; //var b = (2 * (l.ABS - x) * Lvertical);
|
|
Console.WriteLine("L:{0} vert:{1} x:{2}", l.ABS,lvertical, x);
|
|
var bla = (Math.Pow((l.ABS - x), 2)) / (2 * (l.ABS)* (lvertical));
|
|
Console.WriteLine("bla:{0}", bla);
|
|
double angle = Math.Acos(bla);
|
|
angle *= 180;
|
|
angle /= Math.PI;
|
|
Console.WriteLine(angle);
|
|
angleJambe.AngleBassin = (float)-angle;
|
|
angleJambe.AngleGenou = (float)angle;
|
|
}
|
|
public void Avancer(int x)
|
|
{
|
|
PointComplexe m = new PointComplexe(new PointComplexe(base.CSG, base.CSD).Millieux(), new PointComplexe(base.CIG, base.CID).Millieux());//Vecteur entre le haut et le bas du pied
|
|
// var a = ((l.ABS - x) * (l.ABS - x));
|
|
int lvertical = (int)m.ABS;
|
|
|
|
Complex origine = new Complex(base.CSG.X, base.CSG.Y);
|
|
Complex Pointpied = new Complex(this.pied.CSG.X+x, this.pied.CSG.Y);
|
|
Pointpied = Pointpied - origine;
|
|
Complex Pointgenou;
|
|
double genouxX, genouY;
|
|
double a = Math.Pow(Pointpied.Real, 2) + Math.Pow(Pointpied.Imaginary, 2);
|
|
a /= 2 * Pointpied.Imaginary;
|
|
genouxX = 2 * a + 2 * Math.Sqrt(Math.Pow(a, 2)-lvertical);
|
|
genouxX /= 4;
|
|
genouY = a - genouxX;
|
|
Pointgenou = new Complex(genouxX, genouY);
|
|
angleJambe.AngleBassin += (float)Pointgenou.Phase;
|
|
Pointpied = Pointpied - Pointgenou;
|
|
angleJambe.AngleGenou += (float)Pointpied.Phase;
|
|
}
|
|
}
|
|
}
|