Skip to content

Commit

Permalink
added Object::getPositionOnScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
underdoeg committed Jun 28, 2014
1 parent 4881af5 commit 8d1dc1f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
Binary file modified example/bin/data/test.blend
Binary file not shown.
1 change: 0 additions & 1 deletion src/Animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ void Timeline::setTime(unsigned long long t) {
stop();
}
}

for(Marker& marker: markers) {
if(timeOld < marker.time && time > marker.time) {
markerTriggered(marker.name);
Expand Down
21 changes: 20 additions & 1 deletion src/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ void Object::animateTo(Object* obj, float duration, InterpolationType interpolat
animatePositionTo(obj->getPosition(), duration, interpolation);
animateRotationTo(obj->getOrientationQuat(), duration, interpolation);
animateScaleTo(obj->getScale(), duration, interpolation);

}

void Object::animatePositionTo(ofVec3f pos, float duration, InterpolationType interpolation) {
Expand All @@ -258,5 +257,25 @@ void Object::animateScaleTo(ofVec3f scale, float duration, InterpolationType int
timeline.animateTo(getScale(), scale, duration, "scale", 0, interpolation);
}

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

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

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

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

}
}
2 changes: 2 additions & 0 deletions src/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class Object: public ofNode {
void animateRotationTo(ofQuaternion rot, float time, InterpolationType interpolation=LINEAR);
void animateScaleTo(ofVec3f scale, float time, InterpolationType interpolation=LINEAR);

ofVec2f getPositionOnScreen(ofRectangle viewport = ofGetCurrentViewport());

string name;
ObjectType type;
Timeline timeline;
Expand Down
24 changes: 13 additions & 11 deletions src/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@ void Scene::customDraw() {

ofEnableDepthTest();

//update the material properties
//update the material properties
//TODO: could be optimized

for(Material* material: materials){
for(Material* material: materials) {
material->lights = lights;
material->isLightningEnabled = doLightning;
}

//lights
if(doLightning) {

if(lights.size()>0) {
ofSetSmoothLighting(true);
ofEnableLighting();
}

for(Light* light: lights) {
light->begin();
}
Expand Down Expand Up @@ -132,23 +132,23 @@ void Scene::customDraw() {

//end the camera
camera->end();


}

void Scene::addObject(Object* obj) {
if(std::find(objects.begin(), objects.end(), obj) != objects.end()){
if(std::find(objects.begin(), objects.end(), obj) != objects.end()) {
return;
}

objects.push_back(obj);
timeline.add(&obj->timeline);

switch(obj->type) {
case MESH:
meshes.push_back(static_cast<Mesh*>(obj));
for(Material* material: meshes.back()->materials){

for(Material* material: meshes.back()->materials) {
if(material && std::find(materials.begin(), materials.end(), material)==materials.end())
materials.push_back(material);
}
Expand Down Expand Up @@ -229,6 +229,10 @@ Camera* Scene::getActiveCamera() {
return activeCamera;
}

ofCamera* Scene::getDebugCamera() {
return &debugCam;
}

Light* Scene::getLight(string name) {
return getFromVecByName<Light>(lights, name);
}
Expand All @@ -248,5 +252,3 @@ void Scene::setLightningEnabled(bool state) {

}
} //end namespace


1 change: 1 addition & 0 deletions src/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Scene: public ofNode{
void setLightningEnabled(bool state);

Camera* getActiveCamera();
ofCamera* getDebugCamera();
void setActiveCamera(Camera* cam);
void disableCamera();

Expand Down

0 comments on commit 8d1dc1f

Please # to comment.