Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

Viewer.h

00001 //
00002 // OpenVRML
00003 //
00004 // Copyright (C) 1998  Chris Morley
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License, or (at your option) any later version.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 
00021 # ifndef OPENVRML_VIEWER_H
00022 #   define OPENVRML_VIEWER_H
00023 
00024 #   include <stddef.h>
00025 #   include "bvolume.h"
00026 #   include "VrmlFrustum.h"
00027 
00028 namespace OpenVRML {
00029 
00030     class Node;
00031     class BSphere;
00032     class VrmlMatrix;
00033     class Browser;
00034 
00035     class OPENVRML_SCOPE Viewer {
00036     protected:
00037         VrmlFrustum d_frust;
00038 
00039     public:
00040         enum {
00041             MASK_NONE                 = 0,
00042             MASK_CCW                  = 1,
00043             MASK_CONVEX               = 2,
00044             MASK_SOLID                = 4,
00045             MASK_BOTTOM               = 8,
00046             MASK_TOP                  = 16,
00047             MASK_SIDE                 = 32,
00048             MASK_COLOR_PER_VERTEX     = 64,
00049             MASK_NORMAL_PER_VERTEX    = 128
00050         };
00051 
00052         enum RenderMode {
00053             RENDER_MODE_DRAW,
00054             RENDER_MODE_PICK
00055         };
00056 
00057         typedef long Object;
00058         typedef long TextureObject;
00059 
00060         Browser & browser;
00061 
00062         virtual ~Viewer() = 0;
00063 
00064         virtual RenderMode getRenderMode() = 0;
00065         virtual double getFrameRate() = 0;
00066         virtual void resetUserNavigation() = 0;
00067         virtual void getUserNavigation(VrmlMatrix & M) = 0;
00068 
00069         virtual Object beginObject(const char *, bool = false) = 0;
00070         virtual void endObject() = 0;
00071 
00072         virtual Object insertBackground(size_t nGroundAngles = 0,
00073                                         const float * groundAngle = 0,
00074                                         const float * groundColor = 0,
00075                                         size_t nSkyAngles = 0,
00076                                         const float * skyAngle = 0,
00077                                         const float * skyColor = 0,
00078                                         int* whc = 0,
00079                                         unsigned char ** pixels = 0) = 0;
00080 
00081         virtual Object insertBox(float, float, float ) = 0;
00082         virtual Object insertCone(float, float, bool, bool) = 0;
00083         virtual Object insertCylinder(float, float, bool, bool, bool) = 0;
00084         virtual Object insertElevationGrid(unsigned int mask,
00085                                            size_t nx,
00086                                            size_t nz,
00087                                            const float * height,
00088                                            float dx,
00089                                            float dz,
00090                                            const float * tc,
00091                                            const float * normals,
00092                                            const float * colors) = 0;
00093         virtual Object insertExtrusion(unsigned int,
00094                                        size_t nOrientation,
00095                                        const float * orientation,
00096                                        size_t nScale,
00097                                        const float * scale,
00098                                        size_t nCrossSection,
00099                                        const float * crossSection,
00100                                        size_t nSpine,
00101                                        const float * spine) = 0;
00102         virtual Object insertLineSet(size_t nCoords, const float * coord,
00103                                      size_t nCoordIndex, const long * coordIndex,
00104                                      bool colorPerVertex,
00105                                      const float * color,
00106                                      size_t nColorIndex,
00107                                      const long * colorIndex) = 0;
00108         virtual Object insertPointSet(size_t nv, const float * v, const float * c) = 0;
00109         virtual Object insertShell(unsigned int mask,
00110                                    size_t npoints, const float * points,
00111                                    size_t nfaces, const long * faces,
00112                                    const float * tc,
00113                                    size_t ntci, const long * tci,
00114                                    const float * normal,
00115                                    size_t nni, const long * ni,
00116                                    const float * color,
00117                                    size_t nci, const long * ci) = 0;
00118         virtual Object insertSphere(float radius) = 0;
00119         virtual Object insertDirLight(float, float, const float [], const float []) = 0;
00120         virtual Object insertPointLight(float, const float [], const float [],
00121                                         float, const float [], float) = 0;
00122         virtual Object insertSpotLight(float ambientIntensity,
00123                                        const float attenuation[],
00124                                        float beamWidth,
00125                                        const float color[],
00126                                        float cutOffAngle,
00127                                        const float direction[],
00128                                        float intensity,
00129                                        const float location[],
00130                                        float radius) = 0;
00131         virtual Object insertReference(Object existingObject) = 0;
00132 
00133         virtual void removeObject(Object) = 0;
00134 
00135         virtual void enableLighting(bool) = 0;
00136 
00137         virtual void setFog(const float * color,
00138                             float visibilityRange,
00139                             const char * fogType) = 0;
00140 
00141         virtual void setColor(float r, float g, float b, float a = 1.0) = 0;
00142 
00143         virtual void setMaterial(float ambientIntensity,
00144                                  const float diffuseColor[3],
00145                                  const float emissiveColor[3],
00146                                  float shininess,
00147                                  const float specularColor[3],
00148                                  float transparency) = 0;
00149 
00150         virtual void setMaterialMode( int nTexComponents, bool geometryColor ) = 0;
00151 
00152         virtual void setSensitive(Node * object) = 0;
00153 
00154         virtual void scaleTexture(size_t w, size_t h,
00155                                   size_t newW, size_t newH,
00156                                   size_t nc,
00157                                   unsigned char * pixels) = 0;
00158 
00159         // Create a texture object
00160         virtual TextureObject insertTexture(size_t w, size_t h, size_t nc,
00161                                             bool repeat_s,
00162                                             bool repeat_t,
00163                                             const unsigned char * pixels,
00164                                             bool retainHint = false) = 0;
00165 
00166         // Reference/remove a texture object
00167         virtual void insertTextureReference(TextureObject, int) = 0;
00168         virtual void removeTextureObject(TextureObject) = 0;
00169 
00170         virtual void setTextureTransform(const float center[2],
00171                                          float rotation,
00172                                          const float scale[2],
00173                                          const float translation[2]) = 0;
00174 
00175         virtual void setViewpoint(const float position[3],
00176                                   const float orientation[4],
00177                                   float fieldOfView,
00178                                   float avatarSize,
00179                                   float visLimit) = 0;
00180 
00181         virtual void transform(const VrmlMatrix & mat) = 0;
00182 
00183         // The viewer knows the current viewpoint
00184         virtual void transformPoints(int nPoints, float *points) = 0;
00185 
00186         // still working on some navigation api issues, so don't depend on
00187         // thses yet. there's a default implementation in any case, so you
00188         // shouldn't have to worry about it.
00189         //
00190         virtual const VrmlFrustum& getFrustum() const;
00191         virtual void setFrustum(const VrmlFrustum& afrust);
00192 
00193         virtual BVolume::Intersection
00194         intersectViewVolume(const BVolume & bvolume) const;
00195 
00196         virtual void drawBSphere(const BSphere & bs,
00197                                  BVolume::Intersection intersection) = 0;
00198 
00199     protected:
00200         explicit Viewer(Browser & browser);
00201 
00202     private:
00203         // non-copyable
00204         Viewer(const Viewer &);
00205         Viewer & operator=(const Viewer &);
00206     };
00207 }
00208 
00209 # endif // OPENVRML_VIEWER_H