Pages : 1
#1 Le 31/05/2014, à 16:06
- ensberg
bibiothéque .a sous linux
s'il vous pait , j'ai une bibliothèque .a mais je ne sais pas comment faire le linker , parce-que mon code source ne reconnaît pas les fonctions
Hors ligne
#2 Le 31/05/2014, à 16:37
- pingouinux
Re : bibiothéque .a sous linux
Bonjour,
Si la librairie s'appelle /chemin_de_la_librairie/libmachin.a, ajouter ces paramètres à gcc :
gcc ..... -L/chemin_de_la_librairie -lmachin
Hors ligne
#3 Le 31/05/2014, à 17:39
- ensberg
Re : bibiothéque .a sous linux
Bonjour,
Si la librairie s'appelle /chemin_de_la_librairie/libmachin.a, ajouter ces paramètres à gcc :gcc ..... -L/chemin_de_la_librairie -lmachin
j'ai les fichier suivant :
VectorLib.a et VectorLib.o , et le fichier Formes.cpp c'est le fichier source que je veux exécuter
Hors ligne
#4 Le 31/05/2014, à 17:53
- pingouinux
Re : bibiothéque .a sous linux
Je suppose que VectorLib.a et VectorLib.o contiennent les mêmes fonctions.
Il faut d'abord compiler le fichier Formes.cpp. Si les 3 fichiers sont dans le même répertoire, tu te places dans ce répertoire, et tu lances cette commande
gcc -o Formes VectorLib.o Formes.cpp
Tu devrais obtenir un exécutable (Formes), à lancer ainsi
./Formes
Je pense que ceci devrait marcher aussi
gcc -o Formes VectorLib.a Formes.cpp
Hors ligne
#5 Le 31/05/2014, à 18:09
- ensberg
Re : bibiothéque .a sous linux
Je suppose que VectorLib.a et VectorLib.o contiennent les mêmes fonctions.
Il faut d'abord compiler le fichier Formes.cpp. Si les 3 fichiers sont dans le même répertoire, tu te places dans ce répertoire, et tu lances cette commandegcc -o Formes VectorLib.o Formes.cpp
Tu devrais obtenir un exécutable (Formes), à lancer ainsi
./Formes
Je pense que ceci devrait marcher aussi
gcc -o Formes VectorLib.a Formes.cpp
merci pour votre reponse j'ai éxécuter
gcc -o Formes VectorLib.o Formes.cpp
mais j'ai eu cette erreur :
chakib@chakib:~/vec$ gcc -o Formes VectorLib.o Formes.cpp
Formes.cpp:26:17: erreur: ‘VectLib’ is not a namespace-name
Formes.cpp:26:24: erreur: expected namespace-name before ‘;’ token
Formes.cpp:42:8: erreur: ‘Point’ does not name a type
Formes.cpp:43:8: erreur: ‘Point’ does not name a type
Formes.cpp:44:8: erreur: ‘Point’ does not name a type
Formes.cpp:45:8: erreur: ‘Point’ does not name a type
Formes.cpp:47:15: erreur: ‘Point’ was not declared in this scope
Hors ligne
#6 Le 31/05/2014, à 18:10
- ensberg
Re : bibiothéque .a sous linux
je pense qu'il faut faire un linker si j'ai bien compris le fonctionnement
Hors ligne
#7 Le 01/06/2014, à 12:29
- telliam
Re : bibiothéque .a sous linux
non là c'est des erreurs de codage ou d'inclusion de .h
"- Un intellectuel assis va moins loin qu'un con qui marche."
Maurice Biraud - Un Taxi pour Tobrouk
Michel Audiard
Hors ligne
#8 Le 01/06/2014, à 14:22
- ensberg
Re : bibiothéque .a sous linux
non là c'est des erreurs de codage ou d'inclusion de .h
mais le meme code marche sur visual studio , sans problème
Hors ligne
#9 Le 02/06/2014, à 15:10
- claudius01
Re : bibiothéque .a sous linux
Bonjour,
mais le même code marche sur visual studio, sans problème
Avec une connaissance desdits fichiers Formes.cpp et ses fichiers d'inclusion spécifiques .h ou .hpp, cela serait plus confortable pour t'aider...
NB: Les IDE comme Visual Studio et d'autres cachent plein de choses ce qui ne facilitent pas la portabilité vers d'autres plates-formes (voila pourquoi cela peu fonctionner ;-(
Cordialement, A+
--
Claudius
Hors ligne
#10 Le 02/06/2014, à 15:23
- ensberg
Re : bibiothéque .a sous linux
Bonjour,
ensberg a écrit :mais le même code marche sur visual studio, sans problème
Avec une connaissance desdits fichiers Formes.cpp et ses fichiers d'inclusion spécifiques .h ou .hpp, cela serait plus confortable pour t'aider...
NB: Les IDE comme Visual Studio et d'autres cachent plein de choses ce qui ne facilitent pas la portabilité vers d'autres plates-formes (voila pourquoi cela peu fonctionner ;-(
Cordialement, A+
--
Claudius
Merci je vais poster les codes alors
Hors ligne
#11 Le 02/06/2014, à 15:26
- ensberg
Re : bibiothéque .a sous linux
voici le .h de la bibliothèque VectorLib.h
#pragma once
namespace VectLib
{
class Point
{
public :
static float size;
double xval;
double yval;
double getx(void) ;
double gety(void) ;
void setx(int);
void sety(int);
void ini (int , int);
void afficherPoint() ;
Point(double x, double y)
{
xval = x; yval = y;
}
Point(){};
void setCoords(double x, double y)
{
xval = x; yval = y;
}
double getX() {
return xval;
}
double getY() {
return yval;
}
};
class Vecteur
{
public :
static double xval;
static double yval;
double getx(void) ;
double gety(void) ;
};
Vecteur initialiser(double x , double y );
Vecteur initialiserAvecPoint (Point a , Point b);
Point initialiserPoint (double x, double y);
void afficher(Vecteur v) ;
double norme (Vecteur v);
Vecteur additionner(Vecteur v1 ,Vecteur v2 );
Vecteur soustraction (Vecteur v1 ,Vecteur v2 );
double multiplication (Vecteur v1 ,Vecteur v2 );
double distancePoint(Point a, Point b);
double distancePointDroit(Point c, Point a, Point b);
double distanceSegement(Point c, Point a, Point b);
double operator * (Vecteur v, Vecteur w);
Vecteur operator + (Vecteur v, Vecteur w);
Vecteur operator - (Vecteur v, Vecteur w);
}
le fichier .cpp de la lib VectorLib.cpp
#include "VectorLib.h"
#include <cmath>
#include <iostream>
using namespace std;
namespace VectLib
{
double Vecteur::xval = 0;
double Vecteur::yval = 0;
//double Point::xval = 0;
//double Point::yval = 0;
//****************
void Point:: ini (int x ,int y){
xval=x;
yval=y;
}
//********************
void Point :: afficherPoint ( )
{
cout<<"le point "<<xval<<" , "<<yval<<endl;
}
//initialiser les coordonnées d'un Point
/** Point initialiserPoint (int x, int y)
{
Point p;
p.xval= x; p.yval = y;
cout<<"initialisation d'un Point "<<p.xval<<" et "<<p.yval<<endl ;
return p;
}*/
//initialiser un vecteur avec deux coordoonées
Vecteur initialiser(double x , double y )
{
Vecteur v;
v.xval=x;
v.yval=y;
cout<<" initialisation d'un vecteur "<<v.xval <<" et "<<v.yval<<endl ;
return v;
}
//initialiser un vecteur avec deux Points
Vecteur initialiserAvecPoint (Point a , Point b)
{
Vecteur v;
v.xval=b.xval-a.xval;
v.yval=b.yval-a.yval;
cout<<" initialisation d'un vecteur "<<v.xval <<" et "<<v.yval<<endl ;
return v;
}
//afficher un vecteur
void afficher(Vecteur v)
{
cout<<"les coordonnées du vecteur sont "<<v.xval <<" et "<<v.yval<<endl ;
}
//calculer la norme du vecteur
double norme (Vecteur v)
{
double norm(0) ;
double doubleer=(v.xval*v.xval)+(v.yval*v.yval);
norm=sqrt(doubleer);
return norm ;
}
//addition de deux vecteurs
Vecteur additionner(Vecteur v1 ,Vecteur v2 )
{
Vecteur v3 ;
v3.xval=v1.xval+v2.xval;
v3.yval=v1.yval+v2.yval;
return v3 ;
}
//soustraction de deux vecteur
Vecteur soustraction (Vecteur v1 ,Vecteur v2 )
{
Vecteur v3 ;
v3.xval=v1.xval-v2.xval;
v3.yval=v1.yval-v2.yval;
return v3 ;
}
// produit deux vecteurs
double multiplication (Vecteur v1 ,Vecteur v2 )
{
double produit =(v1.xval*v2.xval)+(v1.yval*v2.yval) ;
return produit ;
}
//multiplication par un chiffre
void multipilicationChiffre(Vecteur v, double d){
v.xval = v.xval*d;
v.yval = v.yval*d;
}
//prodiuit vectoriel
/**Vecteur mullitplicationVectorielle(Vecteur v, Vecteur w){
Vecteur z;
z.xval=v.yval *w.zval) - w.gety()*v.getz(),
v.getz()*w.getx() - w.getz()*v.getx(),
v.getx()*w.gety() - w.getx()*v.gety()
return z;
}
*/
//distance entre deux point
double distancePoint(Point a, Point b){
double distance(0);
distance = sqrt(((b.xval - a.xval)*(b.xval - a.xval)) + ((b.yval - a.yval)*(b.yval - a.yval)));
return distance;
}
//distance entre un point et une droit définie par deux point a et b
double distancePointDroit(Point c, Point a, Point b){
double distance(0);
double r(0);
double tailleAB(0);
//point de projection orthogonal
tailleAB = distancePoint(a, b);
r = ((c.xval - a.xval)*(b.yval - a.yval))/tailleAB;
Point p(a.xval + r*(b.xval - a.xval) ,a.yval + r*(b.yval - a.yval)) ;
distance = distancePoint(p, c);
return distance;
}
double distanceSegement(Point c, Point a, Point b){
double distance(0);
double r(0);
double s(0);
double tailleAB(0);
Vecteur AB, AC;
AB = initialiserAvecPoint(a, b);
AC = initialiserAvecPoint(a, c);
; //point de projection orthogonal
tailleAB = distancePoint(a, b);
r = multiplication(AC, AB) / pow(tailleAB, 2);
s = ((c.xval - a.xval)*(b.yval - a.yval)) / tailleAB;
Point p(a.xval + s*(b.xval - a.xval) ,a.yval + s*(b.yval - a.yval) );
if (r <= 0) { distance = distancePoint(p, a); }
else if (r >= 0){ distance = distancePoint(p, b); }
else distance = distancePointDroit( c, a, b);
return distance;
}
//surchargé les operateurs :
double operator * (Vecteur v, Vecteur w)
{
return multiplication(v, w);
}
Vecteur operator + (Vecteur v, Vecteur w)
{
return additionner(v, w);
}
Vecteur operator - (Vecteur v, Vecteur w){
return soustraction(v, w);
}
/** vecteur operator ^ (vecteur v, vecteur w) //produit vectoriel
{
vecteur z(
v.gety()*w.getz() - w.gety()*v.getz(),
v.getz()*w.getx() - w.getz()*v.getx(),
v.getx()*w.gety() - w.getx()*v.gety()
);
return(z);
}
*/
} //Fin du namespace
et la le code qui utilise la lib
#include <cstdlib>
#include <vector>
#include <iostream>
#include <algorithm>
#include <fstream>
#include "VectorLib.h"
#include <string>
#include <string.h>
#include <GL/glut.h>
#ifdef __APPLE__
# include <GLUT/glut.h>
#else
# include <GL/glut.h>
#endif
#ifdef __APPLE__
# include <GLUT/glut.h>
#else
# include <GL/glut.h>
#endif
#define _USE_MATH_DEFINES // for C++
#include <cmath>
#define M_PI 3.14159265358979323846
#include <iostream>
using namespace std;
using namespace VectLib;
// variable globale
static GLsizei width, height; // taille fenetre .
static float taillePoint = 3.0; // taille d'un point
static bool del(false);
static bool dessiner(true);
static bool fin(false);
static bool dessinerf(false);
static bool fichiervide;
static bool liens(false);
static bool cercle(false);
static bool pointsFormesbol(false);
static bool grille(false);
static double dist;
static bool arretdessin(false);
static Point A;
static Point B;
static Point C;
static Point V;
static int I;
static vector<Point> points;
static vector<int> tabrelation[100];
vector<Point> pointsFormes;
vector<int> relation;
static vector<bool> pointsselect;
vector<Point> pointsSupprimer;
vector<double> Listdistance;
vector<double> jambes1; //la forme de selection
vector<double> jambes2; //la forme de selection
static vector<Point> pts;
std::vector<double>::iterator it;
int centrex(50);
int centrey(50);
int rad(10);
static int numforme;
Point currentPoint;
Point inter;
string const nomFichier("Positions.txt");
float Point::size = taillePoint; // Set point size.
void DrawCircle(float cx, float cy, float r, int num_segments){
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINE_LOOP);
for (int ii = 0; ii < num_segments; ii++){
float theta = 2.0f * 3.1415926f * float(ii) / float(num_segments);//get the current angle
float x = r * cosf(theta);//calculate the x component
float y = r * sinf(theta);//calculate the y component
glVertex2f(x + cx, y + cy);//output vertex
}
glEnd();
}
// dessiner ligne :
void DrawLine(float cx, float cy){
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINES);
glVertex2f(cx, cy);//output vertex
glVertex2f(cx, cy);
glEnd();
}
// Fonction dessiner point .
void dessinerPoint(Point p) {
glPointSize(taillePoint);
glBegin(GL_POINTS);
glVertex3f(p.xval, p.yval, 0.0);
glEnd();
}
void VerifierSelection(){
Point centre(centrex, centrey);
for (int j = 0; j<points.size(); j++) {
dist = distancePoint(centre, points[j]);
if (dist < rad) {
pointsselect[j] = true;
glutPostRedisplay();
}
else pointsselect[j] = false;
}
}
double AngleEntrePoints(Point A, Point B, Point C) {
//cout << " le point c est " << C.xval << endl;
//cout << " le point a est " << A.xval << endl;
//cout << " le point b est " << B.xval << endl;
double b = distancePoint(A, C);
//cout << " distance b fonc " << b << endl;
double a = distancePoint(C, B);
//cout << " distance a fonc " << a << endl;
double c = distancePoint(B, A);
//cout << " distance c fonc " << c << endl;
double param1 = (pow(a, 2) + pow(b, 2) - pow(c, 2)) / (2 * b*a);
//cout << "le cos de l'angle fonct est de " << param1 << endl;
return acos(param1) * 180.0 / M_PI;
}
void TabLiens(){
for (int j = 0; j < points.size(); j++) {
if (pointsselect[j] == true) {
for (int unsigned i = 0; i < points.size(); i++) {
if (pointsselect[i] == true && j != i) {
tabrelation[j].push_back(i);
//cout << " le point " << j << " est relié avec " << tabrelation[j].size() << " points " << endl;
}
}
}
}
}
void Enregistrer(){
Point v(C.xval, A.yval);
ofstream monFlux(nomFichier.c_str(), ios::app);
monFlux.clear();
monFlux << "N " << points.size() << endl;
for (int i = 0; i<points.size(); i++) {
monFlux << points[i].xval << " " << 500 - points[i].yval;
if (tabrelation[i].size() != 0){ ////cout << " le point " << i << " est relier " << endl;
for (int j = 0; j < tabrelation[i].size(); j++){
monFlux << " " << tabrelation[i][j];
}
monFlux << endl;
}//fin de if
}//boucle Points
monFlux << "sc ";
for (int j = 0; j<jambes1.size(); j++) {
if (jambes1[j] == true)
monFlux << j << ",";
}
monFlux << endl;
monFlux << "sc ";
//jambes2
for (int j = 0; j<jambes2.size(); j++) {
if (jambes2[j] == true)
monFlux << j << ",";
}
monFlux << endl;
double resultat = AngleEntrePoints(A, B, C);
monFlux << "so " << I - 1 << "," << I << "," << I + 1 << ">>" << resultat << endl;
double resultat2 = AngleEntrePoints(A, V, C);
monFlux << "so " << I + 1 << "," << I << "," << "D" << ">>" << resultat2 << endl;
monFlux << "***************************************************" << endl;
}
//******** vider fichier **************************
void vider(){
ofstream monFlux(nomFichier.c_str(), ios::out);
monFlux.close();
}
//*********** verifier fichier ********************
bool FichierVide(){
bool vide = false;
string ligne;
ifstream monFlux("Positions.txt"); //Ouverture d'un fichier en lecture
if (monFlux)
{
getline(monFlux, ligne);
vide = ligne.empty();
}
else
{
//cout << "ERREUR: Impossible d'ouvrir le fichier en lecture." << endl;
}
return vide;
}
//*********************************************************
void drawGrid()
{
glColor3f(0, 255, 127);
glBegin(GL_LINES);
for (int i = 20; i < 800; i += 20){
glVertex2f(i, 0);
glVertex2f(i, 500);
}
for (int j = 20; j < 800; j += 20){
glVertex2f(0, j);
glVertex2f(500, j);
}
glEnd();
}
//*************************************************************************************************
int Split(vector<string>& vecteur, string chaine, char separateur)
{
vecteur.clear();
string::size_type stTemp = chaine.find(separateur);
while (stTemp != string::npos)
{
vecteur.push_back(chaine.substr(0, stTemp));
chaine = chaine.substr(stTemp + 1);
stTemp = chaine.find(separateur);
}
vecteur.push_back(chaine);
return vecteur.size();
}
//****************************************************************************************
vector<Point> LireLigne(int numLigne, int nbLigne){
vector<Point> liste;
Point Pointcourant;
vector<string> VecStr;
string ligne;
double x, y;
int compte = 0;
int compte2 = 0;
ifstream fichier("Positions.txt", ios::in); // on ouvre en lecture
if (fichier){
while (getline(fichier, ligne)) {
compte++;
if (compte >= numLigne){
//// // // cout << ligne << endl;
int nbTabl = Split(VecStr, ligne, ' ');
x = atoi(VecStr[0].c_str());
y = atoi(VecStr[1].c_str());
Pointcourant.ini(x, 500 - y);
//sPointcourant.ini(x,y);
liste.push_back(Pointcourant);
compte2++;
if (compte2 == nbLigne) break;
}
}
}
return liste;
}//************************************************************************************
void Ecrit(int numLigne, int nbLigne){
vector<Point> liste;
Point Pointcourant;
vector<string> VecStr;
string ligne;
double x, y;
int compte = 0;
int compte2 = 0;
ofstream ecrir("inter.txt", ios::out); // on ouvre en lecture
ifstream fichier("Positions.txt", ios::in); // on ouvre en lecture
if (fichier){
while (getline(fichier, ligne)) {
compte++;
if (compte >= numLigne && compte2<nbLigne){
ecrir << points[compte2].xval << " " << 500 - points[compte2].yval;
if (tabrelation[compte2].size() != 0){ ////cout << " le point " << i << " est relier " << endl;
for (int j = 0; j < tabrelation[compte2].size(); j++){
ecrir << " " << tabrelation[compte2][j];
}//fin for de j
ecrir << endl;
}//fin de if (tabrelation[compte2].size() != 0)
compte2++;
} // fi de if (compte >= numLigne && compte2<nbLigne)
else{ ecrir << ligne << endl; }
} // fin
}
}
//********* Fonction recopier ****************************************//
void recopie(){
string ligne;
ofstream ecrir("Positions.txt", ios::out); // on ouvre en lecture
ifstream fichier("inter.txt", ios::in); // on ouvre en lecture
if (fichier){
while (getline(fichier, ligne)) {
ecrir << ligne<<endl;
}
}
}
//********************* modifier ligne ************************************************
//************************ **********************************//
vector<Point> shape(int numshap)
{
vector<Point> liste;
int compteur = 0;
int egal = 45;
int compten = 0;
int nombredeLigne = 0;
vector<string> VecStr;
string ligne;
ifstream fichier("Positions.txt", ios::in);
if (fichier){
while (getline(fichier, ligne)) {
int nbTabl = Split(VecStr, ligne, ' ');
compteur++;
egal = strcmp(VecStr[0].c_str(), "N");
if (egal == 0){
compten++;
if (compten == numshap){
nombredeLigne = atoi(VecStr[1].c_str());
liste = LireLigne(compteur + 1, nombredeLigne);
}
}
}
}
return liste;
}
//*************** modifier forme **************************************
void ShapeModifie(int numshap)
{
vector<Point> liste;
int compteur = 0;
int egal = 45;
int compten = 0;
int nombredeLigne = 0;
vector<string> VecStr;
string ligne;
ifstream fichier("Positions.txt", ios::in);
if (fichier){
while (getline(fichier, ligne)) {
int nbTabl = Split(VecStr, ligne, ' ');
compteur++;
egal = strcmp(VecStr[0].c_str(), "N");
if (egal == 0){
compten++;
if (compten == numshap){
nombredeLigne = atoi(VecStr[1].c_str());
Ecrit(compteur + 1, nombredeLigne);
}
}
}
}
}
//***************************** Charger Fichier*****************************************************//
vector<Point> dessinerforme(int num) {
vector<Point> pts = shape(num);
glBegin(GL_POINTS);
glColor3f(1.0, 0.0, 0.0);
for (int i = 0; i< pts.size(); i++){
inter = pts[i];
//points.push_back(inter);
dessinerPoint(inter);
}
//glVertex2f(cx, cy);//output vertex
//glVertex2f(cx, cy);
glEnd();
return pts;
}
//*********************************************************
//
vector < vector<int> > Relation() {
vector<Point>liste = shape(1);
for (int i = 0; i<liste.size(); i++){
cout << " xx " << liste[i].xval << " yy " << liste[i].yval << endl;
}
cout << " la taile de la liste " << liste.size() << endl;
vector < vector<int> > relation;
vector<int> listepoints;
int i = 0;
vector<string> VecStr;
string ligne;
double x, y;
int indice;
ifstream fichier("Positions.txt", ios::in);
if (fichier){
cout << " je rentre dans le fichier " << endl;
getline(fichier, ligne);
cout << " la premiére ligne est " << ligne << endl;
while (getline(fichier, ligne)){
//cout<<" je rentre dans le while "<<endl;
int nbTabl = Split(VecStr, ligne, ' ');
x = atof(VecStr[0].c_str());
y = atof(VecStr[1].c_str());
cout << " x " << x << " y " << 500 - y << endl;
//cout<<" xx "<< liste[i].xval<< " yy "<< liste[i].yval <<endl;
if (x == liste[i].xval && 500 - y == liste[i].yval){
cout << " le point " << i << " " << liste[i].xval << " " << liste[i].yval << " " << "est relié avec" << " " << nbTabl - 2 << endl;
for (int j = 2; j<nbTabl; j++){
indice = atoi(VecStr[j].c_str());
cout << liste[indice].xval << " " << liste[indice].yval << endl;
listepoints.push_back(indice);
}
// fichier.close();
// // // cout<<" la taille de la liste "<<listepoints.size();
//// // cout<<endl;
relation.push_back(listepoints);
listepoints.clear();
// }//fin de
}//fin de while
i++; if (i == liste.size()) break;
}//fin de if
//
}//fin
return relation;
}
//************************************************************
void display_CB(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 0.0);
if (grille == true) drawGrid();
if (cercle == true) DrawCircle(centrex, centrey, rad, 50);
if (dessinerf == true) {
cout << "je rentre dans le if" << endl;
points = dessinerforme(numforme);
cout << "******* dessinerforme ******* la taille de vecteur points " << points.size() << endl;
for (int i = 0; i<points.size(); i++){
cout << " je rentre dans le for " << i << endl;
pointsselect.push_back(false);
// cout<<"la taille de la vectt "<<vectt.size();
}
vector < vector<int> > tabb = Relation();
cout << "la taille de la tabb " << tabb.size();
for (int i = 0; i<tabb.size(); i++){
tabrelation[i] = tabb[i];
}
}// fin de if (dessinerf == true)
dessinerf = false;
glColor3f(0.0, 0.0, 0.0);
//dessiner les points rouges de selection
glColor3f(0.0, 0.0, 0.0);
for (int unsigned i = 0; i<points.size(); i++) {
glColor3f(0.0, 0.0, 0.0);
inter = points[i];
if (pointsselect[i] == true) glColor3f(1, 0, 0);
// if (jambes1[i]==true || jambes2[i]==true) glColor3f(0,1, 0);
dessinerPoint(inter);
if (cercle == true) VerifierSelection();
//if (grille == true) { drawGrid(); }
}
fichiervide = FichierVide();
//if (fichiervide != true) //cout << " le fichier n'est pas vide " << endl;
for (int unsigned i = 0; i < points.size(); i++){
if (tabrelation[i].size() != 0) ////cout << " le point " << i << " est relier " << endl;
for (int j = 0; j < tabrelation[i].size(); j++){
////cout << " " << i << " " << tabrelation[i][j] << endl;
glBegin(GL_LINE_STRIP);
glColor3f(0.0, 0.0, 0.0);
glVertex2i(points[i].xval, points[i].yval);
glVertex2i(points[tabrelation[i][j]].xval, points[tabrelation[i][j]].yval);
glEnd();
}
}
// currentPoint.drawPoint();
glFlush();
}
// gestion de la souris .
void mouseControl(int button, int state, int x, int y)
{
// Store the clicked point in the currentPoint variable when left button is pressed.
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
currentPoint.ini(x, y);
cout << x << " , " << y << endl;
}
// Store the currentPoint in the points vector when left button is released.
if (button == GLUT_LEFT_BUTTON && state == GLUT_UP && dessiner == true && fin == false && pointsFormesbol == false && arretdessin == false)
{
points.push_back(currentPoint);
pointsselect.push_back(false);
jambes1.push_back(false);
jambes2.push_back(false);
}
else if (button == GLUT_LEFT_BUTTON && state == GLUT_UP && dessiner == false && pointsFormesbol == false)
pointsSupprimer.push_back(currentPoint);
glutPostRedisplay();
}
void mouse_move_CB(int x, int y)
{
centrex = x;
centrey = y;
glutPostRedisplay();
}
// initialisation .
void setup(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
}
//
void special_CB(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_UP: {for (int unsigned i = 0; i<points.size(); i++) {
if (pointsselect[i] == true) points[i].yval -= 5;
}
glutPostRedisplay();
break;
}
case GLUT_KEY_RIGHT: {for (int unsigned i = 0; i<points.size(); i++) {
if (pointsselect[i] == true) points[i].xval += 5;
}
glutPostRedisplay();
break;
}
case GLUT_KEY_DOWN: {for (int unsigned i = 0; i<points.size(); i++) {
if (pointsselect[i] == true) points[i].yval += 5;
}
glutPostRedisplay();
break;
}
case GLUT_KEY_LEFT: {for (int unsigned i = 0; i<points.size(); i++) {
if (pointsselect[i] == true) points[i].xval -= 5;
}
glutPostRedisplay();
break;
}
}
}
//gestion clavier
void keyboard_CB(unsigned char key, int x, int y)
{
if (key == 27) exit(0); // Touche Escape : quitter le programme
if (key == 32){
for (int j = 0; j<points.size(); j++) {
pointsselect[j] = false;
glutPostRedisplay();
}
}
if (key == 49) {
dessiner = false;
}
if (key == 97) {
cout << " affiche a ";
}
if (key == 70 || key == 102) {
fin = true;
glutPostRedisplay();
}
if (key == 86 || key == 118) {
vider();
}
if (key == 84 || key == 116) {
bool vid = FichierVide();
int g;
if (vid == true) g = 1; else g = 0;
////cout << " le fichier est vide " << vid << endl;
}
if (key == 83 || key == 115){
//pointsSupprimer
for (int i = 0; i <pointsSupprimer.size(); i++)
{
// //cout << "les points sup sont " << pointsSupprimer[i].xval << " , " << pointsSupprimer[i].yval << endl;
for (int j = 0; j<points.size(); j++) {
dist = distancePoint(pointsSupprimer[i], points[j]);
////cout << "la distance avec le point " << j << "egale a " << dist << endl;
Listdistance.push_back(dist);
}
double min = *std::min_element(Listdistance.begin(), Listdistance.end());
////cout << "le minim est " << min << endl;
it = find(Listdistance.begin(), Listdistance.end(), min);
int pos = std::find(Listdistance.begin(), Listdistance.end(), min) - Listdistance.begin();
////cout << "sa position est : " << pos + 1 << endl;;
points.erase(points.begin() + pos);
glutPostRedisplay();
}
}
if (key == 67 || key == 99) {
////cout << "appui sur ooooo";
cercle = true;
glutPostRedisplay();
}
if (key == 113 || key == 81){
rad += 10;
glutPostRedisplay();
}
if (key == 87 || key == 119){
rad -= 10;
glutPostRedisplay();
}
if (key == 88 || key == 120){
//cout << " j'appui sur le z " << endl;
Point centre(centrex, centrey);
for (int j = 0; j<points.size(); j++) {
dist = distancePoint(centre, points[j]);
if (dist < rad) {
points.erase(points.begin() + j);
j--;
glutPostRedisplay();
}
}
}
if (key == 68 || key == 100){
////cout <<" la valeur de 30 en radian est "<< 30*(M_PI/180)<<" " <<endl ;
for (int j = 0; j<points.size(); j++) {
if (pointsselect[j] == true) {
points[j].xval = (points[j].xval - centrex)*cosf((M_PI / 180)) - (points[j].yval - centrey)*sinf((M_PI / 180)) + centrex;
points[j].yval = (points[j].xval - centrex)*sinf((M_PI / 180)) + (points[j].yval - centrey)*cosf((M_PI / 180)) + centrey;
glutPostRedisplay();
}
}
}
if (key == 122 || key == 90){
//cout << "j'appui sur le z " << endl;
Point centre(centrex, centrey);
for (int j = 0; j<points.size(); j++) {
dist = distancePoint(centre, points[j]);
if (dist < rad) {
pointsselect[j] = true;
//cout << "j'ai changé la couleur du point " << j << endl;
glutPostRedisplay();
}
}
}
if (key == 80 || key == 112){
Enregistrer();
}
if (key == 69 && key == 101){
pointsFormesbol = true;
}
if (key == 82 || key == 114){
for (int i = 0; i<points.size(); i++) {
if (pointsselect[i] == true) jambes1[i] = true;
}
}
if (key == 108 || key == 76){
for (int i = 0; i<points.size(); i++) {
if (pointsselect[i] == true) jambes2[i] = true;
}
}
//touche y capteur angulaire
if (key == 89 || key == 121){
for (int i = 0; i<points.size(); i++) {
if (pointsselect[i] == true) {
I = i;
C = points[i];
A = points[i + 1];
B = points[i - 1];
V = Point(C.xval, A.yval);
double r2 = AngleEntrePoints(A, B, C);
double r3 = AngleEntrePoints(A, V, C);
////cout << " le point c est " << C.xval << endl;
////cout << " le point a est " << A.xval << endl;
////cout << " le point b est " << B.xval << endl;
double b = distancePoint(A, C);
////cout << " distance b fonc " << b << endl;
double a = distancePoint(C, B);
////cout << " distance a fonc " << a << endl;
double c = distancePoint(B, A);
////cout << " distance c fonc " << c << endl;
double param1 = (pow(a, 2) + pow(b, 2) - pow(c, 2)) / (2 * b*a);
// //cout << "le cos de l'angle est de " << param1 << endl;
// double result = acos(param1) * 180.0 / M_PI;
////cout << "arco " << result << endl;
//printf ("The arc cosine of %f is %f degrees.\n", param, result);
////cout<<"le point selectionné est "<< i <<" et " << i-1<<" et "<<i+1<< endl ;
//cout << "le resultat de la fonction est de " << r2 << endl;
//cout << "le resultat entre a c v " << r3 << endl;
}
}
}
// j arret dessin
if (key == 74 || key == 106){
arretdessin = true;
}
//***********************************************************************************************
//**** touche o pour modifier ************
if (key == 111 || key == 79){
cout << " ********** oo*********" << endl;
TabLiens();
liens = true;
}
//********* h h h dessiner la grille ************************************************
if (key == 72 || key == 104){
//cout << "*************** h """""""""""""" " << endl;
grille = true;
glutPostRedisplay();
}
//******************* u lire des formes ********************************************
if (key == 85 || key == 117){
cout << " selectionnez le numéro de la fomre " << endl;
cin >> numforme;
cout << " la forme choisie est " << numforme << endl;
//dessinerforme(pts);
dessinerf = true;
glutPostRedisplay();
}
//*************** enregistrer modification de forme *****************************************
if (key == 107 || key == 75){
ShapeModifie(2);
recopie();
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("dessiner");
setup();
glutDisplayFunc(display_CB);
glutKeyboardFunc(keyboard_CB);
glOrtho(0, 500, 500, 0, -1, 1);
glutMouseFunc(mouseControl);
glutSpecialFunc(special_CB);
glutMotionFunc(mouse_move_CB);
glutMainLoop();
return 0;
}
Hors ligne
Pages : 1