//-----------------------------------------------------------------------------
//
// Sets a texture translation transform
//
//-----------------------------------------------------------------------------
void CBaseShader::SetFixedFunctionTextureTranslation( MaterialMatrixMode_t textureTransform, int translationVar )
{
	Assert( !IsSnapshotting() );

	// handle scrolling of base texture
	Vector2D vDelta( 0, 0 );

	if (translationVar != -1)
	{
		s_ppParams[translationVar]->GetVecValue( vDelta.Base(), 2 );
	}

	if( vDelta[0] != 0.0f || vDelta[1] != 0.0f )
	{
		s_pShaderAPI->MatrixMode( textureTransform );

		// only do the upper 3x3 since this is a 2D matrix
		float mat[16];
		mat[0] = 1.0f;		mat[1] = 0.0f;		mat[2] = 0.0f;
		mat[4] = 0.0f;		mat[5] = 1.0f;		mat[6] = 0.0f;
		mat[8] = vDelta[0]; mat[9] = vDelta[1]; mat[10] = 1.0f;

		// Better set the stuff we don't set with some sort of value!
		mat[3] = mat[7] = mat[11] = 0;
		mat[12] = mat[13] = mat[14] = 0;
		mat[15] = 1;

		s_pShaderAPI->LoadMatrix( mat );
	}
	else
	{
		LoadIdentity( textureTransform );
	}
}
示例#2
0
void NtlGetDestination_Follow(float fCurrentHeadingVectorX, float fCurrentHeadingVectorZ, float fSpeedInSecs,
								float fCurrentPositionX, float fCurrentPositionY, float fCurrentPositionZ,
								float fDestinationX, float fDestinationY, float fDestinationZ,
								DWORD dwDeltaTimeInMillisecs,
								float fTargetDistance,
								CNtlVector* pNewHeadingVector, CNtlVector* pDestination)
{
	float fDeltaX = fDestinationX - fCurrentPositionX;
	float fDeltaZ = fDestinationZ - fCurrentPositionZ;

	//  [6/21/2006 zeroera] : 수정 : float 비교 오차 범위
	if ((fabs(fDeltaX) < 0.001f) && (fabs(fDeltaZ) < 0.001f))
	{
		pNewHeadingVector->x = fCurrentHeadingVectorX;
		pNewHeadingVector->y = 0.0f;
		pNewHeadingVector->z = fCurrentHeadingVectorZ;

		pDestination->x = fCurrentPositionX;
		pDestination->y = fCurrentPositionY;
		pDestination->z = fCurrentPositionZ;

		return;
	}

	CNtlVector vDelta(fDeltaX, 0, fDeltaZ);
	float fDeltaLength = vDelta.Length();

	vDelta.Normalize(fDeltaLength);

	pNewHeadingVector->x = vDelta.x;
	pNewHeadingVector->y = 0.0f;
	pNewHeadingVector->z = vDelta.z;

	float fDistanceToGo = fSpeedInSecs * (float)dwDeltaTimeInMillisecs / 1000.0f;

	if (fDeltaLength <= fTargetDistance)
	{
		pDestination->x = fCurrentPositionX;
		pDestination->y = fCurrentPositionY;
		pDestination->z = fCurrentPositionZ;
	}
	else if (fDeltaLength > fTargetDistance && fDeltaLength < fTargetDistance + fDistanceToGo)
	{
		vDelta *= fDeltaLength - fTargetDistance * 0.99f;

		pDestination->x = fCurrentPositionX + vDelta.x;
		pDestination->y = fCurrentPositionY + (fDestinationY - fCurrentPositionY) * (fDeltaLength - fTargetDistance * 0.99f) / fDeltaLength;
		pDestination->z = fCurrentPositionZ + vDelta.z;
	}
	else
	{
		vDelta *= fDistanceToGo;

		pDestination->x = fCurrentPositionX + vDelta.x;
		pDestination->y = fCurrentPositionY + (fDestinationY - fCurrentPositionY) * fDistanceToGo / fDeltaLength;
		pDestination->z = fCurrentPositionZ + vDelta.z;
	}
}
示例#3
0
void NtlGetDestination_Dash(float fCurrentMoveVectorX, float fCurrentMoveVectorZ, float fSpeedInSecs,
							float fCurrentPositionX, float fCurrentPositionY, float fCurrentPositionZ,
							float fDestinationX, float fDestinationY, float fDestinationZ,
							DWORD dwDeltaTimeInMillisecs,
							CNtlVector* pDestination)
{
	float fDeltaX = fDestinationX - fCurrentPositionX;
	float fDeltaZ = fDestinationZ - fCurrentPositionZ;

	//  [6/21/2006 zeroera] : 수정 : float 비교 오차 범위
	if ((fabs(fDeltaX) < 0.001f) && (fabs(fDeltaZ) < 0.001f))
	{
		pDestination->x = fDestinationX;
		pDestination->y = fDestinationY;
		pDestination->z = fDestinationZ;

		return;
	}

	float fDistanceToGo = fSpeedInSecs * (float)dwDeltaTimeInMillisecs / 1000.0f;

	CNtlVector vDelta(fDeltaX, 0, fDeltaZ);
	float fDeltaLength = vDelta.Length();

	if (fDeltaLength <= fDistanceToGo)
	{
		pDestination->x = fDestinationX;
		pDestination->y = fDestinationY;
		pDestination->z = fDestinationZ;
	}
	else
	{
		pDestination->x = fCurrentPositionX + fCurrentMoveVectorX * fDistanceToGo;
		pDestination->y = fCurrentPositionY + (fDestinationY - fCurrentPositionY) * fDistanceToGo / fDeltaLength;
		pDestination->z = fCurrentPositionZ + fCurrentMoveVectorZ * fDistanceToGo;
	}
}
示例#4
0
bool NtlGetDestination(float fCurrentHeadingVectorX, float fCurrentHeadingVectorZ, float fSpeedInSecs,
						float fCurrentPositionX, float fCurrentPositionY, float fCurrentPositionZ,
						float fDestinationX, float fDestinationY, float fDestinationZ,
						BYTE byMoveDirection, DWORD dwDeltaTimeInMillisecs,
						float fAttackDistance,
						float* pfNewHeadingVectorX, float* pfNewHeadingVectorZ,
						float* pfDestinationX, float* pfDestinationY, float* pfDestinationZ,
						float fTurningSpeedRatio)
{
	if (0 == fCurrentHeadingVectorX && 0 == fCurrentHeadingVectorZ)
		return false;

	*pfNewHeadingVectorX = fCurrentHeadingVectorX;
	*pfNewHeadingVectorZ = fCurrentHeadingVectorZ;
	*pfDestinationX = fCurrentPositionX;
	*pfDestinationY = fCurrentPositionY;
	*pfDestinationZ = fCurrentPositionZ;

	float fDistanceInTick = fSpeedInSecs * (float)dwDeltaTimeInMillisecs / 1000.0f;

	switch (byMoveDirection)
	{
	case NTL_MOVE_NONE :
		break;

	case NTL_MOVE_F :
	case NTL_MOVE_B :
	// DON'T delete these lines permanently!
	// 완전히 삭제하지 마시오!
	// by YOSHIKI(2006-09-22)
//	case NTL_MOVE_L :
//	case NTL_MOVE_R :
//	case NTL_MOVE_F_L :
//	case NTL_MOVE_F_R :
//	case NTL_MOVE_B_L :
//	case NTL_MOVE_B_R :
		{
			float fMovementVectorX = 0.0f;
			float fMovementVectorZ = 0.0f;

			if (NTL_MOVE_F == byMoveDirection)
			{
				fMovementVectorX = fCurrentHeadingVectorX;
				fMovementVectorZ = fCurrentHeadingVectorZ;
			}
			else if (NTL_MOVE_B == byMoveDirection)
			{
				RotateVector180Degree(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, &fMovementVectorX, &fMovementVectorZ);
			}
			// DON'T delete these lines permanently!
			// 완전히 삭제하지 마시오!
			// by YOSHIKI(2006-09-22)
/*			else if (NTL_MOVE_L == byMoveDirection)
			{
				RotateVector90DegreeToLeft(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, &fMovementVectorX, &fMovementVectorZ);
			}
			else if (NTL_MOVE_R == byMoveDirection)
			{
				RotateVector90DegreeToRight(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, &fMovementVectorX, &fMovementVectorZ);
			}
			else if (NTL_MOVE_F_L == byMoveDirection)
			{
				RotateVector45DegreeToLeft(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, &fMovementVectorX, &fMovementVectorZ);
			}
			else if (NTL_MOVE_F_R == byMoveDirection)
			{
				RotateVector45DegreeToRight(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, &fMovementVectorX, &fMovementVectorZ);
			}
			else if (NTL_MOVE_B_L == byMoveDirection)
			{
				RotateVector135DegreeToLeft(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, &fMovementVectorX, &fMovementVectorZ);
			}
			else if (NTL_MOVE_B_R == byMoveDirection)
			{
				RotateVector135DegreeToRight(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, &fMovementVectorX, &fMovementVectorZ);
			}*/

			float fSin = 0.0f;
			float fCos = 0.0f;

			if (false == NtlSin(fMovementVectorX, fMovementVectorZ, &fSin))
				return true;
			if (false == NtlCos(fMovementVectorX, fMovementVectorZ, &fCos))
				return true;

			float fDeltaX = fDistanceInTick * fCos;
			float fDeltaZ = fDistanceInTick * fSin;
			*pfDestinationX = fCurrentPositionX + fDeltaX;
			*pfDestinationZ = fCurrentPositionZ + fDeltaZ;
		}
		break;

	case NTL_MOVE_TURN_L :
	case NTL_MOVE_TURN_R :
	case NTL_MOVE_F_TURN_L :
	case NTL_MOVE_F_TURN_R :
	case NTL_MOVE_B_TURN_L :
	case NTL_MOVE_B_TURN_R :
		{
			float fRadian = 2 * NTL_PI * ((float)dwDeltaTimeInMillisecs / (float)NTL_REQUIRED_TIME_FOR_COMPLETE_CIRCULAR_MOVEMENT_IN_MILLISECS);
			fRadian *= fTurningSpeedRatio;

			if (NTL_MOVE_TURN_L == byMoveDirection ||
				NTL_MOVE_F_TURN_L == byMoveDirection ||
				NTL_MOVE_B_TURN_L == byMoveDirection)
			{
				RotateVector(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, fRadian, pfNewHeadingVectorX, pfNewHeadingVectorZ);
			}
			else if (NTL_MOVE_TURN_R == byMoveDirection ||
						NTL_MOVE_F_TURN_R == byMoveDirection ||
						NTL_MOVE_B_TURN_R == byMoveDirection)
			{
				RotateVector(fCurrentHeadingVectorX, fCurrentHeadingVectorZ, -fRadian, pfNewHeadingVectorX, pfNewHeadingVectorZ);
			}

			if (NTL_MOVE_TURN_L == byMoveDirection || NTL_MOVE_TURN_R == byMoveDirection)
			{
				// The position doesn't change.
			}
			else if (NTL_MOVE_F_TURN_L == byMoveDirection || NTL_MOVE_F_TURN_R == byMoveDirection ||
						NTL_MOVE_B_TURN_L == byMoveDirection || NTL_MOVE_B_TURN_R == byMoveDirection)
			{
				float fRadius = 0.0f;
				fRadius = fSpeedInSecs * ((float)NTL_REQUIRED_TIME_FOR_COMPLETE_CIRCULAR_MOVEMENT_IN_MILLISECS / (float)1000) / (2 * NTL_PI);

				float fTempX = fCurrentHeadingVectorX * fRadius / sqrt(fCurrentHeadingVectorX * fCurrentHeadingVectorX + fCurrentHeadingVectorZ * fCurrentHeadingVectorZ);
				float fTempZ = fCurrentHeadingVectorZ * fRadius / sqrt(fCurrentHeadingVectorX * fCurrentHeadingVectorX + fCurrentHeadingVectorZ * fCurrentHeadingVectorZ);

				if (NTL_MOVE_F_TURN_L == byMoveDirection)
				{
					*pfDestinationX = fCurrentPositionX + fTempX * sin(fRadian) + fTempZ * (1 - cos(fRadian));
					*pfDestinationZ = fCurrentPositionZ + fTempZ * sin(fRadian) - fTempX * (1 - cos(fRadian));
				}
				else if (NTL_MOVE_F_TURN_R == byMoveDirection)
				{
					*pfDestinationX = fCurrentPositionX + fTempX * sin(fRadian) - fTempZ * (1 - cos(fRadian));
					*pfDestinationZ = fCurrentPositionZ + fTempZ * sin(fRadian) - fTempX * (1 - cos(fRadian));
				}
				else if (NTL_MOVE_B_TURN_L == byMoveDirection)
				{
					*pfDestinationX = fCurrentPositionX - fTempX * sin(fRadian) - fTempZ * (1 - cos(fRadian));
					*pfDestinationZ = fCurrentPositionZ - fTempZ * sin(fRadian) - fTempX * (1 - cos(fRadian));
				}
				else if (NTL_MOVE_B_TURN_R == byMoveDirection)
				{
					*pfDestinationX = fCurrentPositionX - fTempX * sin(fRadian) + fTempZ * (1 - cos(fRadian));
					*pfDestinationZ = fCurrentPositionZ - fTempZ * sin(fRadian) - fTempX * (1 - cos(fRadian));
				}
			}
		}
		break;

	case NTL_MOVE_MOUSE_MOVEMENT :
		{
			float fDeltaX = fDestinationX - fCurrentPositionX;
			float fDeltaZ = fDestinationZ - fCurrentPositionZ;

			//  [6/21/2006 zeroera] : 수정 : float 비교 오차 범위
			if ( ( fabs( fDeltaX ) < 0.001f ) && ( fabs( fDeltaZ ) < 0.001f ) )
			{
				*pfNewHeadingVectorX = fCurrentHeadingVectorX;
				*pfNewHeadingVectorZ = fCurrentHeadingVectorZ;
				*pfDestinationX = fDestinationX;
				*pfDestinationY = fDestinationY;
				*pfDestinationZ = fDestinationZ;

				return true;
			}

			CNtlVector vDelta(fDeltaX, 0, fDeltaZ);
			float fDeltaLength = vDelta.Length();

			vDelta.Normalize(fDeltaLength);

			*pfNewHeadingVectorX = vDelta.x;
			*pfNewHeadingVectorZ = vDelta.z;

			if (fDeltaLength <= fDistanceInTick)
			{
				*pfDestinationX = fDestinationX;
				*pfDestinationY = fDestinationY;
				*pfDestinationZ = fDestinationZ;
			}
			else
			{
				vDelta *= fDistanceInTick;

				*pfDestinationX = fCurrentPositionX + vDelta.x;
				*pfDestinationY = fCurrentPositionY + (fDestinationY - fCurrentPositionY) * fDistanceInTick / fDeltaLength;
				*pfDestinationZ = fCurrentPositionZ + vDelta.z;
			}
		}
		break;

	case NTL_MOVE_FOLLOW_MOVEMENT :
		{
			float fDeltaX = fDestinationX - fCurrentPositionX;
			float fDeltaZ = fDestinationZ - fCurrentPositionZ;

			//  [6/21/2006 zeroera] : 수정 : float 비교 오차 범위
			if ( ( fabs( fDeltaX ) < 0.001f ) && ( fabs( fDeltaZ ) < 0.001f ) )
			{
				*pfNewHeadingVectorX = fCurrentHeadingVectorX;
				*pfNewHeadingVectorZ = fCurrentHeadingVectorZ;
				*pfDestinationX = fCurrentPositionX;
				*pfDestinationY = fCurrentPositionY;
				*pfDestinationZ = fCurrentPositionZ;

				return true;
			}

			CNtlVector vDelta(fDeltaX, 0, fDeltaZ);
			float fDeltaLength = vDelta.Length();

			vDelta.Normalize(fDeltaLength);

			*pfNewHeadingVectorX = vDelta.x;
			*pfNewHeadingVectorZ = vDelta.z;

			if ( fDeltaLength <= fAttackDistance )
			{
				*pfDestinationX = fCurrentPositionX;
				*pfDestinationY = fCurrentPositionY;
				*pfDestinationZ = fCurrentPositionZ;
			}
			else if ( fDeltaLength > fAttackDistance && fDeltaLength < fAttackDistance + fDistanceInTick)
			{
				vDelta *= ( fDeltaLength - fAttackDistance * 0.99f );

				*pfDestinationX = fCurrentPositionX + vDelta.x;
				*pfDestinationY = fCurrentPositionY + (fDestinationY - fCurrentPositionY) * (fDeltaLength - fAttackDistance * 0.99f) / fDeltaLength;
				*pfDestinationY = fDestinationY;
				*pfDestinationZ = fCurrentPositionZ + vDelta.z;
			}
			else
			{
				vDelta *= fDistanceInTick;

				*pfDestinationX = fCurrentPositionX + vDelta.x;
				*pfDestinationY = fCurrentPositionY + (fDestinationY - fCurrentPositionY) * fDistanceInTick / fDeltaLength;
				*pfDestinationZ = fCurrentPositionZ + vDelta.z;
			}
		}
		break;

	default :
		return false;
		break;
	}

	return true;
}
示例#5
0
void DockPopup::paintEvent(QPaintEvent *e){
	QPainter p;
	QColor mBackground = mPalette.active().background();
	QColor mForeground = mPalette.active().foreground();

	if(mText.isEmpty() || mText.isNull())
		return QWidget::paintEvent(e);

	//Use a mLabel to draw our stuff so that RichText will appear correctly
	mLabel->setText( mText );
	mLabel->resize( mLabel->width(), mLabel->height() );
	//QRect s = mLabel->contentsRect();
	//mLabel->resize( s.width(), s.height() );

	QRect bound = QRect( 0, 0, mLabel->width(), mLabel->height() );

	//Resize this to bound (on both sides/top/bottom)
	resize( bound.width() + 2, bound.height() + 2 );

	//Move this to the correct position, based on mAnchor and mAnchorPosition
	switch( mAnchorPosition ){
		case BottomRight:
			move( mAnchor.x( ) - width( ), mAnchor.y( ) - height( ) );
			break;
		case BottomLeft:
			move( mAnchor.x( ), mAnchor.y( ) - height( ) );
			break;
		case TopLeft:
			move( mAnchor.x( ), mAnchor.y( ) );
			break;
		case TopRight:
			move( mAnchor.x( ) - width( ), mAnchor.y( ) );
			break;
		default:
			//Shouldn't get here! Assume BottomRight.
			move( mAnchor.x( ) - width( ), mAnchor.y( ) - height( ) );
			qDebug( "dockPopup: mAnchorPosition not set\n" );
			break;
	}

	//The pixmap that holds the text:
	mTextPixmap->resize( bound.size() );
	p.begin( mTextPixmap );
	p.setBrush( mBackground );
	p.setPen( mBackground );
	p.drawRect( 0, 0, bound.width(), bound.height() );
	mLabel->drawContents( &p );
	p.end();

	//The actual roundRect and the text
	p.begin( this );
	p.setBrush( mBackground );
	p.drawRect(0, 0, width(), height() );
	p.drawPixmap( 1, 1, *mTextPixmap );
	p.end();

	//The little anchor indicator
	if(drawAnchorPosition){
		p.begin( this );
		//p.setPen( Qt::red );
		p.setPen( mForeground );
		p.setBrush( mForeground );
		int radius = 4;
		QPoint hDelta( radius, 0 );
		QPoint vDelta( 0, radius );

		//The four corners, clockwise order
		QPoint A( 0, 0 );
		QPoint B( width() -2, 0 );
		QPoint C( width() -2, height()-2  );
		QPoint D( 0, height()-2 );
		switch( mAnchorPosition ){
			case TopLeft:
				p.drawPie( QRect( A - hDelta - vDelta, A + hDelta + vDelta ), 0, -4*360 );
				break;
			case TopRight:
				p.drawPie( QRect( B + hDelta - vDelta, B - hDelta + vDelta ), 12*360, -4*360 );
				break;
			case BottomRight:
				p.drawPie( QRect( C + hDelta + vDelta, C - hDelta - vDelta ), 8*360, -4*360 );
				break;
			case BottomLeft:
				p.drawPie( QRect( D - hDelta + vDelta, D + hDelta - vDelta ), 4*360, -4*360 );
				break;
		}
		p.end();
	}

	/* XXX: This is mainly for if the shape requires an alpha mask, e.g. a round
	 * rect or something.  Right now it's just a regular rect, so I'm commenting
	 * it out.
	 
	mMask->resize( size() );
	mMask->fill( Qt::color0 ); //transparent
	p.begin( mMask );
	p.setPen( Qt::color1 );
	p.setBrush( Qt::color1 );
	p.drawRect(0, 0, width(), height() );
	p.end();
	setMask( *mMask );
	**/

	QWidget::paintEvent(e);
}