1 // #define FRAMEINTERLEAVE
7 #include "OSGTransform.h"
10 #include "OSGClusterWindow.h"
11 #include "OSGSceneFileHandler.h"
12 #include "OSGDirectionalLight.h"
13 #include "OSGSimpleGeometry.h"
14 #include "OSGCamera.h"
15 #include "OSGViewport.h"
16 #include "OSGPerspectiveCamera.h"
17 #include "OSGSolidBackground.h"
18 #include "OSGGradientBackground.h"
19 #include "OSGTrackball.h"
20 #include "OSGVolumeDraw.h"
21 #include "OSGGLUTWindow.h"
22 #include "OSGMultiDisplayWindow.h"
23 #include "OSGBalancedMultiWindow.h"
24 #include "OSGSortFirstWindow.h"
25 #include "OSGChunkMaterial.h"
26 #include "OSGSimpleMaterial.h"
27 #include "OSGPolygonChunk.h"
28 #include "OSGGeoFunctions.h"
29 #include "OSGMaterialGroup.h"
30 #include "OSGSortLastWindow.h"
31 #include "OSGImageComposer.h"
32 #include "OSGProxyGroup.h"
33 #ifdef FRAMEINTERLEAVE
34 #include "OSGFrameInterleaveWindow.h"
36 #include "OSGShearedStereoCameraDecorator.h"
37 #include "OSGNameAttachment.h"
38 #include "OSGColorBufferViewport.h"
40 #include "OSGPipelineComposer.h"
41 #include "OSGBinarySwapComposer.h"
42 #include "OSGRenderAction.h"
44 #include "OSGBackgroundLoader.h"
45 #include "OSGModelRequest.h"
51 int winwidth
=300, winheight
=300;
54 OSG::TransformRecPtr cam_trans
;
55 //OSG::PerspectiveCameraRecPtr cam;
56 OSG::ClusterWindowRecPtr clusterWindow
;
57 OSG::RenderActionRefPtr ract
;
58 OSG::GLUTWindowRecPtr clientWindow
;
59 OSG::SortFirstWindowRecPtr sortfirst
;
60 OSG::SortLastWindowRecPtr sortlast
;
61 #ifdef FRAMEINTERLEAVE
62 OSG::FrameInterleaveWindowRecPtr frameinterleave
;
64 OSG::MultiDisplayWindowRecPtr multidisplay
;
65 OSG::BalancedMultiWindowRecPtr balancedmultidisplay
;
71 float ca
=-1,cb
=-1,cc
=-1;
72 OSG::Int32 stereoMode
=0;
73 float eyedistance
=1,zeroparallax
=10;
74 int serverx
=-1,servery
=-1;
75 std::vector
<OSG::Quaternion
> animOri
;
76 std::vector
<OSG::Vec3f
> animPos
;
77 std::string animName
="animation.txt";
78 OSG::Real32 animTime
=0;
79 std::string serviceInterface
;
80 bool serviceInterfaceValid
= false;
81 std::string serviceAddress
;
82 bool serviceAddressValid
= false;
83 OSG::UInt32 interleave
=0;
84 OSG::Real32 _dsFactor
= 1.0; // scale down factor.
85 bool _enablecc
= true; // enable color correction.
86 OSG::PolygonChunkRecPtr polygonChunk
;
89 OSG::Time frame_time
=0;
90 OSG::UInt32 sum_positions
=0;
91 OSG::UInt32 sum_geometries
=0;
92 OSG::UInt32 sum_triangles
=0;
94 std::string connectionDestination
="";
95 std::string connectionInterface
="";
96 OSG::SolidBackgroundRecPtr bkgnd
;
97 OSG::Int32 subtilesize
=-1;
98 bool pipelinedBufferRead
= false;
105 clusterWindow
= NULL
;
109 #ifdef FRAMEINTERLEAVE
110 frameinterleave
= NULL
;
113 balancedmultidisplay
= NULL
;
120 /*! Simple show text function
122 void displayInfo(int x
, int y
)
127 void *font
= (void *) 2;
132 #ifdef OSG_DEBUG_OLD_C_CASTS
133 void *font
= glutBitmap9By15
;
135 void *font
= GLUT_BITMAP_9_BY_15
;
150 glPushAttrib(GL_ALL_ATTRIB_BITS
);
151 glDisable(GL_LIGHTING
);
152 glEnable(GL_COLOR_MATERIAL
);
155 glMatrixMode(GL_PROJECTION
);
158 gluOrtho2D(0,clientWindow
->getWidth(),0,clientWindow
->getHeight());
159 glDisable(GL_DEPTH_TEST
);
161 glBlendFunc(GL_SRC_ALPHA
,GL_ONE_MINUS_SRC_ALPHA
);
168 glColor4f(.1f
, .1f
, .7f
, .5f
);
174 glBegin(GL_LINE_LOOP
);
175 glColor3f(1.0, 1.0, 0.0);
182 glColor3f(1.0, 1.0, 0.0);
184 len
= int(strlen(text
));
185 for (i
= 0; i
< len
; i
++) {
192 glutBitmapCharacter(font
, text
[i
]);
195 glMatrixMode(GL_MODELVIEW
);
200 void prepareSceneGraph(OSG::Node
* const node
)
204 polygonChunk
= OSG::PolygonChunk::create();
208 OSG::NodeCore
*core
=node
->getCore();
211 OSG::Geometry
*geo
= dynamic_cast<OSG::Geometry
*>(core
);
214 OSG::Material
*mat
= geo
->getMaterial();
217 OSG::ChunkMaterial
*cmat
=
218 dynamic_cast<OSG::ChunkMaterial
*>(mat
);
219 if(cmat
->find(OSG::PolygonChunk::getClassType()) == NULL
)
221 cmat
->addChunk(polygonChunk
);
225 OSG::GeoVectorProperty
*positionsPtr
=geo
->getPositions();
226 if(positionsPtr
!= NULL
)
227 sum_positions
+= positionsPtr
->size32();
229 OSG::UInt32 triangle
=0;
232 OSG::UInt32 patches
=0;
233 calcPrimitiveCount(geo
,triangle
,line
,point
, patches
);
234 sum_triangles
+= triangle
;
235 // sum of geometry nodes
240 OSG::MaterialGroup
*matGrp
=
241 dynamic_cast<OSG::MaterialGroup
*>(core
);
244 OSG::Material
*mat
= matGrp
->getMaterial();
247 OSG::ChunkMaterial
*cmat
=
248 dynamic_cast<OSG::ChunkMaterial
*>(mat
);
249 if(cmat
->find(OSG::PolygonChunk::getClassType()) == NULL
)
251 cmat
->addChunk(polygonChunk
);
257 OSG::ProxyGroup
*proxy
= dynamic_cast<OSG::ProxyGroup
*>(core
);
260 sum_triangles
+= proxy
->getTriangles();
261 sum_positions
+= proxy
->getPositions();
262 sum_geometries
+= proxy
->getGeometries();
267 for(OSG::MFUnrecChildNodePtr::const_iterator nI
=node
->getMFChildren()->begin();
268 nI
!= node
->getMFChildren()->end();
271 prepareSceneGraph(*nI
);
277 OSG::Real32 ax
,ay
,az
,r
,x
,y
,z
;
278 FILE *file
=fopen(animName
.c_str(),"r");
284 while(fscanf(file
,"%f %f %f %f,%f %f %f",&ax
,&ay
,&az
,&r
,&x
,&y
,&z
)==7)
286 animOri
.push_back(OSG::Quaternion(OSG::Vec3f(ax
,ay
,az
),r
));
287 animPos
.push_back(OSG::Vec3f(x
,y
,z
));
296 // std::cout << glutGet(GLUT_WINDOW_WIDTH) << std::endl;
298 t
=-OSG::getSystemTime();
300 if(animate
&& animPos
.size()>1)
303 animTime
= frameCount
* (animPos
.size())/float(animLength
);
305 OSG::UInt32 i
=OSG::UInt32(animTime
);
306 OSG::Real32 a
=animTime
-i
;
310 if(i
+1 < animPos
.size())
312 v
= animPos
[i
] + (animPos
[i
+1] - animPos
[i
]) * a
;
313 q
= OSG::Quaternion::slerp(animOri
[i
],animOri
[i
+1],a
);
320 cam_trans
->editMatrix().setTranslate(v
[0],v
[1],v
[2]);
321 cam_trans
->editMatrix().setRotate(q
);
325 cam_trans
->editSFMatrix()->setValue( tball
.getFullTrackballMatrix() );
330 OSG::BackgroundLoader::the()->sync();
333 OSG::Thread::getCurrentChangeList()->commitChanges();
335 clusterWindow
->activate();
336 clusterWindow
->frameInit();
337 clusterWindow
->renderAllViewports(ract
);
339 clusterWindow
->renderNoFinish(ract
);
346 sprintf(text,"FPS: %12.1f",1.0/frame_time);
347 showText(10,70,text);
348 sprintf(text,"Positions: %12d",sum_positions);
349 showText(10,50,text);
350 sprintf(text,"Triangles: %12d",sum_triangles);
351 showText(10,30,text);
352 sprintf(text,"Geometries: %12d",sum_geometries);
353 showText(10,10,text);
358 clusterWindow
->swap();
359 clusterWindow
->frameExit();
361 clusterWindow
->frameFinish();
362 // clear changelist from prototypes
363 OSG::Thread::getCurrentChangeList()->clear();
365 catch(OSG_STDEXCEPTION_NAMESPACE::exception
&e
)
367 std::cout
<< e
.what() << std::endl
;
372 t
+=OSG::getSystemTime();
375 if(animate
&& animPos
.size()>1)
379 printf("Frame %8.3f %8.5f %8.3f\n",
384 if(frameCount
== animLength
)
403 void reshape( int width
, int height
)
405 printf("reshape %d %d\n",width
,height
);
406 glViewport(0, 0, width
, height
);
408 clientWindow
->resize( width
, height
);
413 void motion(int x
, int y
)
415 OSG::Real32 w
= clientWindow
->getWidth(), h
= clientWindow
->getHeight();
418 OSG::Real32 a
= -2. * ( lastx
/ w
- .5 ),
419 b
= -2. * ( .5 - lasty
/ h
),
420 c
= -2. * ( x
/ w
- .5 ),
421 d
= -2. * ( .5 - y
/ h
);
423 if ( mouseb
& ( 1 << GLUT_LEFT_BUTTON
) )
425 tball
.updateRotation( a
, b
, c
, d
);
427 else if ( mouseb
& ( 1 << GLUT_MIDDLE_BUTTON
) )
429 tball
.updatePosition( a
, b
, c
, d
);
431 else if ( mouseb
& ( 1 << GLUT_RIGHT_BUTTON
) )
433 tball
.updatePositionNeg( a
, b
, c
, d
);
440 void mouse(int button
, int state
, int x
, int y
)
446 case GLUT_LEFT_BUTTON
: break;
447 case GLUT_MIDDLE_BUTTON
:tball
.setAutoPosition(true);
449 case GLUT_RIGHT_BUTTON
: tball
.setAutoPositionNeg(true);
452 mouseb
|= 1 << button
;
454 else if ( state
== 1 )
458 case GLUT_LEFT_BUTTON
: break;
459 case GLUT_MIDDLE_BUTTON
:tball
.setAutoPosition(false);
461 case GLUT_RIGHT_BUTTON
: tball
.setAutoPositionNeg(false);
464 mouseb
&= ~(1 << button
);
471 void setHEyeWallParameter(OSG::Real32 dsFactor
, bool enablecc
)
473 static char str
[1024];
475 OSG::NameUnrecPtr parameters
= dynamic_cast<OSG::Name
*>(clusterWindow
->findAttachment(OSG::Name::getClassType()));
477 if(parameters
== NULL
)
479 parameters
= OSG::Name::create();
480 clusterWindow
->addAttachment(parameters
);
483 sprintf(str
, "downScale=%f colorCorrection=%d", dsFactor
, enablecc
);
484 parameters
->editFieldPtr()->getValue().assign(str
);
487 void key(unsigned char key
, int /*x*/, int /*y*/)
498 FILE *file
=fopen(animName
.c_str(),"w");
508 FILE *file
=fopen(animName
.c_str(),"a");
509 OSG::Matrix m
=cam_trans
->getMatrix();
510 OSG::Quaternion
q(m
);
511 OSG::Real32 ax
,ay
,az
,r
;
512 animPos
.push_back(OSG::Vec3f(m
[3][0],
515 animOri
.push_back(q
);
516 q
.getValueAsAxisRad(ax
,ay
,az
,r
);
517 fprintf(file
,"%f %f %f %f,%f %f %f\n",ax
,ay
,az
,r
,
528 FILE *file
=fopen((animName
+".wrl").c_str(),"w");
529 std::vector
<OSG::Quaternion
>::iterator qit
;
531 fprintf(file
,"DEF OriInter OrientationInterpolator {\n\tkey [");
532 for(size_t i
= 0; i
< animOri
.size(); ++i
)
534 fprintf(file
, "%f", i
/ OSG::Real32(animOri
.size() - 1) );
535 if(i
< animOri
.size() - 1)
538 fprintf(file
,"]\n\tkeyValue [");
539 for(qit
= animOri
.begin(); qit
!= animOri
.end(); ++qit
)
541 OSG::Real32 ax
,ay
,az
,r
;
542 (*qit
).getValueAsAxisRad(ax
,ay
,az
,r
);
544 fprintf(file
, "%f %f %f %f", ax
, ay
, az
, r
);
545 if(qit
< animOri
.end() - 1)
548 fprintf(file
,"]\n}\n\n");
550 std::vector
<OSG::Vec3f
>::iterator vit
;
552 fprintf(file
,"DEF PosInter PositionInterpolator {\n\tkey [");
553 for(size_t i
= 0; i
< animPos
.size(); ++i
)
555 fprintf(file
, "%f", i
/ OSG::Real32(animPos
.size() - 1) );
556 if(i
< animPos
.size() - 1)
559 fprintf(file
,"]\n\tkeyValue [");
560 for(vit
= animPos
.begin(); vit
!= animPos
.end(); ++vit
)
564 fprintf(file
, "%f %f %f, ", v
[0], v
[1], v
[2] );
566 fprintf(file
,"]\n}\n\n");
574 sortfirst
->setCompression("JPEG");
580 sortfirst
->setCompression("RLE");
586 sortfirst
->editCompression().erase();
590 showInfo
= !showInfo
;
593 if(polygonChunk
->getFrontMode() == GL_FILL
)
594 polygonChunk
->setFrontMode(GL_LINE
);
596 polygonChunk
->setFrontMode(GL_FILL
);
598 if(polygonChunk
->getBackMode() == GL_FILL
)
599 polygonChunk
->setBackMode(GL_LINE
);
601 polygonChunk
->setBackMode(GL_FILL
);
611 glutIdleFunc(display
);
619 while(root
->getNChildren())
628 setHEyeWallParameter(_dsFactor
, _enablecc
);
632 if(_dsFactor
<= 0.0f
)
634 setHEyeWallParameter(_dsFactor
, _enablecc
);
641 setHEyeWallParameter(_dsFactor
, _enablecc
);
644 if(bkgnd
->getColor()[0] == 0.0)
645 bkgnd
->setColor( OSG::Color3f(1,1,1) );
647 bkgnd
->setColor( OSG::Color3f(0,0,0) );
649 case 27: // should kill the clients here
659 void init(std::vector
<std::string
> &filenames
)
662 OSG::DirectionalLightUnrecPtr dl
;
664 OSG::BoxVolume volume
;
668 glEnable( GL_DEPTH_TEST
);
669 glEnable( GL_LIGHTING
);
670 glEnable( GL_LIGHT0
);
671 // GLint twoSide = 1;
672 // glLightModeliv(GL_LIGHT_MODEL_TWO_SIDE,&twoSide);
673 glPixelStorei( GL_UNPACK_ALIGNMENT
, 1 );
677 // beacon for camera and light
678 OSG::NodeUnrecPtr b1n
= OSG::Node::create();
679 OSG::GroupUnrecPtr b1
= OSG::Group::create();
683 OSG::NodeUnrecPtr t1n
= OSG::Node::create();
684 OSG::TransformUnrecPtr t1
= OSG::Transform::create();
686 t1n
->addChild( b1n
);
692 OSG::NodeUnrecPtr dlight
= OSG::Node::create();
693 dl
= OSG::DirectionalLight::create();
695 dlight
->setCore( dl
);
697 dl
->setAmbient( .3f
, .3f
, .3f
, 1 );
698 dl
->setDiffuse( 1, 1, 1, 1 );
699 dl
->setDirection(0,0,1);
703 root
= OSG::Node::create();
705 OSG::GroupUnrecPtr gr1
= OSG::Group::create();
707 root
->setCore( gr1
);
708 root
->addChild( t1n
);
709 root
->addChild( dlight
);
712 OSG::NodeUnrecPtr scene
= OSG::Node::create();
713 scene
->setCore(OSG::Group::create());
715 OSG::NodeUnrecPtr file
;
716 for(i
=0;i
<filenames
.size();i
++)
719 file
= OSG::SceneFileHandler::the()->read(filenames
[i
].c_str(),0);
721 scene
->addChild(file
);
723 std::cerr
<< "Couldn't load file, ignoring " << filenames
[i
] << std::endl
;
725 OSG::ModelRequestPtr req
=
726 OSG::ModelRequest::create()->init(scene
,
729 req
->setVerifyModel(false );
730 req
->setGraphOp ("none");
732 OSG::BackgroundLoader::the()->addRequest(req
);
734 // if ( filenames.size()==0 )
736 file
= OSG::makeTorus( 5000, 10000, 16, 16 );
737 scene
->addChild(file
);
738 // scene->addChild(makeBox(.6,.6,.6,5,5,5));
741 prepareSceneGraph(scene
);
743 // Start the background loader.
744 OSG::BackgroundLoader::the()->start();
746 OSG::Thread::getCurrentChangeList()->commitChanges();
748 scene
->invalidateVolume();
749 scene
->updateVolume();
750 volume
=scene
->getVolume();
751 volume
.getBounds(min
,max
);
761 OSG::NodeUnrecPtr node
;
762 OSG::NodeUnrecPtr geoNode
;
763 OSG::TransformUnrecPtr trans
;
764 for(x
=-ca
/2.0 ; x
<ca
/2.0 ; x
++)
765 for(y
=-cb
/2.0 ; y
<cb
/2.0 ; y
++)
766 for(z
=-cc
/2.0 ; z
<cc
/2.0 ; z
++)
768 trans
=OSG::Transform::create();
769 node
=OSG::Node::create();
771 node
->setCore(trans
);
772 trans
->editMatrix().setTranslate(
776 geoNode
= OSG::cloneTree(scene
);
777 geoNode
->editSFVolume()->getValue() = scene
->getSFVolume()->getValue();
778 geoNode
->editVolume(false).setValid(true);
779 node
->addChild( geoNode
);
780 dlight
->addChild(node
);
785 dlight
->addChild(scene
);
790 sum_geometries
*=OSG::UInt32(ca
*cb
*cc
);
791 sum_triangles
*=OSG::UInt32(ca
*cb
*cc
);
792 sum_positions
*=OSG::UInt32(ca
*cb
*cc
);
795 OSG::Thread::getCurrentChangeList()->commitChanges();
797 // dlight->invalidateVolume();
798 printf("update Volume\n");
799 dlight
->updateVolume();
800 printf("update Volume OK\n");
802 // should check first. ok for now.
803 const OSG::BoxVolume
&vol
= dlight
->getVolume();
807 vol
.getBounds(min
, max
);
808 vol
.getCenter(center
);
812 std::cout
<< "Volume: from " << min
<< " to " << max
<< std::endl
;
813 std::cout
<< "Center: " << center
<< std::endl
;
817 OSG::PerspectiveCameraUnrecPtr cam
= OSG::PerspectiveCamera::create();
818 cam
->setBeacon( b1n
);
819 cam
->setFov( OSG::osgDegree2Rad( 60 ) );
821 cam
->setFar( 50000 );
824 bkgnd
= OSG::SolidBackground::create();
825 bkgnd
->setColor( OSG::Color3f(0,0,0) );
826 // bkgnd->setColor( OSG::Color3f(.1,.1,.6) );
827 // bkgnd->setColor( OSG::Color3f(1,1,1) );
830 OSG::ViewportUnrecPtr vp1
;
831 OSG::ViewportUnrecPtr vp2
;
834 vp1
= OSG::Viewport::create();
835 vp1
->setCamera ( cam
);
836 vp1
->setBackground( bkgnd
);
837 vp1
->setRoot ( root
);
838 vp1
->setSize ( 0,0, 1,1 );
842 vp2
= OSG::Viewport::create();
843 vp2
->setCamera ( cam
);
844 vp2
->setBackground( bkgnd
);
845 vp2
->setRoot ( root
);
846 vp2
->setSize ( .1f
, .55f
, .7f
,.95f
);
849 else if(stereoMode
== 1)
851 OSG::ShearedStereoCameraDecoratorUnrecPtr deco
;
853 deco
=OSG::ShearedStereoCameraDecorator::create();
854 deco
->setLeftEye(true);
855 deco
->setEyeSeparation(eyedistance
);
856 deco
->setDecoratee(cam
);
857 deco
->setZeroParallaxDistance(zeroparallax
);
858 vp1
= OSG::Viewport::create();
859 vp1
->setCamera ( deco
);
860 vp1
->setBackground( bkgnd
);
861 vp1
->setRoot ( root
);
862 vp1
->setSize ( 0,0, .5,1 );
864 deco
=OSG::ShearedStereoCameraDecorator::create();
865 deco
->setLeftEye(false);
866 deco
->setEyeSeparation(eyedistance
);
867 deco
->setDecoratee(cam
);
868 deco
->setZeroParallaxDistance(zeroparallax
);
869 vp2
= OSG::Viewport::create();
870 vp2
->setCamera ( deco
);
871 vp2
->setBackground( bkgnd
);
872 vp2
->setRoot ( root
);
873 vp2
->setSize ( .5,0,1,1 );
875 else if(stereoMode
== 2)
877 OSG::ShearedStereoCameraDecoratorUnrecPtr deco
;
879 deco
=OSG::ShearedStereoCameraDecorator::create();
880 deco
->setLeftEye(true);
881 deco
->setEyeSeparation(eyedistance
);
882 deco
->setDecoratee(cam
);
883 deco
->setZeroParallaxDistance(zeroparallax
);
885 OSG::ColorBufferViewportUnrecPtr cvp1
=
886 OSG::ColorBufferViewport::create();
887 cvp1
->setCamera ( deco
);
888 cvp1
->setBackground( bkgnd
);
889 cvp1
->setRoot ( root
);
890 cvp1
->setSize ( 0,0, 1,1 );
891 cvp1
->setRed(GL_FALSE
);
892 cvp1
->setGreen(GL_TRUE
);
893 cvp1
->setBlue(GL_TRUE
);
894 cvp1
->setAlpha(GL_TRUE
);
898 deco
=OSG::ShearedStereoCameraDecorator::create();
899 deco
->setLeftEye(false);
900 deco
->setEyeSeparation(eyedistance
);
901 deco
->setDecoratee(cam
);
902 deco
->setZeroParallaxDistance(zeroparallax
);
904 OSG::ColorBufferViewportUnrecPtr cvp2
=
905 OSG::ColorBufferViewport::create();
906 cvp2
->setCamera ( deco
);
907 cvp2
->setBackground( bkgnd
);
908 cvp2
->setRoot ( root
);
909 cvp2
->setSize ( 0,0,1,1 );
910 cvp2
->setRed(GL_TRUE
);
911 cvp2
->setGreen(GL_FALSE
);
912 cvp2
->setBlue(GL_FALSE
);
913 cvp2
->setAlpha(GL_FALSE
);
918 glGetIntegerv( GL_VIEWPORT
, glvp
);
920 if(serverx
>0 && servery
>0)
921 clusterWindow
->setSize( serverx
, servery
);
923 clusterWindow
->setSize( glvp
[2], glvp
[3] );
924 clusterWindow
->addPort( vp1
);
926 if(multiport
|| stereoMode
> 0)
927 clusterWindow
->addPort( vp2
);
929 if(serviceInterfaceValid
== true)
931 clusterWindow
->setServiceInterface(serviceInterface
);
933 fprintf(stderr
, "tcclient use if %s\n", serviceInterface
.c_str());
936 if(serviceAddressValid
== true)
938 clusterWindow
->setServiceAddress(serviceAddress
);
940 fprintf(stderr
, "tcclient use ba %s\n", serviceAddress
.c_str());
945 OSG::Vec3f
pos(min
[0] + ((max
[0] - min
[0]) * 0.5),
946 min
[1] + ((max
[1] - min
[1]) * 0.5),
947 max
[2] + ( max
[2] - min
[2] ) * 1.5 );
949 float scale
= (max
[2] - min
[2] + max
[1] - min
[1] + max
[0] - min
[0]) / 6;
951 tball
.setMode( OSG::Trackball::OSGObject
);
952 tball
.setStartPosition( pos
, true );
953 tball
.setSum( true );
954 tball
.setTranslationMode( OSG::Trackball::OSGFree
);
955 tball
.setTranslationScale(scale
);
956 tball
.setRotationCenter(center
);
957 tball
.setTranslationGen(OSG::Trackball::OSGAbsoluteTranslation
);
960 std::cout
<< size
.length() << std::endl
;
961 cam
->setFar (size
.length() * 100.0);
962 cam
->setNear(size
.length() * 100.0 / 100000.0);
965 int doMain(int argc
,char **argv
)
969 std::vector
<std::string
> filenames
;
970 std::vector
<std::string
> servers
;
971 std::string connectionType
= "StreamSock";
972 std::string connectionParameters
;
976 bool clientRendering
=true;
979 std::string composerType
="";
980 std::string autostart
;
984 if(strlen(argv
[i
])>1 && argv
[i
][0]=='-')
989 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
990 connectionParameters
= opt
;
991 printf("connectionParameters: '%s'\n", connectionParameters
.c_str());
994 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
998 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
999 if(sscanf(opt
,"%f,%f,%f",&ca
,&cb
,&cc
)!=3)
1001 std::cout
<< "Copy opton -D x,y,z" << std::endl
;
1006 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1007 serviceInterface
.assign(opt
);
1008 serviceInterfaceValid
= true;
1011 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1012 serviceAddress
.assign(opt
);
1013 serviceAddressValid
= true;
1016 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1017 filenames
.push_back(opt
);
1018 printf("<%s>\n",opt
);
1021 connectionType
="Multicast";
1024 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1025 if(sscanf(opt
,"%d,%d",&rows
,&cols
) != 2)
1026 sscanf(opt
,"%d",&rows
);
1029 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1030 subtilesize
=atoi(opt
);
1032 #ifdef FRAMEINTERLEAVE
1034 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1035 interleave
=atoi(opt
);
1054 while(argv
[i
][lpos
])
1056 if(argv
[i
][lpos
] == 'B')
1057 composerType
= "BinarySwapComposer";
1058 if(argv
[i
][lpos
] == 'P')
1059 composerType
= "PipelineComposer";
1060 if(argv
[i
][lpos
] == 'S')
1061 composerType
= "SepiaComposer";
1062 if(argv
[i
][lpos
] == 'p')
1063 pipelinedBufferRead
= true;
1084 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1085 sscanf(opt
,"%f",&eyedistance
);
1088 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1089 sscanf(opt
,"%f",&zeroparallax
);
1092 clientRendering
=false;
1098 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1099 sscanf(opt
,"%d",&serverx
);
1102 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1103 sscanf(opt
,"%d",&servery
);
1106 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1112 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1113 if(sscanf(opt
,"%d,%d",&animLoops
,&animLength
) != 2)
1116 if(sscanf(opt
,"%d",&animLoops
) != 1)
1123 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1124 if(sscanf(opt
,"%d,%d,%d,%d",
1125 &winwidth
,&winheight
,&winx
,&winy
) != 4)
1126 sscanf(opt
,"%d,%d",&winwidth
,&winheight
);
1129 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1130 connectionDestination
= opt
;
1133 opt
= argv
[i
][2] ? argv
[i
]+2 : argv
[++i
];
1134 connectionInterface
= opt
;
1137 std::cout
<< argv
[0]
1138 << "-ffile -m -rrows[,cols] -C -M"
1140 std::cout
<< "-m use multicast" << std::endl
1141 << "-G multicast group" << std::endl
1142 << "-i interface" << std::endl
1143 << "-b service interface" << std::endl
1144 << "-M multi display" << std::endl
1145 #ifdef FRAMEINTERLEAVE
1146 << "-I frame interleave" << std::endl
1148 << "-r number of display rows" << std::endl
1149 << "-C compose" << std::endl
1150 << "-F sort-first" << std::endl
1151 << "-L sort-last" << std::endl
1152 << "-h this msg" << std::endl
1153 << "-s stereo" << std::endl
1154 << "-c red/cyan stereo" << std::endl
1155 << "-e eye distance" << std::endl
1156 << "-z zero parallax" << std::endl
1157 << "-d disable client rendering"<<std::endl
1158 << "-v use two viewports" << std::endl
1159 << "-x server x resolution" << std::endl
1160 << "-y server y resolution" << std::endl
1161 << "-t subtile size for img composition" << std::endl
1162 << "-D x,y,z duplicate geometry" << std::endl
1163 << "-A Autostart command" << std::endl
1164 << "-o connection parameter string e.g. \"TTL=8\"" << std::endl
;
1170 servers
.push_back(argv
[i
]);
1174 OSG::ChangeList::setReadWriteDefault(true);
1175 OSG::osgInit(argc
, argv
);
1176 glutInit(&argc
, argv
);
1177 glutInitDisplayMode( GLUT_RGB
| GLUT_DEPTH
| GLUT_DOUBLE
);
1178 if(winx
>=0 && winy
>=0)
1179 glutInitWindowPosition(winx
,winy
);
1180 glutInitWindowSize(winwidth
,winheight
);
1181 winid
= glutCreateWindow("OpenSG Cluster Client");
1182 glutKeyboardFunc(key
);
1183 glutReshapeFunc(reshape
);
1184 glutDisplayFunc(display
);
1186 glutIdleFunc(display
);
1187 glutMouseFunc(mouse
);
1188 glutMotionFunc(motion
);
1189 ract
= OSG::RenderAction::create();
1190 #ifdef OSG_OLD_RENDER_ACTION
1191 ract
->setSortTrans(true);
1192 ract
->setZWriteTrans(true);
1193 ract
->setLocalLights(true);
1194 ract
->setCorrectTwoSidedLighting(true);
1197 // clear changelist from prototypes
1198 OSG::Thread::getCurrentChangeList()->clear();
1200 // create cluster window
1204 multidisplay
=OSG::MultiDisplayWindow::create();
1205 clusterWindow
=multidisplay
;
1208 balancedmultidisplay
=OSG::BalancedMultiWindow::create();
1209 clusterWindow
=balancedmultidisplay
;
1212 sortfirst
=OSG::SortFirstWindow::create();
1214 sortfirst
->setCompose(true);
1216 sortfirst
->setCompose(false);
1217 clusterWindow
=sortfirst
;
1220 sortlast
=OSG::SortLastWindow::create();
1221 if(!composerType
.empty())
1223 OSG::FieldContainerUnrecPtr fcPtr
=
1224 OSG::FieldContainerFactory::the()->
1225 createContainer(composerType
.c_str());
1226 OSG::ImageComposer
*icPtr
=
1227 dynamic_cast<OSG::ImageComposer
*>(fcPtr
.get());
1231 if(dynamic_cast<OSG::PipelineComposer
*>(icPtr
) != NULL
)
1234 dynamic_cast<OSG::PipelineComposer
*>(icPtr
)->setTileSize(subtilesize
);
1235 dynamic_cast<OSG::PipelineComposer
*>(icPtr
)->setPipelined(pipelinedBufferRead
);
1237 if(dynamic_cast<OSG::BinarySwapComposer
*>(icPtr
) != NULL
)
1240 dynamic_cast<OSG::BinarySwapComposer
*>(icPtr
)->setTileSize(subtilesize
);
1242 icPtr
->setStatistics(info
);
1243 // icPtr->setShort(false);
1244 sortlast
->setComposer(icPtr
);
1247 clusterWindow
=sortlast
;
1249 #ifdef FRAMEINTERLEAVE
1251 frameinterleave
=OSG::FrameInterleaveWindow::create();
1252 clusterWindow
=frameinterleave
;
1254 frameinterleave
->setCompose(true);
1256 frameinterleave
->setCompose(false);
1260 sortfirst
=OSG::SortFirstWindow::create();
1261 sortfirst
->setCompose(false);
1262 clusterWindow
=sortfirst
;
1266 if(!autostart
.empty())
1267 clusterWindow
->editMFAutostart()->push_back(autostart
);
1269 for(i
=0 ; i
<int(servers
.size()) ; ++i
)
1270 clusterWindow
->editMFServers()->push_back(servers
[i
]);
1272 cols
= clusterWindow
->getMFServers()->size32() / rows
;
1276 multidisplay
->setHServers(cols
);
1277 multidisplay
->setVServers(rows
);
1280 balancedmultidisplay
->setHServers(cols
);
1281 balancedmultidisplay
->setVServers(rows
);
1282 // balancedmultidisplay->setShowBalancing(true);
1283 // balancedmultidisplay->setShowBalancing(info);
1286 #ifdef FRAMEINTERLEAVE
1287 clusterWindow
->setInterleave(interleave
);
1290 // create client window
1291 clientWindow
=OSG::GLUTWindow::create();
1292 // glutReshapeWindow(800,600);
1293 glutReshapeWindow(winwidth
,winheight
);
1294 clientWindow
->setGlutId(winid
);
1295 clientWindow
->init();
1301 clusterWindow
->setConnectionType(connectionType
);
1302 // needs to be called before init()!
1303 clusterWindow
->setConnectionParams(connectionParameters
);
1306 clusterWindow
->setClientWindow(clientWindow
);
1308 clusterWindow
->setConnectionDestination(connectionDestination
);
1309 clusterWindow
->setConnectionInterface(connectionInterface
);
1310 clusterWindow
->init();
1312 clusterWindow
->resize(serverx
,servery
);
1314 clusterWindow
->resize(winwidth
,winheight
);
1315 clientWindow
->resize(winwidth
,winheight
);
1317 // OSG::FieldContainerFactory::the()->dump();
1319 OSG::commitChanges();
1326 int main(int argc
,char **argv
)