NL3D::CComputedString Struct Reference

#include <computed_string.h>


Detailed Description

CComputedString A CComputedString is a structure which permits to render a string in a driver. It computes 4 vertices per char the renderer draw quads from them.

Author:
Stephane Coutelas

Nevrax France

Date:
2000

Definition at line 82 of file computed_string.h.

Public Types

enum  THotSpot {
  BottomLeft = 0, MiddleLeft, TopLeft, MiddleBottom,
  MiddleMiddle, MiddleTop, BottomRight, MiddleRight,
  TopRight, HotSpotCount
}

Public Member Functions

 CComputedString (bool bSetupVB=true)
CVector getHotSpotVector (THotSpot hotspot)
void render2D (IDriver &driver, float x, float z, THotSpot hotspot=BottomLeft, float scaleX=1, float scaleZ=1, float rotateY=0, bool useScreenAR43=false, bool roundToNearestPixel=true)
void render2DClip (IDriver &driver, CRenderStringBuffer &rdrBuffer, float x, float z, float xmin=0, float ymin=0, float xmax=1, float ymax=1)
void render2DUnProjected (IDriver &driver, CRenderStringBuffer &rdrBuffer, class NL3D::CFrustum &frustum, const NLMISC::CMatrix &scaleMatrix, float x, float z, float depth, float xmin=0, float ymin=0, float xmax=1, float ymax=1)
void render3D (IDriver &driver, CMatrix matrix, THotSpot hotspot=MiddleMiddle)

Data Fields

CRGBA Color
CMaterialMaterial
uint32 SelectSize
uint32 SelectStart
 Optionnal: each render*() method can draw a subset of letters. Default is 0/FFFFFFFF.

float StringHeight
 The height of the string, in pixels (eg: 10).

float StringLine
float StringWidth
 The width of the string, in pixels (eg: 30).

CVertexBuffer Vertices
float XMax
 The BBox of all vertices. used for render2DClip().

float XMin
 The BBox of all vertices. used for render2DClip().

float ZMax
 The BBox of all vertices. used for render2DClip().

float ZMin
 The BBox of all vertices. used for render2DClip().


Member Enumeration Documentation

enum NL3D::CComputedString::THotSpot
 

Hotspot positions (origine for the string placement) You should take care that for vertical hotspot, an imaginary line is defined under letters with no leg (like m,b,c etc..) between the leg of p and the loop of the p.

Enumeration values:
BottomLeft 
MiddleLeft 
TopLeft 
MiddleBottom 
MiddleMiddle 
MiddleTop 
BottomRight 
MiddleRight 
TopRight 
HotSpotCount 

Definition at line 112 of file computed_string.h.

00113         {
00114                 BottomLeft=0,
00115                 MiddleLeft, 
00116                 TopLeft,
00117                 MiddleBottom, 
00118                 MiddleMiddle, 
00119                 MiddleTop, 
00120                 BottomRight, 
00121                 MiddleRight,
00122                 TopRight,
00123 
00124                 HotSpotCount
00125         };


Constructor & Destructor Documentation

NL3D::CComputedString::CComputedString bool  bSetupVB = true  )  [inline]
 

Default constructor

Definition at line 130 of file computed_string.h.

References SelectSize, SelectStart, NL3D::CVertexBuffer::setVertexFormat(), StringHeight, and StringWidth.

00131         {
00132                 StringWidth = 0;
00133                 StringHeight = 0;
00134                 if (bSetupVB)
00135                 {
00136                         Vertices.setVertexFormat (CVertexBuffer::PositionFlag | CVertexBuffer::TexCoord0Flag);
00137                 }
00138                 SelectStart= 0;
00139                 SelectSize= ~0;
00140         }


Member Function Documentation

CVector NL3D::CComputedString::getHotSpotVector THotSpot  hotspot  ) 
 

Get the string's origin

Parameters:
hotspot the origin of the string

Definition at line 49 of file computed_string.cpp.

References BottomRight, MiddleBottom, MiddleLeft, MiddleMiddle, MiddleRight, MiddleTop, StringHeight, StringWidth, TopLeft, and TopRight.

Referenced by render2D(), and render3D().

00050 {
00051         CVector hotspotVector(0,0,0);
00052 
00053         if (hotspot==MiddleLeft)
00054                 hotspotVector = CVector(0,0,-StringHeight/2);
00055         
00056         if (hotspot==TopLeft)
00057                 hotspotVector = CVector(0,0,-StringHeight);
00058         
00059         if (hotspot==MiddleBottom)
00060                 hotspotVector = CVector(-StringWidth/2,0,0);
00061         
00062         if (hotspot==MiddleMiddle)
00063                 hotspotVector = CVector(-StringWidth/2,0,-StringHeight/2);
00064         
00065         if (hotspot==MiddleTop)
00066                 hotspotVector = CVector(-StringWidth/2,0,-StringHeight);
00067         
00068         if (hotspot==BottomRight)
00069                 hotspotVector = CVector(-StringWidth,0,0);
00070         
00071         if (hotspot==MiddleRight)
00072                 hotspotVector = CVector(-StringWidth,0,-StringHeight/2);
00073         
00074         if (hotspot==TopRight)
00075                 hotspotVector = CVector(-StringWidth,0,-StringHeight);
00076 
00077         return hotspotVector;
00078 }

void NL3D::CComputedString::render2D IDriver driver,
float  x,
float  z,
THotSpot  hotspot = BottomLeft,
float  scaleX = 1,
float  scaleZ = 1,
float  rotateY = 0,
bool  useScreenAR43 = false,
bool  roundToNearestPixel = true
 

Render the unicode string in a driver.

Parameters:
driver the driver where to render the primitives
x abscissa
y ordinate
hotspot position of string origine
scaleX abscissa scale
scaleY ordinate scale
rotateY rotation angle (axe perpendicular to screen)
useScreenAR43 if false then string is displayed with a pixel Ratio 1:1 (independent of window resolution). if true, the string is scaled according to window width and height, to support 4:3 aspect ratio even on weird screen resolution such as 640*240 (ie the char still look square, but the pixel ratio is 2:1)
roundToNearestPixel if true, snap the final string position to the nearest pixel. if set to true, and if useScreenAR43= false, you are sure that texels of the fonts fit exactly on centers of pixels (no apparent bi-linear).

Definition at line 84 of file computed_string.cpp.

References NL3D::IDriver::activeVertexBuffer(), Color, getHotSpotVector(), NL3D::CVertexBuffer::getNumVertices(), NL3D::IDriver::getWindowSize(), Material, matrix, min, NL3D::IDriver::renderQuads(), SelectSize, SelectStart, NL3D::CMaterial::setColor(), NL3D::IDriver::setFrustum(), NL3D::IDriver::setupModelMatrix(), NL3D::IDriver::setupViewMatrix(), NL3D::CMaterial::setZFunc(), NL3D::CMaterial::setZWrite(), uint32, NLMISC::CVector::x, x, NLMISC::CVector::z, and z.

Referenced by NL3D::CTextContext::printAt(), and NL3D::CTextContext::printfAt().

00091 {
00092         if (Vertices.getNumVertices() == 0)
00093                 return;
00094 
00095         // get window size
00096         uint32  wndWidth, wndHeight;
00097         driver.getWindowSize(wndWidth, wndHeight);
00098         // scale to window size.
00099         x*= wndWidth;
00100         z*= wndHeight;
00101 
00102         driver.setFrustum(0, (float)wndWidth, 0, (float)wndHeight, -1, 1, false);  // resX/resY
00103 
00104         // Computing hotspot translation vector
00105         CVector hotspotVector = getHotSpotVector(hotspot);
00106 
00107         // tansformation matrix initialized to identity
00108         CMatrix matrix;
00109         matrix.identity();
00110                 
00111         // view matrix <-> identity
00112         driver.setupViewMatrix(matrix);
00113 
00114         // model matrix :
00115         // centering to hotspot, then scaling, rotating, and translating.
00116         matrix.translate(CVector(x,0,z));
00117         matrix.rotateY(rotateY);
00118         matrix.scale(CVector(scaleX,1,scaleZ));
00119         // scale the string to follow window aspect Ratio
00120         if(useScreenAR43)
00121         {
00122                 matrix.scale(CVector((3.0f*wndWidth)/(4.0f*wndHeight),1,1));
00123         }
00124         matrix.translate(hotspotVector);
00125         // if roundToNearestPixel, then snap the position to the nearest pixel
00126         if( roundToNearestPixel)
00127         {
00128                 CVector pos= matrix.getPos();
00129                 pos.x= (float)floor(pos.x+0.5f);
00130                 pos.z= (float)floor(pos.z+0.5f);
00131                 matrix.setPos(pos);
00132         }
00133         // setup the matrix
00134         driver.setupModelMatrix(matrix);
00135         
00136         driver.activeVertexBuffer(Vertices);
00137 
00138         // rendering each primitives 
00139         Material->setZFunc (CMaterial::always);
00140         Material->setZWrite (false);
00141         Material->setColor (Color);
00142         // Clamp for selection
00143         uint32  nNumQuad= Vertices.getNumVertices()/4;
00144         driver.renderQuads (*Material, SelectStart, min(nNumQuad, SelectSize) );
00145 }

void NL3D::CComputedString::render2DClip IDriver driver,
CRenderStringBuffer rdrBuffer,
float  x,
float  z,
float  xmin = 0,
float  ymin = 0,
float  xmax = 1,
float  ymax = 1
 

Special for interface. same as render2D but clip the quads to xmin,ymin/xmax,ymax. NB: behavior is same as render2D with: Hotspot = bottomLeft, scaleX=1, scaleZ=1, rotateY=0, useScreenAR43= false, roundToNearestPixel= false Additionnaly, this method don't render directly to the driver but add primitives to a CRenderStringBuffer Use the method CRenderStringBuffer::flush() to flush it all.

Definition at line 183 of file computed_string.cpp.

References Color, NL3D::CVertexBuffer::getColorOff(), NL3D::CVertexBuffer::getNumVertices(), NL3D::CVertexBuffer::getTexCoordOff(), NL3D::CVertexBuffer::getVertexCoordPointer(), NL3D::CVertexBuffer::getVertexSize(), NL3D::IDriver::getWindowSize(), min, NL3D::CRenderStringBuffer::NumQuads, SelectSize, SelectStart, NL3D::CVertexBuffer::setNumVertices(), sint, NLMISC::CUV::U, uint, uint32, uint8, NLMISC::CUV::V, NL3D::CRenderStringBuffer::Vertices, NLMISC::CVector::x, x, XMax, XMin, NLMISC::CVector::z, z, ZMax, and ZMin.

Referenced by NL3D::CTextContext::printClipAt().

00186 {
00187         if (Vertices.getNumVertices() == 0)
00188                 return;
00189         if(SelectSize==0)
00190                 return;
00191 
00192         // get window size
00193         uint32  wndWidth, wndHeight;
00194         driver.getWindowSize(wndWidth, wndHeight);
00195         // scale to window size.
00196         x*= wndWidth;
00197         z*= wndHeight;
00198         xmin*= wndWidth;
00199         xmax*= wndWidth;
00200         zmin*= wndHeight;
00201         zmax*= wndHeight;
00202 
00203         // Test String Bound against clip window
00204         // If entirely out skip
00205         if (((x+XMin) > xmax) || ((x+XMax) < xmin) ||
00206                 ((z+ZMin) > zmax) || ((z+ZMax) < zmin))
00207                 return;
00208 
00209         // test if entirely in.
00210         bool    allIn;
00211         allIn=  ((x+XMin) >= xmin) && ((x+XMax) <= xmax) &&
00212                         ((z+ZMin) >= zmin) && ((z+ZMax) <= zmax);
00213 
00214 
00215         // How many quad to render?
00216         uint    nNumQuadSrc= Vertices.getNumVertices()/4;
00217         nNumQuadSrc= min(nNumQuadSrc, (uint)SelectSize);
00218 
00219         // Enlarge dest Buffer if needed
00220         if( (rdrBuffer.NumQuads+nNumQuadSrc)*4 > rdrBuffer.Vertices.getNumVertices() )
00221         {
00222                 rdrBuffer.Vertices.setNumVertices( (rdrBuffer.NumQuads+nNumQuadSrc)*4 );
00223         }
00224 
00225         // prepare copy.
00226         sint    ofsSrcUV= Vertices.getTexCoordOff();
00227         sint    ofsDstUV= rdrBuffer.Vertices.getTexCoordOff();
00228         sint    ofsDstColor= rdrBuffer.Vertices.getColorOff();
00229         uint8   *srcPtr= (uint8*)Vertices.getVertexCoordPointer();
00230         uint8   *dstPtr= (uint8*)rdrBuffer.Vertices.getVertexCoordPointer(rdrBuffer.NumQuads*4);
00231         sint    srcSize= Vertices.getVertexSize();
00232         sint    dstSize= rdrBuffer.Vertices.getVertexSize();
00233 
00234         // decal src for selection
00235         srcPtr+= SelectStart*4 * srcSize;
00236 
00237         // **** clipping?
00238         if(allIn)
00239         {
00240                 // copy All vertices 
00241                 uint numVerts= nNumQuadSrc*4;
00242                 for(uint i=0;i<numVerts;i++)
00243                 {
00244                         // copy and translate pos
00245                         ((CVector*)dstPtr)->x= x + ((CVector*)srcPtr)->x;
00246                         ((CVector*)dstPtr)->y= ((CVector*)srcPtr)->y;
00247                         ((CVector*)dstPtr)->z= z + ((CVector*)srcPtr)->z;
00248                         // uv
00249                         *((CUV*)(dstPtr+ofsDstUV))= *((CUV*)(srcPtr+ofsSrcUV));
00250                         // color
00251                         *((CRGBA*)(dstPtr+ofsDstColor))= Color;
00252 
00253                         // next
00254                         srcPtr+= srcSize;
00255                         dstPtr+= dstSize;
00256                 }
00257 
00258                 // update the rdrBuffer
00259                 rdrBuffer.NumQuads+= nNumQuadSrc;
00260         }
00261         else
00262         {
00263                 uint    nNumQuadClipped= 0;
00264 
00265                 // the real number of vertices to comute (with selection)
00266                 uint    numVerts= nNumQuadSrc*4;
00267 
00268                 // clip into VerticesClipped
00269                 CVector *pIniPos0 = (CVector*)srcPtr;
00270                 CVector *pIniPos2 = (CVector*)(((uint8*)pIniPos0) + srcSize*2);
00271                 CVector *pClipPos0 = (CVector*)dstPtr;
00272                 CVector *pClipPos1 = (CVector*)(((uint8*)pClipPos0) + dstSize);
00273                 CVector *pClipPos2 = (CVector*)(((uint8*)pClipPos1) + dstSize);
00274                 CVector *pClipPos3 = (CVector*)(((uint8*)pClipPos2) + dstSize);
00275                 CUV *pClipUV0 = (CUV*)(dstPtr + ofsDstUV );
00276                 CUV *pClipUV1 = (CUV*)(((uint8*)pClipUV0) + dstSize);
00277                 CUV *pClipUV2 = (CUV*)(((uint8*)pClipUV1) + dstSize);
00278                 CUV *pClipUV3 = (CUV*)(((uint8*)pClipUV2) + dstSize);
00279                 float ratio;
00280                 for (uint32 i = 0; i < numVerts; i+=4)
00281                 {
00282                         if (((x+pIniPos0->x) > xmax) || ((x+pIniPos2->x) < xmin) ||
00283                                 ((z+pIniPos0->z) > zmax) || ((z+pIniPos2->z) < zmin))
00284                         {
00285                                 // Totally clipped do nothing
00286                         }
00287                         else
00288                         {
00289                                 // copy with no clip
00290                                 // v0
00291                                 *((CVector*) (dstPtr + dstSize*0))= *((CVector*) (srcPtr + srcSize*0));
00292                                 *((CUV*)         (dstPtr + dstSize*0 + ofsDstUV))= *((CUV*)(srcPtr + srcSize*0 + ofsSrcUV));
00293                                 *((CRGBA*)       (dstPtr + dstSize*0 + ofsDstColor))= Color;
00294                                 // v1
00295                                 *((CVector*) (dstPtr + dstSize*1))= *((CVector*) (srcPtr + srcSize*1));
00296                                 *((CUV*)         (dstPtr + dstSize*1 + ofsDstUV))= *((CUV*)(srcPtr + srcSize*1 + ofsSrcUV));
00297                                 *((CRGBA*)       (dstPtr + dstSize*1 + ofsDstColor))= Color;
00298                                 // v2
00299                                 *((CVector*) (dstPtr + dstSize*2))= *((CVector*) (srcPtr + srcSize*2));
00300                                 *((CUV*)         (dstPtr + dstSize*2 + ofsDstUV))= *((CUV*)(srcPtr + srcSize*2 + ofsSrcUV));
00301                                 *((CRGBA*)       (dstPtr + dstSize*2 + ofsDstColor))= Color;
00302                                 // v3
00303                                 *((CVector*) (dstPtr + dstSize*3))= *((CVector*) (srcPtr + srcSize*3));
00304                                 *((CUV*)         (dstPtr + dstSize*3 + ofsDstUV))= *((CUV*)(srcPtr + srcSize*3 + ofsSrcUV));
00305                                 *((CRGBA*)       (dstPtr + dstSize*3 + ofsDstColor))= Color;
00306 
00307 
00308                                 // translate dest
00309                                 pClipPos0->x += x; pClipPos1->x += x; pClipPos2->x += x; pClipPos3->x += x;
00310                                 pClipPos0->z += z; pClipPos1->z += z; pClipPos2->z += z; pClipPos3->z += z;
00311                                 if ((pClipPos0->x >= xmin) && (pClipPos0->z >= zmin) && (pClipPos2->x <= xmax) && (pClipPos2->z <= zmax))
00312                                 {
00313                                         // Not clipped
00314                                 }
00315                                 else
00316                                 {
00317                                         // Partially clipped
00318 
00319                                         if (pClipPos0->x < xmin)
00320                                         {
00321                                                 ratio = ((float)(xmin - pClipPos0->x))/((float)(pClipPos1->x - pClipPos0->x));
00322                                                 pClipPos3->x = pClipPos0->x = xmin;
00323                                                 pClipUV0->U += ratio*(pClipUV1->U - pClipUV0->U);
00324                                                 pClipUV3->U += ratio*(pClipUV2->U - pClipUV3->U);
00325                                         }
00326 
00327                                         if (pClipPos0->z < zmin)
00328                                         {
00329                                                 ratio = ((float)(zmin - pClipPos0->z))/((float)(pClipPos3->z - pClipPos0->z));
00330                                                 pClipPos1->z = pClipPos0->z = zmin;
00331                                                 pClipUV0->V += ratio*(pClipUV3->V - pClipUV0->V);
00332                                                 pClipUV1->V += ratio*(pClipUV2->V - pClipUV1->V);
00333                                         }
00334 
00335                                         if (pClipPos2->x > xmax)
00336                                         {
00337                                                 ratio = ((float)(xmax - pClipPos2->x))/((float)(pClipPos3->x - pClipPos2->x));
00338                                                 pClipPos2->x = pClipPos1->x = xmax;
00339                                                 pClipUV2->U += ratio*(pClipUV3->U - pClipUV2->U);
00340                                                 pClipUV1->U += ratio*(pClipUV0->U - pClipUV1->U);
00341                                         }
00342 
00343                                         if (pClipPos2->z > zmax)
00344                                         {
00345                                                 ratio = ((float)(zmax - pClipPos2->z))/((float)(pClipPos1->z - pClipPos2->z));
00346                                                 pClipPos2->z = pClipPos3->z = zmax;
00347                                                 pClipUV2->V += ratio*(pClipUV1->V - pClipUV2->V);
00348                                                 pClipUV3->V += ratio*(pClipUV0->V - pClipUV3->V);
00349                                         }
00350                                 }
00351 
00352                                 // next quad out
00353                                 ++nNumQuadClipped;
00354                                 pClipPos0 = (CVector*)(((uint8*)pClipPos0) + dstSize*4);
00355                                 pClipPos1 = (CVector*)(((uint8*)pClipPos0) + dstSize);
00356                                 pClipPos2 = (CVector*)(((uint8*)pClipPos1) + dstSize);
00357                                 pClipPos3 = (CVector*)(((uint8*)pClipPos2) + dstSize);
00358                                 pClipUV0 = (CUV*)( ((uint8*)pClipUV0) + dstSize*4 );
00359                                 pClipUV1 = (CUV*)(((uint8*)pClipUV0) + dstSize);
00360                                 pClipUV2 = (CUV*)(((uint8*)pClipUV1) + dstSize);
00361                                 pClipUV3 = (CUV*)(((uint8*)pClipUV2) + dstSize);
00362                                 dstPtr+=  4*dstSize;
00363                         }
00364                         // next quad in
00365                         pIniPos0 = (CVector*)(((uint8*)pIniPos0) + srcSize*4);
00366                         pIniPos2 = (CVector*)(((uint8*)pIniPos0) + srcSize*2);
00367                         srcPtr+=  4*srcSize;
00368                 }
00369 
00370                 // update the rdrBuffer
00371                 rdrBuffer.NumQuads+= nNumQuadClipped;
00372         }
00373 }

void NL3D::CComputedString::render2DUnProjected IDriver driver,
CRenderStringBuffer rdrBuffer,
class NL3D::CFrustum frustum,
const NLMISC::CMatrix scaleMatrix,
float  x,
float  z,
float  depth,
float  xmin = 0,
float  ymin = 0,
float  xmax = 1,
float  ymax = 1
 

Special for interface. same as render2DClip but unproject the vertices using a frustum and a scale matrix Use the method CRenderStringBuffer::flush() to flush it all.

Definition at line 378 of file computed_string.cpp.

References Color, depth, NL3D::CVertexBuffer::getColorOff(), NL3D::CVertexBuffer::getNumVertices(), NL3D::CVertexBuffer::getTexCoordOff(), NL3D::CVertexBuffer::getVertexCoordPointer(), NL3D::CVertexBuffer::getVertexSize(), NL3D::IDriver::getWindowSize(), min, NL3D::CRenderStringBuffer::NumQuads, SelectSize, SelectStart, NL3D::CVertexBuffer::setNumVertices(), sint, NLMISC::CUV::U, uint, uint32, uint8, NLMISC::CUV::V, NL3D::CRenderStringBuffer::Vertices, NLMISC::CVector::x, x, XMax, XMin, NLMISC::CVector::y, NLMISC::CVector::z, z, ZMax, and ZMin.

Referenced by NL3D::CTextContext::printClipAtUnProjected().

00380 {
00381         if (Vertices.getNumVertices() == 0)
00382                 return;
00383         if(SelectSize==0)
00384                 return;
00385 
00386         // get window size
00387         uint32  wndWidth, wndHeight;
00388         driver.getWindowSize(wndWidth, wndHeight);
00389         // scale to window size.
00390         x*= wndWidth;
00391         z*= wndHeight;
00392         xmin*= wndWidth;
00393         xmax*= wndWidth;
00394         zmin*= wndHeight;
00395         zmax*= wndHeight;
00396 
00397         // Test String Bound against clip window
00398         // If entirely out skip
00399         if (((x+XMin) > xmax) || ((x+XMax) < xmin) ||
00400                 ((z+ZMin) > zmax) || ((z+ZMax) < zmin))
00401                 return;
00402 
00403         // test if entirely in.
00404         bool    allIn;
00405         allIn=  ((x+XMin) >= (xmin-0.001f)) && ((x+XMax) <= (xmax+0.001f)) &&
00406                         ((z+ZMin) >= (zmin-0.001f)) && ((z+ZMax) <= (zmax+0.001f));
00407 
00408 
00409         // How many quad to render?
00410         uint    nNumQuadSrc= Vertices.getNumVertices()/4;
00411         nNumQuadSrc= min(nNumQuadSrc, (uint)SelectSize);
00412 
00413         // Enlarge dest Buffer if needed
00414         if( (rdrBuffer.NumQuads+nNumQuadSrc)*4 > rdrBuffer.Vertices.getNumVertices() )
00415         {
00416                 rdrBuffer.Vertices.setNumVertices( (rdrBuffer.NumQuads+nNumQuadSrc)*4 );
00417         }
00418 
00419         // prepare copy.
00420         sint    ofsSrcUV= Vertices.getTexCoordOff();
00421         sint    ofsDstUV= rdrBuffer.Vertices.getTexCoordOff();
00422         sint    ofsDstColor= rdrBuffer.Vertices.getColorOff();
00423         uint8   *srcPtr= (uint8*)Vertices.getVertexCoordPointer();
00424         uint8   *dstPtr= (uint8*)rdrBuffer.Vertices.getVertexCoordPointer(rdrBuffer.NumQuads*4);
00425         sint    srcSize= Vertices.getVertexSize();
00426         sint    dstSize= rdrBuffer.Vertices.getVertexSize();
00427 
00428         // decal src for selection
00429         srcPtr+= SelectStart*4 * srcSize;
00430 
00431         uint8   *dstPtrBackup = dstPtr;
00432 
00433         // **** clipping?
00434         if(allIn)
00435         {
00436                 // copy All vertices 
00437                 uint numVerts= nNumQuadSrc*4;
00438                 for(uint i=0;i<numVerts;i++)
00439                 {
00440                         // copy and translate pos
00441                         ((CVector*)dstPtr)->x= x + ((CVector*)srcPtr)->x;
00442                         ((CVector*)dstPtr)->z= z + ((CVector*)srcPtr)->z;
00443                         
00444                         // uv
00445                         *((CUV*)(dstPtr+ofsDstUV))= *((CUV*)(srcPtr+ofsSrcUV));
00446                         // color
00447                         *((CRGBA*)(dstPtr+ofsDstColor))= Color;
00448 
00449                         // next
00450                         srcPtr+= srcSize;
00451                         dstPtr+= dstSize;
00452                 }
00453 
00454                 // update the rdrBuffer
00455                 rdrBuffer.NumQuads+= nNumQuadSrc;
00456         }
00457         else
00458         {
00459                 uint    nNumQuadClipped= 0;
00460 
00461                 // the real number of vertices to comute (with selection)
00462                 uint    numVerts= nNumQuadSrc*4;
00463 
00464                 // clip into VerticesClipped
00465                 CVector *pIniPos0 = (CVector*)srcPtr;
00466                 CVector *pIniPos2 = (CVector*)(((uint8*)pIniPos0) + srcSize*2);
00467                 CVector *pClipPos0 = (CVector*)dstPtr;
00468                 CVector *pClipPos1 = (CVector*)(((uint8*)pClipPos0) + dstSize);
00469                 CVector *pClipPos2 = (CVector*)(((uint8*)pClipPos1) + dstSize);
00470                 CVector *pClipPos3 = (CVector*)(((uint8*)pClipPos2) + dstSize);
00471                 CUV *pClipUV0 = (CUV*)(dstPtr + ofsDstUV );
00472                 CUV *pClipUV1 = (CUV*)(((uint8*)pClipUV0) + dstSize);
00473                 CUV *pClipUV2 = (CUV*)(((uint8*)pClipUV1) + dstSize);
00474                 CUV *pClipUV3 = (CUV*)(((uint8*)pClipUV2) + dstSize);
00475                 float ratio;
00476                 for (uint32 i = 0; i < numVerts; i+=4)
00477                 {
00478                         if (((x+pIniPos0->x) > xmax) || ((x+pIniPos2->x) < xmin) ||
00479                                 ((z+pIniPos0->z) > zmax) || ((z+pIniPos2->z) < zmin))
00480                         {
00481                                 // Totally clipped do nothing
00482                         }
00483                         else
00484                         {
00485                                 // copy with no clip
00486                                 // v0
00487                                 *((CVector*) (dstPtr + dstSize*0))= *((CVector*) (srcPtr + srcSize*0));
00488                                 *((CUV*)         (dstPtr + dstSize*0 + ofsDstUV))= *((CUV*)(srcPtr + srcSize*0 + ofsSrcUV));
00489                                 *((CRGBA*)       (dstPtr + dstSize*0 + ofsDstColor))= Color;
00490                                 // v1
00491                                 *((CVector*) (dstPtr + dstSize*1))= *((CVector*) (srcPtr + srcSize*1));
00492                                 *((CUV*)         (dstPtr + dstSize*1 + ofsDstUV))= *((CUV*)(srcPtr + srcSize*1 + ofsSrcUV));
00493                                 *((CRGBA*)       (dstPtr + dstSize*1 + ofsDstColor))= Color;
00494                                 // v2
00495                                 *((CVector*) (dstPtr + dstSize*2))= *((CVector*) (srcPtr + srcSize*2));
00496                                 *((CUV*)         (dstPtr + dstSize*2 + ofsDstUV))= *((CUV*)(srcPtr + srcSize*2 + ofsSrcUV));
00497                                 *((CRGBA*)       (dstPtr + dstSize*2 + ofsDstColor))= Color;
00498                                 // v3
00499                                 *((CVector*) (dstPtr + dstSize*3))= *((CVector*) (srcPtr + srcSize*3));
00500                                 *((CUV*)         (dstPtr + dstSize*3 + ofsDstUV))= *((CUV*)(srcPtr + srcSize*3 + ofsSrcUV));
00501                                 *((CRGBA*)       (dstPtr + dstSize*3 + ofsDstColor))= Color;
00502 
00503 
00504                                 // translate dest
00505                                 pClipPos0->x += x; pClipPos1->x += x; pClipPos2->x += x; pClipPos3->x += x;
00506                                 pClipPos0->z += z; pClipPos1->z += z; pClipPos2->z += z; pClipPos3->z += z;
00507                                 if ((pClipPos0->x >= xmin) && (pClipPos0->z >= zmin) && (pClipPos2->x <= xmax) && (pClipPos2->z <= zmax))
00508                                 {
00509                                         // Not clipped
00510                                 }
00511                                 else
00512                                 {
00513                                         // Partially clipped
00514 
00515                                         if (pClipPos0->x < xmin)
00516                                         {
00517                                                 ratio = ((float)(xmin - pClipPos0->x))/((float)(pClipPos1->x - pClipPos0->x));
00518                                                 pClipPos3->x = pClipPos0->x = xmin;
00519                                                 pClipUV0->U += ratio*(pClipUV1->U - pClipUV0->U);
00520                                                 pClipUV3->U += ratio*(pClipUV2->U - pClipUV3->U);
00521                                         }
00522 
00523                                         if (pClipPos0->z < zmin)
00524                                         {
00525                                                 ratio = ((float)(zmin - pClipPos0->z))/((float)(pClipPos3->z - pClipPos0->z));
00526                                                 pClipPos1->z = pClipPos0->z = zmin;
00527                                                 pClipUV0->V += ratio*(pClipUV3->V - pClipUV0->V);
00528                                                 pClipUV1->V += ratio*(pClipUV2->V - pClipUV1->V);
00529                                         }
00530 
00531                                         if (pClipPos2->x > xmax)
00532                                         {
00533                                                 ratio = ((float)(xmax - pClipPos2->x))/((float)(pClipPos3->x - pClipPos2->x));
00534                                                 pClipPos2->x = pClipPos1->x = xmax;
00535                                                 pClipUV2->U += ratio*(pClipUV3->U - pClipUV2->U);
00536                                                 pClipUV1->U += ratio*(pClipUV0->U - pClipUV1->U);
00537                                         }
00538 
00539                                         if (pClipPos2->z > zmax)
00540                                         {
00541                                                 ratio = ((float)(zmax - pClipPos2->z))/((float)(pClipPos1->z - pClipPos2->z));
00542                                                 pClipPos2->z = pClipPos3->z = zmax;
00543                                                 pClipUV2->V += ratio*(pClipUV1->V - pClipUV2->V);
00544                                                 pClipUV3->V += ratio*(pClipUV0->V - pClipUV3->V);
00545                                         }
00546                                 }
00547                                 
00548                                 // next quad out
00549                                 ++nNumQuadClipped;
00550                                 pClipPos0 = (CVector*)(((uint8*)pClipPos0) + dstSize*4);
00551                                 pClipPos1 = (CVector*)(((uint8*)pClipPos0) + dstSize);
00552                                 pClipPos2 = (CVector*)(((uint8*)pClipPos1) + dstSize);
00553                                 pClipPos3 = (CVector*)(((uint8*)pClipPos2) + dstSize);
00554                                 pClipUV0 = (CUV*)( ((uint8*)pClipUV0) + dstSize*4 );
00555                                 pClipUV1 = (CUV*)(((uint8*)pClipUV0) + dstSize);
00556                                 pClipUV2 = (CUV*)(((uint8*)pClipUV1) + dstSize);
00557                                 pClipUV3 = (CUV*)(((uint8*)pClipUV2) + dstSize);
00558                                 dstPtr+=  4*dstSize;
00559                         }
00560                         // next quad in
00561                         pIniPos0 = (CVector*)(((uint8*)pIniPos0) + srcSize*4);
00562                         pIniPos2 = (CVector*)(((uint8*)pIniPos0) + srcSize*2);
00563                         srcPtr+=  4*srcSize;
00564                 }
00565 
00566                 // update the rdrBuffer
00567                 rdrBuffer.NumQuads+= nNumQuadClipped;
00568         }
00569 
00570         const float OOW = 1.f / (float)wndWidth;
00571         const float OOH = 1.f / (float)wndHeight;
00572         
00573         while (dstPtrBackup != dstPtr)
00574         {
00575                 // preset unprojection
00576                 CVector tmp;
00577                 tmp.x = ((CVector*)dstPtrBackup)->x * OOW;
00578                 tmp.y = ((CVector*)dstPtrBackup)->z * OOH;
00579                 tmp.z = depth;
00580                 // mul by user scale matrix
00581                 tmp= scaleMatrix * tmp;
00582                 // Unproject it
00583                 *((CVector*)dstPtrBackup) = frustum.unProjectZ(tmp);
00584                 dstPtrBackup += dstSize;
00585         }
00586         
00587 }

void NL3D::CComputedString::render3D IDriver driver,
CMatrix  matrix,
THotSpot  hotspot = MiddleMiddle
 

Render the unicode string in a driver, in 3D with a user matrix. NB: size of the string is first scaled by 1/windowHeight.

Parameters:
driver the driver where to render the primitives
matrix transformation matrix
hotspot position of string origine

Definition at line 151 of file computed_string.cpp.

References NL3D::IDriver::activeVertexBuffer(), Color, getHotSpotVector(), NL3D::CVertexBuffer::getNumVertices(), NL3D::IDriver::getWindowSize(), Material, matrix, min, NL3D::IDriver::renderQuads(), SelectSize, SelectStart, NL3D::CMaterial::setColor(), NL3D::IDriver::setupModelMatrix(), NL3D::CMaterial::setZFunc(), NL3D::CMaterial::setZWrite(), and uint32.

Referenced by NL3D::CInstanceGroup::displayDebugClusters(), NL3D::CPSUtil::print(), and NL3D::CTextContextUser::render3D().

00152 {
00153         if (Vertices.getNumVertices() == 0)
00154                 return;
00155 
00156         // get window size
00157         uint32  wndWidth, wndHeight;
00158         driver.getWindowSize(wndWidth, wndHeight);
00159         // scale according to window height (backward compatibility)
00160         matrix.scale(1.0f/wndHeight);
00161 
00162         // Computing hotspot translation vector
00163         CVector hotspotVector = getHotSpotVector(hotspot);
00164         matrix.translate(hotspotVector);
00165 
00166         // render
00167         driver.setupModelMatrix(matrix);
00168         driver.activeVertexBuffer(Vertices);
00169 
00170         // Rendering each primitive blocks
00171         Material->setZFunc (CMaterial::lessequal);
00172         Material->setZWrite (true);
00173         Material->setColor (Color);
00174         // Clamp for selection
00175         uint32  nNumQuad= Vertices.getNumVertices()/4;
00176         driver.renderQuads (*Material, SelectStart, min(nNumQuad, SelectSize) );
00177 }


