|
From: <ju...@us...> - 2007-06-26 07:25:24
|
Revision: 14391
http://bzflag.svn.sourceforge.net/bzflag/?rev=14391&view=rev
Author: judecn
Date: 2007-06-26 00:25:25 -0700 (Tue, 26 Jun 2007)
Log Message:
-----------
Created the SceneBuilder API, which creates and flyweights OSG nodes, geometry data, and textures, and modified the proof-of-concept scene to
demonstrate the new API in action. The three metal cows in the scene are really just one node that has been encapsulated within three different
transformation nodes, and the two parallel ground planes are really just one geometry and one texture encapsulated within two different geodes.
Also, added an INSTALL file.
Modified Paths:
--------------
trunk/bzworkbench/Debug/makefile
trunk/bzworkbench/Debug/model/subdir.mk
trunk/bzworkbench/Debug/sources.mk
trunk/bzworkbench/Debug/subdir.mk
trunk/bzworkbench/dialogs/MasterConfigurationDialog.cpp
trunk/bzworkbench/include/DataEntry.h
trunk/bzworkbench/include/objects/bz2object.h
trunk/bzworkbench/include/windows/View.h
trunk/bzworkbench/objects/bz2object.cpp
trunk/bzworkbench/windows/View.cpp
Added Paths:
-----------
trunk/bzworkbench/INSTALL
trunk/bzworkbench/include/model/SceneBuilder.h
trunk/bzworkbench/model/SceneBuider.cpp
trunk/bzworkbench/share/world/
trunk/bzworkbench/share/world/std_ground.png
Modified: trunk/bzworkbench/Debug/makefile
===================================================================
--- trunk/bzworkbench/Debug/makefile 2007-06-26 05:53:37 UTC (rev 14390)
+++ trunk/bzworkbench/Debug/makefile 2007-06-26 07:25:25 UTC (rev 14391)
@@ -11,7 +11,6 @@
-include subdir.mk
-include windows/subdir.mk
-include widgets/subdir.mk
--include render/subdir.mk
-include objects/subdir.mk
-include model/subdir.mk
-include dialogs/subdir.mk
@@ -49,7 +48,7 @@
bzworkbench: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C++ Linker'
- g++ -L/usr/lib -L/usr/local/lib/ -o"bzworkbench" $(OBJS) $(USER_OBJS) $(LIBS)
+ g++ -L/usr/lib -L/usr/X11R6/lib -L/usr/local/lib/ -o"bzworkbench" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
Modified: trunk/bzworkbench/Debug/model/subdir.mk
===================================================================
--- trunk/bzworkbench/Debug/model/subdir.mk 2007-06-26 05:53:37 UTC (rev 14390)
+++ trunk/bzworkbench/Debug/model/subdir.mk 2007-06-26 07:25:25 UTC (rev 14391)
@@ -5,22 +5,25 @@
# Add inputs and outputs from these tool invocations to the build variables
CPP_SRCS += \
../model/BZWParser.cpp \
-../model/Model.cpp
+../model/Model.cpp \
+../model/SceneBuider.cpp
OBJS += \
./model/BZWParser.o \
-./model/Model.o
+./model/Model.o \
+./model/SceneBuider.o
CPP_DEPS += \
./model/BZWParser.d \
-./model/Model.d
+./model/Model.d \
+./model/SceneBuider.d
# Each subdirectory must supply rules for building sources it contributes
model/%.o: ../model/%.cpp
@echo 'Building file: $<'
@echo 'Invoking: GCC C++ Compiler'
- g++ -I/usr/include/ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
+ g++ -I/usr/include/ -I/usr/X11R6/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
@echo 'Finished building: $<'
@echo ' '
Modified: trunk/bzworkbench/Debug/sources.mk
===================================================================
--- trunk/bzworkbench/Debug/sources.mk 2007-06-26 05:53:37 UTC (rev 14390)
+++ trunk/bzworkbench/Debug/sources.mk 2007-06-26 07:25:25 UTC (rev 14391)
@@ -25,7 +25,6 @@
SUBDIRS := \
windows \
widgets \
-render \
objects \
model \
. \
Modified: trunk/bzworkbench/Debug/subdir.mk
===================================================================
--- trunk/bzworkbench/Debug/subdir.mk 2007-06-26 05:53:37 UTC (rev 14390)
+++ trunk/bzworkbench/Debug/subdir.mk 2007-06-26 07:25:25 UTC (rev 14391)
@@ -24,14 +24,14 @@
%.o: ../%.cxx
@echo 'Building file: $<'
@echo 'Invoking: GCC C++ Compiler'
- g++ -I/usr/include/ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
+ g++ -I/usr/include/ -I/usr/X11R6/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
@echo 'Finished building: $<'
@echo ' '
%.o: ../%.cpp
@echo 'Building file: $<'
@echo 'Invoking: GCC C++ Compiler'
- g++ -I/usr/include/ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
+ g++ -I/usr/include/ -I/usr/X11R6/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
@echo 'Finished building: $<'
@echo ' '
Added: trunk/bzworkbench/INSTALL
===================================================================
--- trunk/bzworkbench/INSTALL (rev 0)
+++ trunk/bzworkbench/INSTALL 2007-06-26 07:25:25 UTC (rev 14391)
@@ -0,0 +1,20 @@
+BZWorkbench Installation Notes
+------------------------------
+
+To compile BZWorkbench, just cd into Debug and run "make all".
+Aside from usual dependency on a GNU build environment, BZWorkbench has
+the following library and source dependencies:
+
+ (*) FLTK 1.1.7
+ (*) OpenSceneGraph 2.0
+ (*) OpenGL 1.4
+
+Currently, BZWorkbench only runs on UNIX platforms (including Mac OS X),
+and has only been tested by the developer on Debian GNU/Linux 4.0. It
+might run on Cygwin; but you're on your own there.
+
+To run BZWorkbench, you should either copy, move, or symlink the
+bzworkbench binary to the root of the source tree. Otherwise, it will
+crash (i.e. it expects to find certain files relative to the root of the
+source tree, rather than relative to the Debug directory). Given that
+this project is still in its infancy, there is no "make install" command.
Modified: trunk/bzworkbench/dialogs/MasterConfigurationDialog.cpp
===================================================================
--- trunk/bzworkbench/dialogs/MasterConfigurationDialog.cpp 2007-06-26 05:53:37 UTC (rev 14390)
+++ trunk/bzworkbench/dialogs/MasterConfigurationDialog.cpp 2007-06-26 07:25:25 UTC (rev 14391)
@@ -11,16 +11,16 @@
string objectStr = object->get();
// read position
- Point3D position = object->getPosition();
+ Point3D position = *(object->getPosition());
// read rotation
- float rotation = object->getRotation();
+ float rotation = *(object->getRotation());
// read size
- Point3D size = object->getSize();
+ Point3D size = *(object->getSize());
// read transformations
- vector<Transform> transforms = object->getTransformations();
+ vector<Transform> transforms = *(object->getTransformations());
// find out the supported transformations and determine their field format
supportedTransformations = string("");
Modified: trunk/bzworkbench/include/DataEntry.h
===================================================================
--- trunk/bzworkbench/include/DataEntry.h 2007-06-26 05:53:37 UTC (rev 14390)
+++ trunk/bzworkbench/include/DataEntry.h 2007-06-26 07:25:25 UTC (rev 14391)
@@ -5,6 +5,8 @@
#include <string>
#include <vector>
+#include <osg/Node>
+
using namespace std;
#include "ftoa.h"
@@ -24,7 +26,8 @@
return string("# unknown DataEntry");
}
- virtual int render(void) = 0;
+ // get the object in the form of something we can render
+ virtual osg::ref_ptr< osg::Node > getRenderable(void) { return NULL; }
// initialize the header and keys
DataEntry(const char* header, const char* keys) {
Added: trunk/bzworkbench/include/model/SceneBuilder.h
===================================================================
--- trunk/bzworkbench/include/model/SceneBuilder.h (rev 0)
+++ trunk/bzworkbench/include/model/SceneBuilder.h 2007-06-26 07:25:25 UTC (rev 14391)
@@ -0,0 +1,63 @@
+#ifndef SCENEDATA_H_
+#define SCENEDATA_H_
+
+#include <osg/Geode>
+#include <osg/Group>
+#include <osg/ShapeDrawable>
+#include <osg/Geometry>
+#include <osg/Texture2D>
+#include <osg/StateSet>
+#include <osg/Image>
+#include <osg/PositionAttitudeTransform>
+#include <osg/CopyOp>
+#include <osgDB/ReadFile>
+
+#define SCENEBUILDER_TAIL_NODE "|node"
+#define SCENEBUILDER_TAIL_GEOMETRY "|geometry"
+#define SCENEBUILDER_TAIL_TEXTURE2D "|texture2d"
+
+#include <map>
+
+using namespace std;
+
+/**
+ * This is a data broker that stores single instances of scene data to save memory, and just passes out references.
+ * This is an API class; methods are accessed statically.
+ */
+class SceneBuilder {
+
+public:
+
+ // initialize
+ static bool init();
+
+ // shut down
+ static bool shutdown();
+
+ // build an object and return a node containing the object
+ static osg::ref_ptr< osg::Node > buildNode( const char* nodeFile );
+
+ // build an object and return a geode containing the object
+ static osg::ref_ptr< osg::Geode > buildGeode( const char* nodeName, osg::Vec3Array* vertexes, osg::DrawElementsUInt* indexes, osg::Vec2Array* texCoords, const char* textureFile );
+ static osg::ref_ptr< osg::Geode > buildGeode( const char* nodeName, osg::Geometry*, const char* textureName );
+
+ // return a PositionAttitudeTransform node encapsulating the node
+ static osg::ref_ptr< osg::PositionAttitudeTransform > transformable( osg::Node* node );
+
+ // get the geometry data from a node
+ static const vector< osg::ref_ptr<osg::Drawable> >* getNodeGeometry( osg::Node* node );
+
+private:
+
+ // map strings to already-loaded nodes
+ static map< string, osg::ref_ptr<osg::Node> > nodeData;
+
+ // map strings to geometry data for already-loaded geodes
+ static map< string, osg::ref_ptr<osg::Geometry> > geoData;
+
+ // map strings to texture data for already-loaded geodes
+ static map< string, osg::ref_ptr<osg::Texture2D> > textureData;
+
+};
+
+#endif /*SCENEDATA_H_*/
Modified: trunk/bzworkbench/include/objects/bz2object.h
===================================================================
--- trunk/bzworkbench/include/objects/bz2object.h 2007-06-26 05:53:37 UTC (rev 14390)
+++ trunk/bzworkbench/include/objects/bz2object.h 2007-06-26 07:25:25 UTC (rev 14391)
@@ -40,16 +40,22 @@
string BZWLines(void);
// data getters (makes MasterConfigurationDialog code easier)
- Point3D getPosition();
- Point3D getSize();
- float getRotation();
+ Point3D* getPosition() { return &this->position; }
+ Point3D* getSize() { return &this->size; }
+ string* getName() { return &this->name; }
+ float* getRotation() { return &this->rotation; }
+ string* getPhyDrv() { return &this->physicsDriver; }
+ vector<Transform>* getTransformations() { return &this->transformations; }
+ vector<string>* getMaterials() { return &this->materials; }
- vector<Transform> getTransformations();
- vector<string> getMaterials();
-
- string getPhysicsDriver();
-
// data setters (makes MasterConfigurationDialog code easier)
+ void setPosition( Point3D* position ) { this->position = *position; }
+ void setSize( Point3D* size ) { this->position = *size; }
+ void setName( const char* name ) { this->name = name; }
+ void setRotation( float rotation ) { this->rotation = rotation; }
+ void setPhyDrv( const char* phydrv ) { this->physicsDriver = phydrv; }
+ void setTransforms( vector<Transform>* transformations ) { this->transformations = *transformations; }
+ void setMaterials( vector<string>* materials ) { this->materials = *materials; }
protected:
Point3D position;
Modified: trunk/bzworkbench/include/windows/View.h
===================================================================
--- trunk/bzworkbench/include/windows/View.h 2007-06-26 05:53:37 UTC (rev 14390)
+++ trunk/bzworkbench/include/windows/View.h 2007-06-26 07:25:25 UTC (rev 14391)
@@ -3,7 +3,7 @@
#include "RenderWindow.h"
#include "../model/Model.h"
-// #include "../render/OSGCamera.h"
+#include "../model/SceneBuilder.h"
#include <osg/Geode>
#include <osg/Group>
Added: trunk/bzworkbench/model/SceneBuider.cpp
===================================================================
--- trunk/bzworkbench/model/SceneBuider.cpp (rev 0)
+++ trunk/bzworkbench/model/SceneBuider.cpp 2007-06-26 07:25:25 UTC (rev 14391)
@@ -0,0 +1,163 @@
+#include "../include/model/SceneBuilder.h"
+
+// static members of SceneBuilder
+map< string, osg::ref_ptr<osg::Node> > SceneBuilder::nodeData;
+map< string, osg::ref_ptr<osg::Geometry> > SceneBuilder::geoData;
+map< string, osg::ref_ptr<osg::Texture2D> > SceneBuilder::textureData;
+
+// constructor
+bool SceneBuilder::init() {
+ nodeData = map< string, osg::ref_ptr<osg::Node> >();
+ geoData = map< string, osg::ref_ptr<osg::Geometry> >();
+ textureData = map< string, osg::ref_ptr<osg::Texture2D> >();
+ return true;
+}
+
+// destructor
+bool SceneBuilder::shutdown() {
+ return true;
+}
+
+/**
+ * Object builder.
+ * This method builds and returns a node loaded from nodeFile
+ */
+osg::ref_ptr< osg::Node > SceneBuilder::buildNode( const char* nodeFile ) {
+ // string-ify the nodeFile and add the corresponsing tail
+ string nodeName = string( nodeFile ) + SCENEBUILDER_TAIL_NODE;
+
+ // see if this node was already loaded
+ if( nodeData[ nodeName ] != NULL ) {
+ return nodeData[ nodeName ];
+ }
+
+ // otherwise, load it in
+ nodeData[ nodeName ] = osgDB::readNodeFile( nodeFile );
+
+ return nodeData[nodeName];
+}
+
+/**
+ * Geometry builder
+ * This method builds and returns a geometry node (a geode) from arrays of vertexes, indexes, texture coordinates, and
+ * a texture filename
+ */
+osg::ref_ptr< osg::Geode > SceneBuilder::buildGeode( const char* _nodeName, osg::Geometry* geometry, const char* textureFile ) {
+ // make the node name
+ string nodeName = string(_nodeName) + SCENEBUILDER_TAIL_NODE;
+
+ // make the geometry name
+ string geometryName = string(_nodeName) + SCENEBUILDER_TAIL_GEOMETRY;
+
+ // string-ify the texture name
+ string textureName = string(textureFile) + SCENEBUILDER_TAIL_TEXTURE2D;
+
+ // make a geode
+ osg::Geode* geode = new osg::Geode();
+
+ // load up the texture
+ // load the image itself
+ if(textureFile != NULL) {
+ // the texture itself
+ osg::Texture2D* texture = NULL;
+
+ // if the texture has already been loaded then initialize it
+ if( textureData[ textureName ] != NULL) {
+ texture = textureData[ textureName ].get();
+ }
+ else {
+ texture = new osg::Texture2D();
+
+ osg::Image* image = osgDB::readImageFile( textureFile );
+
+ if( image != NULL ) { // only build the texture if the image exists!
+
+ // don't allow OSG to optimize the texture (otherwise it may disappear)
+ texture->setDataVariance( osg::Object::DYNAMIC );
+
+ // set the texture's image
+ texture->setImage( image );
+
+ // turn on GL_REPEAT texture wrapping
+ texture->setWrap( osg::Texture::WRAP_R, osg::Texture::REPEAT );
+ texture->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );
+ texture->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );
+ }
+
+ textureData[ textureName ] = texture;
+ }
+
+ // make a new state set for the texture (so we can manipulate the texture attributes)
+ osg::StateSet* texStateSet = new osg::StateSet();
+
+ // assign the texture to the state set and activate it
+ texStateSet->setTextureAttributeAndModes( 0, texture, osg::StateAttribute::ON );
+
+ // finally, attach the texture to the geode
+ geode->setStateSet( texStateSet );
+ }
+
+ // assign the geometry data to the geode (assign it the flyweighted one if it exists; otherwise add this geometry)
+ if( geoData[ geometryName ] == NULL ) {
+ geoData[ geometryName ] = geometry;
+ }
+
+ geode->addDrawable( geoData[ geometryName ].get() );
+
+ // add this geode to nodeData to be reused again
+ if( nodeData[ nodeName ] == NULL )
+ nodeData[ nodeName ] = (osg::Node*)(geode);
+
+ return geode;
+}
+
+// build a geometry and call the other buildGeode method
+osg::ref_ptr< osg::Geode > SceneBuilder::buildGeode( const char* nodeName, osg::Vec3Array* vertexes, osg::DrawElementsUInt* indexes, osg::Vec2Array* texCoords, const char* textureName ) {
+ // don't bother if the data is NULL
+ if(vertexes == NULL || indexes == NULL || texCoords == NULL)
+ return NULL;
+
+ // make a new geometry
+ osg::Geometry* geometry = new osg::Geometry();
+
+ // assign the vertexes
+ geometry->setVertexArray( vertexes );
+
+ // assign the indexes
+ geometry->addPrimitiveSet( indexes );
+
+ // assign the texture coordinates
+ geometry->setTexCoordArray( 0, texCoords );
+
+ return SceneBuilder::buildGeode( nodeName, geometry, textureName );
+}
+
+/**
+ * Gets the geometry data from a node (returns NULL if it has no geometry).
+ * It does NOT look at children nodes.
+ */
+const vector< osg::ref_ptr<osg::Drawable> >* SceneBuilder::getNodeGeometry( osg::Node* node ) {
+ const osg::Geode* geode = dynamic_cast< osg::Geode* > (node);
+ if(!geode) { // return NULL if the dynamic_cast failed
+ return NULL;
+ }
+
+ return &geode->getDrawableList();
+}
+
+/**
+ * Encapsulate a node inside a PositionAttitudeTransform node (i.e. this allows the node to be more easily transformed)
+ */
+osg::ref_ptr< osg::PositionAttitudeTransform > SceneBuilder::transformable( osg::Node* node ) {
+ if(node == NULL)
+ return NULL;
+
+ // make the transform node
+ osg::ref_ptr< osg::PositionAttitudeTransform > transformNode = new osg::PositionAttitudeTransform();
+
+ // assign the node
+ transformNode->addChild( node );
+
+ // return the node
+ return transformNode;
+}
Modified: trunk/bzworkbench/objects/bz2object.cpp
===================================================================
--- trunk/bzworkbench/objects/bz2object.cpp 2007-06-26 05:53:37 UTC (rev 14390)
+++ trunk/bzworkbench/objects/bz2object.cpp 2007-06-26 07:25:25 UTC (rev 14391)
@@ -198,13 +198,3 @@
return ret;
}
-
-// data getters (makes MasterConfigurationDialog code easier)
-Point3D bz2object::getPosition() { return position; }
-Point3D bz2object::getSize() { return size; }
-float bz2object::getRotation() { return rotation; }
-
-vector<Transform> bz2object::getTransformations() { return transformations; }
-vector<string> bz2object::getMaterials() { return materials; }
-
-string bz2object::getPhysicsDriver() { return physicsDriver; }
Added: trunk/bzworkbench/share/world/std_ground.png
===================================================================
(Binary files differ)
Property changes on: trunk/bzworkbench/share/world/std_ground.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/bzworkbench/windows/View.cpp
===================================================================
--- trunk/bzworkbench/windows/View.cpp 2007-06-26 05:53:37 UTC (rev 14390)
+++ trunk/bzworkbench/windows/View.cpp 2007-06-26 07:25:25 UTC (rev 14391)
@@ -4,9 +4,6 @@
View::View(Model* m, int x, int y, int w, int h, const char *label) :
RenderWindow(x,y,w,h) {
- // initialize the camera
- // this->camera = new OSGCamera( this->getCamera() );
-
// set OSG viewport
this->getCamera()->setViewport(new osg::Viewport(0,0,w,h));
@@ -23,39 +20,39 @@
this->root = new osg::Group();
// initialize the ground
- this->initGround( 400.0f );
+ this->initGround( 100.0f );
// add the ground to the root node
this->root->addChild( this->ground.get() );
-
- // load the cow model
- osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile("share/cow.osg");
+
+ osg::ref_ptr<osg::PositionAttitudeTransform> cow1 = SceneBuilder::transformable( SceneBuilder::buildNode( "share/cow.osg" ).get() );
+ osg::ref_ptr<osg::PositionAttitudeTransform> cow2 = SceneBuilder::transformable( SceneBuilder::buildNode( "share/cow.osg" ).get() );
+ osg::ref_ptr<osg::PositionAttitudeTransform> cow3 = SceneBuilder::transformable( SceneBuilder::buildNode( "share/cow.osg" ).get() );
- // make a transformer
- osg::ref_ptr<osg::PositionAttitudeTransform> cowTransform = new osg::PositionAttitudeTransform();
-
- // add the cow model to the transformer
- cowTransform->addChild( loadedModel.get() );
-
// move the cow up a bit
- cowTransform->setPosition( osg::Vec3( 0, 0, 3 ) );
+ cow1->setPosition( osg::Vec3(0, 0, 3) );
+ cow2->setPosition( osg::Vec3(10, 10, 3) );
+ cow3->setPosition( osg::Vec3(-10, 10, 3) );
// add the cow model as a leaf to root
- this->root->addChild( cowTransform.get() );
+ this->root->addChild( cow1.get() );
+ this->root->addChild( cow2.get() );
+ this->root->addChild( cow3.get() );
// add the root node to the scene
this->setSceneData( this->root.get() );
+
+ // make this a trackball manipulator
+ this->setCameraManipulator(new osgGA::TrackballManipulator());
+
+ // add the stats event handler
+ this->addEventHandler(new osgViewer::StatsHandler);
}
// helper method: initialize the ground
void View::initGround( float size ) {
- // initialize the ground geode
- this->ground = new osg::Geode();
-
- // make a geometry
- osg::Geometry* groundGeometry = new osg::Geometry();
-
+
// make a ground mesh (just a plane the size of the world)
// ground points
osg::Vec3Array* groundPoints = new osg::Vec3Array();
@@ -63,7 +60,6 @@
groundPoints->push_back( osg::Vec3( size, -size, 0 ) );
groundPoints->push_back( osg::Vec3( size, size, 0 ) );
groundPoints->push_back( osg::Vec3( -size, size, 0 ) );
- groundGeometry->setVertexArray( groundPoints );
// ground indexes
osg::DrawElementsUInt* groundIndexes = new osg::DrawElementsUInt( osg::PrimitiveSet::QUADS, 0 );
@@ -71,7 +67,6 @@
groundIndexes->push_back( 3 );
groundIndexes->push_back( 2 );
groundIndexes->push_back( 1 );
- groundGeometry->addPrimitiveSet( groundIndexes );
// texture coordinates
osg::Vec2Array* groundTexCoords = new osg::Vec2Array();
@@ -79,97 +74,29 @@
groundTexCoords->push_back( osg::Vec2(size, 0.0) );
groundTexCoords->push_back( osg::Vec2(size, size) );
groundTexCoords->push_back( osg::Vec2(0.0, size) );
- groundGeometry->setTexCoordArray(0, groundTexCoords );
- // the texture itself
- osg::Texture2D* groundTexture = new osg::Texture2D();
- // keep the texture in VRAM
- groundTexture->setDataVariance( osg::Object::DYNAMIC );
- // load the image itself
- osg::Image* groundImage = osgDB::readImageFile( "share/world/std_ground.png" );
- // set the texture's image
- groundTexture->setImage( groundImage );
- // make a new state set for the texture (so we can manipulate the texture attributes)
- osg::StateSet* groundStateSet = new osg::StateSet();
- // assign the texture to the state set and activate it
- groundStateSet->setTextureAttributeAndModes( 0, groundTexture, osg::StateAttribute::ON );
- groundTexture->setWrap( osg::Texture::WRAP_R, osg::Texture::REPEAT );
- groundTexture->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );
- groundTexture->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );
-
// make the member ground geode
- this->ground = new osg::Geode();
- // add the geometry data to the geode
- this->ground->addDrawable( groundGeometry );
+ this->ground = SceneBuilder::buildGeode( "ground", groundPoints, groundIndexes, groundTexCoords, "share/world/std_ground.png" );
- // assign the texture to the geode
- this->ground->setStateSet( groundStateSet );
+ osg::ref_ptr<osg::PositionAttitudeTransform> pat = SceneBuilder::transformable( SceneBuilder::buildGeode( "ground", groundPoints, groundIndexes, groundTexCoords, "share/world/std_ground.png" ).get() );
+ pat->setPosition( osg::Vec3( 0, 0, -30 ) );
+
+ this->root->addChild(pat.get());
}
-// destructor (just free the camera)
-View::~View() {
- /*
- if( this->camera )
- delete this->camera;
- */
-}
+// destructor
+View::~View() { }
float cnt = 0;
// draw method (really simple)
void View::draw(void) {
-
this->frame();
}
// handle events
int View::handle(int event) {
- /*
- // forward FLTK events to OSG
- switch(event){
-
- case FL_KEYDOWN: {
-
- int key = Fl::event_key();
-
- switch (key) {
-
- case FL_Up: {
-
- this->camera->translate( 0.0, 1.0, 0.0 );
- this->redraw();
- return 1;
- }
-
- case FL_Down: {
-
- this->camera->translate( 0.0, -1.0, 0.0 );
- this->redraw();
- return 1;
- }
-
- case FL_Right: {
- this->camera->rotate_z( 1 );
- this->redraw();
- return 1;
- }
-
- case FL_Left: {
- this->camera->rotate_z( -1 );
- this->redraw();
- return 1;
- }
-
- default:
- break;
- }
- }
- case FL_KEYUP:
-
- return 1;
- default:*/
- // pass other events to the base class
- return RenderWindow::handle(event);
- // }
+ // pass other events to the base class
+ return RenderWindow::handle(event);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|