Main Page | Namespace List | Class List | Directories | File List | Namespace Members | Class Members | File Members

iquadric_shading.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 #ifndef _IQUADRIC_SHADING_H_
00017 #define _IQUADRIC_SHADING_H_
00018 
00019 // includes, maya
00020 #include <maya/MPoint.h>
00021 #include <maya/MPlug.h>
00022 #include <maya/M3dView.h>
00023 
00024 // includes, project
00025 #include <imaya_helper.h>
00026 #include <ishading.h>
00027 
00028 // variables, exported
00029 
00030 // declaration, forward
00031 class IMaterial;
00032 
00033 
00034 class IQuadricShading {
00035 
00036   friend class IQuadricUI;
00037 
00038 public:
00039 
00041   IQuadricShading();
00042 
00044   ~IQuadricShading();
00045 
00047   void initCg();
00048 
00050   void initGL();
00051 
00057   inline void activate( M3dView & view, const MMatrix& quadric, const MPoint& ci) const;
00058 
00060   inline void deactivate() const;
00061 
00063   inline void activateFBO() const;
00064 
00066   inline void deactivateFBO() const;
00067 
00069   inline void setLightPosition( MPoint &lightPosition ) const;
00070   
00071   inline void setTransformedLightParameter( M3dView &view ) const;
00072 
00073 private:
00074 
00075   // set shading parameter (called from activate)
00080   void setUniforms( M3dView& view, const MMatrix& q_matrix, const MPoint& ci) const;
00081   
00082   // get IMaterial
00083   IMaterial* getMaterial() const { return materialProperty; };
00084 
00085   // get impl
00086   IShading* getImpl() const { return impl; };
00087 
00088 private:
00089 
00091   CGparameter  quadric;
00092 
00094   CGparameter  clip_infinite;
00095 
00096   // Material Properties and Parameters
00097   class IMaterial* materialProperty;
00098 
00099   // class pimpl for the data members
00100   IShading*  impl;
00101 
00102 };
00103 
00104 
00112 inline void
00113 IQuadricShading::activate( M3dView& view, const MMatrix& quadric, const MPoint& ci) const {
00114 
00115   setUniforms( view, quadric, ci);
00116   impl->activate();
00117 }
00118 
00122 inline void
00123 IQuadricShading::activateFBO() const {
00124 
00125   impl->activateFBO();
00126 }
00127 
00131 inline void
00132 IQuadricShading::deactivate() const {
00133 
00134   impl->deactivate();
00135 }
00136 
00140 inline void
00141 IQuadricShading::deactivateFBO() const {
00142 
00143   impl->readbackFBO();
00144   impl->deactivateFBO();
00145 }
00146 
00153 inline void
00154 IQuadricShading::setUniforms( M3dView& view, const MMatrix& q_matrix, const MPoint& ci) const {
00155 
00156   cgGLSetStateMatrixParameter( impl->mvp, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
00157   cgGLSetStateMatrixParameter( impl->mv, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY);
00158   cgGLSetStateMatrixParameter( impl->p, CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
00159   
00160   // set the quadric parameter
00161   float params_quadric[4][4];
00162   CHECK_MAYA( q_matrix.get( params_quadric));
00163   cgGLSetMatrixParameterfr( quadric, &(params_quadric[0][0]));
00164 
00165   // set clipping information for infinite quadrics
00166   cgGLSetParameter4f( clip_infinite, ci[0], ci[1], ci[2], ci[3]);
00167 
00168   setTransformedLightParameter( view );
00169 }
00170 
00175 void 
00176 IQuadricShading::setLightPosition( MPoint &lightPosition ) const {
00177 
00178   cgGLSetParameter4f( impl->plPos, lightPosition.x, lightPosition.y, lightPosition.z, 1.0 );
00179 }
00180 
00184 void 
00185 IQuadricShading::setTransformedLightParameter( M3dView &view ) const {
00186 
00187   // Get and Transform the Light Position from World
00188   // to View/Eye space.
00189   MPoint pointLocation;
00190   MDagPath cameraDagPath;
00191   
00192   Util::getPointLightPosition( pointLocation );
00193   view.getCamera( cameraDagPath );
00194   
00195   // Get the transform node
00196   cameraDagPath.pop();
00197   MFnTransform cameraTransform( cameraDagPath );
00198 
00199   // Transform the light position in world space
00200   // to view/eye space by multiplying by the 
00201   // *inverse* of the camera transform.
00202   MMatrix cTransformMatrix = cameraTransform.transformationMatrix();
00203   pointLocation = pointLocation * (cTransformMatrix.inverse());
00204   
00205   // Toss the parameter to the shader.
00206   setLightPosition( pointLocation );
00207 }
00208 
00209 
00210 #endif // _IQUADRIC_SHADING_H_

Generated on Sat Dec 31 18:07:49 2005 for ICaster by  doxygen 1.4.4