| Line |
Branch |
Exec |
Source |
| 1 |
|
|
// |
| 2 |
|
|
// leaf-node-light.cpp |
| 3 |
|
|
// gepetto-viewer |
| 4 |
|
|
// |
| 5 |
|
|
// Created by Justin Carpentier, Mathieu Geisert in November 2014. |
| 6 |
|
|
// Copyright (c) 2014 LAAS-CNRS. All rights reserved. |
| 7 |
|
|
// |
| 8 |
|
|
|
| 9 |
|
|
#include <gepetto/viewer/leaf-node-light.h> |
| 10 |
|
|
|
| 11 |
|
|
#include <osgDB/ReadFile> |
| 12 |
|
|
|
| 13 |
|
|
namespace gepetto { |
| 14 |
|
|
namespace viewer { |
| 15 |
|
|
|
| 16 |
|
|
/* Declaration of private function members */ |
| 17 |
|
|
|
| 18 |
|
|
int LeafNodeLight::uniqueLightNumber = 1; |
| 19 |
|
|
|
| 20 |
|
✗ |
void LeafNodeLight::init() { |
| 21 |
|
|
/* Create light object */ |
| 22 |
|
✗ |
::osg::LightRefPtr light = new ::osg::Light(); |
| 23 |
|
✗ |
light->setLightNum(uniqueLightNumber++); |
| 24 |
|
✗ |
light->setPosition(osgVector4(0.0, 0.0, 0.0, 1.0)); |
| 25 |
|
✗ |
light->setDiffuse(osgVector4(0, 0, 0, 1)); |
| 26 |
|
✗ |
light->setSpecular(osgVector4(1.0, 1.0, 1.0, 1.0)); |
| 27 |
|
✗ |
light->setAmbient(osgVector4(0.0, 0.0, 0.0, 1.0)); |
| 28 |
|
✗ |
light_ptr_ = new ::osg::LightSource(); |
| 29 |
|
✗ |
light_ptr_->setLight(light); |
| 30 |
|
|
|
| 31 |
|
✗ |
addProperty( |
| 32 |
|
✗ |
Vector4Property::create("ColorSpecular", |
| 33 |
|
✗ |
Vector4Property::getterFromMemberFunction( |
| 34 |
|
|
light.get(), &osg::Light::getSpecular), |
| 35 |
|
✗ |
Vector4Property::setterFromMemberFunction( |
| 36 |
|
|
light.get(), &osg::Light::setSpecular))); |
| 37 |
|
✗ |
addProperty( |
| 38 |
|
✗ |
Vector4Property::create("ColorAmbient", |
| 39 |
|
✗ |
Vector4Property::getterFromMemberFunction( |
| 40 |
|
|
light.get(), &osg::Light::getAmbient), |
| 41 |
|
✗ |
Vector4Property::setterFromMemberFunction( |
| 42 |
|
|
light.get(), &osg::Light::setAmbient))); |
| 43 |
|
✗ |
addProperty( |
| 44 |
|
✗ |
Vector4Property::create("ColorDiffuse", |
| 45 |
|
✗ |
Vector4Property::getterFromMemberFunction( |
| 46 |
|
|
light.get(), &osg::Light::getDiffuse), |
| 47 |
|
✗ |
Vector4Property::setterFromMemberFunction( |
| 48 |
|
|
light.get(), &osg::Light::setDiffuse))); |
| 49 |
|
|
|
| 50 |
|
|
/* Create PositionAttitudeTransform */ |
| 51 |
|
✗ |
this->asQueue()->addChild(light_ptr_); |
| 52 |
|
|
} |
| 53 |
|
|
|
| 54 |
|
✗ |
LeafNodeLight::LeafNodeLight(const std::string& name, const float& radius) |
| 55 |
|
✗ |
: LeafNodeSphere(name, radius) { |
| 56 |
|
✗ |
init(); |
| 57 |
|
✗ |
setColor(osgVector4(1., 1., 1., 1.)); |
| 58 |
|
|
} |
| 59 |
|
|
|
| 60 |
|
✗ |
LeafNodeLight::LeafNodeLight(const std::string& name, const float& radius, |
| 61 |
|
✗ |
const osgVector4& color) |
| 62 |
|
✗ |
: LeafNodeSphere(name, radius, color) { |
| 63 |
|
✗ |
init(); |
| 64 |
|
✗ |
setColor(color); |
| 65 |
|
|
} |
| 66 |
|
|
|
| 67 |
|
✗ |
LeafNodeLight::LeafNodeLight(const std::string& name, |
| 68 |
|
✗ |
const LeafNodeLight& other) |
| 69 |
|
✗ |
: LeafNodeSphere(name, other) { |
| 70 |
|
✗ |
init(); |
| 71 |
|
✗ |
setColor(other.getColor()); |
| 72 |
|
|
} |
| 73 |
|
|
|
| 74 |
|
✗ |
void LeafNodeLight::initWeakPtr(LeafNodeLightWeakPtr other_weak_ptr) { |
| 75 |
|
✗ |
LeafNodeSphere::initWeakPtr(other_weak_ptr); |
| 76 |
|
✗ |
weak_ptr_ = other_weak_ptr; |
| 77 |
|
|
} |
| 78 |
|
|
|
| 79 |
|
|
/* End of declaration of private function members */ |
| 80 |
|
|
|
| 81 |
|
|
/* Declaration of protected function members */ |
| 82 |
|
|
|
| 83 |
|
✗ |
LeafNodeLightPtr_t LeafNodeLight::create(const std::string& name, |
| 84 |
|
|
const float& radius) { |
| 85 |
|
✗ |
LeafNodeLightPtr_t shared_ptr(new LeafNodeLight(name, radius)); |
| 86 |
|
|
|
| 87 |
|
|
// Add reference to itself |
| 88 |
|
✗ |
shared_ptr->initWeakPtr(shared_ptr); |
| 89 |
|
|
|
| 90 |
|
✗ |
return shared_ptr; |
| 91 |
|
|
} |
| 92 |
|
|
|
| 93 |
|
✗ |
LeafNodeLightPtr_t LeafNodeLight::create(const std::string& name, |
| 94 |
|
|
const float& radius, |
| 95 |
|
|
const osgVector4& color) { |
| 96 |
|
✗ |
LeafNodeLightPtr_t shared_ptr(new LeafNodeLight(name, radius, color)); |
| 97 |
|
|
|
| 98 |
|
|
// Add reference to itself |
| 99 |
|
✗ |
shared_ptr->initWeakPtr(shared_ptr); |
| 100 |
|
|
|
| 101 |
|
✗ |
return shared_ptr; |
| 102 |
|
|
} |
| 103 |
|
|
|
| 104 |
|
✗ |
LeafNodeLightPtr_t LeafNodeLight::createCopy(LeafNodeLightPtr_t other) { |
| 105 |
|
✗ |
LeafNodeLightPtr_t shared_ptr(new LeafNodeLight(*other)); |
| 106 |
|
|
|
| 107 |
|
|
// Add reference to itself |
| 108 |
|
✗ |
shared_ptr->initWeakPtr(shared_ptr); |
| 109 |
|
|
|
| 110 |
|
✗ |
return shared_ptr; |
| 111 |
|
|
} |
| 112 |
|
|
|
| 113 |
|
|
/* End of declaration of protected function members */ |
| 114 |
|
|
|
| 115 |
|
|
/* Declaration of public function members */ |
| 116 |
|
|
|
| 117 |
|
✗ |
LeafNodeLightPtr_t LeafNodeLight::clone(void) const { |
| 118 |
|
✗ |
return LeafNodeLight::createCopy(weak_ptr_.lock()); |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
✗ |
LeafNodeLightPtr_t LeafNodeLight::self(void) const { return weak_ptr_.lock(); } |
| 122 |
|
|
|
| 123 |
|
✗ |
void LeafNodeLight::setColor(const osgVector4& color) { |
| 124 |
|
✗ |
light_ptr_->getLight()->setDiffuse(color); |
| 125 |
|
✗ |
LeafNodeSphere::setColor(color); |
| 126 |
|
✗ |
setDirty(); |
| 127 |
|
|
} |
| 128 |
|
|
|
| 129 |
|
✗ |
void LeafNodeLight::setRoot(GroupNodePtr_t root) { |
| 130 |
|
✗ |
light_ptr_->setLocalStateSetModes(::osg::StateAttribute::ON); |
| 131 |
|
✗ |
light_ptr_->setStateSetModes(*root->getOrCreateRootStateSet(), |
| 132 |
|
|
::osg::StateAttribute::ON); |
| 133 |
|
✗ |
setDirty(); |
| 134 |
|
|
} |
| 135 |
|
|
|
| 136 |
|
✗ |
LeafNodeLight::~LeafNodeLight() { |
| 137 |
|
✗ |
this->asQueue()->removeChild(geode_ptr_); |
| 138 |
|
✗ |
geode_ptr_ = NULL; |
| 139 |
|
|
|
| 140 |
|
✗ |
weak_ptr_.reset(); |
| 141 |
|
|
} |
| 142 |
|
|
|
| 143 |
|
|
/* End of declaration of public function members */ |
| 144 |
|
|
|
| 145 |
|
|
} /* namespace viewer */ |
| 146 |
|
|
|
| 147 |
|
|
} /* namespace gepetto */ |
| 148 |
|
|
|