NL3D::CDeform2d Class Reference

#include <deform_2d.h>


Detailed Description

This perform a 2d deformation effect on the frame buffer, by using the given function and surface. This is intended to be used on small surfaces only (getting back data from the frame buffer to build a texture is really slow...)
Author:
Nicolas Vizerie

Nevrax France

Date:
2001

Definition at line 47 of file deform_2d.h.

Public Types

typedef std::vector< NLMISC::CVector2fTPoint2DVect

Static Public Member Functions

void doDeform (const TPoint2DVect &surf, IDriver *drv, IPerturbUV *uvp)
void setupBuffer (uint width, uint height, uint xGranularity, uint yGranularity, uint xQuad, uint yQuad)

Static Protected Attributes

uint _Height
NLMISC::CSmartPtr< ITexture_Tex
uint _Width
uint _XGranularity
uint _XQuad
uint _YGranularity
uint _YQuad


Member Typedef Documentation

typedef std::vector<NLMISC::CVector2f> NL3D::CDeform2d::TPoint2DVect
 

Definition at line 50 of file deform_2d.h.

Referenced by doDeform().


Member Function Documentation

void NL3D::CDeform2d::doDeform const TPoint2DVect surf,
IDriver drv,
IPerturbUV uvp
[static]
 

Definition at line 85 of file deform_2d.cpp.

References _Tex, _XGranularity, _YGranularity, NL3D::IDriver::activeVertexBuffer(), NL3D::IDriver::copyFrameBufferToTexture(), nlassert, NL3D::CDeform2d::IPerturbUV::perturbUV(), NLMISC::raiseToNextPowerOf2(), NL3D::IDriver::renderQuads(), NL3D::CMaterial::setDoubleSided(), NL3D::IDriver::setFrustum(), NL3D::CMaterial::setLighting(), NL3D::CVertexBuffer::setNumVertices(), NL3D::CVertexBuffer::setTexCoord(), NL3D::CMaterial::setTexture(), NL3D::IDriver::setupModelMatrix(), NL3D::IDriver::setupViewMatrix(), NL3D::CVertexBuffer::setVertexCoord(), NL3D::CVertexBuffer::setVertexFormat(), NL3D::CMaterial::setZFunc(), TPoint2DVect, uint, uint32, v, and NLMISC::CVector::y.

00086 {
00087         
00088         nlassert(uvp);
00089         
00090         typedef CQuadEffect::TPoint2DVect TPoint2DVect;
00091         TPoint2DVect dest;
00092 
00093         CQuadEffect::processPoly(surf, (float) _XGranularity, (float) _YGranularity, dest);
00094         
00095         uint realWidth = NLMISC::raiseToNextPowerOf2(_Width);
00096         uint realHeight= NLMISC::raiseToNextPowerOf2(_Height);
00097 
00098 
00099         // draw the poly contour
00100         /*for (uint k = 0; k < dest.size(); ++k)
00101         {
00102                 CDRU::drawLine(dest[k].x, dest[k].y, dest[(k + 1) % dest.size()].x, dest[(k + 1) % dest.size()].y, *drv, CRGBA::Red);
00103         }*/
00104 
00105 
00106         
00107         
00108         static CMaterial mat;
00109         mat.setDoubleSided(true);
00110         mat.setLighting(false);
00111         mat.setZFunc(CMaterial::always);
00112 /*      mat.setColor(CRGBA::Red);
00113         mat.texEnvOpRGB(0, CMaterial::Add); */
00114         
00115         static CVertexBuffer  vb;
00116         vb.setVertexFormat(CVertexBuffer::PositionFlag | CVertexBuffer::TexCoord0Flag);
00117         
00118         
00119 
00120         drv->setFrustum(0, (float) _Width, 0, (float) _Height, -1, 1, false);
00121         drv->setupViewMatrix(CMatrix::Identity);
00122         drv->setupModelMatrix(CMatrix::Identity);
00123 
00124 
00125         const float iDu = 1.f / _Width;
00126         const float iDv = 1.f / _Height;
00127         const float widthRatio = _Width / (float) realWidth;
00128         const float heightRatio = _Height / (float) realHeight;
00129 
00130 
00131         float u, u2, v;
00132         float du, dv;
00133         
00134         TPoint2DVect::const_iterator it;
00135 
00136         // get back datas from frame buffer
00137         for (it = dest.begin(); it != dest.end(); ++it)
00138         {
00139                 drv->copyFrameBufferToTexture(_Tex, 0, (uint32) it->x,(uint32) it->y, (uint32) it->x, (uint32) it->y, _XGranularity, _YGranularity);            
00140         }
00141 
00142 
00146         vb.setNumVertices(dest.size() << 2);
00147         mat.setTexture(0, _Tex);
00148         uint k = 0; // current index in the vertex buffer
00149         for (it = dest.begin(); it != dest.end(); ++it, k += 4)
00150         {
00151 
00152                 // \todo optimize this by a direct access to the vertex buffer (if needed)
00153                 // blit data to frame buffer and apply deformations
00154 
00155                 vb.setVertexCoord(k, NLMISC::CVector(it->x, 0, it->y));
00156                 vb.setVertexCoord(k + 1, NLMISC::CVector(it->x + _XGranularity, 0, it->y));
00157                 vb.setVertexCoord(k + 2, NLMISC::CVector(it->x + _XGranularity, 0, it->y + _YGranularity));
00158                 vb.setVertexCoord(k + 3, NLMISC::CVector(it->x , 0, it->y + _YGranularity));
00159 
00160                 // perturbation of the uv coordinates
00161 
00162                 u =  it->x * iDu;
00163                 v = it->y * iDv;
00164             uvp->perturbUV(u, v, du, dv);
00165                 vb.setTexCoord(k, 0, (u + du) * widthRatio, (v + dv) * heightRatio );   
00166 
00167                 u2 =  (it->x + _XGranularity) * iDu;
00168                 uvp->perturbUV(u2, v, du, dv);
00169                 vb.setTexCoord(k + 1, 0, (u2 + du) * widthRatio, (v + dv) * heightRatio );      
00170 
00171                 v =  (it->y + _YGranularity) * iDv;
00172                 uvp->perturbUV(u2, v, du, dv);
00173                 vb.setTexCoord(k + 2, 0, (u2 + du) * widthRatio, (v + dv) * heightRatio );      
00174 
00175                 uvp->perturbUV(u, v, du, dv);
00176                 vb.setTexCoord(k + 3, 0, (u + du) * widthRatio, (v + dv) * heightRatio );       
00177         }
00178 
00179         drv->activeVertexBuffer(vb);
00180         drv->renderQuads(mat, 0, dest.size());
00181 }

