00001 /*************************************************************************** 00002 *cr 00003 *cr (C) Copyright 1995-2019 The Board of Trustees of the 00004 *cr University of Illinois 00005 *cr All Rights Reserved 00006 *cr 00007 *cr VRJuggler patches contributed by Martijn Kragtwijk: m.kragtwijk@rug.nl 00008 *cr 00009 ***************************************************************************/ 00010 00011 /*************************************************************************** 00012 * RCS INFORMATION: 00013 * 00014 * $RCSfile: VRJugglerScene.C,v $ 00015 * $Author: johns $ $Locker: $ $State: Exp $ 00016 * $Revision: 1.5 $ $Date: 2019/01/17 21:21:02 $ 00017 * 00018 *************************************************************************** 00019 * DESCRIPTION: 00020 * a VRJuggler specific Scene subclass for VMD 00021 ***************************************************************************/ 00022 00023 #include <stdlib.h> 00024 #include <vrj/Kernel/Kernel.h> 00025 //#include <vrjuggler_ogl.h> 00026 #include <VRJugglerApp.h> 00027 00028 #include "VRJugglerScene.h" 00029 #include "VRJugglerRoutines.h" 00030 //#include "DisplayDevice.h" 00031 #include "VRJugglerDisplayDevice.h" 00032 #include "Inform.h" 00033 #include "utilities.h" 00034 #include "VMDApp.h" // for VMDexit(); 00035 00036 00038 VRJugglerScene::VRJugglerScene(VMDApp *vmdapp) : app(vmdapp) { 00039 // We don't need to set up a barrier here like in CAVE mode; VRJuggler will take care of this 00040 // 00041 } 00042 void VRJugglerScene::init(/*int argc, char* argv[]*/) 00043 { 00044 msgInfo << "VRJugglerScene::init" << sendmsg; 00045 kernel = Kernel::instance(); // Get the kernel 00046 application = new M_VRJapp(); // Instantiate an instance of the app 00047 application->setScene(this); 00048 00049 // IF not args passed to the program 00050 // Display usage information and exit 00051 /*if (argc <= 1) 00052 { 00053 std::cout << "\n\n"; 00054 std::cout << "Usage: " << argv[0] << " vjconfigfile[0] vjconfigfile[1] ... vjconfigfile[n]" << std::endl; 00055 exit(1); 00056 } 00057 00058 // Load any config files specified on the command line 00059 for( int i = 1; i < argc; ++i ) 00060 { 00061 kernel->loadConfigFile(argv[i]); 00062 } 00063 */ 00064 // for now, just load a basic file 00065 //kernel->loadConfigFile("standalone.jconf"); 00066 msgInfo << "just load a basic file" << sendmsg; 00067 kernel->loadConfigFile("HPCV.VMD.cave.jconf"); 00068 // Start the kernel running 00069 msgInfo << "Start the kernel running" << sendmsg; 00070 kernel->start(); 00071 // Give the kernel an application to execute 00072 msgInfo << "Give the kernel an application to execute" << sendmsg; 00073 kernel->setApplication(application); 00074 00075 } 00076 00078 VRJugglerScene::~VRJugglerScene(void) { 00079 msgInfo << "~VRJugglerScene()" << sendmsg; 00080 // free things allocated from shared memory 00081 //free_to_VRJuggler_memory(draw_barrier); 00082 if(kernel) kernel->waitForKernelStop(); // stop(); werkt niet goed? 00083 if(application) delete application; 00084 msgInfo << "~VRJugglerScene() done" << sendmsg; 00085 } 00086 00087 // Called by vrjuggler_renderer 00088 void VRJugglerScene::draw(DisplayDevice *display) { 00089 // Barrier synchronization for all drawing processes and the master 00090 // should now be handled by VRJuggler 00091 // 00092 if (app->jugglerMode == VRJ_SLAVE){ 00093 Scene::draw(display); // draw the scene 00094 } else { 00095 // msgErr << "VRJugglerScene::draw(), not in VRJ_SLAVE mode!!!" << sendmsg; 00096 } 00097 } 00098 00099 // Called by vrjuggler_renderer 00100 void VRJugglerScene::draw_finished() { 00101 if (app->jugglerMode == VRJ_SLAVE){ 00102 Scene::draw_finished(); // draw the scene 00103 } else { 00104 msgErr << "VRJugglerScene::draw_finished(), not in VRJ_SLAVE mode!!!" << sendmsg; 00105 } 00106 } 00107 00108 // called in VMDupdate, this updates the values of numDisplayable[23]D 00109 // this is called by the parent! 00110 int VRJugglerScene::prepare() { 00111 return Scene::prepare(); // call regular scene prepare method 00112 } 00113 00114 void VRJugglerScene::waitForKernelStop(){ 00115 if(kernel){ 00116 kernel->waitForKernelStop(); 00117 } else { 00118 msgInfo << "VRJugglerScene::waitForKernelStop: kernel NULL" << sendmsg; 00119 } 00120 } 00121 void VRJugglerScene::appendCommand(const char* str) 00122 { 00123 //msgInfo << "VRJugglerScene::appendCommand(" << str << ")" << sendmsg; 00124 if (app->jugglerMode == VRJ_MASTER){ 00125 if (application){ 00126 application->appendCommand(str); 00127 } else { 00128 msgErr << "VRJugglerScene::appendCommand(): application NULL!" << sendmsg; 00129 } 00130 } else { 00131 msgErr << "VRJugglerScene::appendCommand(" << str << "), not in VRJ_MASTER mode!" << sendmsg; 00132 } 00133 } 00134 00135 void VRJugglerScene::getWandXYZ(float& x, float& y, float& z) 00136 { 00137 if (application){ 00138 return application->getWandXYZ(x,y,z); 00139 } else { 00140 msgErr << "VRJugglerScene::getWandXYZ(): application NULL!" << sendmsg; 00141 } 00142 } 00143 00144 00145 void VRJugglerScene::getWandRotMat(Matrix4& rot) 00146 { 00147 if (application){ 00148 return application->getWandRotMat(rot); 00149 } else { 00150 msgErr << "VRJugglerScene::getWandRotMat(): application NULL!" << sendmsg; 00151 } 00152 } 00153 bool VRJugglerScene::getWandButton(unsigned nr) 00154 { 00155 if (application){ 00156 return application->getWandButton(nr); 00157 } else { 00158 msgErr << "VRJugglerScene::getWandButton(): application NULL!" << sendmsg; 00159 } 00160 }