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

isphere_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 _ISPHERE_SHADING_H_
00017 #define _ISPHERE_SHADING_H_
00018 
00019 // includes, file
00020 #include <ishading.h>
00021 #include <imaterial.h>
00022 
00023 // includes, maya
00024 #include <maya/MPoint.h>
00025 #include <maya/MPlug.h>
00026 #include <maya/M3dView.h>
00027 
00028 // includes, project
00029 #include <imaya_helper.h>
00030 
00031 // variables, exported
00032 
00034 class ISphereShading {
00035 
00036   friend class ISphereUI;
00037 
00038 private:
00039 
00041   ISphereShading();
00042 
00044   ~ISphereShading();
00045 
00047   void initCg();
00048 
00050   void initGL();
00051 
00053   inline void activate( M3dView & view ) const;
00054 
00056   inline void deactivate() const;
00057 
00059   inline void activateFBO() const;
00060 
00062   inline void deactivateFBO() const;
00063 
00065   inline void setLightPosition( MPoint &lightPosition ) const;
00066  
00068   inline void setTransformedLightParameter( M3dView &view ) const;
00069 
00070   // set shading parameter (called from activate)
00071   void setUniforms( M3dView & view ) const;
00072 
00073   // get IMaterial
00074   IMaterial* getMaterial() const { return materialProperty; };
00075 
00076   // get impl
00077   IShading* getImpl() const { return impl; };
00078 
00079 private:
00080 
00081   // Material Properties and Parameters
00082   IMaterial* materialProperty;
00083 
00084   // class pimpl for the data members
00085   class IShading*  impl;
00086 
00087 };
00088 
00092 inline void
00093 ISphereShading::activate( M3dView & view) const {
00094 
00095   setUniforms( view);
00096   impl->activate();
00097 
00098   IShading::checkCgError( "IShading::init():: Creating program failed.");
00099 }
00100 
00104 inline void
00105 ISphereShading::activateFBO() const {
00106 
00107   impl->activateFBO();
00108 }
00109 
00113 inline void
00114 ISphereShading::deactivate() const {
00115 
00116   impl->deactivate();
00117 
00118   IShading::checkCgError( "IShading::init():: Creating program failed.");
00119 }
00120 
00124 inline void
00125 ISphereShading::deactivateFBO() const {
00126 
00127   impl->readbackFBO();
00128   impl->deactivateFBO();
00129 }
00130 
00134 inline void
00135 ISphereShading::setUniforms( M3dView & view ) const {
00136 
00137   cgGLSetStateMatrixParameter( impl->mvp, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
00138   cgGLSetStateMatrixParameter( impl->mv, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY);
00139   cgGLSetStateMatrixParameter( impl->p, CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
00140   
00141   setTransformedLightParameter( view );
00142 
00143   //getMaterial()->setShaderParameters();
00144 
00145   IShading::checkCgError( "IShading::init():: Creating program failed.");  
00146 }
00147 
00152 void ISphereShading::setLightPosition( MPoint &lightPosition ) const {
00153 
00154   cgGLSetParameter4f( impl->plPos, lightPosition.x, lightPosition.y, lightPosition.z, 1.0 );
00155 }
00156 
00160 void ISphereShading::setTransformedLightParameter( M3dView &view ) const {
00161 
00162   // Get and Transform the Light Position from World
00163   // to View/Eye space.
00164   MPoint pointLocation;
00165   MDagPath cameraDagPath;
00166   
00167   Util::getPointLightPosition( pointLocation );
00168   view.getCamera( cameraDagPath );
00169   
00170   // Get the transform node
00171   cameraDagPath.pop();
00172   MFnTransform cameraTransform( cameraDagPath );
00173 
00174   // Transform the light position in world space
00175   // to view/eye space by multiplying by the 
00176   // *inverse* of the camera transform.
00177   MMatrix cTransformMatrix = cameraTransform.transformationMatrix();
00178   pointLocation = pointLocation * (cTransformMatrix.inverse());
00179   
00180   // Toss the parameter to the shader.
00181   setLightPosition( pointLocation );
00182 }
00183 
00184 
00185 #endif // _ISPHERE_SHADING_H_

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