00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <vrj/vrjConfig.h>
00023
00024 #include <M_VRJapp.h>
00025 #include <VRJugglerScene.h>
00026 #include <VRJugglerRoutines.h>
00027 #include <VMDApp.h>
00028 #include <UIText.h>
00029 #include <Matrix4.h>
00030
00031
00032 #include <iostream>
00033 #include <iomanip>
00034
00035
00036 #include <vrj/Draw/OGL/GlApp.h>
00037
00038 #include <gadget/Type/PositionInterface.h>
00039 #include <gadget/Type/DigitalInterface.h>
00040
00041
00042 #include <GL/gl.h>
00043
00044
00045 #include <gmtl/Matrix.h>
00046 #include <gmtl/Generate.h>
00047 #include <gmtl/Vec.h>
00048
00049 #include "Inform.h"
00050
00051 using namespace gmtl;
00052 using namespace vrj;
00053
00054 void M_VRJapp::init()
00055 {
00056 msgInfo << "---------- M_VRJapp::init() ---------------" << sendmsg;
00057
00058 mWand.init("VJWand");
00059 mHead.init("VJHead");
00060 mButton0.init("VJButton0");
00061 mButton1.init("VJButton1");
00062
00063 msgInfo << " initialising shared data " << sendmsg;
00064 vpr::GUID new_guid("44ab594b-1dfb-40c1-8bf3-9af7b7c0ac8a");
00065 sharedData.init(new_guid);
00066
00067 msgInfo << " initialising shared data done" << sendmsg;
00068 }
00069
00070 void M_VRJapp::contextInit()
00071 {
00072 initGLState();
00073 }
00074
00075 void M_VRJapp::setScene(VRJugglerScene* s)
00076 {
00077 scene = s;
00078 }
00079
00080 void M_VRJapp::appendCommand(const char* str)
00081 {
00082
00083 cmdQueue.push_back(std::string(str));
00084
00085 }
00086
00092 void M_VRJapp::preFrame()
00093 {
00094
00095
00096 if (scene){
00097 if (scene->app){
00098 if (scene->app->jugglerMode == VRJ_MASTER){
00099 if(sharedData.isLocal()){
00100
00101
00102
00103
00104 for (unsigned i = 0; i < cmdQueue.size(); i++){
00105 if(!strupcmp(cmdQueue[i].c_str(), "tool adddevice vrjugglerbuttons 0")) {
00106 msgInfo << "M_VRJapp::preFrame(), skipping string " << cmdQueue[i].c_str() << sendmsg;
00107 msgInfo << "The slaves should not attach the vrjugglerbuttons to the tool," << sendmsg;
00108 msgInfo << "otherwise translating molecules with the tool is done twice on the slaves:" << sendmsg;
00109 msgInfo << "first from their own calculations and then as a commmand from the master." << sendmsg;
00110 } else {
00111 msgInfo << "M_VRJapp::preFrame(), sending string " << cmdQueue[i].c_str() << sendmsg;
00112 sharedData->commandStrings.push_back(cmdQueue[i]);
00113 }
00114 }
00115 }
00116 } else {
00117
00118 }
00119 } else {
00120 msgErr << "M_VRJapp::draw(), scene->app NULL" << sendmsg;
00121 }
00122 } else {
00123 msgErr << "M_VRJapp::draw(), scene NULL" << sendmsg;
00124 }
00125 cmdQueue.clear();
00126
00127
00128 if (mButton0->getData())
00129 {
00130
00131 }
00132
00133 if (mButton1->getData())
00134 {
00135
00136 }
00137
00138
00139
00140 }
00141
00145 void M_VRJapp::latePreFrame()
00146 {
00147 unsigned nrOfCommands = sharedData->commandStrings.size();
00148
00149
00150
00151 if(!sharedData.isLocal()){
00152
00153 for (unsigned i = 0; i< nrOfCommands; i++){
00154 msgInfo << "latePreFrame(), evaluating " << sharedData->commandStrings[i].c_str() << sendmsg;
00155 scene->app->uiText->get_interp()->evalString(sharedData->commandStrings[i].c_str());
00156 }
00157 }
00158 }
00159
00160
00161
00162 void M_VRJapp::bufferPreDraw()
00163 {
00164
00165 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
00166 glClear(GL_COLOR_BUFFER_BIT);
00167 }
00168
00169 void M_VRJapp::draw()
00170 {
00171
00172
00173
00174
00175
00176 if (scene){
00177 if (scene->app){
00178 if (scene->app->jugglerMode == VRJ_SLAVE){
00179
00180 vrjuggler_renderer();
00181 } else {
00182
00183
00184 }
00185 } else {
00186 msgErr << "M_VRJapp::draw(), scene->app NULL" << sendmsg;
00187 }
00188 } else {
00189 msgErr << "M_VRJapp::draw(), scene NULL" << sendmsg;
00190 }
00191
00192 }
00199 void M_VRJapp::intraFrame()
00200 {
00201
00202 }
00203
00210 void M_VRJapp::postFrame()
00211 {
00212
00213
00214 if (scene){
00215 if (scene->app){
00216 if (scene->app->jugglerMode == VRJ_SLAVE){
00217 scene->app->VRJ_VMDupdate(true);
00218 }
00219 } else {
00220 msgErr << "M_VRJapp::postFrame(), scene->app NULL" << sendmsg;
00221 }
00222 } else {
00223 msgErr << "M_VRJapp::postFrame(), scene NULL" << sendmsg;
00224 }
00225 }
00226
00227 void M_VRJapp::initGLState()
00228 {
00229 GLfloat light0_ambient[] = { 0.1f, 0.1f, 0.1f, 1.0f};
00230 GLfloat light0_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f};
00231 GLfloat light0_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f};
00232 GLfloat light0_position[] = {0.0f, 0.75f, 0.75f, 0.0f};
00233
00234 GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
00235 GLfloat mat_diffuse[] = { 1.0f, 0.5f, 0.8f, 1.0f };
00236 GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0};
00237 GLfloat mat_shininess[] = { 50.0};
00238
00239 GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0};
00240
00241 glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
00242 glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
00243 glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);
00244 glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
00245
00246 glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient );
00247 glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse );
00248 glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular );
00249 glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess );
00250 glMaterialfv( GL_FRONT, GL_EMISSION, no_mat);
00251
00252 glEnable(GL_DEPTH_TEST);
00253 glEnable(GL_NORMALIZE);
00254 glEnable(GL_LIGHTING);
00255 glEnable(GL_LIGHT0);
00256 glEnable(GL_COLOR_MATERIAL);
00257 glShadeModel(GL_SMOOTH);
00258 }
00259
00260 void M_VRJapp::getWandXYZ(float& x, float& y, float& z){
00261
00262 float units = 1.0;
00263 gmtl::Matrix44f wand_matrix = mWand->getData(units);
00264 gmtl::Point3f wand_pos = gmtl::makeTrans<gmtl::Point3f>(wand_matrix);
00265 x= wand_pos[0];
00266 y= wand_pos[1];
00267 z= wand_pos[2];
00268 }
00269
00270
00271 void M_VRJapp::getWandRotMat(Matrix4& rot){
00272
00273 float units = 1.0;
00274 gmtl::Matrix44f wand_matrix = mWand->getData(units);
00275 gmtl::Quatf wand_quat = gmtl::make<gmtl::Quatf>(wand_matrix);
00276 gmtl::Matrix44f wand_rot_matrix = gmtl::make<gmtl::Matrix44f>(wand_quat);
00277
00278 for (unsigned i = 0; i < 16; i++){
00279
00280 rot.mat[i] = wand_rot_matrix[i%4][i/4];
00281
00282 }
00283
00284 }
00285
00286
00287 bool M_VRJapp::getWandButton(unsigned nr){
00288 if (nr==0){
00289 return mButton0->getData();
00290 } else if (nr==1){
00291 return mButton1->getData();
00292 } else {
00293 msgErr << "M_VRJapp::getWandButton: unknown button index " << (int)nr << sendmsg;
00294 }
00295 return false;
00296 }