⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fxlight.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 4 页
字号:
			PosTo = PosFrom;

			// Clamp lerp factor.
			LerpFactor = 0.0f;
		}

		// ********************************************
		// Rotation Keys.
		// ********************************************
		if (mRotationKeysLength)
		{
			// No, so calculate Rotation.
			mAnimationRotation = GetLerpKey(mDataBlock->mRotationKeys, PosFrom, PosTo, mDataBlock->mMinRotation, mDataBlock->mMaxRotation, LerpFactor);
		}
		else
		{
			// Set to static Rotation if we failed to set Rotation correctly.
			mAnimationRotation = mDataBlock->mMinRotation;
		}
	}
	else
	{
		// No, so set to static Rotation.
		mAnimationRotation = 0;
	}



	// ********************************************
	// Calculate Offsets.
	// ********************************************

	// Are we attached?
	if (mAttached)
	{
		// Yes, so set to attached position.
		mAnimationPosition = mpAttachedObject->getPosition();

		// Set Current Position.
		setPosition(mAnimationPosition);
	}

	// Reset Animation Offset.
	mAnimationOffset.set(0, 0, 0);

	// Are we animating Offsets?
	if (mDataBlock->mUseOffsets)
	{
		U32 PosFrom;
		U32 PosTo;
		F32	LerpFactor;

		// Yes, so adjust time-base.
		mOffsetElapsedTime += mElapsedTime;

		// Adjust to Bounds.
		while (mOffsetElapsedTime > mDataBlock->mOffsetTime) { mOffsetElapsedTime -= mDataBlock->mOffsetTime; };

		// Scale Time.
		F32 ScaledTime = mOffsetElapsedTime * mOffsetTimeScale;

		// Calculate Position From.
		PosFrom = mFloor(ScaledTime);

		// Are we Lerping?
		if (mDataBlock->mLerpRadius)
		{
			// Yes, so calculate Position To.
			PosTo = mCeil(ScaledTime);

			// Calculate Lerp Factor.
			LerpFactor = ScaledTime - PosFrom;
		}
		else
		{
			// No, so clamp Position.
			PosTo = PosFrom;

			// Clamp lerp factor.
			LerpFactor = 0.0f;
		}

		// ********************************************
		// Offset Keys.
		// ********************************************
		if (mOffsetKeysLength)
		{
			// No, so get static Position.
			if (!mAttached) getRenderTransform().getColumn(3, &mAnimationPosition);

			// Calculte Current Offset.
			//
			// NOTE:- We store this here in-case we need it for the flare position.
			mAnimationOffset.x	= GetLerpKey(mDataBlock->mOffsetKeys, PosFrom, PosTo, mDataBlock->mStartOffset.x, mDataBlock->mEndOffset.x, LerpFactor);
			mAnimationOffset.y	= GetLerpKey(mDataBlock->mOffsetKeys, PosFrom, PosTo, mDataBlock->mStartOffset.y, mDataBlock->mEndOffset.y, LerpFactor);
			mAnimationOffset.z	= GetLerpKey(mDataBlock->mOffsetKeys, PosFrom, PosTo, mDataBlock->mStartOffset.z, mDataBlock->mEndOffset.z, LerpFactor);

			// Lerp to Offset Position.
			mAnimationPosition += mAnimationOffset;
		}
		else
		{
			// Set to static Position if we failed to set Position correctly.
			if (!mAttached) getRenderTransform().getColumn(3, &mAnimationPosition);
		}
	}
	else
	{
		// No, so set to static Position.
		if (!mAttached) getRenderTransform().getColumn(3, &mAnimationPosition);
	}

	// Construct a world box to include light animation.
	//
	// NOTE:-	We do this so that we always scope the object if we have it's
	//			potential volume in the view.
	Point3F Min, Max;
	Min.set(0,0,0);
	Max.set(0,0,0);

	// Calculate Extents.
	Min.setMin(mAnimationOffset);
	Max.setMax(mAnimationOffset);
	Min += Point3F(-0.5f, -0.5f, -0.5f);
	Max += Point3F(+0.5f, +0.5f, +0.5f);
	mObjBox.min.set(Min);
	mObjBox.max.set(Max);
	resetWorldBox();
}

//------------------------------------------------------------------------------

void fxLight::InitialiseAnimation(void)
{
	// Enable Light.
	mEnable					= true;

	// Basis Light.
	mIconSize				= 1.0f;

	// Texture Handles.
	mIconTextureHandle		=
	mFlareTextureHandle		= NULL;

	// Reset Flare Scale.
	mFlareScale				= 0.0f;

	// Reset Animation.
	ResetAnimation();
}