void NL3D::CDeform2d::setupBuffer uint  width,
uint  height,
uint  xGranularity,
uint  yGranularity,
uint  xQuad,
uint  yQuad
[static]
 

resize the granularity of buffers for fxs

Parameters:
width frameBuffer width
height framebuffer height
xGranularity width of the quads taken from the framebuffer
yGranularity height of the quads taken from the framebuffer
xQuad width of the quads used to draw the fx (this is usually lower than xGanularity)
yQuad height of the quads used to draw the fx (this is usually lower than yGanularity)

Definition at line 55 of file deform_2d.cpp.

References _Tex, _XGranularity, _XQuad, _YGranularity, _YQuad, height, NLMISC::raiseToNextPowerOf2(), uint, and width.

00057 {
00058         _Width  = width;
00059         _Height = height;
00060         _XGranularity = xGranularity;
00061         _YGranularity = yGranularity;
00062         _XQuad = xQuad;
00063         _YQuad = yQuad;
00064 
00065         uint realWidth = NLMISC::raiseToNextPowerOf2(_Width);
00066         uint realHeight= NLMISC::raiseToNextPowerOf2(_Height);
00067 
00068         _Tex = new CTextureBlank;
00069         _Tex->resize(realWidth, realHeight, CBitmap::RGBA);
00070 }


Field Documentation

uint NL3D::CDeform2d::_Height [static, protected]
 

Definition at line 47 of file deform_2d.cpp.

NLMISC::CSmartPtr< ITexture > NL3D::CDeform2d::_Tex [static, protected]
 

Definition at line 52 of file deform_2d.cpp.

Referenced by doDeform(), and setupBuffer().

uint NL3D::CDeform2d::_Width [static, protected]
 

Definition at line 46 of file deform_2d.cpp.

uint NL3D::CDeform2d::_XGranularity [static, protected]
 

Definition at line 48 of file deform_2d.cpp.

Referenced by doDeform(), and setupBuffer().

uint NL3D::CDeform2d::_XQuad [static, protected]
 

Definition at line 50 of file deform_2d.cpp.

Referenced by setupBuffer().

uint NL3D::CDeform2d::_YGranularity [static, protected]
 

Definition at line 49 of file deform_2d.cpp.

Referenced by doDeform(), and setupBuffer().

uint NL3D::CDeform2d::_YQuad [static, protected]
 

Definition at line 51 of file deform_2d.cpp.

Referenced by setupBuffer().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 06:45:28 2004 for NeL by doxygen 1.3.6