ClipPlane.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <sofa/component/visualmodel/ClipPlane.h>
00026 #include <sofa/core/ObjectFactory.h>
00027
00028 namespace sofa
00029 {
00030
00031 namespace component
00032 {
00033
00034 namespace visualmodel
00035 {
00036
00037 SOFA_DECL_CLASS(ClipPlane)
00038
00039 int ClipPlaneClass = core::RegisterObject("OpenGL Clipping Plane")
00040 .add< ClipPlane >()
00041 ;
00042
00043
00044 ClipPlane::ClipPlane()
00045 : position(initData(&position, Vector3(0,0,0), "position", "Point crossed by the clipping plane"))
00046 , normal(initData(&normal, Vector3(1,0,0), "normal", "Normal of the clipping plane, pointing toward the clipped region"))
00047 , id(initData(&id, 0, "id", "Clipping plane OpenGL ID"))
00048 , active(initData(&active,true,"active","Control whether the clipping plane should be applied or not"))
00049 {
00050
00051 }
00052
00053 ClipPlane::~ClipPlane()
00054 {
00055 }
00056
00057 void ClipPlane::init()
00058 {
00059 }
00060
00061 void ClipPlane::reinit()
00062 {
00063 }
00064
00065 void ClipPlane::fwdDraw(Pass)
00066 {
00067 wasActive = glIsEnabled(GL_CLIP_PLANE0+id.getValue());
00068 if (active.getValue())
00069 {
00070 glGetClipPlane(GL_CLIP_PLANE0+id.getValue(), saveEq);
00071 Vector3 p = position.getValue();
00072 Vector3 n = normal.getValue();
00073 GLdouble c[4] = { (GLdouble) -n[0], (GLdouble)-n[1], (GLdouble)-n[2], (GLdouble)(p*n) };
00074 glClipPlane(GL_CLIP_PLANE0+id.getValue(), c);
00075 if (!wasActive)
00076 glEnable(GL_CLIP_PLANE0+id.getValue());
00077 }
00078 else
00079 {
00080 if (wasActive)
00081 glDisable(GL_CLIP_PLANE0+id.getValue());
00082 }
00083 }
00084
00085 void ClipPlane::bwdDraw(Pass)
00086 {
00087 if (active.getValue())
00088 {
00089 glClipPlane(GL_CLIP_PLANE0+id.getValue(), saveEq);
00090 if (!wasActive)
00091 glDisable(GL_CLIP_PLANE0+id.getValue());
00092 }
00093 else
00094 {
00095 if (wasActive)
00096 glEnable(GL_CLIP_PLANE0+id.getValue());
00097 }
00098 }
00099
00100 }
00101
00102 }
00103
00104 }