Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive body #1

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions src/creatureviewer/main_cw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ int main(int argc, char *argv[])
cw.showMaximized();
splash.finish(&cw);


// DOESN'T WORK ?!?
// First launch
QSettings mySettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void CreatureViewerWindow::init() {
// ------------------

// Welcome
WelcomeWidget *welcomeWidget = new WelcomeWidget();
WelcomeWidget *welcomeWidget = new WelcomeWidget(this);
welcomeWidget->setMaximumSize(400, 166725);
ui->dwWelcome->setWidget(welcomeWidget);

Expand All @@ -292,9 +292,10 @@ void CreatureViewerWindow::init() {
bonePropertiesController = new BonePropertiesController();
bonePropertiesController->connectToInspectorInputManager(cvim);
ui->dwBone->setWidget(bonePropertiesController);
simulationManager->addGraphicalWidget(bonePropertiesController);

// Stats
statsPropertiesController = new StatisticsPropertiesController();
statsPropertiesController = new StatisticsPropertiesController(this);
ui->dwStats->setWidget(statsPropertiesController);
statsPropertiesController->connectToInspectorInputManager(cvim);

Expand Down Expand Up @@ -360,7 +361,6 @@ void CreatureViewerWindow::init() {
//entitySpawner->start();
connect(entitySpawner, SIGNAL(timeout()), this, SLOT(spawnNew()));


switchToWelcomeMode();
}

Expand Down
1 change: 1 addition & 0 deletions src/genecraft/core/engines/bullet/shapes/btbone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void btBone::init(btScalar length,

this->rigidBody = new btRigidBody(mass,motionState,shape,localInertia);
this->rigidBody->setFriction(friction);
this->rigidBody->setActivationState(DISABLE_DEACTIVATION);
}

void btBone::setup()
Expand Down
4 changes: 0 additions & 4 deletions src/genecraft/core/engines/bullet/shapes/btbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ void btBox::init(btVector3 size, const btTransform &transform, const btScalar de

btScalar friction = 0.9;

qDebug() << transform.getOrigin().x();
qDebug() << transform.getOrigin().y();
qDebug() << transform.getOrigin().z();

// shape
this->shape = new btBoxShape(btVector3(size.x()/2.0,size.y()/2.0,size.z()/2.0));
this->motionState = new btDefaultMotionState(transform);
Expand Down
11 changes: 11 additions & 0 deletions src/genecraft/core/engines/simulationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ namespace GeneCraftCore {

if(fitness)
fitness->step();

}

void SimulationManager::renderUpdate() {
Expand All @@ -132,6 +133,12 @@ namespace GeneCraftCore {
this->eventsManager->afterStep();
//this->translationEngine->afterStep();
this->renderEngine->afterStep();

// Update some graphical widgets
foreach(GraphicalWidget* wi, graphWidgets) {
wi->step();
}

}

void SimulationManager::setPhysicsFreq(int stepBySec) {
Expand All @@ -140,5 +147,9 @@ namespace GeneCraftCore {
stepBySec = 1;
this->stepTimer->setInterval(1000/stepBySec);
}

void SimulationManager::addGraphicalWidget(GraphicalWidget *widget) {
this->graphWidgets.append(widget);
}
}

5 changes: 5 additions & 0 deletions src/genecraft/core/engines/simulationmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ along with Genecraft-Project. If not, see <http://www.gnu.org/licenses/>.

#include "genecraftcoreclasses.h"
#include "widgets/plot/fitnessplot.h"
#include "widgets/graphicalwidget.h"
#include <QObject>
#include <QMap>

#include <QTimer>
#include <QTime>
#include <QMutex>

namespace GeneCraftCore {

Expand All @@ -40,6 +42,7 @@ namespace GeneCraftCore {
SimulationManager(QMap<QString, Engine*>, QObject *parent = 0);

void addEngine(QString name, Engine *engine);
void addGraphicalWidget(GraphicalWidget* widget);
void removeEngine(QString name);

inline int getPhysicsFreq()
Expand Down Expand Up @@ -72,6 +75,8 @@ namespace GeneCraftCore {
Engine* translationEngine;
Engine* eventsManager;

QList<GraphicalWidget*> graphWidgets;

// Execution timer
int nbSteps;
int stepBySec;
Expand Down
4 changes: 4 additions & 0 deletions src/genecraft/core/engines/terrain/terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ namespace GeneCraftCore {
break;
}

if(x == 0 && z == 0)
y = 1;

btVector3 size(terrain->width, terrain->height + terrain->randomHeight, terrain->width);

btVector3 pos(x*terrain->width,
Expand Down Expand Up @@ -180,6 +183,7 @@ namespace GeneCraftCore {

void Terrain::removeTerrain(TerrainData* terrain) {
this->terrains.removeAll(terrain);
qDeleteAll(terrain->blocs);
delete terrain;
}
}
90 changes: 83 additions & 7 deletions src/genecraft/core/entities/body/bone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Bone::Bone(btShapesFactory *shapesFactory, btScalar yAxis, btScalar zAxis, btSca
: QObject(), yAxis(yAxis), zAxis(zAxis), parentFix(NULL), motorsEffector(NULL)
{


motorModifierData = QVariant();
parentCt = 0;
body = shapesFactory->createBone(length, radius, endFixRadius, initTransform);
Expand All @@ -63,6 +64,9 @@ Bone::Bone(btShapesFactory *shapesFactory, btScalar yAxis, btScalar zAxis, btSca
endFix = new Fixation(shapesFactory, rigidBody, endFixRadius, endTransform, this);

this->shapesFactory = shapesFactory;
this->ref = NULL;
this->sym = NULL;
this->rec = NULL;
}

Bone::~Bone()
Expand All @@ -76,13 +80,6 @@ Bone::~Bone()
}

void Bone::remove() {

// do it out of here, else bones are remove from fix and can't be deleted because we lose the pointer...
// if(parentFix != NULL) {
// parentFix->removeBone(this);
// parentFix = NULL;
// }

endFix->remove();
entity->removeLinksToEffector(this->motorsEffector);
disconnectMotor(0);
Expand Down Expand Up @@ -233,7 +230,28 @@ void Bone::connectMotor(int i)
// ----------------------

void Bone::setyAxis(btScalar yAxis) {

// Apply this to all referees
foreach(Bone* b, this->referees) {
b->setyAxis(yAxis);
}

// Do the local modification
QVariantMap localOrientation;
localOrientation["y"] = yAxis;
localOrientation["z"] = zAxis;

QVariantMap boneMap;
boneMap["endFix"] = QVariantMap(); // don't care
boneMap["localRotation"] = localOrientation;

foreach(GenomeModifier* modifier, this->usedModifiers) {
boneMap = modifier->modify(boneMap).toMap();
}

yAxis = boneMap["localRotation"].toMap()["y"].toFloat();
this->yAxis = yAxis;

btQuaternion local1;
local1.setRotation(btVector3(0, 1, 0), yAxis);
btQuaternion local2;
Expand All @@ -244,6 +262,30 @@ void Bone::setyAxis(btScalar yAxis) {
}

void Bone::setZAxis(btScalar zAxis) {
// Apply this to all referees
foreach(Bone* b, this->referees) {
b->setZAxis(zAxis);
}

// Do the local modification
QVariantMap localOrientation;
localOrientation["y"] = yAxis;
localOrientation["z"] = zAxis;

QVariantMap boneMap;
QVariantMap endMap;
endMap["radius"] = 0; // don't care
boneMap["endFix"] = endMap;
boneMap["localRotation"] = localOrientation;

foreach(GenomeModifier* modifier, this->usedModifiers) {
boneMap = modifier->modify(boneMap).toMap();
}

zAxis = boneMap["localRotation"].toMap()["z"].toFloat();
this->zAxis = zAxis;


this->zAxis = zAxis;
btQuaternion local1;
local1.setRotation(btVector3(0, 1, 0), yAxis);
Expand Down Expand Up @@ -390,6 +432,25 @@ void Bone::setSelected(bool selected)

void Bone::setSize(btScalar radius, btScalar length)
{
foreach(Bone* referee, referees) {
referee->setSize(radius, length);
}

// Calculate the new size
QVariantMap boneMap;
boneMap["length"] = length;
boneMap["radius"] = radius;
QVariantMap endFixMap;
endFixMap["radius"] = 0; // Don't care
boneMap["endFix"] = endFixMap;

foreach(GenomeModifier* modifier, this->usedModifiers) {
boneMap = modifier->modify(boneMap).toMap();
}

length = boneMap["length"].toFloat();
radius = boneMap["radius"].toFloat();

btScalar oldLength = this->getLength();
body->setSize(radius,length);

Expand All @@ -405,6 +466,21 @@ void Bone::setSize(btScalar radius, btScalar length)

void Bone::setEndFixationRadius(btScalar radius)
{

// Calculate the new size
QVariantMap boneMap;
boneMap["length"] = 0; // Don't care
boneMap["radius"] = 0; // Don't care
QVariantMap endFixMap;
endFixMap["radius"] = radius;
boneMap["endFix"] = endFixMap;

foreach(GenomeModifier* modifier, this->usedModifiers) {
boneMap = modifier->modify(boneMap).toMap();
}

radius = boneMap["endFix"].toMap()["radius"].toFloat();

body->setEndFixationRadius(radius);

// adapt children connections
Expand Down
36 changes: 36 additions & 0 deletions src/genecraft/core/entities/body/bone.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@ along with Genecraft-Project. If not, see <http://www.gnu.org/licenses/>.
#define BONE_H

#include <QObject>
#include <QDebug>
#include <QVariant>

#include "genecraftcoreclasses.h"
#include "BulletDynamics/Dynamics/btRigidBody.h"
#include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h"
#include "bullet/shapes/btbone.h"

#include "genome/genomemodifier.h"

#include "symmetry.h"
#include "recursion.h"

namespace GeneCraftCore {

class Symmetry;
class Recursion;

class Bone : public QObject
{

Expand All @@ -49,6 +58,7 @@ class Bone : public QObject
* @param initTransform the initial position of the muscle
*/
Bone(btShapesFactory *shapesFactory, btScalar yAxis, btScalar zAxis, btScalar radius, btScalar lenght, btScalar endFixRadius, const btTransform &initTransform);

/**
* @brief destruct and free used ressources
*
Expand Down Expand Up @@ -260,6 +270,24 @@ class Bone : public QObject
*/
void disconnectMotor(int i);

/**
Referent bone
*/
void setRef(Bone* ref) { this->ref = ref; }
Bone* getRef() { return this->ref;}
void addReferee(Bone* referee) { this->referees.prepend(referee); }
QList<Bone*> getReferees() { return this->referees; }

void setModifiers(QList<GenomeModifier*> modifiers) { this->usedModifiers.append(modifiers); qDebug() << "used: " << usedModifiers.size(); }

/**
Special genome element
*/
void setSymmetry(Symmetry* sym) { this->sym = sym; }
Symmetry* getSymmetry() { return this->sym; }
void setRecursion(Recursion* rec) { this->rec = rec; }
Recursion* getRecursion() { return this->rec; }

protected:

// Shape
Expand Down Expand Up @@ -288,6 +316,14 @@ class Bone : public QObject
// Shape factory
btShapesFactory* shapesFactory; /**< TODO */

// Referent bone
Bone* ref;
QList<Bone*> referees;
QList<GenomeModifier*> usedModifiers;

Symmetry* sym;
Recursion* rec;

};

}
Expand Down
7 changes: 0 additions & 7 deletions src/genecraft/core/entities/body/fixation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,4 @@ namespace GeneCraftCore {

return true;
}

// -----------
// -- UTILS --
// -----------
// btWorld *Fixation::getWorld() {
// return sphere->getWorld();
// }
}
9 changes: 9 additions & 0 deletions src/genecraft/core/entities/body/recursion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "recursion.h"
#include "bone.h"

namespace GeneCraftCore {
Recursion::Recursion(QObject *parent) :
QObject(parent)
{
}
}
Loading