And yet more clean up synch with 0.8.42
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
#!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
|
||||
@@ -1,135 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
#!smake
|
||||
include ../../../Make/makedefs
|
||||
|
||||
C++FILES = \
|
||||
hat.cpp\
|
||||
vector.cpp\
|
||||
matrix.cpp\
|
||||
fly.cpp\
|
||||
terrain.cpp\
|
||||
tank.cpp\
|
||||
sky.cpp\
|
||||
base.cpp\
|
||||
trees.cpp\
|
||||
|
||||
|
||||
LIB = ../../../lib/osgPlugins/osgdb_fly.so
|
||||
|
||||
TARGET_LOADER_FILES = osgPlugins/osgdb_fly.so
|
||||
|
||||
C++FLAGS += -I../../../include
|
||||
LDFLAGS += -L../../../lib
|
||||
|
||||
include ../../../Make/makerules
|
||||
|
||||
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
#include <math.h>
|
||||
|
||||
#include <osg/OSG>
|
||||
#include <osg/Geode>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/Texture>
|
||||
#include <osg/GeoState>
|
||||
#include <osg/Registry>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
Node *makeBase( void )
|
||||
{
|
||||
int i, c;
|
||||
float theta;
|
||||
float ir, ori;
|
||||
ir = 6.0;
|
||||
ori = 20.0;
|
||||
|
||||
|
||||
Vec3 *coords = new Vec3[38];
|
||||
Vec2 *tcoords = new Vec2[38];
|
||||
Vec4 *colors = new Vec4[1];
|
||||
int *lengths = new int[1];
|
||||
|
||||
colors[0][0] = colors[0][1] = colors[0][2] = colors[0][3] = 1;
|
||||
|
||||
c = 0;
|
||||
for( i = 0; i <= 18; i++ )
|
||||
{
|
||||
theta = (float)i * 20.0 * M_PI/180.0;
|
||||
|
||||
coords[c][0] = ir * cosf( theta );
|
||||
coords[c][1] = ir * sinf( theta );
|
||||
coords[c][2] = 0.0;
|
||||
tcoords[c][0] = coords[c][0]/36.;
|
||||
tcoords[c][1] = coords[c][1]/36.;
|
||||
|
||||
c++;
|
||||
|
||||
coords[c][0] = ori * cosf( theta );
|
||||
coords[c][1] = ori * sinf( theta );
|
||||
coords[c][2] = 0.0f;
|
||||
|
||||
tcoords[c][0] = coords[c][0]/36.;
|
||||
tcoords[c][1] = coords[c][1]/36.;
|
||||
|
||||
c++;
|
||||
}
|
||||
*lengths = 38;
|
||||
|
||||
|
||||
GeoSet *gset = new GeoSet;
|
||||
|
||||
gset->setCoords( coords );
|
||||
|
||||
gset->setTextureCoords( tcoords );
|
||||
gset->setTextureBinding( GeoSet::BIND_PERVERTEX );
|
||||
|
||||
gset->setColors( colors );
|
||||
gset->setColorBinding( GeoSet::BIND_OVERALL );
|
||||
|
||||
gset->setPrimType( GeoSet::TRIANGLE_STRIP );
|
||||
gset->setNumPrims( 1 );
|
||||
gset->setPrimLengths( lengths );
|
||||
|
||||
Texture *tex = new Texture;
|
||||
|
||||
tex->setImage(Registry::instance()->readImage("water.rgb"));
|
||||
|
||||
tex->setWrap( Texture::WRAP_S, Texture::REPEAT );
|
||||
tex->setWrap( Texture::WRAP_T, Texture::REPEAT );
|
||||
|
||||
GeoState *gstate = new GeoState;
|
||||
gstate->setMode( GeoState::TEXTURE, GeoState::ON );
|
||||
gstate->setMode( GeoState::LIGHTING, GeoState::OFF );
|
||||
gstate->setAttribute( GeoState::TEXTURE, tex );
|
||||
gstate->setAttribute( GeoState::TEXENV, new TexEnv );
|
||||
/*
|
||||
pfFog *fog = new pfFog;
|
||||
|
||||
fog->setFogType( PFFOG_PIX_EXP2 );
|
||||
fog->setColor( 0.1, 0.2, 0.2 );
|
||||
fog->setRange( 16.0, 22.0 );
|
||||
|
||||
gstate->setMode( PFSTATE_ENFOG, PF_ON );
|
||||
gstate->setAttr( PFSTATE_FOG, fog );
|
||||
*/
|
||||
|
||||
gset->setGeoState( gstate );
|
||||
|
||||
|
||||
Geode *geode = new Geode;
|
||||
geode->addGeoSet( gset );
|
||||
|
||||
return geode;
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <osg/OSG>
|
||||
#include <osg/Geode>
|
||||
#include <osg/Group>
|
||||
#include <osg/Registry>
|
||||
#include <osg/Notify>
|
||||
|
||||
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 );
|
||||
|
||||
|
||||
extern "C" {
|
||||
Node* LoadFile_fly( const char *file );
|
||||
void InitConverter_fly( 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 }
|
||||
};
|
||||
|
||||
void InitConverter_fly( void )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Node* LoadFile_fly( const char *file )
|
||||
{
|
||||
char buff[256];
|
||||
|
||||
osg::notify(osg::INFO)<< "sgLoadFile_fly( "<<file<< ")\n";
|
||||
|
||||
FILE *fp;
|
||||
|
||||
if( (fp = fopen( file, "r" )) == (FILE *)0L )
|
||||
{
|
||||
osg::notify(osg::WARN)<< "Unable to open file \""<<file<<"\"\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;
|
||||
}
|
||||
|
||||
class sgReaderWriterFLY : public ReaderWriter {
|
||||
public:
|
||||
virtual const char* className() { return "Default FLY Database Reader/Writer"; }
|
||||
virtual bool acceptsExtension(const std::string& extension) { return extension=="fly"; }
|
||||
|
||||
virtual Node* readNode(const std::string& fileName)
|
||||
{
|
||||
char buff[256];
|
||||
|
||||
osg::notify(osg::INFO)<< "sgReaderWriterFLY::readNode( "<<fileName.c_str()<<" )\n";
|
||||
|
||||
FILE *fp;
|
||||
|
||||
if( (fp = fopen( fileName.c_str(), "r" )) == (FILE *)0L )
|
||||
{
|
||||
osg::notify(osg::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;
|
||||
|
||||
}
|
||||
|
||||
virtual bool writeNode(Node& obj,const std::string& fileName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// now register with sgRegistry to instantiate the above
|
||||
// reader/writer.
|
||||
RegisterReaderWriterProxy<sgReaderWriterFLY> g_readerWriter_FLY_Proxy;
|
||||
@@ -1,149 +0,0 @@
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#pragma warning( disable : 4244 )
|
||||
#endif
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "terrain_data.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,113 +0,0 @@
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "matrix.h"
|
||||
#include <osg/Types>
|
||||
|
||||
static float ID[4][4] = {
|
||||
{ 1.0, 0.0, 0.0, 0.0 },
|
||||
{ 0.0, 1.0, 0.0, 0.0 },
|
||||
{ 0.0, 0.0, 1.0, 0.0 },
|
||||
{ 0.0, 0.0, 0.0, 1.0 },
|
||||
};
|
||||
|
||||
|
||||
static float M[2][4][4];
|
||||
static int mi = 0;
|
||||
static float R[4][4];
|
||||
static float T[4][4];
|
||||
static float S[4][4];
|
||||
|
||||
static void preMultiply( float m[4][4] )
|
||||
{
|
||||
int i, j, k;
|
||||
int mo;
|
||||
|
||||
mo = 1 - mi;
|
||||
|
||||
for( i = 0; i < 4; i++ )
|
||||
{
|
||||
for( j = 0; j < 4; j++ )
|
||||
{
|
||||
M[mo][i][j] = 0.0;
|
||||
for( k = 0; k < 4; k++ )
|
||||
M[mo][i][j] += m[i][k] * M[mi][k][j];
|
||||
}
|
||||
}
|
||||
|
||||
mi = mo;
|
||||
}
|
||||
|
||||
void m_LoadID( void )
|
||||
{
|
||||
memcpy( M[mi], ID, sizeof( float ) * 16 );
|
||||
}
|
||||
|
||||
|
||||
void m_Rotate( float a, char axis )
|
||||
{
|
||||
float theta;
|
||||
|
||||
theta = a * M_PI/180.0;
|
||||
|
||||
memcpy( R, ID, sizeof( float) * 16 );
|
||||
switch( axis )
|
||||
{
|
||||
case 'x' :
|
||||
R[1][1] = cosf( theta );
|
||||
R[1][2] = -sinf( theta );
|
||||
R[2][1] = sinf( theta );
|
||||
R[2][2] = cosf( theta );
|
||||
break;
|
||||
|
||||
case 'y' :
|
||||
R[0][0] = cosf( theta );
|
||||
R[0][2] = -sinf( theta );
|
||||
R[2][0] = sinf( theta );
|
||||
R[2][2] = cosf( theta );
|
||||
break;
|
||||
|
||||
case 'z' :
|
||||
R[0][0] = cosf( theta );
|
||||
R[0][1] = -sinf( theta );
|
||||
R[1][0] = sinf( theta );
|
||||
R[1][1] = cosf( theta );
|
||||
break;
|
||||
}
|
||||
|
||||
preMultiply( R );
|
||||
}
|
||||
|
||||
void m_Translate( float x, float y, float z )
|
||||
{
|
||||
memcpy( T, ID, sizeof( float) * 16 );
|
||||
|
||||
T[3][0] = x;
|
||||
T[3][1] = y;
|
||||
T[3][2] = z;
|
||||
|
||||
preMultiply( T );
|
||||
}
|
||||
|
||||
void m_Scale( float x, float y, float z )
|
||||
{
|
||||
memcpy( S, ID, sizeof( float ) * 16 );
|
||||
|
||||
S[0][0] = x;
|
||||
S[1][1] = y;
|
||||
S[2][2] = z;
|
||||
|
||||
preMultiply( S );
|
||||
}
|
||||
|
||||
|
||||
void m_MultV( float v[4], float r[4] )
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for( i = 0; i < 4; i++ )
|
||||
{
|
||||
r[i] = 0.0;
|
||||
for( j = 0; j < 4; j++ )
|
||||
r[i] += v[j] * M[mi][j][i];
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifndef __MATRIX_H
|
||||
#define __MATRIX_H
|
||||
|
||||
|
||||
|
||||
extern void m_LoadID( void );
|
||||
extern void m_Rotate( float, char );
|
||||
extern void m_Translate( float, float, float );
|
||||
extern void m_Scale( float, float, float );
|
||||
extern void m_MultV( float [4], float [4] );
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,261 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <osg/OSG>
|
||||
#include <osg/Billboard>
|
||||
#include <osg/Group>
|
||||
#include <osg/Geode>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/Texture>
|
||||
#include <osg/Registry>
|
||||
|
||||
#include "hat.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#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 GeoSet *makeTree( _tree *tree, GeoState *gstate )
|
||||
{
|
||||
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 },
|
||||
};
|
||||
|
||||
Vec3 *v = new Vec3[4];
|
||||
Vec2 *t = new Vec2[4];
|
||||
Vec4 *l = new Vec4[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;
|
||||
|
||||
GeoSet *gset = new GeoSet;
|
||||
|
||||
gset->setCoords( v );
|
||||
|
||||
gset->setTextureCoords( t );
|
||||
gset->setTextureBinding( GeoSet::BIND_PERVERTEX );
|
||||
|
||||
gset->setColors( l );
|
||||
gset->setColorBinding( GeoSet::BIND_OVERALL );
|
||||
|
||||
gset->setPrimType( GeoSet::QUADS );
|
||||
gset->setNumPrims( 1 );
|
||||
|
||||
gset->setGeoState( gstate );
|
||||
|
||||
return gset;
|
||||
}
|
||||
|
||||
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(Registry::instance()->readImage("tree0.rgba"));
|
||||
|
||||
GeoState *gstate = new GeoState;
|
||||
gstate->setMode( GeoState::TRANSPARENCY, GeoState::ON );
|
||||
gstate->setAttribute( GeoState::TRANSPARENCY, new Transparency );
|
||||
gstate->setMode( GeoState::TEXTURE, GeoState::ON );
|
||||
gstate->setAttribute( GeoState::TEXTURE, tex );
|
||||
gstate->setAttribute( GeoState::TEXENV, new TexEnv );
|
||||
|
||||
gstate->setMode( GeoState::LIGHTING, GeoState::OFF );
|
||||
|
||||
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 );
|
||||
GeoSet *gset = makeTree( t, gstate );
|
||||
bb->addGeoSet( gset, pos );
|
||||
t++;
|
||||
}
|
||||
group->addChild( bb );
|
||||
ttp++;
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
#include <math.h>
|
||||
|
||||
#include <osg/OSG>
|
||||
#include <osg/Geode>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/Texture>
|
||||
#include <osg/GeoState>
|
||||
#include <osg/Registry>
|
||||
|
||||
#ifdef WIN32
|
||||
#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);
|
||||
|
||||
Vec3 *coords = new Vec3[19*nlev];
|
||||
Vec4 *colors = new Vec4[19*nlev];
|
||||
Vec2 *tcoords = new Vec2[19*nlev];
|
||||
osg::ushort *idx = new osg::ushort[38* nlev];
|
||||
int *lengths = new int[nlev];
|
||||
|
||||
|
||||
int ci, ii;
|
||||
ii = ci = 0;
|
||||
|
||||
for( i = 0; i < nlev; i++ )
|
||||
{
|
||||
for( j = 0; j <= 18; j++ )
|
||||
{
|
||||
alpha = lev[i] * M_PI/180.0;
|
||||
theta = (float)(j*20) * M_PI/180.0;
|
||||
|
||||
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++;
|
||||
|
||||
idx[ii++] = ((i+1)*19+j);
|
||||
idx[ii++] = ((i+0)*19+j);
|
||||
}
|
||||
lengths[i] = 38;
|
||||
}
|
||||
|
||||
GeoSet *gset = new GeoSet;
|
||||
|
||||
gset->setCoords( coords, idx );
|
||||
gset->setTextureCoords( tcoords, idx );
|
||||
gset->setTextureBinding( GeoSet::BIND_PERVERTEX );
|
||||
|
||||
gset->setColors( colors, idx );
|
||||
gset->setColorBinding( GeoSet::BIND_PERVERTEX );
|
||||
|
||||
gset->setPrimType( GeoSet::TRIANGLE_STRIP );
|
||||
gset->setNumPrims( nlev - 1 );
|
||||
gset->setPrimLengths( lengths );
|
||||
|
||||
Texture *tex = new Texture;
|
||||
tex->setImage(Registry::instance()->readImage( "white.rgb"));
|
||||
|
||||
GeoState *gstate = new GeoState;
|
||||
// gstate->setMode( GeoState::TEXTURE, GeoState::ON );
|
||||
gstate->setMode( GeoState::TEXTURE, GeoState::OFF);
|
||||
gstate->setAttribute( GeoState::TEXTURE, tex );
|
||||
gstate->setAttribute( GeoState::TEXENV, new TexEnv );
|
||||
gstate->setMode( GeoState::LIGHTING, GeoState::OFF );
|
||||
gstate->setMode( GeoState::FACE_CULL, GeoState::ON );
|
||||
|
||||
gset->setGeoState( gstate );
|
||||
|
||||
Geode *geode = new Geode;
|
||||
geode->addGeoSet( gset );
|
||||
|
||||
geode->setName( "Sky" );
|
||||
|
||||
return geode;
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
#include <math.h>
|
||||
#include <osg/GL>
|
||||
#include <osg/OSG>
|
||||
#include <osg/Group>
|
||||
#include <osg/Geode>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/Texture>
|
||||
#include <osg/GeoState>
|
||||
#include <osg/DCS>
|
||||
#include <osg/Registry>
|
||||
|
||||
#ifdef WIN32
|
||||
#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._mat[0][i]) +
|
||||
(a[1] * mat._mat[1][i]) +
|
||||
(a[2] * mat._mat[2][i]) +
|
||||
mat._mat[3][i];
|
||||
}
|
||||
b[0] = t[0];
|
||||
b[1] = t[1];
|
||||
b[2] = t[2];
|
||||
}
|
||||
|
||||
Node *makeTank( void )
|
||||
{
|
||||
|
||||
Geode *geode1 = 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
|
||||
);
|
||||
|
||||
Vec3 *vc = new Vec3[42];
|
||||
Vec2 *tc = new Vec2[42];
|
||||
int *lens = new int[1];
|
||||
int i, c;
|
||||
|
||||
c = 0;
|
||||
for( i = 0; i <= 360; i += 18 )
|
||||
{
|
||||
float x, y, z;
|
||||
float s, t;
|
||||
float theta = (float)i * M_PI/180.0;
|
||||
|
||||
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++;
|
||||
}
|
||||
*lens = 42;
|
||||
|
||||
for( i = 0; i < c; i++ )
|
||||
conv( vc[i], *mat, vc[i] );
|
||||
|
||||
GeoSet *gset = new GeoSet;
|
||||
gset->setCoords( vc );
|
||||
|
||||
gset->setTextureCoords( tc );
|
||||
gset->setTextureBinding( GeoSet::BIND_PERVERTEX );
|
||||
|
||||
gset->setPrimType( GeoSet::TRIANGLE_STRIP );
|
||||
gset->setNumPrims( 1 );
|
||||
gset->setPrimLengths( lens );
|
||||
|
||||
Texture *tex = new Texture;
|
||||
|
||||
tex->setWrap( Texture::WRAP_S, Texture::REPEAT );
|
||||
tex->setWrap( Texture::WRAP_T, Texture::REPEAT );
|
||||
tex->setImage(Registry::instance()->readImage( "tank.rgb"));
|
||||
|
||||
GeoState *gstate = new GeoState;
|
||||
gstate->setMode( GeoState::TEXTURE, GeoState::ON );
|
||||
gstate->setAttribute( GeoState::TEXTURE, tex );
|
||||
gstate->setAttribute( GeoState::TEXENV, new TexEnv );
|
||||
|
||||
gset->setGeoState( gstate );
|
||||
geode1->addGeoSet( gset );
|
||||
|
||||
lens = new int[1];
|
||||
*lens = 22;
|
||||
|
||||
vc = new Vec3[22];
|
||||
tc = new Vec2[22];
|
||||
|
||||
c = 0;
|
||||
vc[c][0] = 0;
|
||||
vc[c][1] = 0;
|
||||
vc[c][2] = 1;
|
||||
c++;
|
||||
|
||||
for( i = 0; i <= 360; i += 18 )
|
||||
{
|
||||
float x, y, z;
|
||||
float s, t;
|
||||
float theta = (float)i * M_PI/180.0;
|
||||
|
||||
// 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 = new GeoSet;
|
||||
gset->setCoords( vc );
|
||||
gset->setTextureCoords( tc );
|
||||
gset->setPrimType(GeoSet::TRIANGLE_FAN);
|
||||
gset->setNumPrims( 1 );
|
||||
gset->setPrimLengths( lens );
|
||||
|
||||
gset->setGeoState( gstate );
|
||||
|
||||
Geode *geode2 = new Geode;
|
||||
geode2->addGeoSet( gset );
|
||||
|
||||
|
||||
|
||||
//DCS *dcs = new DCS(mat);
|
||||
//dcs->addChild( geode2 );
|
||||
|
||||
|
||||
Group *grp = new Group;
|
||||
grp->addChild( geode1 );
|
||||
grp->addChild( geode2 );
|
||||
|
||||
geode1->setName( "Geode 1" );
|
||||
geode2->setName( "Geode 2" );
|
||||
|
||||
return grp;
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
// #include <math.h>
|
||||
|
||||
#include <osg/OSG>
|
||||
#include <osg/Geode>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/Texture>
|
||||
#include <osg/GeoState>
|
||||
#include <osg/Registry>
|
||||
|
||||
#include "terrain_data.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;
|
||||
|
||||
Vec3 *v = new Vec3[m*n];
|
||||
Vec2 *t = new Vec2[m*n];
|
||||
Vec4 *col = new Vec4[1];
|
||||
osg::ushort *cidx = new osg::ushort;
|
||||
osg::ushort *idx = new osg::ushort[m*n*2];
|
||||
int *lens = new int[m];
|
||||
|
||||
col[0][0] = col[0][1] = col[0][2] = col[0][3] = 1;
|
||||
*cidx = 0;
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
c = 0;
|
||||
for( i = 0; i < m-2; i++ )
|
||||
{
|
||||
for( j = 0; j < n; j++ )
|
||||
{
|
||||
idx[c++] = (i+0)*n+j;
|
||||
idx[c++] = (i+1)*n+j;
|
||||
}
|
||||
lens[i] = 39*2;
|
||||
}
|
||||
|
||||
GeoSet *gset = new GeoSet;
|
||||
|
||||
gset->setCoords( v, idx );
|
||||
gset->setTextureCoords( t, idx );
|
||||
gset->setTextureBinding( GeoSet::BIND_PERVERTEX );
|
||||
|
||||
gset->setColors( col, cidx );
|
||||
gset->setColorBinding( GeoSet::BIND_OVERALL );
|
||||
|
||||
gset->setPrimType( GeoSet::TRIANGLE_STRIP );
|
||||
gset->setNumPrims( m-2 );
|
||||
gset->setPrimLengths( lens );
|
||||
|
||||
Texture *tex = new Texture;
|
||||
|
||||
tex->setImage(Registry::instance()->readImage("lz.rgb"));
|
||||
|
||||
GeoState *gstate = new GeoState;
|
||||
gstate->setMode( GeoState::TEXTURE, GeoState::ON );
|
||||
gstate->setMode( GeoState::LIGHTING, GeoState::OFF );
|
||||
gstate->setAttribute( GeoState::TEXTURE, tex );
|
||||
gstate->setAttribute( GeoState::TEXENV, new TexEnv );
|
||||
|
||||
gstate->check();
|
||||
|
||||
gset->setGeoState( gstate );
|
||||
|
||||
Geode *geode = new Geode;
|
||||
geode->addGeoSet( gset );
|
||||
|
||||
gset->check();
|
||||
|
||||
return geode;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,265 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <osg/OSG>
|
||||
#include <osg/Billboard>
|
||||
#include <osg/Group>
|
||||
#include <osg/Geode>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/Texture>
|
||||
#include <osg/Registry>
|
||||
|
||||
#include "hat.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#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 GeoSet *makeTree( _tree *tree, GeoState *gstate )
|
||||
{
|
||||
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 },
|
||||
};
|
||||
|
||||
Vec3 *v = new Vec3[4];
|
||||
Vec2 *t = new Vec2[4];
|
||||
Vec4 *l = new Vec4[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;
|
||||
|
||||
GeoSet *gset = new GeoSet;
|
||||
|
||||
gset->setCoords( v );
|
||||
|
||||
gset->setTextureCoords( t );
|
||||
gset->setTextureBinding( GeoSet::BIND_PERVERTEX );
|
||||
|
||||
gset->setColors( l );
|
||||
gset->setColorBinding( GeoSet::BIND_OVERALL );
|
||||
|
||||
gset->setPrimType( GeoSet::QUADS );
|
||||
gset->setNumPrims( 1 );
|
||||
|
||||
gset->setGeoState( gstate );
|
||||
|
||||
return gset;
|
||||
}
|
||||
|
||||
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(Registry::instance()->readImage("tree0.rgba"));
|
||||
|
||||
GeoState *gstate = new GeoState;
|
||||
gstate->setMode( GeoState::TEXTURE, GeoState::ON );
|
||||
gstate->setAttribute( GeoState::TEXTURE, tex );
|
||||
gstate->setAttribute( GeoState::TEXENV, new TexEnv );
|
||||
|
||||
|
||||
AlphaFunc* alphaFunc = new AlphaFunc;
|
||||
alphaFunc->setFunction(AlphaFunc::GEQUAL,0.1f);
|
||||
gstate->setMode( GeoState::ALPHAFUNC, GeoState::ON );
|
||||
gstate->setAttribute( GeoState::ALPHAFUNC, alphaFunc );
|
||||
|
||||
gstate->setMode( GeoState::LIGHTING, GeoState::OFF );
|
||||
|
||||
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 );
|
||||
GeoSet *gset = makeTree( t, gstate );
|
||||
bb->addGeoSet( gset, pos );
|
||||
t++;
|
||||
}
|
||||
group->addChild( bb );
|
||||
ttp++;
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include "vector.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning( disable : 4244 )
|
||||
#pragma warning( disable : 4305 )
|
||||
#endif
|
||||
|
||||
#define SET_VEC( v, a, b, c ) v->x = (a); v->y = (b); v->z = (c)
|
||||
|
||||
Vector NewVector( void )
|
||||
{
|
||||
Vector temp;
|
||||
|
||||
temp = (Vector)calloc( 1, sizeof( struct _vector ) );
|
||||
|
||||
SET_VEC( temp, 0., 0., 0. );
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
void DeleteVector( Vector v )
|
||||
{
|
||||
SET_VEC( v, 0., 0., 0. );
|
||||
free( v );
|
||||
}
|
||||
|
||||
void VectorSet( Vector v, float a, float b, float c )
|
||||
{
|
||||
SET_VEC( v, a, b, c );
|
||||
}
|
||||
|
||||
void VectorGet( Vector v, float *a, float *b, float *c )
|
||||
{
|
||||
*a = v->x;
|
||||
*b = v->y;
|
||||
*c = v->z;
|
||||
}
|
||||
|
||||
float VectorDotProduct( Vector p, Vector q )
|
||||
{
|
||||
return (p->x * p->x) + (p->y * p->y) + (p->z * p->z);
|
||||
}
|
||||
|
||||
|
||||
void VectorNormalize( Vector v )
|
||||
{
|
||||
float f;
|
||||
|
||||
f = sqrt( (v->x*v->x)+(v->y*v->y)+(v->z*v->z));
|
||||
|
||||
if( f == 0.0 )
|
||||
v->x = v->y = v->z = 0.0;
|
||||
else
|
||||
{
|
||||
v->x /= f;
|
||||
v->y /= f;
|
||||
v->z /= f;
|
||||
}
|
||||
}
|
||||
|
||||
void VectorCrossProduct(Vector v1, Vector v2, Vector prod)
|
||||
{
|
||||
struct _vector p; /* in case prod == v1 or v2 */
|
||||
|
||||
p.x = v1->y*v2->z - v2->y*v1->z;
|
||||
p.y = v1->z*v2->x - v2->z*v1->x;
|
||||
p.z = v1->x*v2->y - v2->x*v1->y;
|
||||
prod->x = p.x; prod->y = p.y; prod->z = p.z;
|
||||
}
|
||||
|
||||
void VectorAdd( Vector v1, Vector v2, Vector sum )
|
||||
{
|
||||
sum->x = v1->x + v2->x;
|
||||
sum->y = v1->y + v2->y;
|
||||
sum->z = v1->z + v2->z;
|
||||
}
|
||||
|
||||
void VectorDiff( Vector v1, Vector v2, Vector diff )
|
||||
{
|
||||
diff->x = v1->x - v2->x;
|
||||
diff->y = v1->y - v2->y;
|
||||
diff->z = v1->z - v2->z;
|
||||
}
|
||||
|
||||
float VectorAngle( Vector v1, Vector v2 )
|
||||
{
|
||||
float d;
|
||||
float f1, f2;
|
||||
|
||||
d = ((v1->x*v2->x) + (v1->y*v2->y) + (v1->z*v2->z));
|
||||
|
||||
f1 = sqrt( (v1->x*v1->x) + (v1->y *v1->y) + (v1->z*v1->z) );
|
||||
f2 = sqrt( (v2->x*v2->x) + (v2->y *v2->y) + (v2->z*v2->z) );
|
||||
|
||||
if( f1*f2 == 0.0 ) return 0.0;
|
||||
|
||||
return acos( d/(f1*f2) );
|
||||
}
|
||||
|
||||
char * VectorToA( Vector v, char *ptr, int size )
|
||||
{
|
||||
char buff[512];
|
||||
|
||||
sprintf( buff, "%12.4f %12.4f %12.4f", v->x, v->y, v->z );
|
||||
|
||||
strncpy( ptr, buff, size );
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
float VectorMagnitude( Vector v )
|
||||
{
|
||||
return sqrt( (v->x*v->x) + (v->y *v->y) + (v->z*v->z) );
|
||||
}
|
||||
|
||||
void VectorMagnify( Vector v, float magnitude, Vector res )
|
||||
{
|
||||
float x;
|
||||
float d;
|
||||
|
||||
x = magnitude;
|
||||
d = sqrt( (v->x*v->x) + (v->y*v->y) + (v->z*v->z) );
|
||||
|
||||
if( d == 0.0 )
|
||||
{
|
||||
res->x = res->y = res->z = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
res->x = x * v->x/d;
|
||||
res->y = x * v->y/d;
|
||||
res->z = x * v->z/d;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
#ifndef __VECTOR_H
|
||||
#define __VECTOR_H
|
||||
|
||||
|
||||
struct _vector {
|
||||
float x, y, z;
|
||||
};
|
||||
|
||||
typedef struct _vector *Vector;
|
||||
typedef struct _vector sgvector;
|
||||
|
||||
extern Vector NewVector( void );
|
||||
extern void DeleteVector( Vector v );
|
||||
extern void VectorSet( Vector v, float a, float b, float c );
|
||||
extern void VectorGet( Vector v, float *a, float *b, float *c );
|
||||
extern float VectorDotProduct( Vector p, Vector q );
|
||||
extern void VectorCrossProduct(Vector v1, Vector v2, Vector prod);
|
||||
extern void VectorAdd( Vector v1, Vector v2, Vector diff );
|
||||
extern void VectorDiff( Vector v1, Vector v2, Vector diff );
|
||||
extern void VectorNormalize( Vector v );
|
||||
extern float VectorAngle( Vector v1, Vector v2 );
|
||||
extern char * VectorToA( Vector v, char *cptr, int size );
|
||||
extern float VectorMagnitude( Vector v );
|
||||
extern void VectorMagnify( Vector v, float magnitude, Vector res );
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,600 +0,0 @@
|
||||
#include "ConvertToPerformer.h"
|
||||
|
||||
#include <osg/Scene>
|
||||
#include <osg/Group>
|
||||
#include <osg/DCS>
|
||||
#include <osg/LOD>
|
||||
#include <osg/Switch>
|
||||
#include <osg/Sequence>
|
||||
#include <osg/Geode>
|
||||
#include <osg/Billboard>
|
||||
#include <osg/Texture>
|
||||
#include <osg/Image>
|
||||
#include <osg/FileNameUtils>
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <Performer/pf/pfNode.h>
|
||||
#include <Performer/pf/pfGeode.h>
|
||||
#include <Performer/pf/pfBillboard.h>
|
||||
#include <Performer/pf/pfScene.h>
|
||||
#include <Performer/pf/pfGroup.h>
|
||||
#include <Performer/pf/pfDCS.h>
|
||||
#include <Performer/pf/pfSCS.h>
|
||||
#include <Performer/pf/pfLOD.h>
|
||||
#include <Performer/pf/pfSwitch.h>
|
||||
#include <Performer/pf/pfSequence.h>
|
||||
#include <Performer/pr/pfGeoState.h>
|
||||
#include <Performer/pr/pfMaterial.h>
|
||||
#include <Performer/pr/pfTexture.h>
|
||||
|
||||
#ifdef OSG_USE_IO_DOT_H
|
||||
#include <iostream.h>
|
||||
#else
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#endif
|
||||
|
||||
ConvertToPerformer::ConvertToPerformer()
|
||||
{
|
||||
setTraverseMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);
|
||||
|
||||
_pfParent = NULL;
|
||||
_pfRoot = NULL;
|
||||
|
||||
_gsetPrimMap[osg::GeoSet::POINTS] = PFGS_POINTS;
|
||||
_gsetPrimMap[osg::GeoSet::LINES] = PFGS_LINES;
|
||||
_gsetPrimMap[osg::GeoSet::LINE_STRIP] = PFGS_LINESTRIPS;
|
||||
_gsetPrimMap[osg::GeoSet::TRIANGLES] = PFGS_TRIS;
|
||||
_gsetPrimMap[osg::GeoSet::QUADS] = PFGS_QUADS;
|
||||
_gsetPrimMap[osg::GeoSet::TRIANGLE_STRIP] = PFGS_TRISTRIPS;
|
||||
_gsetPrimMap[osg::GeoSet::FLAT_LINE_STRIP] = PFGS_FLAT_LINESTRIPS;
|
||||
_gsetPrimMap[osg::GeoSet::FLAT_TRIANGLE_STRIP] = PFGS_FLAT_TRISTRIPS;
|
||||
_gsetPrimMap[osg::GeoSet::TRIANGLE_FAN] = PFGS_TRIFANS;
|
||||
_gsetPrimMap[osg::GeoSet::FLAT_TRIANGLE_FAN] = PFGS_FLAT_TRIFANS;
|
||||
_gsetPrimMap[osg::GeoSet::POLYGON] = PFGS_POLYS;
|
||||
_gsetPrimMap[osg::GeoSet::NO_TYPE] = PFGS_NUM_PRIMS;
|
||||
|
||||
_gsetBindMap[osg::GeoSet::BIND_OFF] = PFGS_OFF;
|
||||
_gsetBindMap[osg::GeoSet::BIND_OVERALL] = PFGS_OVERALL;
|
||||
_gsetBindMap[osg::GeoSet::BIND_PERPRIM] = PFGS_PER_PRIM;
|
||||
_gsetBindMap[osg::GeoSet::BIND_PERVERTEX] = PFGS_PER_VERTEX;
|
||||
|
||||
|
||||
_gstateTypeMap[osg::GeoState::TRANSPARENCY] = PFSTATE_TRANSPARENCY;
|
||||
_gstateTypeMap[osg::GeoState::ANTIALIAS] = PFSTATE_ANTIALIAS;
|
||||
_gstateTypeMap[osg::GeoState::LIGHTING] = PFSTATE_ENLIGHTING;
|
||||
_gstateTypeMap[osg::GeoState::TEXTURE] = PFSTATE_ENTEXTURE;
|
||||
_gstateTypeMap[osg::GeoState::FOG] = PFSTATE_ENFOG;
|
||||
_gstateTypeMap[osg::GeoState::FACE_CULL] = PFSTATE_CULLFACE;
|
||||
_gstateTypeMap[osg::GeoState::WIREFRAME] = PFSTATE_ENWIREFRAME;
|
||||
_gstateTypeMap[osg::GeoState::TEXGEN] = PFSTATE_ENTEXGEN;
|
||||
_gstateTypeMap[osg::GeoState::TEXMAT] = PFSTATE_ENTEXMAT;
|
||||
|
||||
}
|
||||
|
||||
ConvertToPerformer::~ConvertToPerformer()
|
||||
{
|
||||
}
|
||||
|
||||
pfNode* ConvertToPerformer::convert(osg::Node* node)
|
||||
{
|
||||
_pfRoot = NULL;
|
||||
if (node)
|
||||
{
|
||||
node->accept(*this);
|
||||
}
|
||||
return _pfRoot;
|
||||
}
|
||||
|
||||
pfObject* ConvertToPerformer::getPfObject(osg::Object* osgObj)
|
||||
{
|
||||
OsgObjectToPfObjectMap::iterator fitr = _osgToPfMap.find(osgObj);
|
||||
if (fitr != _osgToPfMap.end())
|
||||
{
|
||||
osg::notify(osg::DEBUG) << "Found shared object"<<endl;
|
||||
return (*fitr).second;
|
||||
}
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
void ConvertToPerformer::regisiterOsgObjectForPfObject(osg::Object* osgObj,pfObject* pfObj)
|
||||
{
|
||||
_osgToPfMap[osgObj] = pfObj;
|
||||
}
|
||||
|
||||
|
||||
void ConvertToPerformer::apply(osg::Node& node)
|
||||
{
|
||||
node.traverse(*this);
|
||||
}
|
||||
|
||||
void ConvertToPerformer::apply(osg::Group& node)
|
||||
{
|
||||
pfGroup* parent = _pfParent;
|
||||
|
||||
pfGroup* pf_group = dynamic_cast<pfGroup*>(getPfObject(&node));
|
||||
if (pf_group)
|
||||
{
|
||||
if (_pfParent) _pfParent->addChild(pf_group);
|
||||
return;
|
||||
}
|
||||
|
||||
pf_group = new pfGroup;
|
||||
if (!_pfRoot) _pfRoot = pf_group;
|
||||
if (_pfParent) _pfParent->addChild(pf_group);
|
||||
|
||||
regisiterOsgObjectForPfObject(&node,pf_group);
|
||||
|
||||
if (!node.getName().empty()) pf_group->setName(node.getName().c_str());
|
||||
|
||||
_pfParent = pf_group;
|
||||
|
||||
node.traverse(*this);
|
||||
|
||||
_pfParent = parent;
|
||||
}
|
||||
|
||||
void ConvertToPerformer::apply(osg::DCS& osgDCS)
|
||||
{
|
||||
pfGroup* parent = _pfParent;
|
||||
|
||||
pfDCS* pf_dcs = dynamic_cast<pfDCS*>(getPfObject(&osgDCS));
|
||||
if (pf_dcs)
|
||||
{
|
||||
if (_pfParent) _pfParent->addChild(pf_dcs);
|
||||
return;
|
||||
}
|
||||
|
||||
pf_dcs = new pfDCS;
|
||||
if (!_pfRoot) _pfRoot = pf_dcs;
|
||||
if (_pfParent) _pfParent->addChild(pf_dcs);
|
||||
|
||||
regisiterOsgObjectForPfObject(&osgDCS,pf_dcs);
|
||||
|
||||
if (!osgDCS.getName().empty()) pf_dcs->setName(osgDCS.getName().c_str());
|
||||
|
||||
osg::Matrix* matrix = osgDCS.getMatrix();
|
||||
|
||||
pfMatrix pf_matrix(matrix->_mat[0][0],matrix->_mat[0][1],matrix->_mat[0][2],matrix->_mat[0][3],
|
||||
matrix->_mat[1][0],matrix->_mat[1][1],matrix->_mat[1][2],matrix->_mat[1][3],
|
||||
matrix->_mat[2][0],matrix->_mat[2][1],matrix->_mat[2][2],matrix->_mat[2][3],
|
||||
matrix->_mat[3][0],matrix->_mat[3][1],matrix->_mat[3][2],matrix->_mat[3][3]);
|
||||
|
||||
pf_dcs->setMat(pf_matrix);
|
||||
|
||||
|
||||
_pfParent = pf_dcs;
|
||||
|
||||
osgDCS.traverse(*this);
|
||||
|
||||
_pfParent = parent;
|
||||
|
||||
}
|
||||
|
||||
void ConvertToPerformer::apply(osg::Switch& node)
|
||||
{
|
||||
pfGroup* parent = _pfParent;
|
||||
|
||||
pfSwitch* pf_switch = dynamic_cast<pfSwitch*>(getPfObject(&node));
|
||||
if (pf_switch)
|
||||
{
|
||||
if (_pfParent) _pfParent->addChild(pf_switch);
|
||||
return;
|
||||
}
|
||||
|
||||
pf_switch = new pfSwitch;
|
||||
if (!_pfRoot) _pfRoot = pf_switch;
|
||||
if (_pfParent) _pfParent->addChild(pf_switch);
|
||||
|
||||
regisiterOsgObjectForPfObject(&node,pf_switch);
|
||||
|
||||
if (!node.getName().empty()) pf_switch->setName(node.getName().c_str());
|
||||
|
||||
_pfParent = pf_switch;
|
||||
|
||||
node.traverse(*this);
|
||||
|
||||
_pfParent = parent;
|
||||
}
|
||||
|
||||
void ConvertToPerformer::apply(osg::LOD& node)
|
||||
{
|
||||
pfGroup* parent = _pfParent;
|
||||
|
||||
pfLOD* pf_lod = dynamic_cast<pfLOD*>(getPfObject(&node));
|
||||
if (pf_lod)
|
||||
{
|
||||
if (_pfParent) _pfParent->addChild(pf_lod);
|
||||
return;
|
||||
}
|
||||
|
||||
pf_lod = new pfLOD;
|
||||
if (!_pfRoot) _pfRoot = pf_lod;
|
||||
if (_pfParent) _pfParent->addChild(pf_lod);
|
||||
|
||||
regisiterOsgObjectForPfObject(&node,pf_lod);
|
||||
|
||||
if (!node.getName().empty()) pf_lod->setName(node.getName().c_str());
|
||||
|
||||
_pfParent = pf_lod;
|
||||
|
||||
node.traverse(*this);
|
||||
|
||||
_pfParent = parent;
|
||||
}
|
||||
|
||||
void ConvertToPerformer::apply(osg::Scene& scene)
|
||||
{
|
||||
pfGroup* parent = _pfParent;
|
||||
|
||||
pfScene* pf_scene = dynamic_cast<pfScene*>(getPfObject(&scene));
|
||||
if (pf_scene)
|
||||
{
|
||||
if (_pfParent) _pfParent->addChild(pf_scene);
|
||||
return;
|
||||
}
|
||||
|
||||
pf_scene = new pfScene;
|
||||
if (!_pfRoot) _pfRoot = pf_scene;
|
||||
if (_pfParent) _pfParent->addChild(pf_scene);
|
||||
|
||||
regisiterOsgObjectForPfObject(&scene,pf_scene);
|
||||
|
||||
if (!scene.getName().empty()) pf_scene->setName(scene.getName().c_str());
|
||||
|
||||
_pfParent = pf_scene;
|
||||
|
||||
scene.traverse(*this);
|
||||
|
||||
_pfParent = parent;
|
||||
}
|
||||
|
||||
|
||||
void ConvertToPerformer::apply(osg::Billboard& node)
|
||||
{
|
||||
pfGroup* parent = _pfParent;
|
||||
|
||||
pfBillboard* pf_billboard = dynamic_cast<pfBillboard*>(getPfObject(&node));
|
||||
if (pf_billboard)
|
||||
{
|
||||
if (_pfParent) _pfParent->addChild(pf_billboard);
|
||||
return;
|
||||
}
|
||||
|
||||
pf_billboard = new pfBillboard;
|
||||
if (!_pfRoot) _pfRoot = pf_billboard;
|
||||
if (_pfParent) _pfParent->addChild(pf_billboard);
|
||||
|
||||
regisiterOsgObjectForPfObject(&node,pf_billboard);
|
||||
|
||||
if (!node.getName().empty()) pf_billboard->setName(node.getName().c_str());
|
||||
|
||||
for(int i=0;i<node.getNumGeosets();++i)
|
||||
{
|
||||
pfGeoSet* pf_geoset = visitGeoSet(node.getGeoSet(i));
|
||||
if (pf_geoset) pf_billboard->addGSet(pf_geoset);
|
||||
}
|
||||
|
||||
_pfParent = parent;
|
||||
}
|
||||
|
||||
void ConvertToPerformer::apply(osg::Geode& node)
|
||||
{
|
||||
pfGroup* parent = _pfParent;
|
||||
|
||||
pfGeode* pf_geode = dynamic_cast<pfGeode*>(getPfObject(&node));
|
||||
if (pf_geode)
|
||||
{
|
||||
if (_pfParent) _pfParent->addChild(pf_geode);
|
||||
return;
|
||||
}
|
||||
|
||||
pf_geode = new pfGeode;
|
||||
if (!_pfRoot) _pfRoot = pf_geode;
|
||||
if (_pfParent) _pfParent->addChild(pf_geode);
|
||||
|
||||
regisiterOsgObjectForPfObject(&node,pf_geode);
|
||||
|
||||
if (!node.getName().empty()) pf_geode->setName(node.getName().c_str());
|
||||
|
||||
for(int i=0;i<node.getNumGeosets();++i)
|
||||
{
|
||||
pfGeoSet* pf_geoset = visitGeoSet(node.getGeoSet(i));
|
||||
if (pf_geoset) pf_geode->addGSet(pf_geoset);
|
||||
}
|
||||
|
||||
_pfParent = parent;
|
||||
}
|
||||
|
||||
pfGeoSet* ConvertToPerformer::visitGeoSet(osg::GeoSet* geoset)
|
||||
{
|
||||
if (geoset==NULL) return NULL;
|
||||
|
||||
void* arena = pfGetSharedArena();
|
||||
|
||||
pfGeoSet* pf_geoset = new pfGeoSet();
|
||||
|
||||
pf_geoset->setGState(visitGeoState(geoset->getGeoState()));
|
||||
|
||||
int i;
|
||||
|
||||
// number of prims
|
||||
int np = geoset->getNumPrims();
|
||||
int *plen = geoset->getPrimLengths();
|
||||
|
||||
// Number of verticies (may be different than number of coords)
|
||||
geoset->computeNumVerts();
|
||||
|
||||
pf_geoset->setPrimType(_gsetPrimMap[geoset->getPrimType()]);
|
||||
pf_geoset->setNumPrims(np);
|
||||
|
||||
if (plen)
|
||||
{
|
||||
//int *pf_plen = new int [np];
|
||||
int* pf_plen = (int*) pfMalloc(sizeof(int) * np, arena);
|
||||
for(i=0;i<np;++i) pf_plen[i] = plen[i];
|
||||
pf_geoset->setPrimLengths(pf_plen);
|
||||
}
|
||||
|
||||
osg::Vec3 *coords = geoset->getCoords();
|
||||
osg::ushort *ilist = geoset->getCIndex();
|
||||
|
||||
|
||||
// copy the vertex coordinates across.
|
||||
if( coords )
|
||||
{
|
||||
|
||||
int cc = geoset->getNumCoords();
|
||||
|
||||
pfVec3* pf_coords = (pfVec3*) pfMalloc(sizeof(pfVec3) * cc, arena);
|
||||
|
||||
for( i = 0; i < cc; i++ )
|
||||
{
|
||||
pf_coords[i][0] = coords[i][0];
|
||||
pf_coords[i][1] = coords[i][1];
|
||||
pf_coords[i][2] = coords[i][2];
|
||||
}
|
||||
|
||||
if(ilist)
|
||||
{
|
||||
int ni=geoset->getNumIndices();
|
||||
ushort* pf_cindex = (ushort*) pfMalloc(sizeof(ushort) * ni, arena);
|
||||
for( i = 0; i < ni; i++ )
|
||||
{
|
||||
pf_cindex[i] = ilist[i];
|
||||
}
|
||||
pf_geoset->setAttr( PFGS_COORD3, PFGS_PER_VERTEX, pf_coords, pf_cindex );
|
||||
}
|
||||
else
|
||||
{
|
||||
pf_geoset->setAttr( PFGS_COORD3, PFGS_PER_VERTEX, pf_coords, NULL );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
osg::Vec3 *norms = geoset->getNormals();
|
||||
ilist = geoset->getNIndex();
|
||||
|
||||
// copy normals
|
||||
if(norms)
|
||||
{
|
||||
int bind = _gsetBindMap[geoset->getNormalBinding()];
|
||||
|
||||
int cc = geoset->getNumNormals();
|
||||
|
||||
pfVec3* pf_norms = (pfVec3*) pfMalloc(sizeof(pfVec3) * cc, arena);
|
||||
|
||||
for( i = 0; i < cc; i++ )
|
||||
{
|
||||
pf_norms[i][0] = norms[i][0];
|
||||
pf_norms[i][1] = norms[i][1];
|
||||
pf_norms[i][2] = norms[i][2];
|
||||
}
|
||||
|
||||
if(ilist)
|
||||
{
|
||||
int ni=geoset->getNumNIndices();
|
||||
ushort* pf_nindex = (ushort*) pfMalloc(sizeof(ushort) * ni, arena);
|
||||
for( i = 0; i < ni; i++ )
|
||||
{
|
||||
pf_nindex[i] = ilist[i];
|
||||
}
|
||||
pf_geoset->setAttr(PFGS_NORMAL3, bind, pf_norms,pf_nindex);
|
||||
}
|
||||
else
|
||||
{
|
||||
pf_geoset->setAttr(PFGS_NORMAL3, bind, pf_norms,NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
osg::Vec4 *colors = geoset->getColors();
|
||||
ilist = geoset->getColIndex();
|
||||
|
||||
// copy colors
|
||||
if(colors)
|
||||
{
|
||||
int bind = _gsetBindMap[geoset->getColorBinding()];
|
||||
|
||||
int cc = geoset->getNumColors();
|
||||
|
||||
pfVec4* pf_colors = (pfVec4*) pfMalloc(sizeof(pfVec4) * cc, arena);
|
||||
|
||||
for( i = 0; i < cc; i++ )
|
||||
{
|
||||
pf_colors[i][0] = colors[i][0];
|
||||
pf_colors[i][1] = colors[i][1];
|
||||
pf_colors[i][2] = colors[i][2];
|
||||
pf_colors[i][3] = colors[i][3];
|
||||
}
|
||||
|
||||
if(ilist)
|
||||
{
|
||||
int ni=geoset->getNumCIndices();
|
||||
ushort* pf_cindex = (ushort*) pfMalloc(sizeof(ushort) * ni, arena);
|
||||
for( i = 0; i < ni; i++ )
|
||||
{
|
||||
pf_cindex[i] = ilist[i];
|
||||
}
|
||||
pf_geoset->setAttr(PFGS_COLOR4, bind, pf_colors,pf_cindex);
|
||||
}
|
||||
else
|
||||
{
|
||||
pf_geoset->setAttr(PFGS_COLOR4, bind, pf_colors,NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// pfVec2 *tcoords;
|
||||
// geoset->getAttrLists( PFGS_TEXCOORD2, (void **)&tcoords, &ilist );
|
||||
//
|
||||
// // copy texture coords
|
||||
// if(tcoords)
|
||||
// {
|
||||
// int bind = geoset->getAttrBind( PFGS_TEXCOORD2 );
|
||||
// int nn = bind == PFGS_OFF ? 0 :
|
||||
// bind == PFGS_OVERALL ? 1 :
|
||||
// bind == PFGS_PER_PRIM ? geoset->getNumPrims() :
|
||||
// bind == PFGS_PER_VERTEX ? nv : 0;
|
||||
//
|
||||
// // set the normal binding type.
|
||||
// pf_geoset->setTextureBinding(_gsetBindMap[bind]);
|
||||
//
|
||||
// // calc the maximum num of vertex from the index list.
|
||||
// int cc;
|
||||
// if (ilist)
|
||||
// {
|
||||
// cc = 0;
|
||||
// for( i = 0; i < nv; i++ )
|
||||
// if( ilist[i] > cc ) cc = ilist[i];
|
||||
// cc++;
|
||||
// }
|
||||
// else
|
||||
// cc = nn;
|
||||
//
|
||||
//
|
||||
// osg::Vec2* osg_tcoords = new osg::Vec2 [cc];
|
||||
// for( i = 0; i < cc; i++ )
|
||||
// {
|
||||
// osg_tcoords[i][0] = tcoords[i][0];
|
||||
// osg_tcoords[i][1] = tcoords[i][1];
|
||||
// }
|
||||
//
|
||||
// if(ilist)
|
||||
// {
|
||||
// osg::ushort* osg_cindex = new osg::ushort [nn];
|
||||
// for( i = 0; i < nn; i++ )
|
||||
// {
|
||||
// osg_cindex[i] = ilist[i];
|
||||
// }
|
||||
// pf_geoset->setTextureCoords(osg_tcoords, osg_cindex );
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// pf_geoset->setTextureCoords(osg_tcoords);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// pfVec4 *colors;
|
||||
// geoset->getAttrLists( PFGS_COLOR4, (void **)&colors, &ilist );
|
||||
//
|
||||
// // copy color coords
|
||||
// if(colors)
|
||||
// {
|
||||
// int bind = geoset->getAttrBind( PFGS_COLOR4 );
|
||||
// int nn = bind == PFGS_OFF ? 0 :
|
||||
// bind == PFGS_OVERALL ? 1 :
|
||||
// bind == PFGS_PER_PRIM ? geoset->getNumPrims() :
|
||||
// bind == PFGS_PER_VERTEX ? nv-flat_shaded_offset : 0;
|
||||
//
|
||||
// // set the normal binding type.
|
||||
// pf_geoset->setColorBinding(_gsetBindMap[bind]);
|
||||
//
|
||||
// // calc the maximum num of vertex from the index list.
|
||||
// int cc;
|
||||
// if (ilist)
|
||||
// {
|
||||
// cc = 0;
|
||||
// for( i = 0; i < nn; i++ )
|
||||
// if( ilist[i] > cc ) cc = ilist[i];
|
||||
// cc++;
|
||||
// }
|
||||
// else
|
||||
// cc = nn;
|
||||
//
|
||||
//
|
||||
// osg::Vec4* osg_colors = new osg::Vec4 [cc];
|
||||
// for( i = 0; i < cc; i++ )
|
||||
// {
|
||||
// osg_colors[i][0] = colors[i][0];
|
||||
// osg_colors[i][1] = colors[i][1];
|
||||
// osg_colors[i][2] = colors[i][2];
|
||||
// osg_colors[i][3] = colors[i][3];
|
||||
// }
|
||||
//
|
||||
// if(ilist)
|
||||
// {
|
||||
// osg::ushort* osg_cindex = new osg::ushort [nn];
|
||||
// for( i = 0; i < nn; i++ )
|
||||
// {
|
||||
// osg_cindex[i] = ilist[i];
|
||||
// }
|
||||
// pf_geoset->setColors(osg_colors, osg_cindex );
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// pf_geoset->setColors(osg_colors);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
|
||||
|
||||
return pf_geoset;
|
||||
}
|
||||
|
||||
pfGeoState* ConvertToPerformer::visitGeoState(osg::GeoState* geostate)
|
||||
{
|
||||
if (geostate==NULL) return NULL;
|
||||
|
||||
pfGeoState* pf_geostate = new pfGeoState();
|
||||
|
||||
switch(geostate->getMode(osg::GeoState::LIGHTING))
|
||||
{
|
||||
case(osg::GeoState::OVERRIDE_ON):
|
||||
case(osg::GeoState::ON): pf_geostate->setMode(PFSTATE_ENLIGHTING,PF_ON);break;
|
||||
case(osg::GeoState::OVERRIDE_OFF):
|
||||
case(osg::GeoState::OFF): pf_geostate->setMode(PFSTATE_ENLIGHTING,PF_OFF);break;
|
||||
}
|
||||
|
||||
switch(geostate->getMode(osg::GeoState::TEXTURE))
|
||||
{
|
||||
case(osg::GeoState::OVERRIDE_ON):
|
||||
case(osg::GeoState::ON): pf_geostate->setMode(PFSTATE_ENTEXTURE,PF_ON);break;
|
||||
case(osg::GeoState::OVERRIDE_OFF):
|
||||
case(osg::GeoState::OFF): pf_geostate->setMode(PFSTATE_ENTEXTURE,PF_OFF);break;
|
||||
}
|
||||
|
||||
return pf_geostate;
|
||||
}
|
||||
|
||||
pfMaterial* ConvertToPerformer::visitMaterial(osg::Material* material)
|
||||
{
|
||||
if (material==NULL) return NULL;
|
||||
|
||||
pfMaterial* pf_material = new pfMaterial();
|
||||
|
||||
return pf_material;
|
||||
}
|
||||
|
||||
pfTexture* ConvertToPerformer::visitTexture(osg::Texture* tex)
|
||||
{
|
||||
if (tex==NULL) return NULL;
|
||||
|
||||
pfTexture* pf_texture = new pfTexture();
|
||||
|
||||
return pf_texture;
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
#ifndef __CONVERTTOPERFORMER_H
|
||||
#define __CONVERTTOPERFORMER_H
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
// Open Scene Graph includes.
|
||||
#include <osg/Node>
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osg/Group>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/GeoState>
|
||||
|
||||
// Performer includes.
|
||||
#include <Performer/pf/pfNode.h>
|
||||
|
||||
class ConvertToPerformer : protected osg::NodeVisitor {
|
||||
public:
|
||||
|
||||
ConvertToPerformer();
|
||||
~ConvertToPerformer();
|
||||
|
||||
pfNode* convert(osg::Node* node);
|
||||
|
||||
virtual void apply(osg::Node&);
|
||||
|
||||
virtual void apply(osg::Geode& node);
|
||||
virtual void apply(osg::Billboard& node);
|
||||
|
||||
virtual void apply(osg::Group& node);
|
||||
virtual void apply(osg::DCS& node);
|
||||
virtual void apply(osg::Switch& node);
|
||||
virtual void apply(osg::LOD& node);
|
||||
virtual void apply(osg::Scene& node);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
pfGroup* _pfParent;
|
||||
pfNode* _pfRoot;
|
||||
|
||||
virtual pfObject* getPfObject(osg::Object* osgObj);
|
||||
virtual void regisiterOsgObjectForPfObject(osg::Object* osgObj,pfObject* pfObj);
|
||||
|
||||
pfGeoSet* visitGeoSet(osg::GeoSet* geoset);
|
||||
pfGeoState* visitGeoState(osg::GeoState* geostate);
|
||||
pfMaterial* visitMaterial(osg::Material* material);
|
||||
pfTexture* visitTexture(osg::Texture* tex);
|
||||
|
||||
|
||||
typedef std::map<osg::Object*,pfObject*> OsgObjectToPfObjectMap;
|
||||
typedef std::map<osg::GeoSet::PrimitiveType,int> GSetPrimitiveMap;
|
||||
typedef std::map<osg::GeoSet::BindingType,int> GSetBindingMap;
|
||||
typedef std::map<osg::GeoState::AttributeType,int> GStateTypeMap;
|
||||
typedef std::map<osg::GeoState::AttributeMode,int> GStateModeMap;
|
||||
|
||||
OsgObjectToPfObjectMap _osgToPfMap;
|
||||
GSetPrimitiveMap _gsetPrimMap;
|
||||
GSetBindingMap _gsetBindMap;
|
||||
GStateTypeMap _gstateTypeMap;
|
||||
GStateModeMap _gstateModeMap;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,20 +0,0 @@
|
||||
#!smake
|
||||
include ../../Make/makedefs
|
||||
|
||||
C++FILES = \
|
||||
ConvertToPerformer.cpp\
|
||||
osg2pf.cpp
|
||||
|
||||
C++FLAGS += -I../../include -O
|
||||
|
||||
|
||||
LIBS = -losg
|
||||
|
||||
TARGET = ../../bin/osg2pf
|
||||
|
||||
LDFLAGS += -L../../lib -L/usr/X11R6/lib
|
||||
|
||||
LIBS = -losg -lGLU -lm ${PFLIBS}
|
||||
|
||||
include ../../Make/makerules
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#!smake
|
||||
include ../../Make/makedefs
|
||||
|
||||
C++FILES = \
|
||||
ConvertToPerformer.cpp\
|
||||
osg.cpp
|
||||
# osg2pf.cpp\
|
||||
|
||||
|
||||
LIB = ../../lib/libpfosg_ogl.so
|
||||
|
||||
C++FLAGS += -I../../include
|
||||
LDFLAGS += -L../../lib
|
||||
|
||||
include ../../Make/makerules
|
||||
|
||||
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
#include "ConvertToPerformer.h"
|
||||
|
||||
#include <Performer/pf/pfNode.h>
|
||||
|
||||
#include <osg/Registry>
|
||||
#include <osg/FileNameUtils>
|
||||
#include <osg/Group>
|
||||
|
||||
// Performer includes.
|
||||
#include <Performer/pfdu.h>
|
||||
|
||||
#ifdef OSG_USE_IO_DOT_H
|
||||
#include <iostream.h>
|
||||
#else
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#endif
|
||||
|
||||
|
||||
int main( int argc, const char **argv )
|
||||
{
|
||||
|
||||
// create the list of input files from the command line arguments
|
||||
typedef std::vector<std::string> FileList;
|
||||
FileList filelist;
|
||||
|
||||
bool saveImagesAsRGB = false;
|
||||
for(int i=1;i<argc;++i)
|
||||
{
|
||||
if (strcmp(argv[i],"-si")==0) saveImagesAsRGB = true;
|
||||
else filelist.push_back(argv[i]);
|
||||
}
|
||||
|
||||
if (filelist.size()<2)
|
||||
{
|
||||
cerr << "Usage :";
|
||||
cerr << "\t"<<argv[0]<<" [-si] InputFile [InputFile...] OutputFile"<<endl;
|
||||
cerr << "\t"<<"InputFile - input file to be loaded by OSG."<<endl;
|
||||
cerr << "\t"<<"OutputFile - output file to be saved by Performer."<<endl;
|
||||
cerr << "\t"<<"-si - save of texture images as rgb files"<<endl;
|
||||
cerr << "\t"<<" in the OutputFile's directory"<<endl;
|
||||
cerr << endl;
|
||||
}
|
||||
|
||||
|
||||
// create the output file from the command line arguments
|
||||
std::string outfile = filelist.back();
|
||||
filelist.pop_back();
|
||||
std::string outpath = osg::getFilePath(outfile);
|
||||
|
||||
pfInitArenas();
|
||||
pfInit();
|
||||
|
||||
FileList::iterator itr;
|
||||
for(itr=filelist.begin();itr!=filelist.end();++itr)
|
||||
{
|
||||
pfdInitConverter(outfile.c_str());
|
||||
}
|
||||
|
||||
pfConfig();
|
||||
|
||||
std::vector<osg::Node*> nodeList;
|
||||
for(itr=filelist.begin();itr!=filelist.end();++itr)
|
||||
{
|
||||
osg::Node* osg_file_root = osg::Registry::instance()->readNode((*itr).c_str());
|
||||
if (osg_file_root)
|
||||
{
|
||||
nodeList.push_back(osg_file_root);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!nodeList.empty())
|
||||
{
|
||||
osg::Node* osg_root = NULL;
|
||||
if (nodeList.size()==1)
|
||||
{
|
||||
osg_root = nodeList[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::Group* group = new osg::Group();
|
||||
for(std::vector<osg::Node*>::iterator ni=nodeList.begin();
|
||||
ni!=nodeList.end();
|
||||
++ni)
|
||||
{
|
||||
group->addChild(*ni);
|
||||
}
|
||||
osg_root = group;
|
||||
}
|
||||
|
||||
ConvertToPerformer converter;
|
||||
//converter.setSaveImageDirectory(outpath);
|
||||
//converter.setSaveImagesAsRGB(saveImagesAsRGB);
|
||||
|
||||
pfNode* pf_root = converter.convert(osg_root);
|
||||
if (pf_root)
|
||||
{
|
||||
pfdStoreFile(pf_root,outfile.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "error : failed to convert OSG scene graph to Performer."<<endl;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "error : failed to convert any OSG database from input files."<<endl;
|
||||
}
|
||||
|
||||
pfExit();
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,72 +0,0 @@
|
||||
#ifndef __CONVERTFROMPERFORMER_H
|
||||
#define __CONVERTFROMPERFORMER_H
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
// Open Scene Graph includes.
|
||||
#include <osg/Node>
|
||||
#include <osg/Group>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/GeoState>
|
||||
|
||||
// Performer includes.
|
||||
#include <Performer/pf/pfNode.h>
|
||||
|
||||
class ConvertFromPerformer {
|
||||
public:
|
||||
|
||||
ConvertFromPerformer();
|
||||
~ConvertFromPerformer();
|
||||
|
||||
osg::Node* convert(pfNode* node);
|
||||
|
||||
void setSaveImageDirectory(const std::string& directory) { _saveImageDirectory = directory; }
|
||||
void setSaveImagesAsRGB(bool b) { _saveImagesAsRGB=b; }
|
||||
void setSaveAbsoluteImagePath(bool b) { _saveAbsoluteImagePath = b; }
|
||||
|
||||
private:
|
||||
|
||||
osg::Object* getOsgObject(pfObject* pfObj);
|
||||
void regisiterPfObjectForOsgObject(pfObject* pfObj,osg::Object* osgObj);
|
||||
|
||||
osg::Node* visitNode(osg::Group* osgParent,pfNode* node);
|
||||
osg::Node* visitScene(osg::Group* osgParent,pfScene* scene);
|
||||
osg::Node* visitGroup(osg::Group* osgParent,pfGroup* group);
|
||||
osg::Node* visitDCS(osg::Group* osgParent,pfDCS* dcs);
|
||||
osg::Node* visitLOD(osg::Group* osgParent,pfLOD* lod);
|
||||
osg::Node* visitSwitch(osg::Group* osgParent,pfSwitch* switchNode);
|
||||
osg::Node* visitSequence(osg::Group* osgParent,pfSequence* sequence);
|
||||
osg::Node* visitSCS(osg::Group* osgParent,pfSCS* scs);
|
||||
osg::Node* visitGeode(osg::Group* osgParent,pfGeode* geode);
|
||||
osg::Node* visitBillboard(osg::Group* osgParent,pfBillboard* billboard);
|
||||
|
||||
int getNumVerts(pfGeoSet *gset);
|
||||
osg::GeoSet* visitGeoSet(osg::Geode* osgParent,pfGeoSet* geoset);
|
||||
osg::GeoState* visitGeoState(osg::GeoSet* osgGeoSet,pfGeoState* geostate);
|
||||
osg::Material* visitMaterial(osg::GeoState* osgGeoState,pfMaterial* material);
|
||||
osg::Texture* visitTexture(osg::GeoState* osgGeoState,pfTexture* tex);
|
||||
|
||||
typedef std::map<int,osg::GeoSet::PrimitiveType> GSetPrimitiveMap;
|
||||
typedef std::map<int,osg::GeoSet::BindingType> GSetBindingMap;
|
||||
typedef std::map<int,osg::GeoState::AttributeType> GStateTypeMap;
|
||||
typedef std::map<int,osg::GeoState::AttributeMode> GStateModeMap;
|
||||
|
||||
GSetPrimitiveMap _gsetPrimMap;
|
||||
GSetBindingMap _gsetBindMap;
|
||||
GStateTypeMap _gstateTypeMap;
|
||||
GStateModeMap _gstateModeMap;
|
||||
|
||||
bool _saveImagesAsRGB;
|
||||
bool _saveAbsoluteImagePath;
|
||||
std::string _saveImageDirectory;
|
||||
|
||||
typedef std::map<pfObject*,osg::Object*> PfObjectToOsgObjectMap;
|
||||
PfObjectToOsgObjectMap _pfToOsgMap;
|
||||
|
||||
osg::Node* _osgRoot;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,20 +0,0 @@
|
||||
#!smake
|
||||
include ../../Make/makedefs
|
||||
|
||||
C++FILES = \
|
||||
ConvertFromPerformer.cpp\
|
||||
pf2osg.cpp
|
||||
|
||||
C++FLAGS += -I../../include -O
|
||||
|
||||
|
||||
LIBS = -losg
|
||||
|
||||
TARGET = ../../bin/pf2osg
|
||||
|
||||
LDFLAGS += -L../../lib -L/usr/X11R6/lib
|
||||
|
||||
LIBS = -losg -lGLU -lGL -lm ${PFLIBS}
|
||||
|
||||
include ../../Make/makerules
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#!smake
|
||||
include ../../Make/makedefs
|
||||
|
||||
C++FILES = \
|
||||
ConvertFromPerformer.cpp\
|
||||
osg.cpp
|
||||
# pf2osg.cpp\
|
||||
|
||||
|
||||
LIB = ../../lib/libpfosg_ogl.so
|
||||
|
||||
C++FLAGS += -I../../include
|
||||
LDFLAGS += -L../../lib
|
||||
|
||||
include ../../Make/makerules
|
||||
|
||||
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#include "ConvertFromPerformer.h"
|
||||
|
||||
#include <Performer/pf/pfNode.h>
|
||||
#include <Performer/pf/pfGeode.h>
|
||||
#include <Performer/pf/pfBillboard.h>
|
||||
#include <Performer/pf/pfScene.h>
|
||||
#include <Performer/pf/pfGroup.h>
|
||||
#include <Performer/pf/pfDCS.h>
|
||||
#include <Performer/pf/pfSCS.h>
|
||||
#include <Performer/pr/pfGeoState.h>
|
||||
#include <Performer/pr/pfMaterial.h>
|
||||
|
||||
#include <osg/Registry>
|
||||
|
||||
// Performer includes.
|
||||
#include <Performer/pfdu.h>
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
int pfdStoreFile_osg(pfNode *root, const char *fileName);
|
||||
|
||||
};
|
||||
|
||||
|
||||
int pfdStoreFile_osg(pfNode *root, const char *fileName)
|
||||
{
|
||||
ConvertFromPerformer converter;
|
||||
osg::Node* osg_root = converter.convert(root);
|
||||
if (osg_root)
|
||||
{
|
||||
osg::Registry::instance()->writeNode(*osg_root,fileName);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "error : failed to create any perfomer database from input files."<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
#include "ConvertFromPerformer.h"
|
||||
|
||||
#include <Performer/pf/pfNode.h>
|
||||
#include <Performer/pf/pfGeode.h>
|
||||
#include <Performer/pf/pfBillboard.h>
|
||||
#include <Performer/pf/pfScene.h>
|
||||
#include <Performer/pf/pfGroup.h>
|
||||
#include <Performer/pf/pfDCS.h>
|
||||
#include <Performer/pf/pfSCS.h>
|
||||
#include <Performer/pr/pfGeoState.h>
|
||||
#include <Performer/pr/pfMaterial.h>
|
||||
|
||||
#include <osg/Registry>
|
||||
#include <osg/FileNameUtils>
|
||||
#include <osg/Notify>
|
||||
|
||||
// Performer includes.
|
||||
#include <Performer/pfdu.h>
|
||||
|
||||
#ifdef OSG_USE_IO_DOT_H
|
||||
#include <iostream.h>
|
||||
#else
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#endif
|
||||
|
||||
|
||||
int main( int argc, const char **argv )
|
||||
{
|
||||
|
||||
// create the list of input files from the command line arguments
|
||||
typedef std::vector<std::string> FileList;
|
||||
FileList filelist;
|
||||
|
||||
bool saveImagesAsRGB = false;
|
||||
for(int i=1;i<argc;++i)
|
||||
{
|
||||
if (strcmp(argv[i],"-si")==0) saveImagesAsRGB = true;
|
||||
else filelist.push_back(argv[i]);
|
||||
}
|
||||
|
||||
if (filelist.size()<2)
|
||||
{
|
||||
osg::notify(osg::NOTICE) << "Usage :";
|
||||
osg::notify(osg::NOTICE) << "\t"<<argv[0]<<" [-si] InputFile [InputFile...] OutputFile"<<endl;
|
||||
osg::notify(osg::NOTICE) << "\t"<<"InputFile - input file to be loaded by Performer."<<endl;
|
||||
osg::notify(osg::NOTICE) << "\t"<<"OutputFile - output file to be saved by OSG."<<endl;
|
||||
osg::notify(osg::NOTICE) << "\t"<<"-si - save of texture images as rgb files"<<endl;
|
||||
osg::notify(osg::NOTICE) << "\t"<<" in the OutputFile's directory"<<endl;
|
||||
osg::notify(osg::NOTICE) << endl;
|
||||
}
|
||||
|
||||
|
||||
// create the output file from the command line arguments
|
||||
std::string outfile = filelist.back();
|
||||
filelist.pop_back();
|
||||
std::string outpath = osg::getFilePath(outfile);
|
||||
|
||||
pfInit();
|
||||
|
||||
FileList::iterator itr;
|
||||
for(itr=filelist.begin();itr!=filelist.end();++itr)
|
||||
{
|
||||
pfdInitConverter((*itr).c_str());
|
||||
}
|
||||
|
||||
pfConfig();
|
||||
|
||||
std::vector<pfNode*> nodeList;
|
||||
for(itr=filelist.begin();itr!=filelist.end();++itr)
|
||||
{
|
||||
pfNode* pf_file_root = pfdLoadFile((*itr).c_str());
|
||||
if (pf_file_root)
|
||||
{
|
||||
nodeList.push_back(pf_file_root);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!nodeList.empty())
|
||||
{
|
||||
pfNode* pf_root = NULL;
|
||||
if (nodeList.size()==1)
|
||||
{
|
||||
pf_root = nodeList[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
pfGroup* group = new pfGroup;
|
||||
for(std::vector<pfNode*>::iterator ni=nodeList.begin();
|
||||
ni!=nodeList.end();
|
||||
++ni)
|
||||
{
|
||||
group->addChild(*ni);
|
||||
}
|
||||
pf_root = (pfNode*) group;
|
||||
}
|
||||
|
||||
ConvertFromPerformer converter;
|
||||
converter.setSaveImageDirectory(outpath);
|
||||
converter.setSaveImagesAsRGB(saveImagesAsRGB);
|
||||
|
||||
osg::Node* osg_root = converter.convert(pf_root);
|
||||
if (osg_root)
|
||||
{
|
||||
osg::Registry::instance()->writeNode(*osg_root,outfile.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify(osg::NOTICE) << "error : failed to convert perfomer scene graph to OSG."<<endl;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify(osg::NOTICE) << "error : failed to create any perfomer database from input files."<<endl;
|
||||
}
|
||||
|
||||
pfExit();
|
||||
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
#include "pfb.h"
|
||||
|
||||
// Open Scene Graph includes.
|
||||
#include <osg/OSG>
|
||||
#include <osg/Node>
|
||||
#include <osg/Geode>
|
||||
#include <osg/Group>
|
||||
|
||||
#include <osg/Output>
|
||||
#include <osg/Input>
|
||||
#include <osg/Registry>
|
||||
|
||||
// Performer includes.
|
||||
#include <Performer/pfdu.h>
|
||||
|
||||
#include "ConvertFromPerformer.h"
|
||||
#include "ConvertToPerformer.h"
|
||||
|
||||
using namespace osg;
|
||||
|
||||
// now register with Registry to instantiate the pfb reader/writer.
|
||||
RegisterReaderWriterProxy<PerformerReaderWriter> g_performerReaderWriterProxy;
|
||||
|
||||
PerformerReaderWriter::PerformerReaderWriter()
|
||||
{
|
||||
_perfomerInitialised = false;
|
||||
}
|
||||
|
||||
PerformerReaderWriter::~PerformerReaderWriter()
|
||||
{
|
||||
if (_perfomerInitialised)
|
||||
{
|
||||
pfExit();
|
||||
}
|
||||
}
|
||||
|
||||
void PerformerReaderWriter::initialisePerformer(const std::string& fileName)
|
||||
{
|
||||
if (_perfomerInitialised) return;
|
||||
|
||||
pfInit();
|
||||
pfdInitConverter(fileName.c_str());
|
||||
pfConfig();
|
||||
|
||||
_perfomerInitialised = true;
|
||||
}
|
||||
|
||||
osg::Object* PerformerReaderWriter::readObject(const std::string& fileName)
|
||||
{
|
||||
return readNode(fileName);
|
||||
}
|
||||
|
||||
osg::Node* PerformerReaderWriter::readNode(const std::string& fileName)
|
||||
{
|
||||
initialisePerformer(fileName.c_str());
|
||||
|
||||
osg::Node* osg_root = NULL;
|
||||
pfNode* pf_root = pfdLoadFile(fileName.c_str());
|
||||
if (pf_root)
|
||||
{
|
||||
ConvertFromPerformer converter;
|
||||
osg_root = converter.convert(pf_root);
|
||||
}
|
||||
return osg_root;
|
||||
}
|
||||
|
||||
bool PerformerReaderWriter::writeObject(osg::Object& obj,const std::string& fileName)
|
||||
{
|
||||
osg::Node* node = dynamic_cast<osg::Node*>(&obj);
|
||||
if (node) return writeNode(*node,fileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PerformerReaderWriter::writeNode(osg::Node& node,const std::string& fileName)
|
||||
{
|
||||
initialisePerformer(fileName.c_str());
|
||||
|
||||
ConvertToPerformer converter;
|
||||
pfNode* pf_root = converter.convert(&node);
|
||||
|
||||
if (pf_root) {
|
||||
pfdStoreFile(pf_root,fileName.c_str());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
#ifndef __PFB_H
|
||||
#define __PFB_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// Open Scene Graph includes.
|
||||
#include <osg/Registry>
|
||||
|
||||
// Performer includes.
|
||||
#include <Performer/pf/pfNode.h>
|
||||
|
||||
class PerformerReaderWriter : public osg::ReaderWriter
|
||||
{
|
||||
public:
|
||||
|
||||
PerformerReaderWriter();
|
||||
~PerformerReaderWriter();
|
||||
|
||||
virtual const char* className() { return "Performer Reader/Writer"; }
|
||||
virtual bool acceptsExtension(const std::string& extension) { return extension=="pfb"; }
|
||||
|
||||
virtual osg::Object* readObject(const std::string& fileName);
|
||||
virtual osg::Node* readNode(const std::string& fileName);
|
||||
virtual bool writeObject(osg::Object& obj,const std::string& fileName);
|
||||
virtual bool writeNode(osg::Node& node,const std::string& fileName);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void initialisePerformer(const std::string& fileName);
|
||||
|
||||
private:
|
||||
|
||||
bool _perfomerInitialised;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user