Removed the old hangglide directory.
This commit is contained in:
@@ -1,242 +0,0 @@
|
||||
#include "GliderManipulator.h"
|
||||
|
||||
#include <osg/Types>
|
||||
#include <osg/Notify>
|
||||
|
||||
using namespace osg;
|
||||
using namespace osgGA;
|
||||
|
||||
GliderManipulator::GliderManipulator()
|
||||
{
|
||||
_modelScale = 0.01f;
|
||||
_velocity = 0.0f;
|
||||
_yawMode = YAW_AUTOMATICALLY_WHEN_BANKED;
|
||||
}
|
||||
|
||||
|
||||
GliderManipulator::~GliderManipulator()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GliderManipulator::setNode(osg::Node* node)
|
||||
{
|
||||
_node = node;
|
||||
if (_node.get())
|
||||
{
|
||||
const osg::BoundingSphere& boundingSphere=_node->getBound();
|
||||
_modelScale = boundingSphere._radius;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const osg::Node* GliderManipulator::getNode() const
|
||||
{
|
||||
return _node.get();
|
||||
}
|
||||
|
||||
|
||||
void GliderManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
|
||||
{
|
||||
if(_node.get() && _camera.get())
|
||||
{
|
||||
|
||||
const osg::BoundingSphere& boundingSphere=_node->getBound();
|
||||
|
||||
osg::Vec3 eye = boundingSphere._center+osg::Vec3(-boundingSphere._radius*0.25f,-boundingSphere._radius*0.25f,-boundingSphere._radius*0.03f);
|
||||
|
||||
_camera->setView(eye,
|
||||
eye+osg::Vec3(1.0f,1.0f,-0.1f),
|
||||
osg::Vec3(0.0f,0.0f,1.0f));
|
||||
|
||||
_velocity = boundingSphere._radius*0.01f;
|
||||
|
||||
us.requestRedraw();
|
||||
|
||||
us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2,(ea.getYmin()+ea.getYmax())/2);
|
||||
|
||||
flushMouseEventStack();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GliderManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
|
||||
{
|
||||
flushMouseEventStack();
|
||||
|
||||
us.requestContinuousUpdate(false);
|
||||
|
||||
const osg::BoundingSphere& boundingSphere=_node->getBound();
|
||||
_velocity = boundingSphere._radius*0.01f;
|
||||
|
||||
us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2,(ea.getYmin()+ea.getYmax())/2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool GliderManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
|
||||
{
|
||||
if(!_camera.get()) return false;
|
||||
|
||||
switch(ea.getEventType())
|
||||
{
|
||||
case(GUIEventAdapter::PUSH):
|
||||
{
|
||||
|
||||
addMouseEvent(ea);
|
||||
us.requestContinuousUpdate(true);
|
||||
if (calcMovement()) us.requestRedraw();
|
||||
return true;
|
||||
}
|
||||
|
||||
case(GUIEventAdapter::RELEASE):
|
||||
{
|
||||
|
||||
addMouseEvent(ea);
|
||||
us.requestContinuousUpdate(true);
|
||||
if (calcMovement()) us.requestRedraw();
|
||||
return true;
|
||||
}
|
||||
|
||||
case(GUIEventAdapter::DRAG):
|
||||
{
|
||||
|
||||
addMouseEvent(ea);
|
||||
us.requestContinuousUpdate(true);
|
||||
if (calcMovement()) us.requestRedraw();
|
||||
return true;
|
||||
}
|
||||
|
||||
case(GUIEventAdapter::MOVE):
|
||||
{
|
||||
|
||||
addMouseEvent(ea);
|
||||
us.requestContinuousUpdate(true);
|
||||
if (calcMovement()) us.requestRedraw();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case(GUIEventAdapter::KEYBOARD):
|
||||
if (ea.getKey()==' ')
|
||||
{
|
||||
flushMouseEventStack();
|
||||
home(ea,us);
|
||||
us.requestRedraw();
|
||||
us.requestContinuousUpdate(false);
|
||||
return true;
|
||||
}
|
||||
else if (ea.getKey()=='+')
|
||||
{
|
||||
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()*1.25f);
|
||||
return true;
|
||||
}
|
||||
else if (ea.getKey()=='-')
|
||||
{
|
||||
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()/1.25f);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
case(GUIEventAdapter::FRAME):
|
||||
addMouseEvent(ea);
|
||||
if (calcMovement()) us.requestRedraw();
|
||||
return true;
|
||||
|
||||
case(GUIEventAdapter::RESIZE):
|
||||
init(ea,us);
|
||||
us.requestRedraw();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GliderManipulator::flushMouseEventStack()
|
||||
{
|
||||
_ga_t1 = NULL;
|
||||
_ga_t0 = NULL;
|
||||
}
|
||||
|
||||
|
||||
void GliderManipulator::addMouseEvent(const GUIEventAdapter& ea)
|
||||
{
|
||||
_ga_t1 = _ga_t0;
|
||||
_ga_t0 = &ea;
|
||||
}
|
||||
|
||||
|
||||
bool GliderManipulator::calcMovement()
|
||||
{
|
||||
_camera->setFusionDistanceMode(osg::Camera::PROPORTIONAL_TO_SCREEN_DISTANCE);
|
||||
|
||||
// return if less then two events have been added.
|
||||
if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;
|
||||
|
||||
|
||||
float dt = _ga_t0->time()-_ga_t1->time();
|
||||
|
||||
if (dt<0.0f)
|
||||
{
|
||||
notify(WARN) << "warning dt = "<<dt<< std::endl;
|
||||
dt = 0.0f;
|
||||
}
|
||||
|
||||
unsigned int buttonMask = _ga_t1->getButtonMask();
|
||||
if (buttonMask==GUIEventAdapter::LEFT_MOUSE_BUTTON)
|
||||
{
|
||||
// pan model.
|
||||
|
||||
_velocity += dt*_modelScale*0.05f;
|
||||
|
||||
}
|
||||
else if (buttonMask==GUIEventAdapter::MIDDLE_MOUSE_BUTTON ||
|
||||
buttonMask==(GUIEventAdapter::LEFT_MOUSE_BUTTON|GUIEventAdapter::RIGHT_MOUSE_BUTTON))
|
||||
{
|
||||
|
||||
_velocity = 0.0f;
|
||||
|
||||
}
|
||||
else if (buttonMask==GUIEventAdapter::RIGHT_MOUSE_BUTTON)
|
||||
{
|
||||
|
||||
_velocity -= dt*_modelScale*0.05f;
|
||||
|
||||
}
|
||||
|
||||
float mx = (_ga_t0->getXmin()+_ga_t0->getXmax())/2.0f;
|
||||
float my = (_ga_t0->getYmin()+_ga_t0->getYmax())/2.0f;
|
||||
|
||||
float dx = _ga_t0->getX()-mx;
|
||||
float dy = _ga_t0->getY()-my;
|
||||
|
||||
osg::Vec3 center = _camera->getEyePoint();
|
||||
osg::Vec3 sv = _camera->getSideVector();
|
||||
osg::Vec3 lv = _camera->getLookVector();
|
||||
|
||||
float pitch = inDegrees(dy*0.15f*dt);
|
||||
float roll = inDegrees(dx*0.1f*dt);
|
||||
|
||||
osg::Matrix mat;
|
||||
mat.makeTranslate(-center);
|
||||
mat *= Matrix::rotate(pitch,sv.x(),sv.y(),sv.z());
|
||||
mat *= Matrix::rotate(roll,lv.x(),lv.y(),lv.z());
|
||||
if (_yawMode==YAW_AUTOMATICALLY_WHEN_BANKED)
|
||||
{
|
||||
float bank = asinf(sv.z());
|
||||
float yaw = inRadians(bank)*dt;
|
||||
mat *= Matrix::rotate(yaw,0.0f,0.0f,1.0f);
|
||||
}
|
||||
|
||||
lv *= (_velocity*dt);
|
||||
|
||||
mat *= Matrix::translate(center+lv);
|
||||
|
||||
_camera->transformLookAt(mat);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
#ifndef HANGGLIDE_GLIDERMANIPULATOR
|
||||
#define HANGGLIDE_GLIDERMANIPULATOR 1
|
||||
|
||||
#include <osgGA/CameraManipulator>
|
||||
|
||||
class GliderManipulator : public osgGA::CameraManipulator
|
||||
{
|
||||
public:
|
||||
|
||||
GliderManipulator();
|
||||
virtual ~GliderManipulator();
|
||||
|
||||
/** Attach a node to the manipulator.
|
||||
Automatically detaches previously attached node.
|
||||
setNode(NULL) detaches previously nodes.
|
||||
Is ignored by manipulators which do not require a reference model.*/
|
||||
virtual void setNode(osg::Node*);
|
||||
|
||||
/** Return node if attached.*/
|
||||
virtual const osg::Node* getNode() const;
|
||||
|
||||
/** Move the camera to the default position.
|
||||
May be ignored by manipulators if home functionality is not appropriate.*/
|
||||
virtual void home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
|
||||
|
||||
/** Start/restart the manipulator.*/
|
||||
virtual void init(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
|
||||
|
||||
/** handle events, return true if handled, false otherwise.*/
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
|
||||
|
||||
enum YawControlMode {
|
||||
YAW_AUTOMATICALLY_WHEN_BANKED,
|
||||
NO_AUTOMATIC_YAW
|
||||
};
|
||||
|
||||
/** Set the yaw control between no yaw and yawing when banked.*/
|
||||
void setYawControlMode(YawControlMode ycm) { _yawMode = ycm; }
|
||||
|
||||
private:
|
||||
|
||||
/** Reset the internal GUIEvent stack.*/
|
||||
void flushMouseEventStack();
|
||||
/** Add the current mouse GUIEvent to internal stack.*/
|
||||
void addMouseEvent(const osgGA::GUIEventAdapter& ea);
|
||||
|
||||
/** For the give mouse movement calculate the movement of the camera.
|
||||
Return true is camera has moved and a redraw is required.*/
|
||||
bool calcMovement();
|
||||
|
||||
// Internal event stack comprising last three mouse events.
|
||||
osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t1;
|
||||
osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t0;
|
||||
|
||||
osg::ref_ptr<osg::Node> _node;
|
||||
|
||||
float _modelScale;
|
||||
float _velocity;
|
||||
|
||||
YawControlMode _yawMode;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
TOPDIR = ../../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
base.cpp\
|
||||
GliderManipulator.cpp\
|
||||
hangglide.cpp\
|
||||
hat.cpp\
|
||||
ReaderWriterFLY.cpp\
|
||||
sky.cpp\
|
||||
tank.cpp\
|
||||
terrain.cpp\
|
||||
trees.cpp\
|
||||
|
||||
HEADERFILES = \
|
||||
GliderManipulator.h\
|
||||
hat.h\
|
||||
terrain_coords.h\
|
||||
terrain_normals.h\
|
||||
terrain_texcoords.h\
|
||||
|
||||
LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
INSTFILES = \
|
||||
$(CXXFILES)\
|
||||
$(HEADERFILES)\
|
||||
Makefile.inst=Makefile
|
||||
|
||||
EXEC = osghangglide
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
@@ -1,19 +0,0 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
base.cpp\
|
||||
GliderManipulator.cpp\
|
||||
hangglide.cpp\
|
||||
hat.cpp\
|
||||
ReaderWriterFLY.cpp\
|
||||
sky.cpp\
|
||||
tank.cpp\
|
||||
terrain.cpp\
|
||||
trees.cpp\
|
||||
|
||||
LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
EXEC = osghangglide
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
@@ -1,13 +0,0 @@
|
||||
A simple hang gliding flight simulator demo. The current GliderManipulator
|
||||
does not yet have any dynamics built into it, something TODO...
|
||||
|
||||
A small database is built into the program - Ed Levin park, Don's local flying
|
||||
to be precise! You'll need the textures found in the OpenSceneGraph-Data
|
||||
distribution. To run type :
|
||||
|
||||
hangglide
|
||||
|
||||
To run type with other databases, treat it just like sgv such as :
|
||||
|
||||
hangglide town.osg
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <osg/Geode>
|
||||
#include <osg/Group>
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <osgDB/FileNameUtils>
|
||||
#include <osgDB/Registry>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
extern Node *makeTerrain( void );
|
||||
extern Node *makeTrees( void );
|
||||
extern Node *makeTank( void );
|
||||
extern Node *makeWindsocks( void );
|
||||
extern Node *makeGliders( void );
|
||||
extern Node *makeGlider( void );
|
||||
extern Node *makeSky( void );
|
||||
extern Node *makeBase( void );
|
||||
extern Node *makeClouds( void );
|
||||
|
||||
static struct _nodes
|
||||
{
|
||||
char *name;
|
||||
Node *(*fptr)(void);
|
||||
}
|
||||
|
||||
|
||||
nodes[] =
|
||||
{
|
||||
{ "terrain", makeTerrain },
|
||||
{ "tank", makeTank },
|
||||
{ "sky", makeSky },
|
||||
{ "base", makeBase },
|
||||
{ "trees", makeTrees },
|
||||
// { "gliders", makeGliders },
|
||||
// { "clouds", makeClouds },
|
||||
|
||||
{ 0L, 0L }
|
||||
};
|
||||
|
||||
class ReaderWriterFLY : public osgDB::ReaderWriter
|
||||
{
|
||||
public:
|
||||
virtual const char* className() { return "FLY Database Reader"; }
|
||||
|
||||
virtual bool acceptsExtension(const std::string& extension)
|
||||
{
|
||||
return osgDB::equalCaseInsensitive(extension,"fly");
|
||||
}
|
||||
|
||||
virtual ReadResult readNode(const std::string& fileName,const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
|
||||
std::string ext = osgDB::getFileExtension(fileName);
|
||||
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
char buff[256];
|
||||
|
||||
notify(INFO)<< "ReaderWriterFLY::readNode( "<<fileName.c_str()<<" )\n";
|
||||
|
||||
FILE *fp;
|
||||
|
||||
if( (fp = fopen( fileName.c_str(), "r" )) == (FILE *)0L )
|
||||
{
|
||||
notify(WARN)<< "Unable to open file \""<<fileName.c_str()<<"\"\n";
|
||||
return 0L;
|
||||
}
|
||||
Group *grp = new Group;
|
||||
|
||||
while( !feof( fp ) )
|
||||
{
|
||||
_nodes *nptr;
|
||||
fgets( buff, sizeof( buff ), fp );
|
||||
if( buff[0] == '#' )
|
||||
continue;
|
||||
|
||||
for( nptr = nodes; nptr->name; nptr ++ )
|
||||
{
|
||||
if( !strncmp( buff, nptr->name, strlen( nptr->name ) ))
|
||||
{
|
||||
Node *node = nptr->fptr();
|
||||
node->setName( nptr->name );
|
||||
grp->addChild( node );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose( fp );
|
||||
|
||||
return grp;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// now register with osgDB::Registry to instantiate the above
|
||||
// reader/writer.
|
||||
osgDB::RegisterReaderWriterProxy<ReaderWriterFLY> g_readerWriter_FLY_Proxy;
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
#include <math.h>
|
||||
|
||||
#include <osg/Geode>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Texture>
|
||||
#include <osg/TexEnv>
|
||||
#include <osg/Depth>
|
||||
#include <osg/StateSet>
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
Node *makeBase( void )
|
||||
{
|
||||
int i, c;
|
||||
float theta;
|
||||
float ir = 20.0f;
|
||||
|
||||
Vec3Array *coords = new Vec3Array(19);
|
||||
Vec2Array *tcoords = new Vec2Array(19);
|
||||
Vec4Array *colors = new Vec4Array(1);
|
||||
|
||||
(*colors)[0].set(1.0f,1.0f,1.0f,1.0f);
|
||||
|
||||
c = 0;
|
||||
(*coords)[c].set(0.0f,0.0f,0.0f);
|
||||
(*tcoords)[c].set(0.0f,0.0f);
|
||||
|
||||
for( i = 0; i <= 18; i++ )
|
||||
{
|
||||
theta = osg::DegreesToRadians((float)i * 20.0);
|
||||
|
||||
(*coords)[c].set(ir * cosf( theta ), ir * sinf( theta ), 0.0f);
|
||||
(*tcoords)[c].set((*coords)[c][0]/36.0f,(*coords)[c][1]/36.0f);
|
||||
|
||||
c++;
|
||||
}
|
||||
|
||||
Geometry *geom = new Geometry;
|
||||
|
||||
geom->setVertexArray( coords );
|
||||
|
||||
geom->setTexCoordArray( 0, tcoords );
|
||||
|
||||
geom->setColorArray( colors );
|
||||
geom->setColorBinding( Geometry::BIND_OVERALL );
|
||||
|
||||
geom->addPrimitive( new DrawArrays(Primitive::TRIANGLE_FAN,0,19) );
|
||||
|
||||
Texture *tex = new Texture;
|
||||
|
||||
tex->setImage(osgDB::readImageFile("Images/water.rgb"));
|
||||
tex->setWrap( Texture::WRAP_S, Texture::REPEAT );
|
||||
tex->setWrap( Texture::WRAP_T, Texture::REPEAT );
|
||||
|
||||
StateSet *dstate = new StateSet;
|
||||
dstate->setMode( GL_LIGHTING, StateAttribute::OFF );
|
||||
dstate->setTextureAttributeAndModes(0, tex, StateAttribute::ON );
|
||||
|
||||
dstate->setTextureAttribute(0, new TexEnv );
|
||||
|
||||
// clear the depth to the far plane.
|
||||
osg::Depth* depth = new osg::Depth;
|
||||
depth->setFunction(osg::Depth::ALWAYS);
|
||||
depth->setRange(1.0,1.0);
|
||||
dstate->setAttributeAndModes(depth,StateAttribute::ON );
|
||||
|
||||
dstate->setRenderBinDetails(-1,"RenderBin");
|
||||
|
||||
|
||||
geom->setStateSet( dstate );
|
||||
|
||||
Geode *geode = new Geode;
|
||||
geode->addDrawable( geom );
|
||||
|
||||
return geode;
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
#include <osg/Group>
|
||||
#include <osg/Notify>
|
||||
#include <osg/Depth>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/EarthSky>
|
||||
#include <osg/Transform>
|
||||
|
||||
#include <osgUtil/CullVisitor>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include <osgGLUT/glut>
|
||||
#include <osgGLUT/Viewer>
|
||||
|
||||
#include "GliderManipulator.h"
|
||||
|
||||
extern osg::Node *makeTerrain( void );
|
||||
extern osg::Node *makeTrees( void );
|
||||
extern osg::Node *makeTank( void );
|
||||
extern osg::Node *makeWindsocks( void );
|
||||
extern osg::Node *makeGliders( void );
|
||||
extern osg::Node *makeGlider( void );
|
||||
extern osg::Node *makeSky( void );
|
||||
extern osg::Node *makeBase( void );
|
||||
extern osg::Node *makeClouds( void );
|
||||
|
||||
struct MoveEarthySkyWithEyePointCallback : public osg::Transform::ComputeTransformCallback
|
||||
{
|
||||
/** Get the transformation matrix which moves from local coords to world coords.*/
|
||||
virtual const bool computeLocalToWorldMatrix(osg::Matrix& matrix,const osg::Transform*, osg::NodeVisitor* nv) const
|
||||
{
|
||||
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
|
||||
if (cv)
|
||||
{
|
||||
osg::Vec3 eyePointLocal = cv->getEyeLocal();
|
||||
matrix.preMult(osg::Matrix::translate(eyePointLocal.x(),eyePointLocal.y(),0.0f));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Get the transformation matrix which moves from world coords to local coords.*/
|
||||
virtual const bool computeWorldToLocalMatrix(osg::Matrix& matrix,const osg::Transform*, osg::NodeVisitor* nv) const
|
||||
{
|
||||
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
|
||||
if (cv)
|
||||
{
|
||||
osg::Vec3 eyePointLocal = cv->getEyeLocal();
|
||||
matrix.postMult(osg::Matrix::translate(-eyePointLocal.x(),-eyePointLocal.y(),0.0f));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
glutInit( &argc, argv );
|
||||
|
||||
// create the commandline args.
|
||||
std::vector<std::string> commandLine;
|
||||
for(int i=1;i<argc;++i) commandLine.push_back(argv[i]);
|
||||
|
||||
// initialize the viewer.
|
||||
osgGLUT::Viewer viewer;
|
||||
viewer.setWindowTitle(argv[0]);
|
||||
|
||||
// configure the viewer from the commandline arguments, and eat any
|
||||
// parameters that have been matched.
|
||||
viewer.readCommandLine(commandLine);
|
||||
|
||||
// configure the plugin registry from the commandline arguments, and
|
||||
// eat any parameters that have been matched.
|
||||
osgDB::readCommandLine(commandLine);
|
||||
|
||||
// load the nodes from the commandline arguments.
|
||||
osg::Node* rootnode = osgDB::readNodeFiles(commandLine);
|
||||
if (!rootnode)
|
||||
{
|
||||
// no database loaded so automatically create Ed Levin Park..
|
||||
osg::Group* group = new osg::Group;
|
||||
rootnode = group;
|
||||
|
||||
// the base and sky subgraphs go to set the earth sky of the
|
||||
// model and clear the color and depth buffer for us, by using
|
||||
// osg::Depth, and setting their bin numbers to less than 0,
|
||||
// to force them to draw before the rest of the scene.
|
||||
|
||||
osg::EarthSky* earthSky = osgNew osg::EarthSky;
|
||||
earthSky->setRequiresClear(false); // we've got base and sky to do it.
|
||||
|
||||
// use a transform to make the sky and base around with the eye point.
|
||||
osg::Transform* transform = osgNew osg::Transform;
|
||||
|
||||
// transform's value isn't knowm until in the cull traversal so its bounding
|
||||
// volume is can't be determined, therefore culling will be invalid,
|
||||
// so switch it off, this cause all our paresnts to switch culling
|
||||
// off as well. But don't worry culling will be back on once underneath
|
||||
// this node or any other branch above this transform.
|
||||
transform->setCullingActive(false);
|
||||
|
||||
// set the compute transform callback to do all the work of
|
||||
// determining the transform according to the current eye point.
|
||||
transform->setComputeTransformCallback(osgNew MoveEarthySkyWithEyePointCallback);
|
||||
|
||||
// add the sky and base layer.
|
||||
transform->addChild(makeSky()); // bin number -2 so drawn first.
|
||||
transform->addChild(makeBase()); // bin number -1 so draw second.
|
||||
|
||||
// add the transform to the earth sky.
|
||||
earthSky->addChild(transform);
|
||||
|
||||
// add to earth sky to the scene.
|
||||
group->addChild(earthSky);
|
||||
|
||||
// the rest of the scene drawn after the base and sky above.
|
||||
group->addChild(makeTrees()); // will drop into a transparent, depth sorted bin (1)
|
||||
group->addChild(makeTerrain()); // will drop into default bin - state sorted 0
|
||||
group->addChild(makeTank()); // will drop into default bin - state sorted 0
|
||||
// add the following in the future...
|
||||
// makeGliders
|
||||
// makeClouds
|
||||
|
||||
}
|
||||
|
||||
viewer.addViewport( rootnode );
|
||||
|
||||
unsigned int pos = viewer.registerCameraManipulator(new GliderManipulator());
|
||||
|
||||
// Open window so camera manipulator's warp pointer request will succeed
|
||||
viewer.open();
|
||||
|
||||
viewer.selectCameraManipulator(pos);
|
||||
|
||||
viewer.run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
#ifdef _MSC_VER
|
||||
#include <Windows.h>
|
||||
#pragma warning( disable : 4244 )
|
||||
#endif
|
||||
|
||||
#include <osg/GL>
|
||||
#include <osg/Math>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "terrain_coords.h"
|
||||
#include "hat.h"
|
||||
|
||||
static int inited = 0;
|
||||
|
||||
static float dbcenter[3];
|
||||
static float dbradius;
|
||||
|
||||
static void getDatabaseCenterRadius( float dbcenter[3], float *dbradius )
|
||||
{
|
||||
int i;
|
||||
double n=0.0;
|
||||
double center[3] = { 0.0f, 0.0f, 0.0f };
|
||||
float cnt;
|
||||
|
||||
cnt = 39 * 38;
|
||||
for( i = 0; i < cnt; i++ )
|
||||
{
|
||||
center[0] += (double)vertex[i][0];
|
||||
center[1] += (double)vertex[i][1];
|
||||
center[2] += (double)vertex[i][2];
|
||||
|
||||
n = n + 1.0;
|
||||
}
|
||||
|
||||
center[0] /= n;
|
||||
center[1] /= n;
|
||||
center[2] /= n;
|
||||
|
||||
float r = 0.0;
|
||||
|
||||
// for( i = 0; i < sizeof( vertex ) / (sizeof( float[3] )); i++ )
|
||||
for( i = 0; i < cnt; i++ )
|
||||
{
|
||||
double d = sqrt(
|
||||
(((double)vertex[i][0] - center[0]) * ((double)vertex[i][0] - center[0])) +
|
||||
(((double)vertex[i][1] - center[1]) * ((double)vertex[i][1] - center[1])) +
|
||||
(((double)vertex[i][2] - center[2]) * ((double)vertex[i][2] - center[2])) );
|
||||
|
||||
if( d > (double)r ) r = (float)d;
|
||||
|
||||
}
|
||||
|
||||
*dbradius = r;
|
||||
dbcenter[0] = (float)center[0];
|
||||
dbcenter[1] = (float)center[1];
|
||||
dbcenter[2] = (float)center[2];
|
||||
|
||||
int index = 19 * 39 + 19;
|
||||
dbcenter[0] = vertex[index][0] - 0.15;
|
||||
dbcenter[1] = vertex[index][1];
|
||||
dbcenter[2] = vertex[index][2] + 0.35;
|
||||
}
|
||||
|
||||
|
||||
static void init( void )
|
||||
{
|
||||
getDatabaseCenterRadius( dbcenter, &dbradius );
|
||||
inited = 1;
|
||||
}
|
||||
|
||||
|
||||
static void getNormal( float *v1, float *v2, float *v3, float *n )
|
||||
{
|
||||
float V1[4], V2[4];
|
||||
float f;
|
||||
int i;
|
||||
|
||||
/* Two vectors v2->v1 and v2->v3 */
|
||||
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
V1[i] = v1[i] - v2[i];
|
||||
V2[i] = v3[i] - v2[i];
|
||||
}
|
||||
|
||||
/* Cross product between V1 and V2 */
|
||||
|
||||
n[0] = (V1[1] * V2[2]) - (V1[2] * V2[1]);
|
||||
n[1] = -((V1[0] * V2[2]) - ( V1[2] * V2[0] ));
|
||||
n[2] = (V1[0] * V2[1] ) - (V1[1] * V2[0] );
|
||||
|
||||
/* Normalize */
|
||||
|
||||
f = sqrtf( ( n[0] * n[0] ) + ( n[1] * n[1] ) + ( n[2] * n[2] ) );
|
||||
n[0] /= f;
|
||||
n[1] /= f;
|
||||
n[2] /= f;
|
||||
}
|
||||
|
||||
|
||||
float Hat( float x, float y, float z )
|
||||
{
|
||||
int m, n;
|
||||
int i, j;
|
||||
float tri[3][3];
|
||||
float norm[3];
|
||||
float d, pz;
|
||||
|
||||
if( inited == 0 ) init();
|
||||
|
||||
// m = columns
|
||||
// n = rows
|
||||
m = (sizeof( vertex ) /(sizeof( float[3])))/39;
|
||||
n = 39;
|
||||
|
||||
i = 0;
|
||||
while( i < ((m-1)*39) && x > (vertex[i+n][0] - dbcenter[0]) )
|
||||
i += n;
|
||||
|
||||
j = 0;
|
||||
|
||||
while( j < n-1 && y > (vertex[i+j+1][1] - dbcenter[1]) )
|
||||
j++;
|
||||
|
||||
tri[0][0] = vertex[i+0+j+0][0] - dbcenter[0];
|
||||
tri[0][1] = vertex[i+0+j+0][1] - dbcenter[1];
|
||||
//tri[0][2] = vertex[i+0+j+0][2] - dbcenter[2];
|
||||
tri[0][2] = vertex[i+0+j+0][2];
|
||||
|
||||
tri[1][0] = vertex[i+n+j+0][0] - dbcenter[0];
|
||||
tri[1][1] = vertex[i+n+j+0][1] - dbcenter[1];
|
||||
//tri[1][2] = vertex[i+n+j+0][2] - dbcenter[2];
|
||||
tri[1][2] = vertex[i+n+j+0][2];
|
||||
|
||||
tri[2][0] = vertex[i+0+j+1][0] - dbcenter[0];
|
||||
tri[2][1] = vertex[i+0+j+1][1] - dbcenter[1];
|
||||
//tri[2][2] = vertex[i+0+j+1][2] - dbcenter[2];
|
||||
tri[2][2] = vertex[i+0+j+1][2];
|
||||
|
||||
getNormal( tri[0], tri[1], tri[2], norm );
|
||||
|
||||
d = (tri[0][0] * norm[0]) +
|
||||
(tri[0][1] * norm[1]) +
|
||||
(tri[0][2] * norm[2]);
|
||||
|
||||
d *= -1;
|
||||
pz = (-(norm[0] * x) - (norm[1] * y) - d)/norm[2];
|
||||
|
||||
return z - pz;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifndef __HAT_H
|
||||
#define __HAT_H
|
||||
extern float Hat( float x, float y, float z );
|
||||
#endif
|
||||
@@ -1,125 +0,0 @@
|
||||
#include <math.h>
|
||||
|
||||
#include <osg/Geode>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Texture>
|
||||
#include <osg/TexEnv>
|
||||
#include <osg/Depth>
|
||||
#include <osg/StateSet>
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( disable : 4244 )
|
||||
#pragma warning( disable : 4305 )
|
||||
#endif
|
||||
|
||||
using namespace osg;
|
||||
|
||||
Node *makeSky( void )
|
||||
{
|
||||
int i, j;
|
||||
float lev[] = { -5, -1.0, 1.0, 15.0, 30.0, 60.0, 90.0 };
|
||||
float cc[][4] =
|
||||
{
|
||||
{ 0.0, 0.0, 0.15 },
|
||||
{ 0.0, 0.0, 0.15 },
|
||||
{ 0.4, 0.4, 0.7 },
|
||||
{ 0.2, 0.2, 0.6 },
|
||||
{ 0.1, 0.1, 0.6 },
|
||||
{ 0.1, 0.1, 0.6 },
|
||||
{ 0.1, 0.1, 0.6 },
|
||||
};
|
||||
float x, y, z;
|
||||
float alpha, theta;
|
||||
float radius = 20.0f;
|
||||
int nlev = sizeof( lev )/sizeof(float);
|
||||
|
||||
Geometry *geom = new Geometry;
|
||||
|
||||
Vec3Array& coords = *(new Vec3Array(19*nlev));
|
||||
Vec4Array& colors = *(new Vec4Array(19*nlev));
|
||||
Vec2Array& tcoords = *(new Vec2Array(19*nlev));
|
||||
|
||||
|
||||
int ci, ii;
|
||||
ii = ci = 0;
|
||||
|
||||
for( i = 0; i < nlev; i++ )
|
||||
{
|
||||
for( j = 0; j <= 18; j++ )
|
||||
{
|
||||
alpha = osg::DegreesToRadians(lev[i]);
|
||||
theta = osg::DegreesToRadians((float)(j*20));
|
||||
|
||||
x = radius * cosf( alpha ) * cosf( theta );
|
||||
y = radius * cosf( alpha ) * -sinf( theta );
|
||||
z = radius * sinf( alpha );
|
||||
|
||||
coords[ci][0] = x;
|
||||
coords[ci][1] = y;
|
||||
coords[ci][2] = z;
|
||||
|
||||
colors[ci][0] = cc[i][0];
|
||||
colors[ci][1] = cc[i][1];
|
||||
colors[ci][2] = cc[i][2];
|
||||
colors[ci][3] = 1.0;
|
||||
|
||||
tcoords[ci][0] = (float)j/18.0;
|
||||
tcoords[ci][0] = (float)i/(float)(nlev-1);
|
||||
|
||||
ci++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
for( i = 0; i < nlev-1; i++ )
|
||||
{
|
||||
UShortDrawElements* drawElements = new UShortDrawElements(Primitive::TRIANGLE_STRIP);
|
||||
drawElements->reserve(38);
|
||||
|
||||
for( j = 0; j <= 18; j++ )
|
||||
{
|
||||
drawElements->push_back((i+1)*19+j);
|
||||
drawElements->push_back((i+0)*19+j);
|
||||
}
|
||||
|
||||
geom->addPrimitive(drawElements);
|
||||
}
|
||||
|
||||
geom->setVertexArray( &coords );
|
||||
geom->setTexCoordArray( 0, &tcoords );
|
||||
|
||||
geom->setColorArray( &colors );
|
||||
geom->setColorBinding( Geometry::BIND_PER_VERTEX );
|
||||
|
||||
|
||||
Texture *tex = new Texture;
|
||||
tex->setImage(osgDB::readImageFile("Images/white.rgb"));
|
||||
|
||||
StateSet *dstate = new StateSet;
|
||||
|
||||
dstate->setTextureAttributeAndModes(0, tex, StateAttribute::OFF );
|
||||
dstate->setTextureAttribute(0, new TexEnv );
|
||||
dstate->setMode( GL_LIGHTING, StateAttribute::OFF );
|
||||
dstate->setMode( GL_CULL_FACE, StateAttribute::ON );
|
||||
|
||||
|
||||
// clear the depth to the far plane.
|
||||
osg::Depth* depth = new osg::Depth;
|
||||
depth->setFunction(osg::Depth::ALWAYS);
|
||||
depth->setRange(1.0,1.0);
|
||||
dstate->setAttributeAndModes(depth,StateAttribute::ON );
|
||||
|
||||
dstate->setRenderBinDetails(-2,"RenderBin");
|
||||
|
||||
geom->setStateSet( dstate );
|
||||
|
||||
Geode *geode = new Geode;
|
||||
geode->addDrawable( geom );
|
||||
|
||||
geode->setName( "Sky" );
|
||||
|
||||
return geode;
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
#include <math.h>
|
||||
|
||||
#include <osg/GL>
|
||||
#include <osg/Group>
|
||||
#include <osg/Geode>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Texture>
|
||||
#include <osg/TexEnv>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Matrix>
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( disable : 4244 )
|
||||
#pragma warning( disable : 4305 )
|
||||
#endif
|
||||
|
||||
using namespace osg;
|
||||
|
||||
extern void getDatabaseCenterRadius( float dbcenter[3], float *dbradius );
|
||||
|
||||
static float radius = 2.0;
|
||||
static float dbcenter[3], dbradius;
|
||||
|
||||
static void conv( const Vec3& a, const Matrix& mat, Vec3& b )
|
||||
{
|
||||
int i;
|
||||
Vec3 t;
|
||||
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
t[i] = (a[0] * mat(0,i)) +
|
||||
(a[1] * mat(1,i)) +
|
||||
(a[2] * mat(2,i)) +
|
||||
mat(3,i);
|
||||
}
|
||||
b[0] = t[0];
|
||||
b[1] = t[1];
|
||||
b[2] = t[2];
|
||||
}
|
||||
|
||||
|
||||
Node *makeTank( void )
|
||||
{
|
||||
|
||||
Geode *geode = new Geode;
|
||||
|
||||
getDatabaseCenterRadius( dbcenter, &dbradius );
|
||||
|
||||
ref_ptr<Matrix> mat = new Matrix(
|
||||
0.05, 0, 0, 0,
|
||||
0, 0.05, 0, 0,
|
||||
0, 0, 0.05, 0,
|
||||
1.5999 - 0.3,
|
||||
3.1474,
|
||||
dbcenter[2] + 0.6542 - 0.09,
|
||||
1
|
||||
);
|
||||
|
||||
// 42 required for sodes, 22 for the top.
|
||||
Vec3Array& vc = *(new Vec3Array(42+22));
|
||||
Vec2Array& tc = *(new Vec2Array(42+22));
|
||||
|
||||
Geometry *gset = new Geometry;
|
||||
gset->setVertexArray( &vc );
|
||||
gset->setTexCoordArray( 0, &tc );
|
||||
|
||||
// create the sides of the tank.
|
||||
unsigned int i, c = 0;
|
||||
for( i = 0; i <= 360; i += 18 )
|
||||
{
|
||||
float x, y, z;
|
||||
float s, t;
|
||||
float theta = osg::DegreesToRadians((float)i);
|
||||
|
||||
s = (float)i/90.0;
|
||||
t = 1.0;
|
||||
|
||||
x = radius * cosf( theta );
|
||||
y = radius * sinf( theta );
|
||||
z = 1.0;
|
||||
|
||||
vc[c][0] = x;
|
||||
vc[c][1] = y;
|
||||
vc[c][2] = z;
|
||||
|
||||
tc[c][0] = s;
|
||||
tc[c][1] = t;
|
||||
|
||||
c++;
|
||||
|
||||
t = 0.0;
|
||||
z = 0.0;
|
||||
|
||||
vc[c][0] = x;
|
||||
vc[c][1] = y;
|
||||
vc[c][2] = z;
|
||||
|
||||
tc[c][0] = s;
|
||||
tc[c][1] = t;
|
||||
c++;
|
||||
}
|
||||
|
||||
gset->addPrimitive( new DrawArrays(Primitive::TRIANGLE_STRIP,0,c) );
|
||||
|
||||
// create the top of the tank.
|
||||
|
||||
int prev_c = c;
|
||||
|
||||
vc[c][0] = 0.0f;
|
||||
vc[c][1] = 0.0f;
|
||||
vc[c][2] = 1.0f;
|
||||
|
||||
tc[c][0] = 0.0f;
|
||||
tc[c][1] = 0.0f;
|
||||
c++;
|
||||
|
||||
for( i = 0; i <= 360; i += 18 )
|
||||
{
|
||||
float x, y, z;
|
||||
float s, t;
|
||||
float theta = osg::DegreesToRadians((float)i);
|
||||
|
||||
// s = (float)i/360.0;
|
||||
// t = 1.0;
|
||||
s = cosf( theta );
|
||||
t = sinf( theta );
|
||||
|
||||
x = radius * cosf( theta );
|
||||
y = radius * sinf( theta );
|
||||
z = 1.0;
|
||||
|
||||
vc[c][0] = x;
|
||||
vc[c][1] = y;
|
||||
vc[c][2] = z;
|
||||
|
||||
tc[c][0] = s;
|
||||
tc[c][1] = t;
|
||||
|
||||
c++;
|
||||
}
|
||||
|
||||
for( i = 0; i < c; i++ )
|
||||
conv( vc[i], *mat, vc[i] );
|
||||
|
||||
gset->addPrimitive(new DrawArrays(Primitive::TRIANGLE_FAN,prev_c,c-prev_c));
|
||||
|
||||
|
||||
|
||||
|
||||
Texture *tex = new Texture;
|
||||
|
||||
tex->setWrap( Texture::WRAP_S, Texture::REPEAT );
|
||||
tex->setWrap( Texture::WRAP_T, Texture::REPEAT );
|
||||
tex->setImage(osgDB::readImageFile("Images/tank.rgb"));
|
||||
|
||||
StateSet *dstate = new StateSet;
|
||||
dstate->setTextureAttributeAndModes(0, tex, StateAttribute::ON );
|
||||
dstate->setTextureAttribute(0, new TexEnv );
|
||||
|
||||
gset->setStateSet( dstate );
|
||||
geode->addDrawable( gset );
|
||||
|
||||
return geode;
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
// #include <math.h>
|
||||
|
||||
#include <osg/Geode>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Texture>
|
||||
#include <osg/TexEnv>
|
||||
#include <osg/StateSet>
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include "terrain_coords.h"
|
||||
#include "terrain_texcoords.h"
|
||||
|
||||
using namespace osg;
|
||||
|
||||
void getDatabaseCenterRadius( float dbcenter[3], float *dbradius )
|
||||
{
|
||||
int i;
|
||||
double n=0.0;
|
||||
double center[3] = { 0.0f, 0.0f, 0.0f };
|
||||
float cnt;
|
||||
|
||||
cnt = 39 * 38;
|
||||
for( i = 0; i < cnt; i++ )
|
||||
{
|
||||
center[0] += (double)vertex[i][0];
|
||||
center[1] += (double)vertex[i][1];
|
||||
center[2] += (double)vertex[i][2];
|
||||
|
||||
n = n + 1.0;
|
||||
}
|
||||
|
||||
center[0] /= n;
|
||||
center[1] /= n;
|
||||
center[2] /= n;
|
||||
|
||||
float r = 0.0;
|
||||
|
||||
// for( i = 0; i < sizeof( vertex ) / (sizeof( float[3] )); i++ )
|
||||
for( i = 0; i < cnt; i++ )
|
||||
{
|
||||
double d = sqrt(
|
||||
(((double)vertex[i][0] - center[0]) * ((double)vertex[i][0] - center[0])) +
|
||||
(((double)vertex[i][1] - center[1]) * ((double)vertex[i][1] - center[1])) +
|
||||
(((double)vertex[i][2] - center[2]) * ((double)vertex[i][2] - center[2])) );
|
||||
|
||||
if( d > (double)r ) r = (float)d;
|
||||
|
||||
}
|
||||
|
||||
*dbradius = r;
|
||||
dbcenter[0] = (float)center[0];
|
||||
dbcenter[1] = (float)center[1];
|
||||
dbcenter[2] = (float)center[2];
|
||||
|
||||
int index = 19 * 39 + 19;
|
||||
dbcenter[0] = vertex[index][0] - 0.15;
|
||||
dbcenter[1] = vertex[index][1];
|
||||
dbcenter[2] = vertex[index][2] + 0.35;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Node *makeTerrain( void )
|
||||
{
|
||||
int m, n;
|
||||
int i, j, c;
|
||||
float dbcenter[3];
|
||||
float dbradius;
|
||||
|
||||
getDatabaseCenterRadius( dbcenter, &dbradius );
|
||||
|
||||
m = (sizeof( vertex ) /(sizeof( float[3])))/39;
|
||||
n = 39;
|
||||
|
||||
Vec3Array& v = *(new Vec3Array(m*n));
|
||||
Vec2Array& t = *(new Vec2Array(m*n));
|
||||
Vec4Array& col = *(new Vec4Array(1));
|
||||
|
||||
col[0][0] = col[0][1] = col[0][2] = col[0][3] = 1.0f;
|
||||
|
||||
for( i = 0; i < m * n; i++ )
|
||||
{
|
||||
v[i][0] = vertex[i][0] - dbcenter[0];
|
||||
v[i][1] = vertex[i][1] - dbcenter[1];
|
||||
v[i][2] = vertex[i][2];
|
||||
|
||||
t[i][0] = texcoord[i][0] + 0.025;
|
||||
t[i][1] = texcoord[i][1];
|
||||
}
|
||||
|
||||
Geometry *geom = new Geometry;
|
||||
|
||||
geom->setVertexArray( &v );
|
||||
geom->setTexCoordArray( 0, &t );
|
||||
|
||||
geom->setColorArray( &col );
|
||||
geom->setColorBinding( Geometry::BIND_OVERALL );
|
||||
|
||||
c = 0;
|
||||
for( i = 0; i < m-2; i++ )
|
||||
{
|
||||
UShortDrawElements* elements = new UShortDrawElements(Primitive::TRIANGLE_STRIP);
|
||||
elements->reserve(39*2);
|
||||
for( j = 0; j < n; j++ )
|
||||
{
|
||||
elements->push_back((i+0)*n+j);
|
||||
elements->push_back((i+1)*n+j);
|
||||
}
|
||||
geom->addPrimitive(elements);
|
||||
}
|
||||
|
||||
|
||||
Texture *tex = new Texture;
|
||||
|
||||
tex->setImage(osgDB::readImageFile("Images/lz.rgb"));
|
||||
|
||||
StateSet *dstate = new StateSet;
|
||||
dstate->setMode( GL_LIGHTING, StateAttribute::OFF );
|
||||
dstate->setTextureAttributeAndModes(0, tex, StateAttribute::ON );
|
||||
dstate->setTextureAttribute(0, new TexEnv );
|
||||
|
||||
geom->setStateSet( dstate );
|
||||
|
||||
Geode *geode = new Geode;
|
||||
geode->addDrawable( geom );
|
||||
|
||||
return geode;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,273 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <osg/Billboard>
|
||||
#include <osg/Group>
|
||||
#include <osg/Geode>
|
||||
#include <osg/Geometry>
|
||||
#include <osg/Texture>
|
||||
#include <osg/TexEnv>
|
||||
#include <osg/BlendFunc>
|
||||
#include <osg/AlphaFunc>
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include "hat.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( disable : 4244 )
|
||||
#pragma warning( disable : 4305 )
|
||||
#endif
|
||||
|
||||
using namespace osg;
|
||||
|
||||
#define sqr(x) ((x)*(x))
|
||||
|
||||
extern void getDatabaseCenterRadius( float dbcenter[3], float *dbradius );
|
||||
|
||||
static float dbcenter[3], dbradius;
|
||||
|
||||
static struct _tree
|
||||
{
|
||||
int n;
|
||||
float x, y, z;
|
||||
float w, h;
|
||||
}
|
||||
|
||||
|
||||
trees[] =
|
||||
{
|
||||
{ 0, -0.4769, -0.8972, -0.4011, 0.2000, 0.1200 },
|
||||
{ 1, -0.2543, -0.9117, -0.3873, 0.2000, 0.1200 },
|
||||
{ 2, -0.0424, -0.8538, -0.3728, 0.2000, 0.1200 },
|
||||
{ 3, 0.1590, -0.8827, -0.3594, 0.2000, 0.1200 },
|
||||
{ 4, -0.4981, -1.0853, -0.4016, 0.3500, 0.1200 },
|
||||
{ 5, -0.5405, -1.2590, -0.4050, 0.2000, 0.1200 },
|
||||
{ 6, -0.5723, -1.5339, -0.4152, 0.2000, 0.1200 },
|
||||
{ 7, -0.6252, -1.8667, -0.4280, 0.2000, 0.1200 },
|
||||
{ 8, -0.5617, -2.1851, -0.4309, 0.2000, 0.1200 },
|
||||
{ 9, -0.5087, -2.4166, -0.4215, 0.2000, 0.1200 },
|
||||
{ 10, -0.4345, -2.3443, -0.4214, 0.2000, 0.1200 },
|
||||
{ 11, -3.0308, -1.5484, -0.4876, 0.2000, 0.1200 },
|
||||
{ 12, -3.0202, -1.6497, -0.4963, 0.2000, 0.1200 },
|
||||
{ 13, -2.9355, -1.8378, -0.4969, 0.2000, 0.1200 },
|
||||
{ 14, -0.6040, -2.0259, -0.4300, 0.2000, 0.1200 },
|
||||
{ 15, -0.5442, -1.3442, -0.4080, 0.1000, 0.1200 },
|
||||
{ 16, -0.5639, -1.6885, -0.4201, 0.1000, 0.1200 },
|
||||
{ 17, 0.9246, 3.4835, 0.5898, 0.2500, 0.1000 },
|
||||
{ 18, 0.0787, 3.8687, 0.3329, 0.2500, 0.1200 },
|
||||
{ 19, 0.2885, 3.7130, 0.4047, 0.2500, 0.1200 },
|
||||
{ 20, 0.2033, 3.6228, 0.3704, 0.2500, 0.1200 },
|
||||
{ 21, -0.2098, 3.9015, 0.2327, 0.2500, 0.1200 },
|
||||
{ 22, -0.3738, 3.7376, 0.1722, 0.2500, 0.1200 },
|
||||
{ 23, -0.2557, 3.6064, 0.1989, 0.2500, 0.1200 },
|
||||
{ 24, 0.0590, 3.7294, 0.3210, 0.2500, 0.1200 },
|
||||
{ 25, -0.4721, 3.8851, 0.1525, 0.2500, 0.1200 },
|
||||
{ 26, 0.9639, 3.2048, 0.5868, 0.1200, 0.0800 },
|
||||
{ 27, 0.7082, -1.0409, -0.3221, 0.1000, 0.1000 },
|
||||
{ 28, -0.2426, -2.3442, -0.4150, 0.1000, 0.1380 },
|
||||
{ 29, -0.1770, -2.4179, -0.4095, 0.1000, 0.1580 },
|
||||
{ 30, -0.0852, -2.5327, -0.4056, 0.1000, 0.1130 },
|
||||
{ 31, -0.0131, -2.6065, -0.4031, 0.1000, 0.1150 },
|
||||
{ 32, 0.0787, -2.6638, -0.4012, 0.1000, 0.1510 },
|
||||
{ 33, 0.1049, -2.7622, -0.3964, 0.1000, 0.1270 },
|
||||
{ 34, 0.1770, -2.8687, -0.3953, 0.1000, 0.1100 },
|
||||
{ 35, 0.3213, -2.9507, -0.3974, 0.1000, 0.1190 },
|
||||
{ 36, 0.4065, -3.0163, -0.4014, 0.1000, 0.1120 },
|
||||
{ 37, 0.3738, -3.1802, -0.4025, 0.1000, 0.1860 },
|
||||
{ 38, 0.5508, -3.2048, -0.3966, 0.1000, 0.1490 },
|
||||
{ 39, 0.5836, -3.3031, -0.3900, 0.1000, 0.1670 },
|
||||
{ 40, -0.3082, -2.7212, -0.3933, 0.1000, 0.1840 },
|
||||
{ 41, -0.1967, -2.6474, -0.4017, 0.1000, 0.1600 },
|
||||
{ 42, -0.1180, -2.7458, -0.3980, 0.1000, 0.1250 },
|
||||
{ 43, -0.3344, -2.8359, -0.3964, 0.1000, 0.1430 },
|
||||
{ 44, -0.2492, -2.8933, -0.3838, 0.1000, 0.1890 },
|
||||
{ 45, -0.1246, -3.0491, -0.3768, 0.1000, 0.1830 },
|
||||
{ 46, 0.0000, -3.0818, -0.3696, 0.1000, 0.1370 },
|
||||
{ 47, -0.2295, -3.0409, -0.3706, 0.1000, 0.1660 },
|
||||
{ 48, -1.3245, 2.6638, 0.0733, 0.0500, 0.0500 },
|
||||
{ 49, 2.2425, -1.5491, -0.2821, 0.2300, 0.1200 },
|
||||
{ 50, 0.2164, -2.1311, -0.4000, 0.1000, 0.0690 },
|
||||
{ 51, 0.2885, -2.2130, -0.4000, 0.1000, 0.0790 },
|
||||
{ 52, 0.3606, -2.2786, -0.4000, 0.1000, 0.0565 },
|
||||
{ 53, 0.4328, -2.3442, -0.4000, 0.1000, 0.0575 },
|
||||
{ 54, 0.5246, -2.4343, -0.4086, 0.1000, 0.0755 },
|
||||
{ 55, 0.6360, -2.5245, -0.4079, 0.1000, 0.0635 },
|
||||
{ 56, 0.7541, -2.4261, -0.4007, 0.1000, 0.0550 },
|
||||
{ 57, 0.7934, -2.2786, -0.3944, 0.1000, 0.0595 },
|
||||
{ 58, 1.0295, -2.2868, -0.3837, 0.1000, 0.0560 },
|
||||
{ 59, 0.8459, -2.6474, -0.4051, 0.1000, 0.0930 },
|
||||
{ 60, 1.0426, -2.6884, -0.4001, 0.1000, 0.0745 },
|
||||
{ 61, 1.1475, -2.7458, -0.3883, 0.1000, 0.0835 },
|
||||
{ 62, -0.1967, -1.4180, -0.3988, 0.1000, 0.0920 },
|
||||
{ 63, -0.0131, -1.2704, -0.3856, 0.1000, 0.0690 },
|
||||
{ 64, 0.2098, -1.2049, -0.3664, 0.1000, 0.0790 },
|
||||
{ 65, 0.3410, -1.3196, -0.3652, 0.1000, 0.0565 },
|
||||
{ 66, 0.5705, -1.2704, -0.3467, 0.1000, 0.0575 },
|
||||
{ 67, 0.6360, -1.4344, -0.3532, 0.1000, 0.0755 },
|
||||
{ 68, 0.9246, -1.4180, -0.3329, 0.1000, 0.0635 },
|
||||
{ 69, 1.0623, -1.3360, -0.3183, 0.1000, 0.0550 },
|
||||
{ 70, 1.2393, -1.3934, -0.3103, 0.1000, 0.0595 },
|
||||
{ 71, 1.3639, -1.4753, -0.3079, 0.1000, 0.0560 },
|
||||
{ 72, 1.4819, -1.5983, -0.3210, 0.1000, 0.0930 },
|
||||
{ 73, 1.7835, -1.5819, -0.3065, 0.1000, 0.0745 },
|
||||
{ 74, 1.9343, -2.1065, -0.3307, 0.1000, 0.0835 },
|
||||
{ 75, 2.1245, -2.3196, -0.3314, 0.1000, 0.0920 },
|
||||
{ 76, 2.2556, -2.3032, -0.3230, 0.1000, 0.0800 },
|
||||
{ 77, 2.4196, -2.3688, -0.3165, 0.1000, 0.0625 },
|
||||
{ 78, 1.7835, -2.5327, -0.3543, 0.1000, 0.0715 },
|
||||
{ 79, 1.7180, -2.8933, -0.3742, 0.1000, 0.0945 },
|
||||
{ 80, 1.9343, -3.0409, -0.3727, 0.1000, 0.0915 },
|
||||
{ 81, 2.4524, -3.4671, -0.3900, 0.1000, 0.0685 },
|
||||
{ 82, 2.4786, -2.8851, -0.3538, 0.1000, 0.0830 },
|
||||
{ 83, 2.3343, -2.6228, -0.3420, 0.1000, 0.0830 },
|
||||
{ 84, 2.8130, -2.0737, -0.2706, 0.1000, 0.0890 },
|
||||
{ 85, 2.6360, -1.8278, -0.2661, 0.1000, 0.0975 },
|
||||
{ 86, 2.3958, -1.7130, -0.2774, 0.2000, 0.1555 },
|
||||
{ 87, 2.2688, -1.2868, -0.2646, 0.1000, 0.0835 },
|
||||
{ 88, 2.4196, -1.1147, -0.2486, 0.1000, 0.0770 },
|
||||
{ 89, 2.7802, -2.3933, -0.3017, 0.1000, 0.0655 },
|
||||
{ 90, 3.0163, -2.4179, -0.2905, 0.1000, 0.0725 },
|
||||
{ 91, 2.9310, -2.2540, -0.2798, 0.1000, 0.0910 },
|
||||
{ 92, 2.6622, -2.0983, -0.2823, 0.1000, 0.0680 },
|
||||
{ 93, 2.3147, -1.9753, -0.2973, 0.1000, 0.0620 },
|
||||
{ 94, 2.1573, -1.8770, -0.3013, 0.1000, 0.0525 },
|
||||
{ 95, 2.0196, -1.7868, -0.3044, 0.1000, 0.0970 },
|
||||
{ 96, 2.7802, -3.3031, -0.3900, 0.1000, 0.0510 },
|
||||
{ 97, 2.8589, -3.1720, -0.3900, 0.1000, 0.0755 },
|
||||
{ 98, 3.0163, -2.8114, -0.3383, 0.1000, 0.0835 },
|
||||
{ 99, 3.5081, -2.4179, -0.2558, 0.1000, 0.0770 },
|
||||
{ 100, 3.5277, -2.3196, -0.2366, 0.1000, 0.0765 },
|
||||
{ 101, 3.6654, -2.5819, -0.2566, 0.1000, 0.0805 },
|
||||
{ 102, 3.7179, -2.7622, -0.2706, 0.1000, 0.0980 },
|
||||
{ 103, 3.7769, -2.4671, -0.2339, 0.1000, 0.0640 },
|
||||
{ 104, 3.3441, -2.4671, -0.2693, 0.1000, 0.0940 },
|
||||
{ -1, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
static Geometry *makeTree( _tree *tree, StateSet *dstate )
|
||||
{
|
||||
float vv[][3] =
|
||||
{
|
||||
{ -tree->w/2.0, 0.0, 0.0 },
|
||||
{ tree->w/2.0, 0.0, 0.0 },
|
||||
{ tree->w/2.0, 0.0, 2 * tree->h },
|
||||
{ -tree->w/2.0, 0.0, 2 * tree->h },
|
||||
};
|
||||
|
||||
Vec3Array& v = *(new Vec3Array(4));
|
||||
Vec2Array& t = *(new Vec2Array(4));
|
||||
Vec4Array& l = *(new Vec4Array(1));
|
||||
|
||||
int i;
|
||||
|
||||
l[0][0] = l[0][1] = l[0][2] = l[0][3] = 1;
|
||||
|
||||
for( i = 0; i < 4; i++ )
|
||||
{
|
||||
v[i][0] = vv[i][0];
|
||||
v[i][1] = vv[i][1];
|
||||
v[i][2] = vv[i][2];
|
||||
}
|
||||
|
||||
t[0][0] = 0.0; t[0][1] = 0.0;
|
||||
t[1][0] = 1.0; t[1][1] = 0.0;
|
||||
t[2][0] = 1.0; t[2][1] = 1.0;
|
||||
t[3][0] = 0.0; t[3][1] = 1.0;
|
||||
|
||||
Geometry *geom = new Geometry;
|
||||
|
||||
geom->setVertexArray( &v );
|
||||
|
||||
geom->setTexCoordArray( 0, &t );
|
||||
|
||||
geom->setColorArray( &l );
|
||||
geom->setColorBinding( Geometry::BIND_OVERALL );
|
||||
|
||||
geom->addPrimitive( new DrawArrays(Primitive::QUADS,0,4) );
|
||||
|
||||
geom->setStateSet( dstate );
|
||||
|
||||
return geom;
|
||||
}
|
||||
|
||||
|
||||
static float ttx, tty;
|
||||
|
||||
static int ct( const void *a, const void *b )
|
||||
{
|
||||
_tree *ta = (_tree *)a;
|
||||
_tree *tb = (_tree *)b;
|
||||
|
||||
float da = sqrtf( sqr(ta->x - ttx) + sqr(ta->y - tty) );
|
||||
float db = sqrtf( sqr(tb->x - ttx) + sqr(tb->y - tty) );
|
||||
|
||||
if( da < db )
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Node *makeTrees( void )
|
||||
{
|
||||
Group *group = new Group;
|
||||
int i;
|
||||
|
||||
getDatabaseCenterRadius( dbcenter, &dbradius );
|
||||
struct _tree *t;
|
||||
|
||||
Texture *tex = new Texture;
|
||||
tex->setImage(osgDB::readImageFile("Images/tree0.rgba"));
|
||||
|
||||
StateSet *dstate = new StateSet;
|
||||
|
||||
dstate->setTextureAttributeAndModes(0, tex, StateAttribute::ON );
|
||||
dstate->setTextureAttribute(0, new TexEnv );
|
||||
|
||||
dstate->setAttributeAndModes( new BlendFunc, StateAttribute::ON );
|
||||
|
||||
AlphaFunc* alphaFunc = new AlphaFunc;
|
||||
alphaFunc->setFunction(AlphaFunc::GEQUAL,0.05f);
|
||||
dstate->setAttributeAndModes( alphaFunc, StateAttribute::ON );
|
||||
|
||||
dstate->setMode( GL_LIGHTING, StateAttribute::OFF );
|
||||
|
||||
dstate->setRenderingHint( StateSet::TRANSPARENT_BIN );
|
||||
|
||||
int tt[] = { 15, 30, 45, 58, 72, 75, 93, 96, 105, -1 };
|
||||
int *ttp = tt;
|
||||
|
||||
i = 0;
|
||||
while( i < 105 )
|
||||
{
|
||||
ttx = trees[i].x;
|
||||
tty = trees[i].y;
|
||||
qsort( &trees[i], 105 - i, sizeof( _tree ), ct );
|
||||
|
||||
i += *ttp;
|
||||
ttp++;
|
||||
}
|
||||
|
||||
t = trees;
|
||||
i = 0;
|
||||
ttp = tt;
|
||||
while( *ttp != -1 )
|
||||
{
|
||||
Billboard *bb = new Billboard;
|
||||
//int starti = i;
|
||||
|
||||
for( ; i < (*ttp); i++ )
|
||||
{
|
||||
t->x -= 0.3f;
|
||||
float h = Hat(t->x, t->y, t->z );
|
||||
Vec3 pos( t->x, t->y, t->z-h );
|
||||
Geometry *geom = makeTree( t, dstate );
|
||||
bb->addDrawable( geom, pos );
|
||||
t++;
|
||||
}
|
||||
group->addChild( bb );
|
||||
ttp++;
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
Reference in New Issue
Block a user