~ubuntu-branches/ubuntu/saucy/3depict/saucy

« back to all changes in this revision

Viewing changes to src/effect.h

  • Committer: Package Import Robot
  • Author(s): D Haley
  • Date: 2013-05-17 00:52:39 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130517005239-7bl4mnhkvrhc2ba6
Tags: 0.0.13-1
Upload to unstable 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *      effect.h - opengl 3D effects header
3
 
 *      Copyright (C) 2011, D Haley 
4
 
 
5
 
 *      This program is free software: you can redistribute it and/or modify
6
 
 *      it under the terms of the GNU General Public License as published by
7
 
 *      the Free Software Foundation, either version 3 of the License, or
8
 
 *      (at your option) any later version.
9
 
 
10
 
 *      This program is distributed in the hope that it will be useful,
11
 
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *      GNU General Public License for more details.
14
 
 
15
 
 *      You should have received a copy of the GNU General Public License
16
 
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 
*/
18
 
 
19
 
#ifndef EFFECT_H
20
 
#define EFFECT_H
21
 
 
22
 
#include <string>
23
 
 
24
 
#undef ATTRIBUTE_PRINTF
25
 
#include <libxml/xmlreader.h>
26
 
#undef ATTRIBUTE_PRINTF
27
 
 
28
 
//OpenGL includes
29
 
//MacOS is "special" and puts it elsewhere
30
 
#ifdef __APPLE__ 
31
 
        #include <OpenGL/glu.h>
32
 
#else
33
 
        #include <GL/glu.h>
34
 
#endif
35
 
 
36
 
#include "cameras.h"
37
 
 
38
 
 
39
 
//opengl allows up to 6 clipping planes
40
 
const unsigned int MAX_OPENGL_CLIPPLANES=6;
41
 
 
42
 
                        
43
 
 
44
 
//Effect IDs
45
 
enum
46
 
{
47
 
        EFFECT_BOX_CROP=0,
48
 
        EFFECT_ANAGLYPH,
49
 
        EFFECT_ENUM_END
50
 
};
51
 
 
52
 
 
53
 
enum{
54
 
        //Colour mask methods
55
 
        ANAGLYPH_REDBLUE,
56
 
        ANAGLYPH_REDGREEN,
57
 
        ANAGLYPH_REDCYAN,
58
 
        ANAGLYPH_GREENMAGENTA,
59
 
        //Colour matrix +accumulation buffer methods
60
 
        ANAGLYPH_HALF_COLOUR,
61
 
        ANAGLYPH_MIXED,
62
 
        ANAGLYPH_ENUM_END //Not a method. end of enum
63
 
};
64
 
 
65
 
class Effect
66
 
{
67
 
        protected:
68
 
                static Camera *curCam;
69
 
                static BoundCube bc;
70
 
                unsigned int effectType;
71
 
        public:
72
 
                Effect();
73
 
                virtual ~Effect() {};
74
 
                virtual void enable(unsigned int pass=0) const =0;
75
 
                virtual void disable() const=0;
76
 
                std::string getName() const;
77
 
 
78
 
 
79
 
                //Write the effect's state information to file
80
 
                virtual bool writeState(std::ofstream &f, 
81
 
                                unsigned int format, unsigned int depth) const=0;
82
 
                //read the effects state information from an XML file
83
 
                virtual bool readState(xmlNodePtr n)=0;
84
 
 
85
 
                virtual bool needCamUpdate() const { return false;}
86
 
 
87
 
                //!Returns true if the effect has any influence on the output
88
 
                virtual bool willDoSomething() const=0;
89
 
 
90
 
                virtual unsigned int numPassesNeeded() const { return 1;}
91
 
 
92
 
                virtual unsigned int getType() const { return effectType;};
93
 
                static void setCurCam(Camera *c) {curCam=c;}
94
 
                static void setBoundingCube(const BoundCube &c) {bc=c;}
95
 
 
96
 
};
97
 
 
98
 
 
99
 
class BoxCropEffect : public Effect
100
 
