[artoolkit-commits] SF.net SVN: artoolkit: [273] trunk/artoolkit/lib/SRC/ARvrml
Optical marker tracking and overlay for augmented reality.
Brought to you by:
philip_lamb
From: <phi...@us...> - 2007-11-06 20:33:32
|
Revision: 273 http://artoolkit.svn.sourceforge.net/artoolkit/?rev=273&view=rev Author: philip_lamb Date: 2007-11-06 12:33:30 -0800 (Tue, 06 Nov 2007) Log Message: ----------- Provide linkage to OpenVRML-0.14.3 for Visual Studio .NET 2003. Fix usage in libARvrml for openvrml-0.16.6 under Windows. Modified Paths: -------------- trunk/artoolkit/lib/SRC/ARvrml/arViewer.cpp trunk/artoolkit/lib/SRC/ARvrml/arViewer.h trunk/artoolkit/lib/SRC/ARvrml/libARvrml.vcproj Added Paths: ----------- trunk/artoolkit/lib/SRC/ARvrml/arViewerCapi_openvrml-0.14.3.cpp trunk/artoolkit/lib/SRC/ARvrml/arViewer_openvrml-0.14.3.cpp trunk/artoolkit/lib/SRC/ARvrml/arViewer_openvrml-0.14.3.h Modified: trunk/artoolkit/lib/SRC/ARvrml/arViewer.cpp =================================================================== --- trunk/artoolkit/lib/SRC/ARvrml/arViewer.cpp 2007-10-29 02:05:23 UTC (rev 272) +++ trunk/artoolkit/lib/SRC/ARvrml/arViewer.cpp 2007-11-06 20:33:30 UTC (rev 273) @@ -58,8 +58,8 @@ public: explicit file_resource_istream(const std::string & path): resource_istream(&this->buf_) { - if (!this->buf_.open(path.c_str(), ios_base::in)) { - this->setstate(ios_base::failbit); + if (!this->buf_.open(path.c_str(), ios_base::in | ios_base::binary)) { + this->setstate(ios_base::badbit); } } @@ -78,7 +78,8 @@ { // // A real application should use OS facilities for this. This - // is a crude hack. + // is a crude hack because sdl-viewer uses std::filebuf in + // order to remain simple and portable. // using std::find; using std::string; @@ -95,9 +96,9 @@ find(next(dot_pos.base()), this->url_.end(), '#'); const string ext(dot_pos.base(), hash_pos); if (iequals(ext, "wrl")) { - media_type = "model/vrml"; + media_type = openvrml::vrml_media_type; } else if (iequals(ext, "x3dv")) { - media_type = "model/x3d+vrml"; + media_type = openvrml::x3d_vrml_media_type; } else if (iequals(ext, "png")) { media_type = "image/png"; } else if (iequals(ext, "jpg") || iequals(ext, "jpeg")) { @@ -120,8 +121,23 @@ // file:// // ^ // 01234567 + static const string::size_type authority_start_index = 7; + // - string path = uri.substr(uri.find_first_of('/', 7)); + // On Windows we want to start at the drive letter, which is after the + // first slash in the path. + // + // We ignore the content of the authority; a smarter implementation + // should confirm that it is localhost, the machine name, or zero + // length. + // + string::size_type path_start_index = +# ifdef _WIN32 + uri.find_first_of('/', authority_start_index) + 1; +# else + uri.find_first_of('/', authority_start_index); +# endif + string path = uri.substr(path_start_index); auto_ptr<resource_istream> in(new file_resource_istream(path)); static_cast<file_resource_istream *>(in.get())->url(uri); @@ -130,7 +146,7 @@ } -arVrmlViewer::arVrmlViewer() : gl::viewer::viewer() +arVrmlViewer::arVrmlViewer() { internal_light = true; Modified: trunk/artoolkit/lib/SRC/ARvrml/arViewer.h =================================================================== --- trunk/artoolkit/lib/SRC/ARvrml/arViewer.h 2007-10-29 02:05:23 UTC (rev 272) +++ trunk/artoolkit/lib/SRC/ARvrml/arViewer.h 2007-11-06 20:33:30 UTC (rev 273) @@ -45,7 +45,7 @@ class arVrmlViewer : public openvrml::gl::viewer { public: - arVrmlViewer(); + explicit arVrmlViewer(); ~arVrmlViewer() throw (); char filename[512]; Added: trunk/artoolkit/lib/SRC/ARvrml/arViewerCapi_openvrml-0.14.3.cpp =================================================================== --- trunk/artoolkit/lib/SRC/ARvrml/arViewerCapi_openvrml-0.14.3.cpp (rev 0) +++ trunk/artoolkit/lib/SRC/ARvrml/arViewerCapi_openvrml-0.14.3.cpp 2007-11-06 20:33:30 UTC (rev 273) @@ -0,0 +1,165 @@ +#include <AR/arvrml.h> +#include "arViewer_openvrml-0.14.3.h" +#include <iostream> +#include <vector> +#include <string> +#ifdef __APPLE__ +# include <GLUT/glut.h> +#else +# include <GL/glut.h> +#endif +#include <stdio.h> +#include <string.h> + +#define AR_VRML_MAX 100 + +static arVrmlViewer *viewer[AR_VRML_MAX]; +static int init = 1; +static int vrID = -1; + +static char *get_buff( char *buf, int n, FILE *fp ); + + +int arVrmlLoadFile(const char *file) +{ + + FILE *fp; + openvrml::browser * myBrowser = 0; + char buf[256], buf1[256]; + char buf2[256]; + int id; + int i; + + if( init ) { + for( i = 0; i < AR_VRML_MAX; i++ ) viewer[i] = NULL; + init = 0; + } + for( i = 0; i < AR_VRML_MAX; i++ ) { + if( viewer[i] == NULL ) break; + } + if( i == AR_VRML_MAX ) return -1; + id = i; + + + if( (fp=fopen(file, "r")) == NULL ) return -1; + + get_buff(buf, 256, fp); + if( sscanf(buf, "%s", buf1) != 1 ) {fclose(fp); return -1;} + for( i = 0; file[i] != '\0'; i++ ) buf2[i] = file[i]; + for( ; i >= 0; i-- ) { + if( buf2[i] == '/' ) break; + } + buf2[i+1] = '\0'; + sprintf(buf, "%s%s", buf2, buf1); + + myBrowser = new openvrml::browser(std::cout, std::cerr); + if( !myBrowser) {fclose(fp); return -1;} + + std::vector<std::string> uri(1, buf); + std::vector<std::string> parameter; + myBrowser->load_url(uri, parameter); + + viewer[id] = new arVrmlViewer(*myBrowser); + if(!viewer[id]) + { + delete myBrowser; + fclose(fp); + return -1; + } + strcpy( viewer[id]->filename, buf ); + + get_buff(buf, 256, fp); + if( sscanf(buf, "%lf %lf %lf", &viewer[id]->translation[0], + &viewer[id]->translation[1], &viewer[id]->translation[2]) != 3 ) { + delete viewer[id]; + viewer[id] = NULL; + fclose(fp); + return -1; + } + + get_buff(buf, 256, fp); + if( sscanf(buf, "%lf %lf %lf %lf", &viewer[id]->rotation[0], + &viewer[id]->rotation[1], &viewer[id]->rotation[2], &viewer[id]->rotation[3]) != 4 ) { + delete viewer[id]; + viewer[id] = NULL; + fclose(fp); + return -1; + } + + get_buff(buf, 256, fp); + if( sscanf(buf, "%lf %lf %lf", &viewer[id]->scale[0], &viewer[id]->scale[1], + &viewer[id]->scale[2]) != 3 ) { + delete viewer[id]; + viewer[id] = NULL; + fclose(fp); + return -1; + } + fclose(fp); + + return id; +} + +int arVrmlFree( int id ) +{ + if( viewer[id] == NULL ) return -1; + + delete viewer[id]; + viewer[id] = NULL; + + if( vrID == id ) { + vrID = -1; + } + + return 0; +} + +int arVrmlTimerUpdate() +{ + int i; + + for( i = 0; i < AR_VRML_MAX; i++ ) { + if( viewer[i] == NULL ) continue; + viewer[i]->timerUpdate(); + } + return 0; +} + +int arVrmlDraw( int id ) +{ + if( viewer[id] == NULL ) return -1; + viewer[id]->redraw(); + return 0; +} + +int arVrmlSetInternalLight( int flag ) +{ + int i; + + if( flag ) { + for( i = 0; i < AR_VRML_MAX; i++ ) { + if( viewer[i] == NULL ) continue; + viewer[i]->setInternalLight(true); + } + } + else { + for( i = 0; i < AR_VRML_MAX; i++ ) { + if( viewer[i] == NULL ) continue; + viewer[i]->setInternalLight(false); + } + } + + return 0; +} + +static char *get_buff( char *buf, int n, FILE *fp ) +{ + char *ret, buf1[256]; + + for(;;) { + ret = fgets( buf, n, fp ); + if( ret == NULL ) return(NULL); + if( sscanf(buf, "%s", buf1) != 1 ) continue; + + if( buf1[0] != '#' ) return(ret); + } +} Added: trunk/artoolkit/lib/SRC/ARvrml/arViewer_openvrml-0.14.3.cpp =================================================================== --- trunk/artoolkit/lib/SRC/ARvrml/arViewer_openvrml-0.14.3.cpp (rev 0) +++ trunk/artoolkit/lib/SRC/ARvrml/arViewer_openvrml-0.14.3.cpp 2007-11-06 20:33:30 UTC (rev 273) @@ -0,0 +1,196 @@ +/* +modif: +version 0.14.3 + +remove vrmlScene since we use reference now. +remove culling pb +*/ + +#include <iostream> +#include <math.h> +#ifdef __APPLE__ +# include <GLUT/glut.h> +#else +# include <GL/glut.h> +#endif +#include "arViewer_openvrml-0.14.3.h" + +using namespace openvrml; + +arVrmlViewer::arVrmlViewer(openvrml::browser& browser) : gl::viewer(browser) +{ + internal_light = true; + + translation[0] = 0.0; + translation[1] = 0.0; + translation[2] = 0.0; + + rotation[0] = 0.0; + rotation[1] = 0.0; + rotation[2] = 0.0; + rotation[3] = 0.0; + + scale[0] = 1.0; + scale[1] = 1.0; + scale[2] = 1.0; +} + +arVrmlViewer::~arVrmlViewer() +{ + +} + +void arVrmlViewer::timerUpdate() +{ + this->update(0.0); +} + + + +void arVrmlViewer::setInternalLight(bool flag) +{ + internal_light = flag; +} + +void arVrmlViewer::redraw() +{ + double start = browser::current_time(); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glTranslated( translation[0], translation[1], translation[2] ); + if (rotation[0] != 0.0) { + glRotated(rotation[0], rotation[1], rotation[2], rotation[3]); + } + glScaled(scale[0], scale[1], scale[2]); + +#if USE_STENCIL_SHAPE + glEnable(GL_STENCIL_TEST); + glStencilFunc(GL_ALWAYS, 1, 1); + glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); +#endif + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_FOG); // this is a global attribute + glDisable(GL_TEXTURE_2D); + glEnable(GL_CULL_FACE); + glFrontFace(GL_CCW); + glCullFace(GL_BACK); + + if (internal_light) { + if (lit) glEnable(GL_LIGHTING); + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); + glEnable(GL_NORMALIZE); + glDisable(GL_COLOR_MATERIAL); + glDisable(GL_BLEND); + glShadeModel(GL_SMOOTH); + + for (int i = 0; i < max_lights; ++i) { + light_info_[i].type = light_unused; + GLenum light = (GLenum) (GL_LIGHT0 + i); + glDisable(light); + } + } + + objects = 0; + nested_objects = 0; + sensitive = 0; + + this->browser.render(*this); + + if (internal_light) { + if (lit) glDisable(GL_LIGHTING); + } + glDisable(GL_BLEND); + glDisable(GL_CULL_FACE); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} + +void arVrmlViewer::post_redraw() +{ + +} +void arVrmlViewer::set_cursor(cursor_style c) +{ + +} + +void arVrmlViewer::swap_buffers() +{ + +} + +void arVrmlViewer::set_timer(double t) +{ + +} + + +void arVrmlViewer::set_viewpoint(const openvrml::vec3f & position, + const openvrml::rotation & orientation, + float fieldOfView, + float avatarSize, + float visibilityLimit) +{ + +} + +viewer::object_t arVrmlViewer::insert_background(const std::vector<float> & groundAngle, + const std::vector<openvrml::color> & groundColor, + const std::vector<float> & skyAngle, + const std::vector<openvrml::color> & skyColor, + size_t * whc, + unsigned char ** pixels) +{ + return 0; +} + +viewer::object_t arVrmlViewer::insert_dir_light(float ambientIntensity, + float intensity, + const openvrml::color & color, + const openvrml::vec3f & direction) +{ + if (internal_light) return gl::viewer::insert_dir_light(ambientIntensity, intensity, color, direction); + return 0; +} + +viewer::object_t arVrmlViewer::insert_point_light(float ambientIntensity, + const openvrml::vec3f & attenuation, + const openvrml::color & color, + float intensity, + const openvrml::vec3f & location, + float radius) +{ + if (internal_light) return gl::viewer::insert_point_light(ambientIntensity, attenuation, color, intensity, location, radius); + + return 0; +} + + +viewer::object_t arVrmlViewer::insert_spot_light(float ambientIntensity, + const openvrml::vec3f & attenuation, + float beamWidth, + const openvrml::color & color, + float cutOffAngle, + const openvrml::vec3f & direction, + float intensity, + const openvrml::vec3f & location, + float radius) +{ + if (internal_light) return gl::viewer::insert_spot_light(ambientIntensity, attenuation, beamWidth, color,cutOffAngle, direction, intensity, location, radius); + return 0; +} + + bounding_volume::intersection +arVrmlViewer::intersect_view_volume(const bounding_volume & bvolume) const +{ + // if( d_cull ) { + //return openvrml::viewer::intersect_view_volume(bvolume); + // } + // else { + return bounding_volume::inside; + //} +} Added: trunk/artoolkit/lib/SRC/ARvrml/arViewer_openvrml-0.14.3.h =================================================================== --- trunk/artoolkit/lib/SRC/ARvrml/arViewer_openvrml-0.14.3.h (rev 0) +++ trunk/artoolkit/lib/SRC/ARvrml/arViewer_openvrml-0.14.3.h 2007-11-06 20:33:30 UTC (rev 273) @@ -0,0 +1,71 @@ +// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; -*- + +#ifndef AR_VRMLINT_H +#define AR_VRMLINT_H + +#include <openvrml/browser.h> +#include <openvrml/gl/viewer.h> +#include <openvrml/bounding_volume.h> + +class arVrmlViewer : public openvrml::gl::viewer { + +public: + arVrmlViewer(openvrml::browser& browser); + ~arVrmlViewer(); + + char filename[512]; + double translation[3]; + double rotation[4]; + double scale[3]; + bool internal_light; + + void timerUpdate(); + void redraw(); + void setInternalLight( bool f ); + +protected: + virtual void post_redraw(); + virtual void set_cursor(openvrml::gl::viewer::cursor_style c); + virtual void swap_buffers(); + virtual void set_timer(double); + + + virtual void set_viewpoint(const openvrml::vec3f & position, + const openvrml::rotation & orientation, + float fieldOfView, + float avatarSize, + float visibilityLimit); + + virtual viewer::object_t insert_background(const std::vector<float> & groundAngle, + const std::vector<openvrml::color> & groundColor, + const std::vector<float> & skyAngle, + const std::vector<openvrml::color> & skyColor, + size_t * whc = 0, + unsigned char ** pixels = 0); + + virtual viewer::object_t insert_dir_light(float ambientIntensity, + float intensity, + const openvrml::color & color, + const openvrml::vec3f & direction); + + virtual viewer::object_t insert_point_light(float ambientIntensity, + const openvrml::vec3f & attenuation, + const openvrml::color & color, + float intensity, + const openvrml::vec3f & location, + float radius); + + virtual viewer::object_t insert_spot_light(float ambientIntensity, + const openvrml::vec3f & attenuation, + float beamWidth, + const openvrml::color & color, + float cutOffAngle, + const openvrml::vec3f & direction, + float intensity, + const openvrml::vec3f & location, + float radius); + virtual openvrml::bounding_volume::intersection + intersect_view_volume(const openvrml::bounding_volume & bvolume) const; +}; + +#endif Modified: trunk/artoolkit/lib/SRC/ARvrml/libARvrml.vcproj =================================================================== --- trunk/artoolkit/lib/SRC/ARvrml/libARvrml.vcproj 2007-10-29 02:05:23 UTC (rev 272) +++ trunk/artoolkit/lib/SRC/ARvrml/libARvrml.vcproj 2007-11-06 20:33:30 UTC (rev 273) @@ -20,7 +20,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="$(ProjectDir)..\..\..\include;$(ProjectDir)..\..\..\OpenVRML\include;$(ProjectDir)..\..\..\OpenVRML\dependencies\include" - PreprocessorDefinitions="WIN32;_DEBUG;_LIB;S;OPENVRML_ENABLE_IMAGETEXTURE_NODE;OPENVRML_ENABLE_GZIP" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;" BasicRuntimeChecks="3" RuntimeLibrary="3" UsePrecompiledHeader="0" @@ -99,10 +99,10 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> <File - RelativePath=".\arViewer.cpp"> + RelativePath=".\arViewer_openvrml-0.14.3.cpp"> </File> <File - RelativePath=".\arViewerCapi.cpp"> + RelativePath=".\arViewerCapi_openvrml-0.14.3.cpp"> </File> </Filter> <Filter @@ -110,10 +110,10 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> <File - RelativePath=".\arViewer.h"> + RelativePath=".\arViewer_openvrml-0.14.3.h"> </File> <File - RelativePath="..\..\..\include\Ar\arvrml.h"> + RelativePath="..\..\..\include\AR\arvrml.h"> </File> </Filter> <Filter @@ -121,9 +121,6 @@ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> </Filter> - <File - RelativePath=".\ReadMe.txt"> - </File> </Files> <Globals> </Globals> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |