2018-01-03 13:18:01 +01:00
|
|
|
|
/*
|
2018-01-09 20:19:49 +01:00
|
|
|
|
* Base des objets Bras et jambe
|
2018-01-03 13:18:01 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-01-05 01:51:12 +01:00
|
|
|
|
using System.Drawing;
|
2018-01-03 13:18:01 +01:00
|
|
|
|
using System.Linq;
|
2018-01-05 01:51:12 +01:00
|
|
|
|
using System.Numerics;
|
2018-01-03 13:18:01 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-01-04 14:03:06 +01:00
|
|
|
|
using System.Windows.Forms;
|
2018-01-03 13:18:01 +01:00
|
|
|
|
|
|
|
|
|
namespace Bonhomme02
|
|
|
|
|
{
|
2018-01-05 16:28:13 +01:00
|
|
|
|
class BaseBJ : Peau
|
2018-01-03 13:18:01 +01:00
|
|
|
|
{
|
2018-01-05 01:51:12 +01:00
|
|
|
|
enum Articulation { Epaule, Coude, Poignet, Bassin = Epaule, Genou = Coude, Cheville = Poignet };
|
2018-01-05 16:28:13 +01:00
|
|
|
|
public Peau Haut, Millieux, Bas;
|
2018-01-05 01:51:12 +01:00
|
|
|
|
double longueur;
|
2018-01-04 11:34:30 +01:00
|
|
|
|
public BaseBJ()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2018-01-05 12:19:46 +01:00
|
|
|
|
public BaseBJ(PictureBox Hebergeur, ref Peau parent, Peau bas, double longueur, double epaisseur, double angle) : this( Hebergeur, ref parent, longueur, epaisseur, angle)
|
2018-01-04 11:34:30 +01:00
|
|
|
|
{
|
2018-01-04 14:03:06 +01:00
|
|
|
|
this.Bas = bas;
|
|
|
|
|
this.Bas.parent = this.Millieux;
|
2018-01-05 12:19:46 +01:00
|
|
|
|
|
|
|
|
|
}
|
2018-01-05 16:28:13 +01:00
|
|
|
|
public BaseBJ(PictureBox Hebergeur, ref Peau parent, double longueur, double epaisseur, double angle) : base(Hebergeur, ref parent, longueur / 2, epaisseur, angle)
|
2018-01-05 12:19:46 +01:00
|
|
|
|
{
|
|
|
|
|
this.parent = parent;
|
|
|
|
|
this.longueur = longueur;
|
2018-01-05 16:28:13 +01:00
|
|
|
|
this.Haut = this;
|
2018-01-05 12:19:46 +01:00
|
|
|
|
this.Millieux = new Peau(Hebergeur, ref this.Haut, longueur / 2, epaisseur, angle);
|
2018-01-09 20:19:49 +01:00
|
|
|
|
|
2018-01-04 14:03:06 +01:00
|
|
|
|
}
|
2018-01-09 20:19:49 +01:00
|
|
|
|
|
2018-01-05 16:28:13 +01:00
|
|
|
|
public new void Afficher(IntPtr handle)
|
2018-01-04 14:03:06 +01:00
|
|
|
|
{
|
2018-01-05 22:18:28 +01:00
|
|
|
|
if(base.Visible)
|
|
|
|
|
{
|
|
|
|
|
Haut.Afficher(handle);
|
|
|
|
|
Millieux.Afficher(handle);
|
|
|
|
|
Bas.Afficher(handle);
|
|
|
|
|
}
|
2018-01-09 20:19:49 +01:00
|
|
|
|
|
2018-01-04 11:34:30 +01:00
|
|
|
|
}
|
2018-01-05 16:28:13 +01:00
|
|
|
|
public new void Cacher(IntPtr handle)
|
2018-01-05 01:51:12 +01:00
|
|
|
|
{
|
|
|
|
|
Haut.Cacher(handle);
|
|
|
|
|
Millieux.Cacher(handle);
|
|
|
|
|
Bas.Cacher(handle);
|
|
|
|
|
}
|
2018-01-09 20:19:49 +01:00
|
|
|
|
public new void Afficher(Graphics gr)
|
|
|
|
|
{
|
|
|
|
|
if(base.Visible)
|
|
|
|
|
{
|
|
|
|
|
Haut.Afficher(gr);
|
|
|
|
|
Millieux.Afficher(gr);
|
|
|
|
|
Bas.Afficher(gr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public new void Cacher(Graphics gr)
|
|
|
|
|
{
|
|
|
|
|
Haut.Cacher(gr);
|
|
|
|
|
Millieux.Cacher(gr);
|
|
|
|
|
Bas.Cacher(gr);
|
|
|
|
|
}
|
2018-01-05 01:51:12 +01:00
|
|
|
|
public double TrouverAngleHaut(Point pt)
|
|
|
|
|
{
|
|
|
|
|
Point ptOrigine = parent.Coordonnee + parent.longueur;
|
|
|
|
|
Complex vecteur = new Complex(pt.X- ptOrigine.X, pt.Y- ptOrigine.Y);
|
|
|
|
|
return vecteur.Phase;
|
|
|
|
|
}
|
|
|
|
|
public double TrouverAngleMillieux(Point pt)
|
|
|
|
|
{
|
|
|
|
|
Point ptOrigine = Millieux.Coordonnee;
|
|
|
|
|
Complex vecteur = new Complex(pt.X - ptOrigine.X, pt.Y - ptOrigine.Y);
|
|
|
|
|
return vecteur.Phase;
|
|
|
|
|
}
|
|
|
|
|
public Point TouverPointMillieux(Point bas)
|
|
|
|
|
{
|
2018-01-05 12:19:46 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Point H = Haut.Coordonnee;
|
|
|
|
|
//Point M = new Point() ; //Inconnue
|
2018-01-05 16:28:13 +01:00
|
|
|
|
Point B = new Point(bas.X - H.X, bas.Y - H.Y); //On part du principe que H est 0;0 , on rapatrie donc B pour que se soit le cas
|
2018-01-05 01:51:12 +01:00
|
|
|
|
|
2018-01-05 12:19:46 +01:00
|
|
|
|
Complex tt = new Complex(B.X, B.Y);
|
2018-01-05 01:51:12 +01:00
|
|
|
|
|
2018-01-05 12:19:46 +01:00
|
|
|
|
double a = Math.Sqrt(4 * Math.Pow(Haut.longueur.ABS, 2) - Math.Pow(B.X, 2) - Math.Pow(B.Y, 2));
|
|
|
|
|
double b = Math.Sqrt(Math.Pow(B.X, 2) + Math.Pow(B.Y, 2));
|
2018-01-05 01:51:12 +01:00
|
|
|
|
|
2018-01-05 12:19:46 +01:00
|
|
|
|
double cooMX = (B.Y * a + B.X * b);
|
|
|
|
|
cooMX /= 2 * b;
|
|
|
|
|
double cooMY = -(B.X * a - B.Y * b);
|
|
|
|
|
cooMY /= 2 * b;
|
2018-01-05 01:51:12 +01:00
|
|
|
|
|
2018-01-05 12:19:46 +01:00
|
|
|
|
Complex t = new Complex(cooMX, cooMY);
|
|
|
|
|
cooMX += H.X;
|
|
|
|
|
cooMY += H.Y;
|
|
|
|
|
int xx = (int)Math.Round(cooMX);
|
|
|
|
|
int yy = (int)Math.Round(cooMY);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
if(Double.IsNaN(a) || Double.IsNaN(b))
|
|
|
|
|
{
|
|
|
|
|
return Millieux.Coordonnee;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return new Point(xx, yy);
|
2018-01-05 12:19:46 +01:00
|
|
|
|
}
|
|
|
|
|
catch(Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Erreur Point millieux : " + e);
|
|
|
|
|
return new Point(0, 0);
|
|
|
|
|
}
|
2018-01-05 01:51:12 +01:00
|
|
|
|
}
|
2018-01-06 16:56:46 +01:00
|
|
|
|
public void BougerBas(int X, int Y)
|
2018-01-05 01:51:12 +01:00
|
|
|
|
{
|
|
|
|
|
Point nouveauPtBas = new Point(Bas.X + X, Bas.Y + Y);
|
|
|
|
|
Point nouveauPtMillieux = TouverPointMillieux(nouveauPtBas);
|
2018-01-05 12:19:46 +01:00
|
|
|
|
if(nouveauPtMillieux.X != 0 || nouveauPtMillieux.Y != 0)
|
2018-01-05 01:51:12 +01:00
|
|
|
|
{
|
|
|
|
|
Haut.Angle = TrouverAngleHaut(nouveauPtMillieux);
|
|
|
|
|
Millieux.Angle = TrouverAngleMillieux(nouveauPtBas);
|
2018-01-09 20:19:49 +01:00
|
|
|
|
}
|
2018-01-05 01:51:12 +01:00
|
|
|
|
}
|
2018-01-06 16:56:46 +01:00
|
|
|
|
public void BougerXHaut(int x, ref Bonhomme bonhomme)
|
|
|
|
|
{
|
|
|
|
|
Point oldPtBas = Bas.Coordonnee;
|
|
|
|
|
Vecteur oldVecteurHautBas = new Vecteur(Bas.Coordonnee, Haut.Coordonnee);
|
|
|
|
|
Vecteur newVecteurHautBas;
|
|
|
|
|
Point newCooHaut = TrouverPointSurCerlceSelonX(Bas.Coordonnee, oldVecteurHautBas.ABS, Haut.Coordonnee.X + x);
|
|
|
|
|
bonhomme.Coordonnee = new Point(newCooHaut.X, (int)Math.Round(newCooHaut.Y - bonhomme.longueur.ABS));
|
|
|
|
|
|
|
|
|
|
Point nouveauPtMillieux = TouverPointMillieux(oldPtBas);
|
|
|
|
|
if (nouveauPtMillieux.X != 0 || nouveauPtMillieux.Y != 0)
|
|
|
|
|
{
|
|
|
|
|
Haut.Angle = TrouverAngleHaut(nouveauPtMillieux);
|
|
|
|
|
Millieux.Angle = TrouverAngleMillieux(oldPtBas);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-05 22:18:28 +01:00
|
|
|
|
public void SetAngle(double h, double m, double b)
|
|
|
|
|
{
|
|
|
|
|
Haut.Angle = h;
|
|
|
|
|
Millieux.Angle = m;
|
|
|
|
|
Bas.Angle = b;
|
|
|
|
|
}
|
2018-01-06 16:56:46 +01:00
|
|
|
|
public Point TrouverPointSurCerlceSelonX(Point centre, double rayon, int nouveauX)
|
|
|
|
|
{
|
|
|
|
|
double racine = Math.Sqrt(rayon * rayon - nouveauX * nouveauX + 2 * centre.X * nouveauX - centre.X * centre.X);
|
|
|
|
|
double y = -(racine - centre.Y);
|
|
|
|
|
return new Point(nouveauX, (int)Math.Round(y));
|
|
|
|
|
}
|
2018-01-03 13:18:01 +01:00
|
|
|
|
}
|
|
|
|
|
}
|