{
101
 
        private:
102
 
                //controlling ID values for gl plane. No more than MAX_OPENGL_CLIPPLANES allowed
103
 
                unsigned int openGLIdStart,openGLIdEnd;
104
 
                //Cropping margins (Fraction from edge towards opposite edge (complete)). 0->1. 
105
 
                //Opposing edges must sum to 0->1. (xLo,xHi,yLo...)
106
 
                float cropFractions[6];
107
 
                //!True if we should transform to camera coordinates before applying crop
108
 
                bool useCamCoordinates;
109
 
 
110
 
                //!Aspect ratio of output image
111
 
                float outputAspect;
112
 
 
113
 
                void doClip(const Point3D &origin, const Point3D & normal,unsigned int glOffset) const;
114
 
        public:
115
 
                BoxCropEffect(){useCamCoordinates=false;effectType=EFFECT_BOX_CROP;openGLIdStart=0; }
116
 
                virtual ~BoxCropEffect(){}; 
117
 
 
118
 
                //!Enable the clipping plane. Values *must* be set before calling
119
 
                void enable(unsigned int pass) const;
120
 
 
121
 
                //!DIsable the clipping plane
122
 
                void disable() const;
123
 
 
124
 
 
125
 
 
126
 
                //Write the effect's state information to file
127
 
                bool writeState(std::ofstream &f, unsigned int format,
128
 
                                unsigned int depth) const;
129
 
                //read the effects state information from an XML file
130
 
                bool readState(xmlNodePtr n);
131
 
 
132
 
                //!Returns true if the effect has any influence on the output
133
 
                bool willDoSomething() const;
134
 
 
135
 
                //!Set the fractions of cube from margin
136
 
                //-- there should be 6 floats (x,y,z)_(low,high) (x_lo, x_hi....)
137
 
                //  each low/hi should form a sum between 0 and 1.
138
 
                void setFractions(const float *fractionArray);
139
 
 
140
 
                void useCamCoords(bool enable){useCamCoordinates=enable;};
141
 
 
142
 
                //!Alters the input box to generate cropping bounding box
143
 
                //note the box may be inside out if the cropping limits
144
 
                //exceed themselves..
145
 
                void getCroppedBounds(BoundCube &b) const;
146
 
 
147
 
                float getCropValue(unsigned int pos) const {ASSERT(pos<6); return cropFractions[pos];}
148
 
};
149
 
 
150
 
class AnaglyphEffect : public Effect
151
 
{
152
 
        private:
153
 
                unsigned int colourMode;
154
 
                bool eyeFlip;
155
 
                
156
 
                mutable Camera *oldCam;
157
 
                float baseShift;
158
 
 
159
 
        public:
160
 
                AnaglyphEffect(){effectType=EFFECT_ANAGLYPH;colourMode=ANAGLYPH_REDBLUE;oldCam=0;baseShift=0.01f; eyeFlip=false;}
161
 
                ~AnaglyphEffect(){}; 
162
 
 
163
 
                //!Enable the clipping plane. Values *must* be set before calling
164
 
                void enable(unsigned int pass) const;
165
 
 
166
 
                //!DIsable the clipping plane
167
 
                void disable() const;
168
 
 
169
 
                //Write the effect's state information to file
170
 
                bool writeState(std::ofstream &f, unsigned int format,
171
 
                                unsigned int depth) const;
172
 
                //read the effects state information from an XML file
173
 
                bool readState(xmlNodePtr n);
174
 
                
175
 
                //!Whether we should be flipping the lens from its hard-coded left-right
176
 
                void setFlip(bool shouldFlip) {eyeFlip=shouldFlip;};
177
 
 
178
 
                void setMode(unsigned int mode){ASSERT(colourMode<ANAGLYPH_ENUM_END);colourMode=mode;};
179
 
                void setBaseShift(float shift) { baseShift=shift;};
180
 
 
181
 
                bool needCamUpdate() const { return true;}
182
 
                //!Returns true if the effect has any influence on the output
183
 
                bool willDoSomething() const {return true;};
184
 
 
185
 
                virtual unsigned int numPassesNeeded() const { return 2;}
186
 
 
187
 
 
188
 
                float getBaseShift() const { return baseShift;};
189
 
                unsigned int getMode() const { return colourMode;};
190
 
 
191
 
                        
192
 
};
193
 
 
194
 
 
195
 
Effect *makeEffect(unsigned int effectID);
196
 
 
197
 
Effect *makeEffect(const std::string &s);
198
 
 
199
 
 
200
 
#endif