Skip to content

Commit

Permalink
add gldisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
julien.rodriguez-tao committed Oct 21, 2017
1 parent 8b9eabd commit 3ffd3a1
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 98 deletions.
16 changes: 13 additions & 3 deletions cell.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
#ifndef CELL_H
#define CELL_H

#include <vector>
using namespace std;

#include "linkcell.h"
class Cell;

class LinkCell
{
public:
int typ;//0 rigid 1 free 2 actif
Cell *c;
LinkCell(Cell *_c, int _typ) :c(_c),typ(_typ) {}
};

class Cell
{
public:

vector<Cell*> stator;
vector<Cell*> rotor;
vector<LinkCell*> stator;
vector<LinkCell*> rotor;

int id;
float px,py,diameter;
Expand Down
55 changes: 37 additions & 18 deletions celldrawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,38 @@ class CellDrawer

}

void drawQuiver (Cell *c, Cell *d, float c1, float c2, float c3)
{
float px=d->px - c->px;
float py=d->py - c->py;
float pd=sqrt(px*px+py*py);
px/=pd/c1;
py/=pd/c1;

glBegin(GL_LINES);

glVertex3f(c->px,c->py,0.0f);
glVertex3f(d->px-px*(2),d->py-py*(2),0.0f);



glVertex3f(d->px-px,d->py-py,0.0f); glVertex3f(d->px+py*c3-px*c2,d->py-px*c3-py*c2,0.0f);

glVertex3f(d->px-px,d->py-py,0.0f); glVertex3f(d->px-py*c3-px*c2,d->py+px*c3-py*c2,0.0f);


glVertex3f(d->px+py*c3-px*c2,d->py-px*c3-py*c2,0.0f);
glVertex3f(d->px-py*c3-px*c2,d->py+px*c3-py*c2,0.0f);

glEnd();


}

void draw(CellManager *cm)
{
int i,j;
float px,py,pd;
Cell *c;
for (i=0; i<cm->nodes.size(); i++)
{
Expand All @@ -45,33 +74,23 @@ class CellDrawer
glBegin(GL_LINES);
for (j=0; j<c->stator.size(); j++)
{
glVertex3f(c->px,c->py,0.0f);
glVertex3f(c->stator[j]->px,c->stator[j]->py,0.0f);
drawQuiver(c,c->stator[j]->c,4,2,2);

}
glEnd();

glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_LINES);
for (j=0; j<c->rotor.size(); j++)
{
glVertex3f(c->px,c->py,0.0f);
glVertex3f(c->rotor[j]->px,c->rotor[j]->py,0.0f);
}
glEnd();
}
if (c->rotor[j]->typ==1)
glColor3f(0.2f,0.7f,0.7f);
else
glColor3f(0.8f,0.2f,0.2f);


drawQuiver(c,c->rotor[j]->c,12,2,1);

/*int i;
for (i=0; i<cell->stator.size(); i++)
{
draw(cm->cell->stator[i]);
}
}
for (i=0; i<cell->rotor.size(); i++)
{
draw(cell->rotor[i]);
}*/
}

CellDrawer();
Expand Down
20 changes: 13 additions & 7 deletions cellmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

