//Main
int main(int argc, char *argv[])
{
SoOneShotSensor *sensor = new SoOneShotSensor (simulationStep, NULL);
root->ref();
myObject = new genObject();
myObject->buildtree(root);
//Update Scene
sensor->schedule();
...
}
//simulationStep
void simulationStep(void *data, SoSensor *sensor)
{
...
SbVec3f *cameraPosition = new SbVec3f
(myPerspectiveCamera->position.getValue()[0],
myPerspectiveCamera->position.getValue()[1], myPerspectiveCamera->position.getValue()[2]);
myObject->setScale(cameraPosition);
myObject->buildtree(root);
sensor->schedule();
}
//myObject->setScale(cameraPosition)
void genObject::setScale(SbVec3f *cameraPosition)
{
this->cameraPosition = cameraPosition;
SbVec3f tempPos = SbVec3f(this->getLatitude(),
this->getAltitude(),
this->getLongitude());
if (tempPos.length() == 0)
{
this->scaleFactor = 1;
} else
{
this->newScaleFactor = cameraPosition->length() / tempPos.length();
this->scaleFactor = this->newScaleFactor;
}
}
//myObject->buildtree(root)
void genObject:: buildtree(SoSeparator *root)
{
this->group = new SoSeparator();
root->addChild(this->group);
this->model = new SoFile;
model->name.setValue("OwnObject.iv");
...
this->size = new SoScale();
this->size->scaleFactor.setValue(this->getScale(), this->getScale(), this->getScale());
this->group->addChild(this->size);
this->group->addChild(model);
};
//genObject
#pragma once
class genObject
{
private:
float altitude;
float latitude;
float longitude;
float scaleFactor;
float newScaleFactor;
SbVec3f *cameraPosition;
SoSeparator *group;
SoScale *size;
SoFile *model;
public:
genObject();
void setAltitude(float alt);
void setLongitude(float lon);
void setLatitude(float lat);
void setScale(SbVec3f *cameraPosition);
void buildtree(SoSeparator *root);
float getAltitude() {return this->altitude;}
float getLongitude(){return this->longitude;}
float getLatitude() {return this->latitude;}
float getScale() {return this->scaleFactor;}
public:
~genObject(void);
};