Field Documentation

CRGBA NL3D::CComputedString::Color
 

Definition at line 88 of file computed_string.h.

Referenced by NL3D::CFontManager::computeString(), NL3D::CFontManager::computeStringInfo(), NL3D::CTextContext::printAt(), NL3D::CTextContext::printClipAt(), NL3D::CTextContext::printClipAtUnProjected(), NL3D::CTextContext::printfAt(), render2D(), render2DClip(), render2DUnProjected(), render3D(), and NL3D::CTextContextUser::setStringColor().

CMaterial* NL3D::CComputedString::Material
 

Definition at line 87 of file computed_string.h.

Referenced by NL3D::CFontManager::computeString(), render2D(), and render3D().

uint32 NL3D::CComputedString::SelectSize
 

Definition at line 105 of file computed_string.h.

Referenced by CComputedString(), render2D(), render2DClip(), render2DUnProjected(), and render3D().

uint32 NL3D::CComputedString::SelectStart
 

Optionnal: each render*() method can draw a subset of letters. Default is 0/FFFFFFFF.

Definition at line 104 of file computed_string.h.

Referenced by CComputedString(), render2D(), render2DClip(), render2DUnProjected(), and render3D().

float NL3D::CComputedString::StringHeight
 

The height of the string, in pixels (eg: 10).

