Initial revision
This commit is contained in:
29
src/Demos/Makefile
Normal file
29
src/Demos/Makefile
Normal file
@@ -0,0 +1,29 @@
|
||||
#!smake
|
||||
SHELL=/bin/sh
|
||||
|
||||
DIRS = sgv cube
|
||||
|
||||
all :
|
||||
for f in $(DIRS) ; do cd $$f; make ; cd ..; done
|
||||
|
||||
clean :
|
||||
for f in $(DIRS) ; do cd $$f; make clean; cd ..; done
|
||||
|
||||
clobber :
|
||||
for f in $(DIRS) ; do cd $$f; make clobber; cd ..; done
|
||||
|
||||
depend :
|
||||
for f in $(DIRS) ; do cd $$f; make depend; cd ..; done
|
||||
|
||||
to_unix :
|
||||
for f in $(DIRS) ; do cd $$f; to_unix Makefile Makefile; cd ..; done
|
||||
for f in $(DIRS) ; do cd $$f; make to_unix; cd ..; done
|
||||
|
||||
install :
|
||||
for f in $(DIRS) ; do cd $$f; make install; cd ..; done
|
||||
|
||||
instlinks :
|
||||
for f in $(DIRS) ; do cd $$f; make instlinks; cd ..; done
|
||||
|
||||
instclean :
|
||||
for f in $(DIRS) ; do cd $$f; make instclean; cd ..; done
|
||||
0
src/Demos/cube/Makedepend
Normal file
0
src/Demos/cube/Makedepend
Normal file
15
src/Demos/cube/Makefile
Normal file
15
src/Demos/cube/Makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
#!smake
|
||||
include ../../../Make/makedefs
|
||||
|
||||
C++FILES = \
|
||||
cube.cpp
|
||||
|
||||
TARGET = ../../../bin/cube
|
||||
|
||||
TARGET_BIN_FILES = cube
|
||||
|
||||
LIBS = -losgGLUT -losgUtil -losg -lglut -lGLU -lGL -lm -lXmu -lX11 -lXi
|
||||
C++FLAGS += -I../../../include
|
||||
LDFLAGS += -L../../../lib -L/usr/X11R6/lib
|
||||
|
||||
include ../../../Make/makerules
|
||||
135
src/Demos/cube/cube.cpp
Normal file
135
src/Demos/cube/cube.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
#include "osgGLUT/Viewer"
|
||||
|
||||
#include "osg/Geode"
|
||||
#include "osg/GeoSet"
|
||||
#include "osg/GeoState"
|
||||
#include "osg/Material"
|
||||
#include "osg/Vec3"
|
||||
#include "osg/DCS"
|
||||
|
||||
#include <GL/glut.h>
|
||||
#include <math.h>
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Global variables - this is basically the stuff which will be animated
|
||||
// ----------------------------------------------------------------------
|
||||
osg::DCS* myDCS;
|
||||
osg::GeoSet* cube;
|
||||
|
||||
int mytime=0; // in milliseconds
|
||||
unsigned int dt=50; // in milliseconds
|
||||
double omega=0.002; // in inverse milliseconds
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// This is the callback function registered with GLUT to be called
|
||||
// at a future time in the GLUT loop
|
||||
// ----------------------------------------------------------------
|
||||
void timedCB( int delta_t )
|
||||
{
|
||||
|
||||
static float lastdx = 0;
|
||||
static float lastdy = 0;
|
||||
static float lastdz = 0;
|
||||
|
||||
mytime+=dt;
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Update the DCS so that the cube will appear to oscillate
|
||||
// ---------------------------------------------------------
|
||||
double dx = 0.5 * cos( (double) omega * (double) mytime );
|
||||
double dy = 0.5 * sin( (double) omega * (double) mytime );
|
||||
double dz = 0.0;
|
||||
myDCS->preTranslate( -lastdx, -lastdy, -lastdz );
|
||||
myDCS->preTranslate( (float) dx, (float) dy, dz );
|
||||
lastdx=dx; lastdy=dy; lastdz=dz;
|
||||
|
||||
// Graeme, commeted out this call as the cube itself remains static.
|
||||
// cube->dirtyDisplayList();
|
||||
|
||||
// -------------------------------------------
|
||||
// If required, reschedule the timed callback
|
||||
// -------------------------------------------
|
||||
if ( delta_t != 0 ) {
|
||||
glutTimerFunc( (unsigned int) delta_t, timedCB, delta_t );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
|
||||
// -------------------------------------------
|
||||
// Set up a new GeoSet which will be our cube
|
||||
// -------------------------------------------
|
||||
cube = new osg::GeoSet();
|
||||
|
||||
cube->setPrimType( osg::GeoSet::POLYGON );
|
||||
cube->setNumPrims( 6 ); // the six square faces
|
||||
|
||||
int cubeLengthList[6] = { 4, 4, 4, 4, 4, 4 }; // each has 4 vertices
|
||||
cube->setPrimLengths( cubeLengthList );
|
||||
|
||||
osg::Vec3 cubeCoords[24];
|
||||
cubeCoords[0].set( -1.0000f, 1.0000f, -1.000f );
|
||||
cubeCoords[1].set( 1.0000f, 1.0000f, -1.0000f );
|
||||
cubeCoords[2].set( 1.0000f, -1.0000f, -1.0000f );
|
||||
cubeCoords[3].set( -1.0000f, -1.0000f, -1.000 );
|
||||
cubeCoords[4].set( 1.0000f, 1.0000f, -1.0000f );
|
||||
cubeCoords[5].set( 1.0000f, 1.0000f, 1.0000f );
|
||||
cubeCoords[6].set( 1.0000f, -1.0000f, 1.0000f );
|
||||
cubeCoords[7].set( 1.0000f, -1.0000f, -1.0000f );
|
||||
cubeCoords[8].set( 1.0000f, 1.0000f, 1.0000f );
|
||||
cubeCoords[9].set( -1.0000f, 1.0000f, 1.000f );
|
||||
cubeCoords[10].set( -1.0000f, -1.0000f, 1.000f );
|
||||
cubeCoords[11].set( 1.0000f, -1.0000f, 1.0000f );
|
||||
cubeCoords[12].set( -1.0000f, 1.0000f, 1.000 );
|
||||
cubeCoords[13].set( -1.0000f, 1.0000f, -1.000 );
|
||||
cubeCoords[14].set( -1.0000f, -1.0000f, -1.000 );
|
||||
cubeCoords[15].set( -1.0000f, -1.0000f, 1.000 );
|
||||
cubeCoords[16].set( -1.0000f, 1.0000f, 1.000 );
|
||||
cubeCoords[17].set( 1.0000f, 1.0000f, 1.0000f );
|
||||
cubeCoords[18].set( 1.0000f, 1.0000f, -1.0000f );
|
||||
cubeCoords[19].set( -1.0000f, 1.0000f, -1.000f );
|
||||
cubeCoords[20].set( -1.0000f, -1.0000f, 1.000f );
|
||||
cubeCoords[21].set( -1.0000f, -1.0000f, -1.000f );
|
||||
cubeCoords[22].set( 1.0000f, -1.0000f, -1.0000f );
|
||||
cubeCoords[23].set( 1.0000f, -1.0000f, 1.0000f );
|
||||
cube->setCoords( cubeCoords );
|
||||
|
||||
// ---------------------------------------
|
||||
// Set up a GeoState to make the cube red
|
||||
// ---------------------------------------
|
||||
osg::GeoState* cubeState = new osg::GeoState();
|
||||
osg::Material* redMaterial = new osg::Material();
|
||||
osg::Vec4 red( 1.0f, 0.0f, 0.0f, 0.0f );
|
||||
redMaterial->setEmission( osg::Material::FACE_FRONT_AND_BACK, red );
|
||||
redMaterial->setAmbient( osg::Material::FACE_FRONT_AND_BACK, red );
|
||||
redMaterial->setDiffuse( osg::Material::FACE_FRONT_AND_BACK, red );
|
||||
redMaterial->setSpecular( osg::Material::FACE_FRONT_AND_BACK, red );
|
||||
cubeState->setAttribute( osg::GeoState::MATERIAL, redMaterial );
|
||||
|
||||
cube->setGeoState( cubeState );
|
||||
|
||||
geode->addGeoSet( cube );
|
||||
|
||||
myDCS = new osg::DCS();
|
||||
myDCS->addChild( geode );
|
||||
|
||||
glutInit( &argc, argv );
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Register a timer callback with GLUT, in the first instance as a test
|
||||
// This will call the function "timedCB(value)" after dt ms
|
||||
// I have decided to use value as the time for the next scheduling
|
||||
// If the last parameter=0 then don't reschedule the timer.
|
||||
// ---------------------------------------------------------------------
|
||||
glutTimerFunc( dt, timedCB, dt );
|
||||
|
||||
osgGLUT::Viewer viewer;
|
||||
viewer.init( myDCS );
|
||||
viewer.run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
0
src/Demos/sgv/Makedepend
Normal file
0
src/Demos/sgv/Makedepend
Normal file
19
src/Demos/sgv/Makefile
Normal file
19
src/Demos/sgv/Makefile
Normal file
@@ -0,0 +1,19 @@
|
||||
#!smake
|
||||
include ../../../Make/makedefs
|
||||
|
||||
C++FILES = \
|
||||
sgv.cpp
|
||||
|
||||
TARGET = ../../../bin/sgv
|
||||
|
||||
TARGET_BIN_FILES = sgv
|
||||
|
||||
# LIBS = -losg -lglut -lGLU -lGL -lm -lXmu -lX11 -lXi
|
||||
# C++FLAGS += -I../../include
|
||||
# LDFLAGS += -L../../lib -L/usr/X11R6/lib
|
||||
|
||||
LIBS = -losgGLUT -losgUtil -losg -lglut -lGLU -lGL -lm -lXmu -lX11 -lXi
|
||||
C++FLAGS += -I../../../include
|
||||
LDFLAGS += -L../../../lib -L/usr/X11R6/lib
|
||||
|
||||
include ../../../Make/makerules
|
||||
118
src/Demos/sgv/sgv.cpp
Normal file
118
src/Demos/sgv/sgv.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
#include "osg/OSG"
|
||||
#include "osg/Node"
|
||||
#include "osg/Registry"
|
||||
#include "osg/Notify"
|
||||
|
||||
#include <GL/glut.h>
|
||||
#include "osgGLUT/Viewer"
|
||||
|
||||
/*
|
||||
* Function to read several files (typically one) as specified on the command
|
||||
* line, and return them in an osg::Node
|
||||
*/
|
||||
osg::Node* getNodeFromFiles(int argc,char **argv)
|
||||
{
|
||||
osg::Node *rootnode = new osg::Node;
|
||||
|
||||
int i;
|
||||
|
||||
typedef std::vector<osg::Node*> NodeList;
|
||||
NodeList nodeList;
|
||||
for( i = 1; i < argc; i++ )
|
||||
{
|
||||
|
||||
if (argv[i][0]=='-')
|
||||
{
|
||||
switch(argv[i][1])
|
||||
{
|
||||
case('l'):
|
||||
++i;
|
||||
if (i<argc)
|
||||
{
|
||||
osg::Registry::instance()->loadLibrary(argv[i]);
|
||||
}
|
||||
break;
|
||||
case('e'):
|
||||
++i;
|
||||
if (i<argc)
|
||||
{
|
||||
std::string libName = osg::Registry::instance()->createLibraryNameForExt(argv[i]);
|
||||
osg::Registry::instance()->loadLibrary(libName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else
|
||||
{
|
||||
osg::Node *node = osg::loadNodeFile( argv[i] );
|
||||
|
||||
if( node != (osg::Node *)0L )
|
||||
{
|
||||
if (node->getName().empty()) node->setName( argv[i] );
|
||||
nodeList.push_back(node);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (nodeList.size()==0)
|
||||
{
|
||||
osg::notify(osg::WARN) << "No data loaded."<<endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (nodeList.size()==1)
|
||||
{
|
||||
rootnode = nodeList.front();
|
||||
}
|
||||
else // size >1
|
||||
{
|
||||
osg::Group* group = new osg::Group();
|
||||
for(NodeList::iterator itr=nodeList.begin();
|
||||
itr!=nodeList.end();
|
||||
++itr)
|
||||
{
|
||||
group->addChild(*itr);
|
||||
}
|
||||
|
||||
rootnode = group;
|
||||
}
|
||||
|
||||
return rootnode;
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
|
||||
if (argc<2)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"usage:"<<endl;
|
||||
osg::notify(osg::NOTICE)<<" sgv [options] infile1 [infile2 ...]"<<endl;
|
||||
osg::notify(osg::NOTICE)<<endl;
|
||||
osg::notify(osg::NOTICE)<<"options:"<<endl;
|
||||
osg::notify(osg::NOTICE)<<" -l libraryName - load plugin of name libraryName"<<endl;
|
||||
osg::notify(osg::NOTICE)<<" i.e. -l osgdb_pfb"<<endl;
|
||||
osg::notify(osg::NOTICE)<<" Useful for loading reader/writers which can load"<<endl;
|
||||
osg::notify(osg::NOTICE)<<" other file formats in addition to its extension."<<endl;
|
||||
osg::notify(osg::NOTICE)<<" -e extensionName - load reader/wrter plugin for file extension"<<endl;
|
||||
osg::notify(osg::NOTICE)<<" i.e. -e pfb"<<endl;
|
||||
osg::notify(osg::NOTICE)<<" Useful short hand for specifying full library name as"<<endl;
|
||||
osg::notify(osg::NOTICE)<<" done with -l above, as it automatically expands to the"<<endl;
|
||||
osg::notify(osg::NOTICE)<<" full library name appropriate for each platform."<<endl;
|
||||
osg::notify(osg::NOTICE)<<endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
osg::Node* rootnode = getNodeFromFiles( argc, argv);
|
||||
|
||||
osgGLUT::Viewer viewer;
|
||||
glutInit( &argc, argv );
|
||||
viewer.init( rootnode );
|
||||
viewer.run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user