OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ClipPlane.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSG_CLIPPLANE
15 #define OSG_CLIPPLANE 1
16 
17 #include <osg/Vec4d>
18 #include <osg/Plane>
19 #include <osg/StateAttribute>
20 
21 #ifndef GL_CLIP_PLANE0
22  #define GL_CLIP_PLANE0 0x3000
23  #define GL_CLIP_PLANE1 0x3001
24  #define GL_CLIP_PLANE2 0x3002
25  #define GL_CLIP_PLANE3 0x3003
26  #define GL_CLIP_PLANE4 0x3004
27  #define GL_CLIP_PLANE5 0x3005
28 #endif
29 
30 namespace osg {
31 
35 {
36  public :
37 
38  ClipPlane();
39  inline ClipPlane(unsigned int no):_clipPlaneNum(no) {}
40  inline ClipPlane(unsigned int no,const Vec4d& plane):_clipPlaneNum(no) { setClipPlane(plane); }
41  inline ClipPlane(unsigned int no,const Plane& plane):_clipPlaneNum(no) { setClipPlane(plane); }
42  inline ClipPlane(unsigned int no,double a,double b,double c,double d): _clipPlaneNum(no) { setClipPlane(a,b,c,d); }
43 
45  ClipPlane(const ClipPlane& cp,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
46  StateAttribute(cp,copyop)
47  {
48  _clipPlane[0]=cp._clipPlane[0];
49  _clipPlane[1]=cp._clipPlane[1];
50  _clipPlane[2]=cp._clipPlane[2];
51  _clipPlane[3]=cp._clipPlane[3];
52  _clipPlaneNum=cp._clipPlaneNum;
53  }
54 
55  virtual osg::Object* cloneType() const { return new ClipPlane( _clipPlaneNum ); }
56  virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new ClipPlane(*this,copyop); }
57  virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ClipPlane *>(obj)!=NULL; }
58  virtual const char* libraryName() const { return "osg"; }
59  virtual const char* className() const { return "ClipPlane"; }
60  virtual Type getType() const { return CLIPPLANE; }
61 
63  virtual int compare(const StateAttribute& sa) const
64  {
65  // Check for equal types, then create the rhs variable
66  // used by the COMPARE_StateAttribute_Parameter macros below.
68 
69  // Compare each parameter in turn against the rhs.
75 
76  return 0; // Passed all the above comparison macros, so must be equal.
77  }
78 
79  virtual unsigned int getMember() const { return _clipPlaneNum; }
80 
81  virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
82  {
83  usage.usesMode((GLMode)(GL_CLIP_PLANE0+_clipPlaneNum));
84  return true;
85  }
86 
87 
89  void setClipPlane(const Plane& plane)
90  {
91  _clipPlane.set(plane[0],plane[1],plane[2],plane[3]);
92  }
93 
95  void setClipPlane(double a,double b,double c,double d)
96  {
97  _clipPlane.set(a,b,c,d);
98  }
99 
101  inline void setClipPlane(const Vec4d& plane) { _clipPlane = plane; }
102 
104  const Vec4d& getClipPlane() const { return _clipPlane; }
105 
106 
108  void setClipPlaneNum(unsigned int num);
109 
111  unsigned int getClipPlaneNum() const;
112 
114  virtual void apply(State& state) const;
115 
116  protected :
117 
118  virtual ~ClipPlane();
119 
121  unsigned int _clipPlaneNum;
122 
123 };
124 
125 }
126 
127 #endif
#define OSG_EXPORT
Definition: Export.h:43
#define NULL
Definition: Export.h:59
virtual osg::Object * clone(const osg::CopyOp &copyop) const
Definition: ClipPlane.h:56
void setClipPlane(double a, double b, double c, double d)
Definition: ClipPlane.h:95
#define COMPARE_StateAttribute_Types(TYPE, rhs_attribute)
void setClipPlane(const Plane &plane)
Definition: ClipPlane.h:89
ClipPlane(const ClipPlane &cp, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition: ClipPlane.h:45
virtual bool getModeUsage(StateAttribute::ModeUsage &usage) const
Definition: ClipPlane.h:81
virtual bool isSameKindAs(const osg::Object *obj) const
Definition: ClipPlane.h:57
virtual void usesMode(GLMode mode)=0
void setClipPlane(const Vec4d &plane)
Definition: ClipPlane.h:101
virtual Type getType() const
Definition: ClipPlane.h:60
#define GL_CLIP_PLANE0
Definition: ClipPlane.h:22
virtual osg::Object * cloneType() const
Definition: ClipPlane.h:55
virtual const char * libraryName() const
Definition: ClipPlane.h:58
virtual const char * className() const
Definition: ClipPlane.h:59
A plane class. It can be used to represent an infinite plane.
Definition: Plane.h:33
Vec4d _clipPlane
Definition: ClipPlane.h:120
Definition: AlphaFunc.h:19
#define COMPARE_StateAttribute_Parameter(parameter)
const Vec4d & getClipPlane() const
Definition: ClipPlane.h:104
ClipPlane(unsigned int no, double a, double b, double c, double d)
Definition: ClipPlane.h:42
virtual int compare(const StateAttribute &sa) const
Definition: ClipPlane.h:63
ClipPlane(unsigned int no, const Vec4d &plane)
Definition: ClipPlane.h:40
virtual unsigned int getMember() const
Definition: ClipPlane.h:79
ClipPlane(unsigned int no, const Plane &plane)
Definition: ClipPlane.h:41
unsigned int _clipPlaneNum
Definition: ClipPlane.h:121
ClipPlane(unsigned int no)
Definition: ClipPlane.h:39