Definition at line 92 of file computed_string.h.

Referenced by CComputedString(), NL3D::CFontManager::computeString(), NL3D::CFontManager::computeStringInfo(), getHotSpotVector(), and NL3D::CTextContextUser::getStringInfo().

float NL3D::CComputedString::StringLine
 

StringLine is the size from bottom of the whole string image to the hotspot in pixels. for instance if the hotspot is bottomLeft the imaginary line of the string "bpc" is under the b, under the loop of the p but over the leg of the p. So StringLine is a positive value in this case. It may be a negative value for the string "^" for example.

Definition at line 101 of file computed_string.h.

Referenced by NL3D::CFontManager::computeString(), NL3D::CFontManager::computeStringInfo(), and NL3D::CTextContextUser::getStringInfo().

float NL3D::CComputedString::StringWidth
 

The width of the string, in pixels (eg: 30).

Definition at line 90 of file computed_string.h.

Referenced by CComputedString(), NL3D::CFontManager::computeString(), NL3D::CFontManager::computeStringInfo(), getHotSpotVector(), and NL3D::CTextContextUser::getStringInfo().

CVertexBuffer NL3D::CComputedString::Vertices
 

Definition at line 86 of file computed_string.h.

Referenced by NL3D::CFontManager::computeString().

float NL3D::CComputedString::XMax
 

The BBox of all vertices. used for render2DClip().

Definition at line 94 of file computed_string.h.

Referenced by NL3D::CFontManager::computeString(), render2DClip(), and render2DUnProjected().

float NL3D::CComputedString::XMin
 

The BBox of all vertices. used for render2DClip().

Definition at line 94 of file computed_string.h.

Referenced by NL3D::CFontManager::computeString(), render2DClip(), and render2DUnProjected().

float NL3D::CComputedString::ZMax
 

The BBox of all vertices. used for render2DClip().

Definition at line 94 of file computed_string.h.

Referenced by NL3D::CFontManager::computeString(), render2DClip(), and render2DUnProjected().

float NL3D::CComputedString::ZMin
 

The BBox of all vertices. used for render2DClip().

Definition at line 94 of file computed_string.h.

Referenced by NL3D::CFontManager::computeString(), render2DClip(), and render2DUnProjected().


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