CellManager::CellManager() : GeneticLowlevelGrammar()
{
initLLcmdsz ();
initLLcmds ();
cmdnm.push_back("cellgen ");
cmdsz.push_back(3);
cmdnm.push_back("celllink ");
Expand All @@ -17,26 +17,32 @@ CellManager::CellManager() : GeneticLowlevelGrammar()

void CellManager::makeLink(int idcell, int mld1, int mld2)
{

if (mld2<0) return;
if (mld2>=nodes.size()) return;


switch (mld1)
{
case 0:
{
nodes[idcell]->stator.push_back( nodes[mld2] );
nodes[idcell]->stator.push_back(new LinkCell(nodes[mld2],mld1) );

} break;

case 1:
{
nodes[idcell]->rotor.push_back( nodes[mld2] );
nodes[idcell]->rotor.push_back(new LinkCell(nodes[mld2],mld1) );

} break;

/*case 2:
case 2:
{
nodes[idcell]->rotor.push_back(new LinkCell(nodes[mld2],mld1) );

} break;

case 3:
/*case 3:
{
} break;*/
Expand All @@ -61,15 +67,15 @@ int CellManager::TranslateHLCode(GeneticBase *gb, int idcell)
float dia = gb->data[3]+ad+12;
Cell *nc=new Cell(nodes.size(),apx+cos(ang)*(dia),apy+sin(ang)*(dia),12);
nodes.push_back(nc);
makeLink(idcell,gb->data[1],nodes.size()-1);
//makeLink(idcell,gb->data[1],nodes.size()-1);
return 0;
}
break;

case 3://generate new link from active cell to cell (uint)*(data+2)
{

makeLink(idcell,gb->data[1],gb->data[2]);
makeLink(idcell,gb->data[1],idcell+gb->data[2]);
return 0;
}
break;
Expand Down
41 changes: 41 additions & 0 deletions geneticdata.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
#include "geneticdata.h"



GeneticLowlevelGrammar::GeneticLowlevelGrammar()
{
}

void GeneticLowlevelGrammar::initLLcmds ()
{
cmdnm.push_back("cmdend ");
cmdsz.push_back(0);
cmdnm.push_back("cmdifmv ");
cmdsz.push_back(2);

}

int GeneticLowlevelGrammar::TranslateLLCode(GeneticBase *gb, int idcmd, int idcell)
{
switch (gb->data[0])
{
case 0://end transcription
{
return 256;
}
break;

case 1://test and branch instruction
{
if (idcell<*(gb->data+1))
return *(gb->data+2);
else
return 1;
}
break;

default: //high level command
return 1;
break;
}

}
48 changes: 4 additions & 44 deletions geneticdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ class GeneticData
public:

deque<GeneticBase*> data;

GeneticData()
{

}

GeneticData() {}
};

class GeneticLowlevelGrammar
Expand All @@ -40,45 +35,10 @@ class GeneticLowlevelGrammar
public :


GeneticLowlevelGrammar()
{
}

void initLLcmdsz ()
{
cmdnm.push_back("cmdend ");
cmdsz.push_back(0);
cmdnm.push_back("cmdifmv ");
cmdsz.push_back(2);

}

int TranslateLLCode(GeneticBase *gb, int idcmd, int idcell)
{
switch (gb->data[0])
{
case 0://end transcription
{
return 256;
}
break;

case 1://test and branch instruction
{
if (idcell<*(gb->data+1))
return *(gb->data+2);
else
return 1;
}
break;

default: //high level command
return 1;
break;
}

}
GeneticLowlevelGrammar();

void initLLcmds ();
int TranslateLLCode(GeneticBase *gb, int idcmd, int idcell);
};

#endif // GENETICDATA_H
6 changes: 0 additions & 6 deletions linkcell.cpp

This file was deleted.

15 changes: 0 additions & 15 deletions linkcell.h

This file was deleted.

9 changes: 4 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
#include "cellmanager.h"
#include "celldrawer.h"


// example dvlpt genetic code
vector<int8_t> rv={2,0,0,25, 3,1,1, 4,1, 2,0,-10,25, 2,0,10,25, 3,0,1, 3,0,2, 2,0,0,100, 3,1,3, 4,1, 3,2,2, 4,1, 3,2,1, 1,7,-11, 0};

CellManager cellmanager;
GeneticData *geneticdata;

CellDrawer celldrawer;

void renderScene() // this function is called when you need to redraw the scene
Expand Down Expand Up @@ -88,10 +91,6 @@ void reshapeScene(int w, int h)

void init() // called to glEnable features or to init display lists
{
// raw genetic code
vector<int8_t> rv={2,0,-10,25, 2,0,10,25, 2,0,0,50, 4,3, 2,1,0,75, 4,1, 1,5,-6, 0};

// asm genetic code
geneticdata = new GeneticData();
// asm parser
cellmanager.geneticDataFromRawCode(geneticdata,rv);
Expand Down

0 comments on commit 3ffd3a1

Please sign in to comment.