Exemplo n.º 1
0
//----------------------------------------------------------------------------
bool SkinController::Update (double applicationTime)
{
	if (!Controller::Update(applicationTime))
	{
		return false;
	}

	// 获得要访问的VertexBuffer
	Renderable* renderable = StaticCast<Renderable>(mObject);
	assertion(mNumVertices == renderable->GetVertexBuffer()->GetNumElements(),
		"Controller must have the same number of vertices as the buffer\n");
	VertexBufferAccessor vba(renderable);

	// skin中的网格的顶点在网格的坐标系(世界坐标系)中。mOffsets记录顶点相对各
	// 个骨骼的位置,左乘骨骼变换矩阵得到该骨骼下的网格坐标系位置。

	renderable->WorldTransform = Transform::IDENTITY;
	renderable->WorldTransformIsCurrent = true;

	// 计算skin顶点位置
	for (int vertex = 0; vertex < mNumVertices; ++vertex)
	{
		APoint position = APoint::ORIGIN;
		for (int bone = 0; bone < mNumBones; ++bone)
		{
			float weight = mWeights[vertex][bone];
			if (weight != 0.0f)
			{
				APoint offset = mOffsets[vertex][bone];
				APoint worldOffset = mBones[bone]->WorldTransform*offset;
				position += weight*worldOffset;
			}
		}
		vba.Position<Float3>(vertex) = position;
	}

	renderable->UpdateModelSpace(Renderable::GU_NORMALS);
	Renderer::UpdateAll(renderable->GetVertexBuffer());
	return true;
}
Exemplo n.º 2
0
//----------------------------------------------------------------------------
bool SkinController::Update(double applicationTime, double elapsedTime)
{
	if (!Controller::Update(applicationTime, elapsedTime))
	{
		return false;
	}

	// 获得要访问的VertexBuffer
	Renderable* renderable = StaticCast<Renderable>(mObject);
	renderable->WorldTransform = Transform::IDENTITY;
	renderable->WorldTransformIsCurrent = true;
	renderable->IsSkinCtrlSetWroldTrans = true;

	if (mIsUseCPU)
	{
		assertion(mNumVertices == renderable->GetVertexBuffer()->GetNumElements(),
			"Controller must have the same number of vertices as the buffer\n");
		VertexBufferAccessor vba(renderable);

		if (!mOriginPoses)
		{
			mOriginPoses = new1<APoint>(mNumVertices);
			for (int vertex=0; vertex<mNumVertices; ++vertex)
			{
				mOriginPoses[vertex] = vba.Position<Float3>(vertex);
			}
		}

		// skin中的网格的顶点在网格的坐标系(世界坐标系)中。mOffsets记录顶点相对各
		// 个骨骼的位置,左乘骨骼变换矩阵得到该骨骼下的网格坐标系位置。

		// 计算skin顶点位置
		for (int vertex = 0; vertex < mNumVertices; ++vertex)
		{
			APoint position = APoint::ORIGIN;
			for (int bone = 0; bone < mNumBones; ++bone)
			{
				float weight = mWeights[vertex][bone];

				if (weight != 0.0f)
				{
					APoint offset = mOffsets[vertex][bone];
					APoint worldOffset;

					worldOffset = mBones[bone]->WorldTransform*offset;

					position += weight*worldOffset;
				}
			}
			vba.Position<Float3>(vertex) = position;
		}

		//renderable->  (Renderable::GU_NORMALS);
		Renderer::UpdateAll(renderable->GetVertexBuffer());
	}
	else
	{
		for (int bone = 0; bone < mNumBones; ++bone)
		{
			if (mBones[bone])
			{
				const HMatrix &boneMat = mBones[bone]->WorldTransform.Matrix();
				mGPUMatrixs[bone] = boneMat * mTMMatrixs[bone];
			}
		}
	}

	return true;
}