//------------------------------------------------------------------------------

void fxLight::ResetAnimation(void)
{
	// Check Animation Keys.
	CheckAnimationKeys();

	// Reset Times.
	mColourElapsedTime		=
	mBrightnessElapsedTime	=
	mRadiusElapsedTime		=
	mOffsetElapsedTime		=
	mRotationElapsedTime	=	0.0f;

	// Reset Last Animation Time.
	mLastAnimateTime = mLastRenderTime = F32(Platform::getVirtualMilliseconds());

	// Exit if no datablock is ready.
	if (!mDataBlock) return;

	// Check Flare Details.
	if (mDataBlock->mFarDistance < 0) mDataBlock->mFarDistance = 0.001f;
	if (mDataBlock->mNearDistance >= mDataBlock->mFarDistance) mDataBlock->mNearDistance = mDataBlock->mFarDistance - 0.001f;	// Stop Division by 0!
	if (mDataBlock->mBlendMode > 2) mDataBlock->mBlendMode = 0;
}

//------------------------------------------------------------------------------

F32 fxLight::GetLerpKey(StringTableEntry Key, U32 PosFrom, U32 PosTo, F32 ValueFrom, F32 ValueTo, F32 Lerp)
{
	// Get Key at Selected Positions.
	char KeyFrameFrom	= dToupper(*(Key + PosFrom)) - 65;
	char KeyFrameTo		= dToupper(*(Key + PosTo)) - 65;

	// Calculate Range.
	F32 ValueRange = (ValueTo-ValueFrom)/25.0f;
	// Calculate Key Lerp.
	F32 KeyFrameLerp = (KeyFrameTo - KeyFrameFrom) * Lerp;

	// Return Lerped Value.
	return ValueFrom + ((KeyFrameFrom + KeyFrameLerp) * ValueRange);
}

//------------------------------------------------------------------------------

U32 fxLight::CheckKeySyntax(StringTableEntry Key)
{
	// Return problem.
	if (!Key) return 0;

	// Copy KeyCheck.
	StringTableEntry KeyCheck = Key;

	// Give benifit of doubt!
	bool KeyValid = true;

	// Check Key-frame validity.
	do
	{
		if (dToupper(*KeyCheck) < 'A' && dToupper(*KeyCheck) > 'Z') KeyValid = false;

	} while (*(KeyCheck++));

	// Return result.
	if (KeyValid)
		return dStrlen(Key);
	else
		return 0;
}

//------------------------------------------------------------------------------

void fxLight::CheckAnimationKeys(void)
{
	if (!mDataBlock) return;

	// Check Key Validities.
	mRedKeysLength				= CheckKeySyntax(mDataBlock->mRedKeys);
	mGreenKeysLength			= CheckKeySyntax(mDataBlock->mGreenKeys);
	mBlueKeysLength				= CheckKeySyntax(mDataBlock->mBlueKeys);
	mBrightnessKeysLength		= CheckKeySyntax(mDataBlock->mBrightnessKeys);
	mRadiusKeysLength			= CheckKeySyntax(mDataBlock->mRadiusKeys);
	mOffsetKeysLength			= CheckKeySyntax(mDataBlock->mOffsetKeys);
	mRotationKeysLength			= CheckKeySyntax(mDataBlock->mRotationKeys);

	// Calculate Time Scales.
	if (mDataBlock->mColourTime) mColourTimeScale			= (mRedKeysLength-1) / mDataBlock->mColourTime;
	if (mDataBlock->mBrightnessTime) mBrightnessTimeScale	= (mBrightnessKeysLength-1) / mDataBlock->mBrightnessTime;
	if (mDataBlock->mRadiusTime) mRadiusTimeScale			= (mRadiusKeysLength-1) / mDataBlock->mRadiusTime;
	if (mDataBlock->mOffsetTime) mOffsetTimeScale			= (mOffsetKeysLength-1) / mDataBlock->mOffsetTime;
	if (mDataBlock->mRotationTime) mRotationTimeScale		= (mRotationKeysLength-1) / mDataBlock->mRotationTime;
}

//------------------------------------------------------------------------------

