Skip to content

Commit

Permalink
animation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
underdoeg committed Jul 10, 2014
1 parent fcf3aa3 commit d2f3c40
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 23 deletions.
2 changes: 1 addition & 1 deletion example/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void ofApp::setup() {
file.load("test.blend");
file.exportStructure();
scene = file.getScene(0);
//scene->setDebug(true);
scene->setDebug(true);
scene->timeline.play();
//scene->timeline.setLoop(true);
//scene->timeline.setEndless(true);
Expand Down
15 changes: 10 additions & 5 deletions src/Animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void Timeline::setTime(unsigned long long t) {
//timeOld = time;
return;
}

Timeline* _this = this;
ofNotifyEvent(preFrame, _this);

Expand Down Expand Up @@ -168,20 +168,25 @@ std::vector<Marker> Timeline::getMarkers() {
return markers;
}

void Timeline::clear() {
for(Animation_* anim: animations) {
anim->clear();
}
}

//check if animation exists
bool Timeline::hasAnimation(string key) {
for(Animation_* anim:animations){
if(anim->address == key){
for(Animation_* anim:animations) {
if(anim->address == key) {
return true;
}
}
return false;
}

bool Timeline::hasAnimation(string key, int channel) {
for(Animation_* anim:animations){
if(anim->channel == channel && anim->address == key){
for(Animation_* anim:animations) {
if(anim->channel == channel && anim->address == key) {
return true;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ class Timeline {
void setDuration(double duration);
void setLoop(bool loopState);
void setEndless(bool endlessState);
void clear();

bool isAnimating();
bool hasAnimation(string key);
Expand Down
10 changes: 6 additions & 4 deletions src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Camera::~Camera() {

void Camera::preDraw() {
setLens(lens);
//updateCamPos();
}

void Camera::customDraw() {
Expand All @@ -30,16 +31,17 @@ void Camera::customDraw() {
}

void Camera::onOrientationChanged() {
Object::onOrientationChanged();
camera.setOrientation(getGlobalOrientation());
//Object::onOrientationChanged();
//camera.setOrientation(getGlobalOrientation());
}

void Camera::onPositionChanged() {
Object::onPositionChanged();
camera.setPosition(getGlobalPosition());
//Object::onPositionChanged();
//camera.setPosition(getGlobalPosition());
}

void Camera::updateCamPos() {
camera.setTransformMatrix(getGlobalTransformMatrix());
}

void Camera::setLens(float l) {
Expand Down
4 changes: 2 additions & 2 deletions src/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class Camera: public ofx::blender::Object {
void setLens(float lens);
float getLens();
void updateLens();
void updateCamPos();
void animateLensTo(float targetLens, float duration, InterpolationType interpolation=LINEAR);
ofCamera camera;
private:
void preDraw();

void onAnimationDataFloat(float value, string address, int channel);
void updateCamPos();

ofMesh debugMesh;
float lens;
};
Expand Down
36 changes: 25 additions & 11 deletions src/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,43 @@ void Object::draw(Scene* scn) {
if(!layer->isVisible())
return;
}

preDraw();

ofNode::transformGL();
customDraw();
ofNode::restoreTransformGL();

for(Object* child: children) {
child->draw(scn);
}

postDraw();
}

void Object::customDraw() {
}

void Object::addChild(Object* child, bool keepGlobalTransform) {
if(hasChild(child))
return;
child->parent = this;
child->setParent(*this, keepGlobalTransform);
children.push_back(child);
}

void Object::removeChild(Object* child) {
if(!hasChild(child))
return;

child->clearParent();
children.erase(std::remove(children.begin(), children.end(), child), children.end());
}

bool Object::hasChild(Object* obj) {
return (std::find(children.begin(), children.end(), obj) != children.end());
}

std::vector<Object*> Object::getChildren() {
return children;
}
Expand Down Expand Up @@ -104,7 +118,7 @@ void Object::toggleVisibility() {
show();
}

void Object::setVisible(bool state){
void Object::setVisible(bool state) {
if(state)
show();
else
Expand Down Expand Up @@ -270,21 +284,21 @@ void Object::animateScaleTo(ofVec3f scale, float duration, InterpolationType int

ofVec2f Object::getPositionOnScreen(ofRectangle viewport) {
ofVec2f ret;
if(!scene){
if(!scene) {
ofLogWarning(OFX_BLENDER) << "Object::getPositionOnScreen - scene not set";
return ret;
}
if(scene->isDebugEnabled()){

if(scene->isDebugEnabled()) {
return scene->getDebugCamera()->worldToScreen(getGlobalPosition(), viewport);
}

Camera* cam = scene->getActiveCamera();
if(!cam){
if(!cam) {
ofLogWarning(OFX_BLENDER) << "Object::getPositionOnScreen - scene not set";
return ret;
}

return cam->camera.worldToScreen(getGlobalPosition(), viewport);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class Object: public ofNode {
virtual void postDraw(){};

void addChild(Object* child, bool keepGlobalTransform=false);
void removeChild(Object* child);
bool hasChild(Object* obj);

std::vector<Object*> getChildren();
Object* getParent();
bool hasParent();
Expand Down
1 change: 1 addition & 0 deletions src/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void Scene::customDraw() {
ofCamera* camera = &debugCam;
if(activeCamera){

activeCamera->updateCamPos();
activeCamera->updateLens();

if(!doDebug)
Expand Down

0 comments on commit d2f3c40

Please # to comment.