|
Revision 13041, 2.2 kB
(checked in by robert, 15 months ago)
|
|
Ran script to remove trailing spaces and tabs
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | #include <osg/LightSource> |
|---|
| 14 | |
|---|
| 15 | using namespace osg; |
|---|
| 16 | |
|---|
| 17 | LightSource::LightSource(): |
|---|
| 18 | _value(StateAttribute::ON), |
|---|
| 19 | _referenceFrame(RELATIVE_RF) |
|---|
| 20 | { |
|---|
| 21 | |
|---|
| 22 | setCullingActive(false); |
|---|
| 23 | setStateSet(new StateSet); |
|---|
| 24 | _light = new Light; |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | LightSource::~LightSource() |
|---|
| 29 | { |
|---|
| 30 | |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | void LightSource::setReferenceFrame(ReferenceFrame rf) |
|---|
| 34 | { |
|---|
| 35 | _referenceFrame = rf; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | void LightSource::setLight(Light* light) |
|---|
| 39 | { |
|---|
| 40 | _light = light; |
|---|
| 41 | setLocalStateSetModes(_value); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | void LightSource::setStateSetModes(StateSet& stateset,StateAttribute::GLModeValue value) const |
|---|
| 46 | { |
|---|
| 47 | if (_light.valid()) |
|---|
| 48 | { |
|---|
| 49 | stateset.setAssociatedModes(_light.get(),value); |
|---|
| 50 | } |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | void LightSource::setLocalStateSetModes(StateAttribute::GLModeValue value) |
|---|
| 54 | { |
|---|
| 55 | if (!_stateset) setStateSet(new StateSet); |
|---|
| 56 | |
|---|
| 57 | _stateset->clear(); |
|---|
| 58 | setStateSetModes(*_stateset,value); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | BoundingSphere LightSource::computeBound() const |
|---|
| 62 | { |
|---|
| 63 | BoundingSphere bsphere(Group::computeBound()); |
|---|
| 64 | |
|---|
| 65 | if (_light.valid() && _referenceFrame==RELATIVE_RF) |
|---|
| 66 | { |
|---|
| 67 | const Vec4& pos = _light->getPosition(); |
|---|
| 68 | if (pos[3]!=0.0f) |
|---|
| 69 | { |
|---|
| 70 | float div = 1.0f/pos[3]; |
|---|
| 71 | bsphere.expandBy(Vec3(pos[0]*div,pos[1]*div,pos[2]*div)); |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | return bsphere; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | void LightSource::setThreadSafeRefUnref(bool threadSafe) |
|---|
| 79 | { |
|---|
| 80 | Group::setThreadSafeRefUnref(threadSafe); |
|---|
| 81 | |
|---|
| 82 | if (_light.valid()) _light->setThreadSafeRefUnref(threadSafe); |
|---|
| 83 | } |
|---|