bool fxLight::onNewDataBlock(GameBaseData* dptr)
{
	// Cast new Datablock.
	mDataBlock = dynamic_cast<fxLightData*>(dptr);
	// Check for problems.
	if (!mDataBlock || !Parent::onNewDataBlock(dptr))return false;

	// Reset Animation.
	ResetAnimation();

	// Set Flare Bitmap.
	setFlareBitmap(mDataBlock->mFlareTextureName);

	// Script-it.
	scriptOnNewDataBlock();

	// Return OK.
	return true;
}

//------------------------------------------------------------------------------

bool fxLight::onAdd()
{
	// Add Parent.
	if(!Parent::onAdd()) return(false);

	// Set Default Object Box.
	mObjBox.min.set( -0.5, -0.5, -0.5 );
	mObjBox.max.set(  0.5,  0.5,  0.5 );
	// Reset the World Box.
	resetWorldBox();

	// Set the Render Transform.
	setRenderTransform(mObjToWorld);

	// Add to Scene.
	addToScene();
	mAddedToScene = true;

	// Only on client.
	if (isClientObject())
	{
		// Fetch Textures.
		mIconTextureHandle = TextureHandle(FXLIGHTDBICONTEXTURE, BitmapTexture, true);
		setFlareBitmap(mDataBlock->mFlareTextureName);

		// Add object to Light Set.
		Sim::getLightSet()->addObject(this);
	}

	// Return OK.
	return(true);
}

//------------------------------------------------------------------------------

void fxLight::onRemove()
{
	// Detach from Object.
	detachFromObject();

	// Remove from Scene.
	removeFromScene();
	mAddedToScene = false;

	// Only on client.
	if (isClientObject())
	{
		// Remove Texture References.
		mIconTextureHandle = mFlareTextureHandle = NULL;

		// Remove object from Light Set.
		Sim::getLightSet()->removeObject(this);
	}

	// Do Parent.
	Parent::onRemove();
}

//------------------------------------------------------------------------------

void fxLight::onDeleteNotify(SimObject* Obj)
{
#ifdef TGE_RPGCLIENT2 /// TGE_RPGIsServerObject
		if (mAttached) clearNotify(mpAttachedObject);
		detachFromObject();
#else
	// Server?
	if (isServerObject())
	{
		// Yes, so detach the server way!
		detachFromObject();
	}
	else
	{
		// No, so do it manually (if needed).
		if (mAttached) clearNotify(mpAttachedObject);

		// Store it happening.
		mAttached = false;
	}

#endif

	// Do Parent.
	Parent::onDeleteNotify(Obj);
}

//------------------------------------------------------------------------------

void fxLight::inspectPostApply()
{
	// Reset Animation.
	ResetAnimation();

	// Set Parent.
	Parent::inspectPostApply();

	// Fetch Icon Texture.
	if (isServerObject()) mIconTextureHandle = TextureHandle(FXLIGHTDBICONTEXTURE, BitmapTexture, true);

	// Set Config Change Mask.
	setMaskBits(fxLightConfigChangeMask);
}

//------------------------------------------------------------------------------

bool fxLight::prepRenderImage(SceneState* state, const U32 stateKey, const U32 startZone,
								const bool modifyBaseZoneState)
{
	// No need to render without a flare when not editing mission!
	if (!mDataBlock->mFlareOn && !gEditingMission) return false;

	// Return if last state.
	if (isLastState(state, stateKey)) return false;
	// Set Last State.
	setLastState(state, stateKey);

   // Is Object Rendered?
   if (state->isObjectRendered(this))
   {	
		// Yes, so get a SceneRenderImage.
		SceneRenderImage* image = new SceneRenderImage;
		// Populate it.
		image->obj = this;
		image->isTranslucent = true;
		image->sortType = SceneRenderImage::EndSort;
		// Insert it into the scene images.
		state->insertRenderImage(image);
   }

   return false;
}

//------------------------------------------------------------------------------

void fxLight::renderObject(SceneState* state, SceneRenderImage*)
{
	if ( !mEnable ) return;

	// Check we are in Canonical State.
	AssertFatal(dglIsInCanonicalState(), "Error, GL not in canonical state on entry");

	// Cannot render without appropriate texture!
	if (!mDataBlock->mFlareOn && !mIconTextureHandle) return;
	if (mDataBlock->mFlareOn && !mFlareTextureHandle) return;

	MatrixF ModelView;
	MatrixF RXF;
	Point4F Position;
	F32		BBRadius;

	// Calculate Elapsed Time.
	F32 mElapsedTime = (F32)((Platform::getRealMilliseconds() - mLastRenderTime) / 1000.0f);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -