> renderObject extract: F32 wobX = 0.0f,"> GL Units, conversions and such ... | Torque Game Builder | Forums | Community | GarageGames.com

Game Development Community

GL Units, conversions and such ...

by Christian Armeanu · in Torque Game Builder · 09/21/2005 (6:32 pm) · 0 replies

Hi,

I am trying to create some fxSprite2D effect extensions, but got stuck with probably a unit conversion issue ... The following code is a simplified "wobble" extension I tried to visualize my problem:

>> renderObject extract:

F32 wobX = 0.0f, wobY = 0.0f;

//----------------------------------------------------------------------
// calculate and apply wobble effect if set
//----------------------------------------------------------------------
if( mWobbleXrate != 0 && mWobbleXfactor > 0 ) {
mWobXangle = mFmod(mWobXangle + mWobbleXrate, 360.0f);
F32 sin = mSin(mWobXangle);
wobX = mClampResolutionF( sin ) * mWobbleXfactor;
}

if( mWobbleYrate != 0 && mWobbleYfactor > 0 ) {
mWobYangle = mFmod(mWobYangle + mWobbleYrate, 360.0f);
F32 cos = mCos(mWobYangle);
wobY = mClampResolutionF( cos ) * mWobbleYfactor;
}
//----------------------------------------------------------------------

glEnable ( GL_TEXTURE_2D );
glBindTexture ( GL_TEXTURE_2D, mImageMapDataBlock->getImageMapTexture().getGLName() );
glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

// Set Blend Options.
setBlendOptions();

// Fetch Current Frame Region.
fxImageMapDatablock2D::tMapRegion region = mImageMapDataBlock->getImageMapRegion(mFrame);
/// Fetch Positions.
F32 minX = region.mMinX;
F32 minY = region.mMinY;
F32 maxX = region.mMaxX;
F32 maxY = region.mMaxY;

fxVector2D tmp[4];

tmp[0] = mWorldClipBoundary[0]+fxVector2D(-wobX,-wobY);
tmp[1] = mWorldClipBoundary[1]+fxVector2D(wobX,-wobY);
tmp[2] = mWorldClipBoundary[2]+fxVector2D(-wobX,wobY);
tmp[3] = mWorldClipBoundary[3]+fxVector2D(wobX,wobY);

// Draw Object.
glBegin(GL_QUADS);
glTexCoord2f( minX - wobX, minY - wobY );
glVertex2fv ( (GLfloat*)&(tmp[0]) );
glTexCoord2f( maxX + wobX, minY - wobY);
glVertex2fv ( (GLfloat*)&(tmp[1]) );
glTexCoord2f( maxX + wobX, maxY + wobY );
glVertex2fv ( (GLfloat*)&(tmp[2]) );
glTexCoord2f( minX - wobX , maxY + wobY );
glVertex2fv ( (GLfloat*)&(tmp[3]) );
glEnd();

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Now, with this code the sprite would "wobble", but however, the texture seems to grow/shrink at a different unit size as the vertex quad ... why, or better how do I get the quad to match the texture dimensions?

Thanks,
Chris