00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <iostream>
00010 #include <math.h>
00011 #ifdef __APPLE__
00012 # include <GLUT/glut.h>
00013 #else
00014 # include <GL/glut.h>
00015 #endif
00016 #include "arViewer_openvrml-0.14.3.h"
00017
00018 using namespace openvrml;
00019
00020 arVrmlViewer::arVrmlViewer(openvrml::browser& browser) : gl::viewer(browser)
00021 {
00022 internal_light = true;
00023
00024 translation[0] = 0.0;
00025 translation[1] = 0.0;
00026 translation[2] = 0.0;
00027
00028 rotation[0] = 0.0;
00029 rotation[1] = 0.0;
00030 rotation[2] = 0.0;
00031 rotation[3] = 0.0;
00032
00033 scale[0] = 1.0;
00034 scale[1] = 1.0;
00035 scale[2] = 1.0;
00036 }
00037
00038 arVrmlViewer::~arVrmlViewer()
00039 {
00040
00041 }
00042
00043 void arVrmlViewer::timerUpdate()
00044 {
00045 this->update(0.0);
00046 }
00047
00048
00049
00050 void arVrmlViewer::setInternalLight(bool flag)
00051 {
00052 internal_light = flag;
00053 }
00054
00055 void arVrmlViewer::redraw()
00056 {
00057 double start = browser::current_time();
00058 glMatrixMode(GL_MODELVIEW);
00059 glPushMatrix();
00060 glTranslated( translation[0], translation[1], translation[2] );
00061 if (rotation[0] != 0.0) {
00062 glRotated(rotation[0], rotation[1], rotation[2], rotation[3]);
00063 }
00064 glScaled(scale[0], scale[1], scale[2]);
00065
00066 #if USE_STENCIL_SHAPE
00067 glEnable(GL_STENCIL_TEST);
00068 glStencilFunc(GL_ALWAYS, 1, 1);
00069 glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
00070 #endif
00071 glEnable(GL_DEPTH_TEST);
00072 glDepthFunc(GL_LEQUAL);
00073 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00074 glDisable(GL_FOG);
00075 glDisable(GL_TEXTURE_2D);
00076 glEnable(GL_CULL_FACE);
00077 glFrontFace(GL_CCW);
00078 glCullFace(GL_BACK);
00079
00080 if (internal_light) {
00081 if (lit) glEnable(GL_LIGHTING);
00082 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00083 glEnable(GL_NORMALIZE);
00084 glDisable(GL_COLOR_MATERIAL);
00085 glDisable(GL_BLEND);
00086 glShadeModel(GL_SMOOTH);
00087
00088 for (int i = 0; i < max_lights; ++i) {
00089 light_info_[i].type = light_unused;
00090 GLenum light = (GLenum) (GL_LIGHT0 + i);
00091 glDisable(light);
00092 }
00093 }
00094
00095 objects = 0;
00096 nested_objects = 0;
00097 sensitive = 0;
00098
00099 this->browser.render(*this);
00100
00101 if (internal_light) {
00102 if (lit) glDisable(GL_LIGHTING);
00103 }
00104 glDisable(GL_BLEND);
00105 glDisable(GL_CULL_FACE);
00106 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
00107
00108 glMatrixMode(GL_MODELVIEW);
00109 glPopMatrix();
00110 }
00111
00112 void arVrmlViewer::post_redraw()
00113 {
00114
00115 }
00116 void arVrmlViewer::set_cursor(cursor_style c)
00117 {
00118
00119 }
00120
00121 void arVrmlViewer::swap_buffers()
00122 {
00123
00124 }
00125
00126 void arVrmlViewer::set_timer(double t)
00127 {
00128
00129 }
00130
00131
00132 void arVrmlViewer::set_viewpoint(const openvrml::vec3f & position,
00133 const openvrml::rotation & orientation,
00134 float fieldOfView,
00135 float avatarSize,
00136 float visibilityLimit)
00137 {
00138
00139 }
00140
00141 viewer::object_t arVrmlViewer::insert_background(const std::vector<float> & groundAngle,
00142 const std::vector<openvrml::color> & groundColor,
00143 const std::vector<float> & skyAngle,
00144 const std::vector<openvrml::color> & skyColor,
00145 size_t * whc,
00146 unsigned char ** pixels)
00147 {
00148 return 0;
00149 }
00150
00151 viewer::object_t arVrmlViewer::insert_dir_light(float ambientIntensity,
00152 float intensity,
00153 const openvrml::color & color,
00154 const openvrml::vec3f & direction)
00155 {
00156 if (internal_light) return gl::viewer::insert_dir_light(ambientIntensity, intensity, color, direction);
00157 return 0;
00158 }
00159
00160 viewer::object_t arVrmlViewer::insert_point_light(float ambientIntensity,
00161 const openvrml::vec3f & attenuation,
00162 const openvrml::color & color,
00163 float intensity,
00164 const openvrml::vec3f & location,
00165 float radius)
00166 {
00167 if (internal_light) return gl::viewer::insert_point_light(ambientIntensity, attenuation, color, intensity, location, radius);
00168
00169 return 0;
00170 }
00171
00172
00173 viewer::object_t arVrmlViewer::insert_spot_light(float ambientIntensity,
00174 const openvrml::vec3f & attenuation,
00175 float beamWidth,
00176 const openvrml::color & color,
00177 float cutOffAngle,
00178 const openvrml::vec3f & direction,
00179 float intensity,
00180 const openvrml::vec3f & location,
00181 float radius)
00182 {
00183 if (internal_light) return gl::viewer::insert_spot_light(ambientIntensity, attenuation, beamWidth, color,cutOffAngle, direction, intensity, location, radius);
00184 return 0;
00185 }
00186
00187 bounding_volume::intersection
00188 arVrmlViewer::intersect_view_volume(const bounding_volume & bvolume) const
00189 {
00190
00191
00192
00193
00194 return bounding_volume::inside;
00195
00196 }