From 442b266f2e54676f39dd23ecfa4014e1283124be Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 16 Jul 2002 15:12:36 +0000 Subject: [PATCH] Added the beginings of an osglight demo. --- VisualStudio/Demos/osglight/osglight.dsp | 95 +++++++++ VisualStudio/VisualStudio.dsw | 54 +++++ src/Demos/osglight/Makefile | 16 ++ src/Demos/osglight/Makefile.inst | 12 ++ src/Demos/osglight/osglight.cpp | 246 +++++++++++++++++++++++ 5 files changed, 423 insertions(+) create mode 100644 VisualStudio/Demos/osglight/osglight.dsp create mode 100644 src/Demos/osglight/Makefile create mode 100644 src/Demos/osglight/Makefile.inst create mode 100644 src/Demos/osglight/osglight.cpp diff --git a/VisualStudio/Demos/osglight/osglight.dsp b/VisualStudio/Demos/osglight/osglight.dsp new file mode 100644 index 000000000..834fe8601 --- /dev/null +++ b/VisualStudio/Demos/osglight/osglight.dsp @@ -0,0 +1,95 @@ +# Microsoft Developer Studio Project File - Name="Demo osglight" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=Demo osglight - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "osglight.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "osglight.mak" CFG="Demo osglight - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "Demo osglight - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "Demo osglight - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "Demo osglight - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /pdb:none /machine:I386 /out:"../../../bin/osglight.exe" /libpath:"../../../lib" + +!ELSEIF "$(CFG)" == "Demo osglight - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /vd0 /GR /GX /Zi /Od /I "../../../include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /FR /YX /FD /c +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 glut32.lib glu32.lib opengl32.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"../../../bin/osglightd.exe" /pdbtype:sept /libpath:"../../../lib" +# SUBTRACT LINK32 /incremental:no + +!ENDIF + +# Begin Target + +# Name "Demo osglight - Win32 Release" +# Name "Demo osglight - Win32 Debug" +# Begin Source File + +SOURCE=..\..\..\src\Demos\osglight\osglight.cpp +# End Source File +# End Target +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Project diff --git a/VisualStudio/VisualStudio.dsw b/VisualStudio/VisualStudio.dsw index afa0d62ea..07a64e26f 100644 --- a/VisualStudio/VisualStudio.dsw +++ b/VisualStudio/VisualStudio.dsw @@ -1302,6 +1302,60 @@ Package=<4> +Project: "Demo osglight"=.\Demos\osglight\osglight.dsp - Package Owner=<4> + + + +Package=<5> + +{{{ + +}}} + + + +Package=<4> + +{{{ + + Begin Project Dependency + + Project_Dep_Name Core osg + + End Project Dependency + + Begin Project Dependency + + Project_Dep_Name Core osgDB + + End Project Dependency + + Begin Project Dependency + + Project_Dep_Name Core osgGA + + End Project Dependency + + Begin Project Dependency + + Project_Dep_Name Core osgGLUT + + End Project Dependency + + Begin Project Dependency + + Project_Dep_Name Core osgUtil + + End Project Dependency + +}}} + + + +############################################################################### + + + Project: "Demo osgviews"=.\Demos\osgviews\osgviews.dsp - Package Owner=<4> diff --git a/src/Demos/osglight/Makefile b/src/Demos/osglight/Makefile new file mode 100644 index 000000000..0229e07e3 --- /dev/null +++ b/src/Demos/osglight/Makefile @@ -0,0 +1,16 @@ +TOPDIR = ../../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osglight.cpp\ + +LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +INSTFILES = \ + $(CXXFILES)\ + Makefile.inst=Makefile + +EXEC = osglight + +include $(TOPDIR)/Make/makerules + diff --git a/src/Demos/osglight/Makefile.inst b/src/Demos/osglight/Makefile.inst new file mode 100644 index 000000000..609367a28 --- /dev/null +++ b/src/Demos/osglight/Makefile.inst @@ -0,0 +1,12 @@ +TOPDIR = ../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osglight.cpp\ + +LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +EXEC = osglight + + +include $(TOPDIR)/Make/makerules diff --git a/src/Demos/osglight/osglight.cpp b/src/Demos/osglight/osglight.cpp new file mode 100644 index 000000000..2c4611e40 --- /dev/null +++ b/src/Demos/osglight/osglight.cpp @@ -0,0 +1,246 @@ +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "stdio.h" + + + +osg::Node* createLights(osg::BoundingBox& bb,osg::StateSet* rootStateSet) +{ + osg::Group* lightGroup = new osg::Group; + + float modelSize = bb.radius(); + + // create a spot light. + osg::Light* myLight1 = new osg::Light; + myLight1->setLightNum(0); + myLight1->setPosition(osg::Vec4(bb.corner(4),1.0f)); + myLight1->setAmbient(osg::Vec4(1.0f,0.0f,0.0f,1.0f)); + myLight1->setDiffuse(osg::Vec4(1.0f,0.0f,0.0f,1.0f)); + myLight1->setSpotCutoff(20.0f); + myLight1->setDirection(osg::Vec3(1.0f,1.0f,-1.0f)); + + osg::LightSource* lightS1 = new osg::LightSource; + lightS1->setLight(myLight1); + lightS1->setLocalStateSetModes(osg::StateAttribute::ON); + + lightS1->setStateSetModes(*rootStateSet,osg::StateAttribute::ON); + lightGroup->addChild(lightS1); + + + // create a local light. + osg::Light* myLight2 = new osg::Light; + myLight2->setLightNum(1); + myLight2->setPosition(osg::Vec4(bb.corner(1),1.0f)); + myLight2->setAmbient(osg::Vec4(0.0f,1.0f,1.0f,1.0f)); + myLight2->setDiffuse(osg::Vec4(0.0f,1.0f,1.0f,1.0f)); + myLight2->setConstantAttenuation(1.0f); + myLight2->setLinearAttenuation(2.0f/modelSize); + myLight2->setQuadraticAttenuation(2.0f/osg::square(modelSize)); + + osg::LightSource* lightS2 = new osg::LightSource; + lightS2->setLight(myLight2); + lightS2->setLocalStateSetModes(osg::StateAttribute::ON); + + lightS2->setStateSetModes(*rootStateSet,osg::StateAttribute::ON); + lightGroup->addChild(lightS2); + + + return lightGroup; +} + +osg::Geometry* createWall(const osg::Vec3& v1,const osg::Vec3& v2,const osg::Vec3& v3,osg::StateSet* stateset) +{ + + // create a drawable for occluder. + osg::Geometry* geom = osgNew osg::Geometry; + + geom->setStateSet(stateset); + + unsigned int noXSteps = 100; + unsigned int noYSteps = 100; + + osg::Vec3Array* coords = osgNew osg::Vec3Array; + coords->reserve(noXSteps*noYSteps); + + + osg::Vec3 dx = (v2-v1)/((float)noXSteps-1.0f); + osg::Vec3 dy = (v3-v1)/((float)noYSteps-1.0f); + + unsigned int row; + osg::Vec3 vRowStart = v1; + for(row=0;rowpush_back(v); + v += dx; + } + vRowStart+=dy; + } + + geom->setVertexArray(coords); + + osg::Vec4Array* colors = osgNew osg::Vec4Array(1); + (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); + geom->setColorArray(colors); + geom->setColorBinding(osg::Geometry::BIND_OVERALL); + + + for(row=0;rowreserve(noXSteps*2); + for(unsigned int col=0;colpush_back((row+1)*noXSteps+col); + quadstrip->push_back(row*noXSteps+col); + } + geom->addPrimitive(quadstrip); + } + + // create the normals. + osgUtil::SmoothingVisitor::smooth(*geom); + + return geom; + +} + + +osg::Node* createRoom(osg::Node* loadedModel) +{ + // default scale for this model. + osg::BoundingSphere bs(osg::Vec3(0.0f,0.0f,0.0f),1.0f); + + osg::Group* root = new osg::Group; + + if (loadedModel) + { + root->addChild(loadedModel); + bs = loadedModel->getBound(); + } + + // create a bounding box, which we'll use to size the room. + osg::BoundingBox bb; + bb.expandBy(bs); + + + // create statesets. + osg::StateSet* rootStateSet = new osg::StateSet; + root->setStateSet(rootStateSet); + + osg::StateSet* wall = new osg::StateSet; + wall->setMode(GL_CULL_FACE,osg::StateAttribute::ON); + + osg::StateSet* floor = new osg::StateSet; + floor->setMode(GL_CULL_FACE,osg::StateAttribute::ON); + + osg::StateSet* roof = new osg::StateSet; + roof->setMode(GL_CULL_FACE,osg::StateAttribute::ON); + + osg::Geode* geode = new osg::Geode; + + // create front side. + geode->addDrawable(createWall(bb.corner(0), + bb.corner(4), + bb.corner(1), + wall)); + + // right side + geode->addDrawable(createWall(bb.corner(1), + bb.corner(5), + bb.corner(3), + wall)); + + // left side + geode->addDrawable(createWall(bb.corner(2), + bb.corner(6), + bb.corner(0), + wall)); + // back side + geode->addDrawable(createWall(bb.corner(3), + bb.corner(7), + bb.corner(2), + wall)); + + // floor + geode->addDrawable(createWall(bb.corner(0), + bb.corner(1), + bb.corner(2), + floor)); + + // roof + geode->addDrawable(createWall(bb.corner(6), + bb.corner(7), + bb.corner(4), + roof)); + + root->addChild(geode); + + root->addChild(createLights(bb,rootStateSet)); + + return root; + +} + +int main( int argc, char **argv ) +{ + + // initialize the GLUT + glutInit( &argc, argv ); + + // create the commandline args. + std::vector commandLine; + for(int i=1;i