00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _SHADOWVOLUME_HXX
00024 #define _SHADOWVOLUME_HXX
00025
00026 #include <simgear/compiler.h>
00027 #include <simgear/props/props.hxx>
00028
00029 #include <vector>
00030 #include <map>
00031
00032 using std::vector;
00033 using std::map;
00034
00035 class ssgBranch;
00036 class ssgLeaf;
00037 class SGPropertyNode;
00038
00042 class SGShadowVolume {
00043
00044 public:
00045 SGShadowVolume( ssgBranch *root );
00046 ~SGShadowVolume();
00047
00048 typedef enum {
00049 occluderTypeAircraft,
00050 occluderTypeAI,
00051 occluderTypeTileObject
00052 } OccluderType;
00053
00054 void init(SGPropertyNode *sim_rendering_options);
00055 void startOfFrame(void);
00056 void addOccluder(ssgBranch *occluder, OccluderType occluder_type, ssgBranch *tile=0);
00057 void deleteOccluder(ssgBranch *occluder);
00058 void deleteOccluderFromTile(ssgBranch *tile);
00059 void setupShadows(double lon, double lat,
00060 double gst, double SunRightAscension, double SunDeclination, double sunAngle );
00061 void endOfFrame(void);
00062 static int ACpostTravCB( ssgEntity *entity, int traversal_mask );
00063
00064 private:
00065
00066 class ShadowCaster
00067 {
00068 public:
00069 typedef struct {
00070 sgVec4 planeEquations;
00071 int neighbourIndices[3];
00072 bool isSilhouetteEdge[3];
00073 bool isFacingLight;
00074 } triData;
00075
00076 ssgSharedPtr<ssgBranch> geometry_leaf;
00077 ssgSharedPtr<ssgBranch> scenery_object;
00078 ssgSharedPtr<ssgBranch> lib_object;
00079 ssgSharedPtr<ssgBranch> first_select;
00080 sgVec3 last_lightpos;
00081 sgMat4 last_transform;
00082 int frameNumber;
00083
00084 int *indices;
00085 int numTriangles;
00086 triData *triangles;
00087
00088 sgVec4 * vertices;
00089 GLushort *silhouetteEdgeIndices;
00090 int lastSilhouetteIndicesCount;
00091 bool isTranslucent;
00092
00093 ShadowCaster( int _num_tri, ssgBranch * _geometry_leaf );
00094 ~ShadowCaster();
00095 void addLeaf( int & tri_idx, int & ind_idx, ssgLeaf *_geometry_leaf );
00096 void SetConnectivity();
00097 void CalculateSilhouetteEdges(sgVec3 lightPosition);
00098 void DrawInfiniteShadowVolume(sgVec3 lightPosition, bool drawCaps);
00099 void computeShadows(sgMat4 rotation, sgMat4 rotation_translation, OccluderType occluder_type);
00100 void getNetTransform ( ssgBranch * branch, sgMat4 xform );
00101 bool isSelected ( ssgBranch * branch, float dist);
00102
00103 bool sameVertex(int edge1, int edge2);
00104 };
00105 typedef vector<ShadowCaster *> ShadowCaster_list;
00106
00107 class SceneryObject {
00108 public:
00109 SceneryObject(ssgBranch *_scenery_object, OccluderType _occluder_type);
00110 ~SceneryObject();
00111 void computeShadows(void);
00112 void traverseTree(ssgBranch *branch);
00113 void find_trans(void);
00114 ssgSharedPtr<ssgBranch> scenery_object;
00115 ssgSharedPtr<ssgBranch> lib_object;
00116 ssgSharedPtr<ssgBranch> pending_object;
00117 ssgSharedPtr<ssgBranch> tile;
00118 ShadowCaster_list parts;
00119 OccluderType occluder_type;
00120 };
00121 typedef map<ssgSharedPtr<ssgBranch>, SceneryObject *> SceneryObject_map;
00122
00123
00124 private:
00125 void update_light_view(void);
00126 void computeShadows(void);
00127 void cull ( ssgBranch *b, sgFrustum *f, sgMat4 m, int test_needed );
00128
00129 bool shadows_enabled;
00130 bool shadowsAC_enabled, shadowsAI_enabled, shadowsTO_enabled, shadowsDebug_enabled;
00131 bool shadowsAC_transp_enabled;
00132 bool use_alpha;
00133 bool canDoAlpha, canDoStencil;
00134 SGPropertyNode_ptr sim_rendering;
00135
00136 sgVec3 sunPos;
00137 int frameNumber;
00138 int lastTraverseTreeFrame;
00139 sgMat4 CameraViewM;
00140 double sun_angle;
00141 SceneryObject_map sceneryObjects;
00142 ssgSharedPtr<ssgBranch> ssg_root;
00143 bool shadows_rendered;
00144 };
00145
00146 #endif // _SHADOWVOLUME_HXX