00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <freevr.h>
00023 #include "Inform.h"
00024 #include "FreeVRDisplayDevice.h"
00025
00026
00027 static const char *freevrStereoNameStr[1] = {"FreeVR"};
00028
00030 FreeVRDisplayDevice::FreeVRDisplayDevice(void) : OpenGLRenderer("FreeVR") {
00031 stereoNames = freevrStereoNameStr;
00032 stereoModes = 1;
00033 doneGLInit = FALSE;
00034 num_display_processes = vrContext->config->num_windows;
00035
00036
00037
00038 aaAvailable = TRUE;
00039 cueingAvailable = FALSE;
00040 cullingAvailable = FALSE;
00041 ext->hasstereo = TRUE;
00042 ext->stereodrawforced = FALSE;
00043
00044 ogl_useblendedtrans = 0;
00045 ogl_transpass = 0;
00046 ogl_useglslshader = 0;
00047 ogl_acrobat3dcapture = 0;
00048 ogl_lightingenabled = 0;
00049 ogl_rendstateserial = 1;
00050 ogl_glslserial = 0;
00051 ogl_glsltoggle = 1;
00052 ogl_glslmaterialindex = -1;
00053 ogl_glslprojectionmode = DisplayDevice::PERSPECTIVE;
00054 ogl_glsltexturemode = 0;
00055
00056
00057
00058 }
00059
00061 FreeVRDisplayDevice::~FreeVRDisplayDevice(void) {
00062
00063 }
00064
00065
00067
00068
00069 void FreeVRDisplayDevice::freevr_gl_init_fn(void) {
00070 setup_initial_opengl_state();
00071
00072
00073 aaAvailable = TRUE;
00074 cueingAvailable = FALSE;
00075 cullingAvailable = FALSE;
00076 ext->hasstereo = TRUE;
00077 ext->stereodrawforced = FALSE;
00078
00079 glClearColor(0.0, 0.0, 0.0, 0.0);
00080
00081 aa_on();
00082 cueing_off();
00083
00084
00085 set_sphere_mode(sphereMode);
00086 set_sphere_res(sphereRes);
00087 set_line_width(lineWidth);
00088 set_line_style(lineStyle);
00089
00090 clear();
00091 update();
00092
00093
00094 (transMat.top()).translate(0.0, 3.0, -2.0);
00095 (transMat.top()).scale(VMD_PI);
00096
00097 doneGLInit = TRUE;
00098 }
00099
00100 void FreeVRDisplayDevice::set_stereo_mode(int) {
00101
00102 }
00103
00104 void FreeVRDisplayDevice::normal(void) {
00105
00106
00107
00108 }
00109
00110
00111 void FreeVRDisplayDevice::render(const VMDDisplayList *cmdlist) {
00112 if(!doneGLInit) {
00113 freevr_gl_init_fn();
00114 }
00115
00116
00117 glPushMatrix();
00118 multmatrix((transMat.top()));
00119
00120
00121
00122
00123
00124 glGetFloatv(GL_PROJECTION_MATRIX, ogl_pmatrix);
00125 glGetFloatv(GL_MODELVIEW_MATRIX, ogl_mvmatrix);
00126 ogl_textMat.identity();
00127 ogl_textMat.multmatrix(ogl_pmatrix);
00128 ogl_textMat.multmatrix(ogl_mvmatrix);
00129
00130
00131 OpenGLRenderer::render(cmdlist);
00132 glPopMatrix();
00133 }
00134
00135
00136 void FreeVRDisplayDevice::update(int do_update) {
00137
00138
00139
00140
00141 #if 0
00142 vrSystemSetStatusDescription("in update!");
00143 if (vrGet2switchValue(2)) {
00144 vrUserTravelTranslate3d(VR_ALLUSERS, 0.0, 0.0, 0.1);
00145 }
00146 #endif
00147
00148
00149
00150
00151 #define WAND_SENSOR 1
00152 #define JS_EPSILON 0.125
00153 #define MOVE_FACTOR 2.5
00154 #define TURN_FACTOR 25.0
00155 #define SUB_JS_EPSILON(a) ((a)-copysign(JS_EPSILON,(a)))
00156 static vrTime last_time = -1.0;
00157 vrTime sim_time = vrCurrentSimTime();
00158 double delta_time;
00159 double delta_move;
00160 double joy_x, joy_y;
00161 vrVector wand_rw_pointvec;
00162
00163
00164 static vrMatrix wand_at_grab;
00165 static vrMatrix travel_at_grab;
00166 static int world_grabbed = 0;
00167 vrMatrix new_world_matrix;
00168 vrMatrix current_wand_matrix;
00169 vrMatrix invmat;
00170
00171
00173
00174 if (last_time == -1.0)
00175 delta_time = 0.0;
00176 else delta_time = sim_time - last_time;
00177 last_time = sim_time;
00178
00179
00180 if (delta_time <= 0.0)
00181 return;
00182
00183
00185
00186
00187
00188 if (vrGet2switchValue(3)) {
00189 vrUserTravelReset(VR_ALLUSERS);
00190 }
00191
00192
00193
00194 joy_x = vrGetValuatorValue(0);
00195 joy_y = vrGetValuatorValue(1);
00196
00197 if (fabs(joy_x) > JS_EPSILON && !world_grabbed)
00198 vrUserTravelRotateId(VR_ALLUSERS, VR_Y, (delta_time * SUB_JS_EPSILON(joy_x) * -TURN_FACTOR));
00199
00200 if (fabs(joy_y) > JS_EPSILON && !world_grabbed) {
00201 delta_move = delta_time * SUB_JS_EPSILON(joy_y) * MOVE_FACTOR;
00202 vrVectorGetRWFrom6sensorDir(&wand_rw_pointvec, WAND_SENSOR, VRDIR_FORE);
00203 vrUserTravelTranslate3d(VR_ALLUSERS,
00204 wand_rw_pointvec.v[VR_X] * delta_move,
00205 wand_rw_pointvec.v[VR_Y] * delta_move,
00206 wand_rw_pointvec.v[VR_Z] * delta_move);
00207 }
00208
00209
00210
00211 switch (vrGet2switchDelta(2)) {
00212 case 1:
00213
00214
00215 vrMatrixGet6sensorValues(&wand_at_grab, WAND_SENSOR);
00216 vrMatrixGetUserTravel(&travel_at_grab, 0);
00217 world_grabbed = 1;
00218 break;
00219 case 0:
00220 if (world_grabbed) {
00221
00222 vrMatrixGet6sensorValues(¤t_wand_matrix, WAND_SENSOR);
00223 vrMatrixInvert(&invmat, &wand_at_grab);
00224 vrMatrixPostMult(&invmat, ¤t_wand_matrix);
00225 new_world_matrix = invmat;
00226
00227
00228 vrUserTravelLockSet(VR_ALLUSERS);
00229 vrUserTravelReset(VR_ALLUSERS);
00230 vrUserTravelTransformMatrix(VR_ALLUSERS, &travel_at_grab);
00231 vrUserTravelTransformMatrix(VR_ALLUSERS, &new_world_matrix);
00232 vrUserTravelLockRelease(VR_ALLUSERS);
00233 }
00234 break;
00235 case -1:
00236 world_grabbed = 0;
00237 break;
00238 }
00239
00240 }
00241