source: Swollen/swollen/directionallight.cpp @ 100

Last change on this file since 100 was 88, checked in by darran, 19 years ago
  • Commented out lighting marker pending removal (not a good paradigm)
  • Commented out "picture in picture" hack
  • compiles against OSG 0.9.9 on OSX, can't get focus on window and doesn't accept keyboard input
File size: 1.7 KB
Line 
1
2#include <math.h>
3#include <directionallight.h>
4#include <osg/Texture2D>
5// #include <osg/ShapeDrawable>
6// #include <osgDB/ReadFile>
7
8#include <iostream>
9
10// #define DEF_DEFAULT_CYLINDER_RADIUS 0.25
11// #define DEF_DEFAULT_CYLINDER_HEIGHT 0.50
12
13
14
15DirectionalLight::DirectionalLight(osg::StateSet* rootStateSet, int num)
16{
17    // positioning container
18    _transform = new osg::MatrixTransform;
19    _transform->setCullingActive(false);
20
21    // OpenGL light
22    _light = new osg::Light;
23    _light->setLightNum(num);
24
25    // homogeneous coordinates (x,y,z,w), w=0 indicates position at infinity
26    _light->setPosition( osg::Vec4( 0, 0, 1, 0 ) );
27
28    _light->setAmbient( osg::Vec4( 0.7, 0.7, 0.7, 1.0 ) );
29    _light->setDiffuse( osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) );
30    _light->setSpecular( osg::Vec4( 1.0, 1.0, 1.0, 1.0) );
31
32    // Scenegraph node
33    _source = new osg::LightSource;
34    _source->setReferenceFrame( osg::LightSource::RELATIVE_RF );
35    _source->setLight( _light );
36    _source->setLocalStateSetModes( osg::StateAttribute::ON ); 
37    _source->setStateSetModes( *rootStateSet, osg::StateAttribute::ON );
38    _transform->addChild( _source );
39
40    // marker geometry, texture and state
41    //_marker = osgDB::readNodeFile( "light.osg" );
42    //_transform->addChild( _marker );
43
44    setPosition( osg::Vec3(0,0,1) );  // default overhead
45}
46
47
48
49void DirectionalLight::setPosition(osg::Vec3 v)
50{
51
52    //std::cout << "[DirectionalLight::setPosition] vector = " << v << std::endl;
53    osg::Vec3 origindir;
54    osg::Quat quat;
55    origindir.set( -v );
56    origindir.normalize();
57    quat.makeRotate( osg::Vec3(0,0,-1), origindir );
58
59    _transform->setMatrix( osg::Matrix::rotate( quat ) * osg::Matrix::translate(v) );
60}
61
62
63
64DirectionalLight::~DirectionalLight()
65{
66}
Note: See TracBrowser for help on using the repository browser.