Commit f741d976 authored by lapupe's avatar lapupe
Browse files

ok

parent 0341d42e
......@@ -12,7 +12,7 @@ LIBS += -L ../lib \
-lcsg \
-limage \
-lvectorMatrix \
# -lparticle
-lparticle
......
......@@ -114,12 +114,12 @@ void MainWindow::createPrimtive()
m_prim = static_cast<csgPrimitive*> (crp);
}
m_tree.addPrimitive(m_currentNode);
BoundingBox bbox = m_currentNode->bbox_();
/*BoundingBox bbox = m_currentNode->bbox_();
Vec2f haut_doite = bbox.pos_haut_droite_();
Vec2f bas_gauche = bbox.pos_bas_gauche_();
std::cout << haut_doite[0] << " " << haut_doite[1] << std::endl;
std::cout << bas_gauche[0] << " " << bas_gauche[1] << std::endl;
*/
drawTree();
ui->currentNode->setValue(m_currentNode->getId()); // recupere l'id du noeud cree
updateTextGraph();
......@@ -146,11 +146,11 @@ void MainWindow::createOperation()
case 0:
oper = new csgOperation("union", UNION, m_tree.getNode(left), m_tree.getNode(right));
break;
case 1:
case 1:
oper = new csgOperation("intersection", INTERSECTION, m_tree.getNode(left), m_tree.getNode(right));
break;
case 2:
oper = new csgOperation("intersection", DIFFERENCE, m_tree.getNode(left), m_tree.getNode(right));
break;
default:
std::cerr << "unknown operation" << std::endl;
......@@ -161,12 +161,12 @@ void MainWindow::createOperation()
m_tree.joinPrimitive(oper);
m_tree.afficheTree();
drawTree();
BoundingBox bbox = oper->bbox_();
/*BoundingBox bbox = oper->bbox_();
Vec2f haut_doite = bbox.pos_haut_droite_();
Vec2f bas_gauche = bbox.pos_bas_gauche_();
std::cout << haut_doite[0] << " " << haut_doite[1] << std::endl;
std::cout << bas_gauche[0] << " " << bas_gauche[1] << std::endl;
*/
if (oper != NULL)
ui->currentNode->setValue(oper->getId());
......@@ -212,7 +212,13 @@ void MainWindow::transfoChanged()
{
// recupere la primitive courante et lui applique les transformations
// VOTRE CODE ICI
m_prim->translation(Vec2f(ui->translationX->value(), ui->translationY->value()));
if(ui->translationX->value() != 0 || ui->translationY->value() != 0) {
m_prim->translation(Vec2f(ui->translationX->value(), ui->translationY->value()));
}
if(ui->rotation->value() != 0) {
csgRegularPolygon *crp = static_cast<csgRegularPolygon*>(m_prim);
crp->rotation(ui->rotation->value());
}
// Option: de même avec un noeud Operation !
......@@ -220,8 +226,10 @@ void MainWindow::transfoChanged()
drawTree();
ui->dsb_tx->setValue(0);
ui->dsb_ty->setValue(0);
ui->dsb_Rot->setValue(0);
ui->translationX->setValue(0);
ui->translationY->setValue(0);
ui->rotation->setValue(0);
}
#define S1_FACTOR 10.0
......@@ -309,6 +317,7 @@ void MainWindow::saveImage()
{
std::string strFN = fileName.toStdString();
std::cout << "Save "<< strFN << "not implemented" << std::endl;
m_render->saveTexture(strFN);
}
}
......@@ -384,9 +393,27 @@ void MainWindow::clearCSG()
void MainWindow::clone()
{
// VOTRE CODE ICI
Particule p;
p.setPos_courante_(Vec2f(50, 0));
p.setDate_(100);
while(p.date_() < 20000 ) {
if ((p.date_() % 1000) == 0) {
//std::cout << "date : " << m_parti_test.date_() << std::endl;
//std::cout << "position courante : " << m_parti_test.pos_courante_()[0] << " " << m_parti_test.pos_courante_()[1] << std::endl;
}
p.calculPosFuture();
p.calculVitFuture();
m_render->setPixel(p.pos_courante_()[0], p.pos_courante_()[1], 0 );
m_render->setPixel(p.pos_courante_()[0], p.pos_courante_()[1], 250 );
p.validPosition();
p.setDate_(p.date_() + 100);
drawTree();
}
updateTextGraph();
drawTree();
//updateTextGraph();
//drawTree();
}
......
......@@ -43,7 +43,9 @@ void RenderImg::loadTexture(const std::string& filename)
glBindTexture(GL_TEXTURE_2D, 0);
}
void RenderImg::saveTexture(const std::string& filename) {
m_imgGrey_.sauvegarderPgm(filename);
}
void RenderImg::updateDataTexture()
{
......@@ -275,14 +277,24 @@ void RenderImg::drawSobel()
}
glEnd();
}
Particule RenderImg::parti_test() const
{
return m_parti_test;
}
void RenderImg::setParti_test(const Particule &parti_test)
{
m_parti_test = parti_test;
}
/*
void RenderImg::drawBB(const BoundingBox& bb)
{
glBegin(GL_LINE_LOOP);
glColor3f(1.0f,0.5f,0.5f);
glBegin(GL_LINE_LOOP);
glColor3f(1.0f,0.5f,0.5f);
// glVertex2f( xImg2GL(??), yImg2GL(??) );
// glVertex2f( xImg2GL(??), yImg2GL(??) );
// glVertex2f( xImg2GL(??), yImg2GL(??) );
......@@ -294,3 +306,22 @@ void RenderImg::drawBB(const BoundingBox& bb)
void RenderImg::setPixel(int x, int y, int value) {
m_imgGrey_.setPixel(x, y, value);
}
void RenderImg::boucleParticule() {
m_parti_test.setPos_courante_(Vec2f(50, 0));
m_parti_test.setDate_(100);
while(m_parti_test.date_() < 50000 ) {
if ((m_parti_test.date_() % 1000) == 0) {
std::cout << "date : " << m_parti_test.date_() << std::endl;
std::cout << "position courante : " << m_parti_test.pos_courante_()[0] << " " << m_parti_test.pos_courante_()[1] << std::endl;
}
m_parti_test.calculPosFuture();
m_parti_test.calculVitFuture();
this->setPixel(m_parti_test.pos_courante_()[0], m_parti_test.pos_courante_()[1], 0 );
this->setPixel(m_parti_test.pos_courante_()[0], m_parti_test.pos_courante_()[1], 250 );
m_parti_test.validPosition();
m_parti_test.setDate_(m_parti_test.date_() + 100);
}
}
......@@ -5,7 +5,7 @@
#include "image2grey.h"
//#include "vec2f.h"
//#include "particle.h"
#include "particule.h"
//forward declaration
class BoundingBox;
......@@ -19,7 +19,8 @@ public:
~RenderImg();
void loadTexture(const std::string& filename);
void updateDataTexture();
void saveTexture(const std::string& filename);
void updateDataTexture();
Image2Grey & getImg();
unsigned int getWidth();
......@@ -39,12 +40,17 @@ public:
void setBBDraw(bool v) { m_BBdraw = v;}
void boucleParticule();
Particule parti_test() const;
void setParti_test(const Particule &parti_test);
protected:
/// Qt callbacks
void initializeGL();
void paintGL();
void resizeGL(int width, int height);
/// Qt callbacks
void initializeGL();
void paintGL();
void resizeGL(int width, int height);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent* event);
......@@ -100,6 +106,9 @@ protected:
// la fontaine de particule
// Fountain fountain;
Particule m_parti_test;
};
#endif // RENDERIMG_H
......@@ -13,6 +13,8 @@ csgOperation::csgOperation(char *label, Operation op, csgNode *cn1, csgNode* cn2
this->setBbox_(cn1->bbox_() + cn2->bbox_());
} else if (op == INTERSECTION) {
this->setBbox_(cn1->bbox_() ^ cn2->bbox_());
}else {
this->setBbox_(cn1->bbox_() - cn2->bbox_());
}
std::cout << "Noeud csgOperation : " << m_label_ << " " << m_id_ << " est construit !!!" << std::endl;
......@@ -80,7 +82,7 @@ bool csgOperation::intersect(Vec2f v) {
} else {
if(m_fils_gauche_->intersect(v) && m_fils_droit_->intersect(v)) {
return false;
} else {
} else if (m_fils_gauche_->intersect(v) || m_fils_droit_->intersect(v)){
return true;
}
}
......
......@@ -115,8 +115,59 @@ void csgRegularPolygon::translation(Vec2f trans) {
m_tab_sommet_[i][0] = new3f[0]/new3f[2];
m_tab_sommet_[i][1] = new3f[1]/new3f[2];
m_bbox_ = this->calculeBoundingBox();
}
m_bbox_ = this->calculeBoundingBox();
}
Vec2f csgRegularPolygon::getBarycentre() {
int i;
Vec2f barycentre;
barycentre[0] = 0;
barycentre[1] = 0;
for (i = 0; i < m_nbface_; i++) {
barycentre[0] += m_tab_sommet_[i][0];
barycentre[1] += m_tab_sommet_[i][1];
}
barycentre[0] = barycentre[0]/m_nbface_;
barycentre[1] = barycentre[1]/m_nbface_;
/*printf("x = %d\n", barycentre->x);
printf("y = %d\n", barycentre->y);*/
return barycentre;
}
void csgRegularPolygon::rotation(float angle) {
Vec3f new3f;
Vec2f transInverse = this->getBarycentre();
std::cout << transInverse[0] << " " << transInverse[1] << std::endl;
for (int i = 0; i < m_nbface_; i++) {
m_matrix_.setTranslation(-transInverse[0], -transInverse[1]);
new3f = m_matrix_.MulVec3f(Vec3f(m_tab_sommet_[i],1));
//std::cout << "ici" << new3f[0] << " " << new3f[1] << std::endl;
m_matrix_.setRotation(angle);
new3f = m_matrix_.MulVec3f(new3f);
//std::cout << new3f[0] << " " << new3f[1] << std::endl;
m_matrix_.setTranslation(transInverse[0], transInverse[1]);
new3f = m_matrix_.MulVec3f((new3f));
//std::cout << new3f[0] << " " << new3f[1] << std::endl;
m_tab_sommet_[i][0] = new3f[0]/new3f[2];
m_tab_sommet_[i][1] = new3f[1]/new3f[2];
}
/*for(int i = 0; i < m_nbface_; i++) {
std::cout << m_tab_sommet_[i][0] << " " << m_tab_sommet_[i][1] << std::endl;
}*/
m_bbox_ = this->calculeBoundingBox();
}
......
......@@ -32,6 +32,10 @@ public:
bool intersect(Vec2f p);
void translation(Vec2f trans);
void rotation(float angle);
Vec2f getBarycentre();
};
#endif // CSGREGULARPOLYGON_H
#include "csgTree.h"
#include "csgOperation.h"
std::set<csgNode *> csgTree::csgTreeSet_() const
{
return m_csgTreeSet_;
}
void csgTree::setCsgTreeSet_(const std::set<csgNode *> &csgTreeSet_)
{
m_csgTreeSet_ = csgTreeSet_;
}
csgTree::csgTree() {
}
void csgTree::addPrimitive(csgNode *cn) {
m_csgTreeSet_.insert(cn);
m_csgTreeMap_.insert(std::pair<int, csgNode*>(cn->getId(), cn));
}
void csgTree::joinPrimitive(csgNode *cn) {
std::set<csgNode*>::iterator it;
csgOperation *co = static_cast<csgOperation*>(cn);
it = m_csgTreeSet_.find(co->getFilsDroit());
//std::cout << (*it)->getLabel() << ' ' << (*it)->getId() << ' ';
m_csgTreeSet_.erase(*it);
it = m_csgTreeSet_.find(co->getFilsGauche());
//std::cout << (*it)->getLabel() << ' ' << (*it)->getId() << ' ';
m_csgTreeSet_.erase(*it);
m_csgTreeSet_.insert(cn);
}
void csgTree::afficheTree() {
std::set<csgNode*>::iterator it = m_csgTreeSet_.begin();
/*for(it = m_csgTreeSet_.begin(); it != m_csgTreeSet_.end(); it++) {
std::cout << *it.getId() << std::endl;
}*/
/*for (int i = 0; i < m_csgTreeSet_.size(); i++) {
std::cout << m_csgTreeSet_[i]->getId() << std::endl;
}*/
for (it= m_csgTreeSet_.begin(); it!=m_csgTreeSet_.end(); ++it)
std::cout << (*it)->getLabel() << ' ' << (*it)->getId() << ' ';
std::cout << std::endl;
}
csgNode* csgTree::getNode(int id) {
csgNode * cn;
cn = m_csgTreeMap_.find(id)->second;
return cn;
}
#ifndef CSGTREE_H
#define CSGTREE_H
#include <set>
#include <map>
#include "csgNode.h"
class csgTree {
protected:
std::set<csgNode*> m_csgTreeSet_;
std::map<int, csgNode*> m_csgTreeMap_;
public:
csgTree();
void addPrimitive(csgNode *cn);
void joinPrimitive(csgNode *cn);
void afficheTree();
std::set<csgNode *> csgTreeSet_() const;
void setCsgTreeSet_(const std::set<csgNode *> &csgTreeSet_);
csgNode* getNode(int id);
};
#endif // CSGTREE_H
......@@ -14,3 +14,9 @@ LIBS += -L ../lib -limage -lvectorMatrix
#HEADERS += *.h
DESTDIR = ../lib
SOURCES += \
particule.cpp
HEADERS += \
particule.h
#include "particule.h"
#include <math.h>
Vec2f Particule::pos_courante_() const
{
return m_pos_courante_;
}
void Particule::setPos_courante_(const Vec2f &pos_courante_)
{
m_pos_courante_ = pos_courante_;
}
Vec2f Particule::pos_future_() const
{
return m_pos_future_;
}
void Particule::setPos_future_(const Vec2f &pos_future_)
{
m_pos_future_ = pos_future_;
}
double Particule::vit_courante_() const
{
return m_vit_courante_;
}
void Particule::setVit_courante_(double vit_courante_)
{
m_vit_courante_ = vit_courante_;
}
double Particule::vit_future_() const
{
return m_vit_future_;
}
void Particule::setVit_future_(double vit_future_)
{
m_vit_future_ = vit_future_;
}
int Particule::date_() const
{
return m_date_;
}
void Particule::setDate_(int date_)
{
m_date_ = date_;
}
Particule::Particule() {
m_date_ = 0;
m_vit_courante_ = 1;
}
void Particule::calculVitFuture() {
int date = m_date_/1000;
m_vit_future_ = m_vit_courante_ + GRAVITY * date;
}
void Particule::calculPosFuture() {
m_pos_future_[0] = m_pos_courante_[0];
int date = m_date_/1000;
m_pos_future_[1] = m_pos_courante_[1] + m_vit_courante_ * date + (1/2) * GRAVITY * pow(date,2);
std::cout << m_pos_future_[1] << std::endl;
}
void Particule::validPosition() {
m_pos_courante_= m_pos_future_;
m_vit_future_ = m_vit_courante_;
}
#ifndef PARTICULE_H
#define PARTICULE_H
#include "vec2f.h"
#define GRAVITY 0.0981
class Particule {
protected:
Vec2f m_pos_courante_;
Vec2f m_pos_future_;
double m_vit_courante_;
double m_vit_future_;
int m_date_;
public :
Particule();
void calculVitFuture();
void calculPosFuture();
void validPosition();
Vec2f pos_courante_() const;
void setPos_courante_(const Vec2f &pos_courante_);
Vec2f pos_future_() const;
void setPos_future_(const Vec2f &pos_future_);
double vit_courante_() const;
void setVit_courante_(double vit_courante_);
double vit_future_() const;
void setVit_future_(double vit_future_);
int date_() const;
void setDate_(int date_);
};
#endif // PARTICULE_H
......@@ -63,9 +63,13 @@ void Matrix33f::print() {
//Set & apply transltaion
void Matrix33f::setTranslation(float tx, float ty) {
m_data_[0] = 1;
m_data_[1] = 0;
m_data_[2] = tx;
m_data_[3] = 0;
m_data_[4] = 1;
m_data_[5] = ty;
m_data_[6] = 0;
m_data_[7] = 0;
m_data_[8] = 1;
}
......@@ -98,8 +102,12 @@ Matrix33f& Matrix33f::applyTranslation(const Matrix33f& m) {
void Matrix33f::setRotation(float angle) {
m_data_[0] = cos(angle);
m_data_[1] = -sin(angle);
m_data_[2] = 0;
m_data_[3] = sin(angle);
m_data_[4] = cos(angle);
m_data_[5] = 0;
m_data_[6] = 0;
m_data_[7] = 0;
m_data_[8] = 1;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment