view.H

00001 /*
00002  * This file is part of the "Archon" framework.
00003  * (http://files3d.sourceforge.net)
00004  *
00005  * Copyright © 2002 by Kristian Spangsege and Brian Kristiansen.
00006  *
00007  * Permission to use, copy, modify, and distribute this software and
00008  * its documentation under the terms of the GNU General Public License is
00009  * hereby granted. No representations are made about the suitability of
00010  * this software for any purpose. It is provided "as is" without express
00011  * or implied warranty. See the GNU General Public License
00012  * (http://www.gnu.org/copyleft/gpl.html) for more details.
00013  *
00014  * The characters in this file are ISO8859-1 encoded.
00015  *
00016  * The documentation in this file is in "Doxygen" style
00017  * (http://www.doxygen.org).
00018  */
00019 
00020 #ifndef ARCHON_X3D_VIEW_H
00021 #define ARCHON_X3D_VIEW_H
00022 
00023 #include <stack>
00024 #include <set>
00025 
00026 #include <archon/math/coord_system.H>
00027 
00028 #include <archon/x3d/server/exception.H>
00029 #include <archon/x3d/server/x3d.H>
00030 #include <archon/x3d/server/scene.H>
00031 
00032 namespace Archon
00033 {
00034   namespace X3D
00035   {
00036     struct Viewer
00037     {
00038       Viewer(Ref<Server>,
00039              int resolutionX, int resolutionY,
00040              bool useMipmapedTextures,
00041              string initialViewpointName,
00042              const CoordSystem3x3 &defaultViewpoint,
00043              double fieldOfView,
00044              double depthOfRotation,
00045              const Vector4 &backgroundColor,
00046              int subdivisionX, int subdivisionY,
00047              bool headLight,
00048              bool showLightSources,
00049              bool showNormals,
00050              bool textAsQuadsMode,
00051              bool wireframeMode,
00052              bool enableTexture);
00053 
00059       bool bindViewpoint(string name);
00060 
00066       void resetViewpoint(string initialViewpointName,
00067                           const CoordSystem3x3 &defaultViewpoint);
00072       void setPointingDeviceActive(bool m);
00073 
00078       void setInitialPointingDevicePosition2D(Vector2);
00079 
00085       void setPointingDevicePosition2D(Vector2);
00086 
00091       void renderFrame();
00092 
00098       bool getOverStatus() const { return !pointingDeviceOverSet.empty(); }
00099 
00104       bool getDragStatus() const { return !pointingDeviceActiveSet.empty(); }
00105 
00106       bool getHeadLight() const               { return headLight; }
00107       void setHeadLight(bool m = true)        { headLight = m; }
00108 
00109       bool getShowLightSources() const        { return showLightSources; }
00110       void setShowLightSources(bool m = true) { showLightSources = m; }
00111 
00112       bool getDisregardSensors() const        { return disregardSensors; }
00113       void setDisregardSensors(bool m = true) { disregardSensors = m; }
00114 
00115       bool getEnableTexture() const           { return enableTexture; }
00116       void setEnableTexture(bool m = true)    { enableTexture = m; }
00117 
00118       bool getWireframeMode() const
00119       {
00120         return renderConfig.wireframeMode;
00121       }
00122 
00123       void setWireframeMode(bool m = true)
00124       {
00125         renderConfig.wireframeMode = m;
00126         updateShapeCacheDuringNextFrame = true; // Text nodes need this.
00127       }
00128 
00129       bool getShowNormals() const
00130       {
00131         return renderConfig.showNormals;
00132       }
00133 
00134       void setShowNormals(bool m = true)
00135       {
00136         renderConfig.showNormals = m;
00137         updateShapeCacheDuringNextFrame = true;
00138       }
00139 
00140       bool getTextAsQuadsMode() const
00141       {
00142         return renderConfig.textAsQuadsMode;
00143       }
00144 
00145       void setTextAsQuadsMode(bool m = true)
00146       {
00147         renderConfig.textAsQuadsMode = m;
00148         updateShapeCacheDuringNextFrame = true;
00149       }
00150 
00151       bool getSeparateSpecularColorMode() const        { return separateSpecularColorMode; }
00152       void setSeparateSpecularColorMode(bool m = true) { separateSpecularColorMode = m; }
00153 
00154       bool getLightModelLocalViewerMode() const        { return lightModelLocalViewerMode; }
00155       void setLightModelLocalViewerMode(bool m = true) { lightModelLocalViewerMode = m ; }
00156 
00157       CoordSystem3x3 &manipViewCoordSystem()
00158       {
00159         boundViewpoint = 0;
00160         return viewCoordSystem;
00161       }
00162 
00163       double getDepthOfRotation() const
00164       {
00165         return depthOfRotation;
00166       }
00167 
00168       void setDepthOfRotation(double d)
00169       {
00170         boundViewpoint = 0;
00171         depthOfRotation = d;
00172         renderConfig.normalLength = d/10;
00173       }
00174 
00175     private:
00176       unsigned maxLights;
00177 
00178       Ref<Server> server;
00179 
00180       const int resolutionX;
00181       const int resolutionY;
00182       const double aspectRatio;
00183 
00184       const double nearClippingDist;
00185       const double farClippingDist;
00186 
00187       const bool useMipmapedTextures;
00188 
00189       CoordSystem3x3 viewCoordSystem;
00190       double fieldOfView;
00191       double depthOfRotation;
00192 
00193       Ref<const Viewpoint> boundViewpoint;
00194 
00195       Vector2 viewPlane;
00196 
00197       RenderConfig renderConfig;
00198 
00199       bool headLight;
00200       bool showLightSources;
00201       bool disregardSensors;
00202 
00203       bool enableTexture;
00204 
00205       bool separateSpecularColorMode;
00206       bool lightModelLocalViewerMode;
00207 
00208       int numberOfEnabledLights;
00209       bool tracePointingRay;
00210       Vector3 pointingRay; // Direction vector is generally does not have unit length
00211       vector<const GroupingNode *> hitGroupThread;
00212       vector<Rotation3> hitGroupThreadBillboardRotations; // One entry for each Billboard pointer in hitGroupThread in the same order
00213       int hitGroupThreadLowerLevel;
00214       int level; // Nesting level of groups, 0 is root group
00215 
00216       bool updateShapeCacheDuringNextFrame;
00217 
00218       set<Ref<PointingDeviceSensorNode> > pointingDeviceOverSet;   // The isOver set
00219       set<Ref<PointingDeviceSensorNode> > pointingDeviceActiveSet; // The isActive set
00220       bool anyActiveDragSensors;
00221       Vector2 pointingDevicePosition; // For conventional 2-D mice
00222       bool pointingDevicePositionChangedSinceLastFrame;
00223       bool pointingDeviceActive;
00224       bool pointingDeviceLastActive; // Value of pointingDeviceActive at last frame
00225       CoordSystem3x3 eyeToSensorMap; // For mapping pointing ray while dragging
00226       Vector3 initialDragHitPoint; // In the inverse eyeToSensorMap coordinate system
00227       Sphere3 virtualSphereSensor;
00228       double virtualCylinderSensorRadius;
00229       double virtualCylinderSensorAngle;
00230 
00231       void setupViewpoint();
00232       Viewpoint *findBoundViewpoint_group
00233       (const GroupingNode *, stack<const Transform *> *transformPath=0);
00234       Viewpoint *findBoundViewpoint_child
00235       (ChildNode *, stack<const Transform *> *transformPath=0);
00236 
00237       void calculateBillboardRotation(const Billboard *, Rotation3 &);
00238 
00239       void setupLight(bool headLight, bool showLightSources);
00240       void lightPointLight(const PointLight *, int &, bool);
00241       void lightSpotLight(const SpotLight *, int &, bool);
00242       void lightDispatchLightNode(const LightNode *, int &, bool);
00243       void lightTransform(const Transform *, int &, bool);
00244       void lightBillboard(const Billboard *, int &, bool);
00245       void lightSwitch(const Switch *, int &, bool);
00246       void lightDispatchGroupingNode(const GroupingNode *, int &, bool);
00247       void lightGroupingNode(const GroupingNode *, int &, bool);
00248 
00249       void dispatchChildNode(const ChildNode *);
00250       void drawGroupingNode(GroupingNode *, bool, const Rotation3 *billboardRotation = 0);
00251       void dispatchGroupingNode(GroupingNode *, bool);
00252       void drawTransform(Transform *, bool);
00253       void drawBillboard(Billboard *, bool);
00254       void drawSubSceneNode(SubSceneNode *, bool);
00255       Shape *drawShape(ShapeNode *);
00256 
00257       struct Hit
00258       {
00259         const Shape *node;
00260         int where;
00261         double distance;
00262         Math::Ray3 localRay;
00263       };
00264 
00265       Hit hit;
00266 
00267       struct ShapeCache;
00268     };
00269   }
00270 }
00271 
00272 #endif // ARCHON_X3D_VIEW_H

Generated on Sun Jul 30 22:55:43 2006 for Archon by  doxygen 1.4.4