コード例 #1
0
void BoneAnimation::Interpolate(float t, XMFLOAT4X4& M)const
{
	if( t <= Keyframes.front().TimePos )
	{
		XMVECTOR S = XMLoadFloat3(&Keyframes.front().Scale);
		XMVECTOR P = XMLoadFloat3(&Keyframes.front().Translation);
		XMVECTOR Q = XMLoadFloat4(&Keyframes.front().RotationQuat);

		XMVECTOR zero = XMVectorSet(0.0f, 0.0f, 0.0f, 1.0f);
		XMStoreFloat4x4(&M, XMMatrixAffineTransformation(S, zero, Q, P));
	}
	else if( t >= Keyframes.back().TimePos )
	{
		XMVECTOR S = XMLoadFloat3(&Keyframes.back().Scale);
		XMVECTOR P = XMLoadFloat3(&Keyframes.back().Translation);
		XMVECTOR Q = XMLoadFloat4(&Keyframes.back().RotationQuat);

		XMVECTOR zero = XMVectorSet(0.0f, 0.0f, 0.0f, 1.0f);
		XMStoreFloat4x4(&M, XMMatrixAffineTransformation(S, zero, Q, P));
	}
	else
	{
		for(UINT i = 0; i < Keyframes.size()-1; ++i)
		{
			if( t >= Keyframes[i].TimePos && t <= Keyframes[i+1].TimePos )
			{
				float lerpPercent = (t - Keyframes[i].TimePos) / (Keyframes[i+1].TimePos - Keyframes[i].TimePos);

				XMVECTOR s0 = XMLoadFloat3(&Keyframes[i].Scale);
				XMVECTOR s1 = XMLoadFloat3(&Keyframes[i+1].Scale);

				XMVECTOR p0 = XMLoadFloat3(&Keyframes[i].Translation);
				XMVECTOR p1 = XMLoadFloat3(&Keyframes[i+1].Translation);

				XMVECTOR q0 = XMLoadFloat4(&Keyframes[i].RotationQuat);
				XMVECTOR q1 = XMLoadFloat4(&Keyframes[i+1].RotationQuat);

				XMVECTOR S = XMVectorLerp(s0, s1, lerpPercent);
				XMVECTOR P = XMVectorLerp(p0, p1, lerpPercent);
				XMVECTOR Q = XMQuaternionSlerp(q0, q1, lerpPercent);

				XMVECTOR zero = XMVectorSet(0.0f, 0.0f, 0.0f, 1.0f);
				XMStoreFloat4x4(&M, XMMatrixAffineTransformation(S, zero, Q, P));

				break;
			}
		}
	}
}
コード例 #2
0
Enemy::Enemy() : mEnemyPosition(0.0f, 0.0f, 0.0f), mEnemyScale(3.0f, 3.0f, 3.0f), mEnemyRotation(0.0f, 0.0f, 0.0f, 1.0f),
mEnemyRotationQuad(0.0f, 0.0f, 0.0f, 0.0f), mEnemyPositionOne(0.0f, 0.0f, 0.0f), mEnemyPositionTwo(0.0f, 0.0f, 0.0f), travelToPoint(2), timesThrough(0)
{



	///initialize player
	XMVECTOR S = XMLoadFloat3(&mEnemyScale);
	XMVECTOR P = XMLoadFloat3(&mEnemyPosition);
	XMVECTOR Q = XMLoadFloat4(&mEnemyRotationQuad);
	XMVECTOR rot = XMLoadFloat4(&mEnemyRotation);
	XMStoreFloat4x4(&mEnemyWorld, XMMatrixAffineTransformation(S, rot, Q, P));


	currCharDirection = XMVectorSet(0.0f, 3.0f, 0.0f, 0.0f);
	oldCharDirection = XMVectorSet(0.0f, 3.0f, 0.0f, 0.0f);
	charPosition = XMVectorSet(0.0f, 3.0f, 0.0f, 0.0f);
	EnemyForward = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);
	EnemyRight = XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f);


	direction = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);
	lastPoint = mEnemyPositionOne;

}
コード例 #3
0
ファイル: LevelParts.cpp プロジェクト: kyllindros/Gawky3
void LevelParts::setWorld(XMFLOAT4X4 tempLevelPartsWorld)
{


	mLevelPartsWorld = tempLevelPartsWorld;


	XMMATRIX tempWorld = XMLoadFloat4x4(&mLevelPartsWorld);


	XMVECTOR Scale;
	XMVECTOR Position;
	XMVECTOR Rotation;


	XMMatrixDecompose(&Scale, &Rotation, &Position, tempWorld);

	XMStoreFloat3(&mLevelPartsPosition, Position);

	XMStoreFloat3(&mLevelPartsScale, Scale);

	XMStoreFloat4(&mLevelPartsRotation, Rotation);





	XMVECTOR S = XMLoadFloat3(&mLevelPartsScale);
	XMVECTOR P = XMLoadFloat3(&mLevelPartsPosition);
	XMVECTOR Q = XMLoadFloat4(&mLevelPartsRotationQuad);
	XMVECTOR rot = XMLoadFloat4(&mLevelPartsRotation);

	XMStoreFloat4x4(&mLevelPartsStartingWorld, XMMatrixAffineTransformation(S, rot, Q, P));

}
コード例 #4
0
	void XM_CALLCONV PrimitveDrawer::DrawCylinder(FXMVECTOR P1, FXMVECTOR P2, float radius, FXMVECTOR Color)
	{
		auto center = 0.5f * XMVectorAdd(P1, P2);
		auto dir = XMVectorSubtract(P1, P2);
		auto scale = XMVector3Length(dir);
		scale = XMVectorSet(radius, XMVectorGetX(scale), radius, 1.0f);
		XMVECTOR rot;
		if (XMVector4Equal(dir, g_XMZero))
			rot = XMQuaternionIdentity();
		else
			rot = XMQuaternionRotationVectorToVector(g_XMIdentityR1, dir);
		XMMATRIX world = XMMatrixAffineTransformation(scale, g_XMZero, rot, center);
		m_pCylinder->Draw(world, ViewMatrix, ProjectionMatrix, Color);
	}
コード例 #5
0
void Enemy::update(FLOAT dt)
{

	move(dt);

	XMVECTOR S = XMLoadFloat3(&mEnemyScale);
	XMVECTOR P = XMLoadFloat3(&mEnemyPosition);
	XMVECTOR Q = XMLoadFloat4(&mEnemyRotationQuad);
	XMVECTOR rot = XMLoadFloat4(&mEnemyRotation);
	XNA::AxisAlignedBox tempEnemyBox;

	tempEnemyBox.Center = mEnemyPosition;

	EnemyBox = &tempEnemyBox;


	XMStoreFloat4x4(&mEnemyWorld, XMMatrixAffineTransformation(S, rot, Q, P));

}
コード例 #6
0
ファイル: LevelParts.cpp プロジェクト: kyllindros/Gawky3
void LevelParts::update(FLOAT dt)
{

	//move(dt);

	XMVECTOR S = XMLoadFloat3(&mLevelPartsScale);
	XMVECTOR P = XMLoadFloat3(&mLevelPartsPosition);
	XMVECTOR Q = XMLoadFloat4(&mLevelPartsRotationQuad);
	XMVECTOR rot = XMLoadFloat4(&mLevelPartsRotation);
	XNA::AxisAlignedBox tempLevelPartsBox;

	tempLevelPartsBox.Center = mLevelPartsPosition;

	LevelPartsBox = &tempLevelPartsBox;


	XMStoreFloat4x4(&mLevelPartsWorld, XMMatrixAffineTransformation(S, rot, Q, P));

}
コード例 #7
0
ファイル: Skeleton.cpp プロジェクト: marinedzl/SakuraEngine
bool Skeleton::LoadFromFile(const char * filename)
{
	bool ret = false;
	const Vector3 scaling(1, 1, 1);
	buffer buff;

	CHECK(LoadBinaryFile(buff, filename));

	const char* data = (const char*)buff.ptr();
	SkeletonFile::Head* head = (SkeletonFile::Head*)data;
	data += sizeof(SkeletonFile::Head);

	mBoneCount = head->boneCount;

	mInverseTMs.resize(mBoneCount);

	for (size_t i = 0; i < mBoneCount; ++i)
	{
		const char* name = (const char*)data;
		data += sizeof(char) * SkeletonFile::MaxBoneName;

		mBoneNames.insert(std::make_pair(name, i));

		const Vector3& pos = *(const Vector3*)data;
		data += sizeof(Vector3);

		const Quat& rot = *(const Quat*)data;
		data += sizeof(Quat);

		XMVECTOR p = XMLoadFloat3((const XMFLOAT3*)&pos);
		XMVECTOR q = XMLoadFloat4((const XMFLOAT4*)&rot);
		XMVECTOR s = XMLoadFloat3((const XMFLOAT3*)&scaling);
		XMMATRIX m = XMMatrixAffineTransformation(s, XMQuaternionIdentity(), q, p);
		m = XMMatrixInverse(nullptr, m);
		XMStoreFloat4x4((XMFLOAT4X4*)&mInverseTMs[i], m);
	}

	ret = true;
Exit0:
	return ret;
}
コード例 #8
0
ファイル: D3D11Renderer.cpp プロジェクト: pentestoy/DRON
void D3D11Renderer::FillInstanceBuffer(
	std::vector< Entity >& entities,
	DataBuffer< InstanceData >& buffer )
{
	std::vector< Entity >::iterator e_iter = entities.begin();
	btAlignedObjectArray< InstanceData > id_array;

	while( e_iter != entities.end() )
	{
		const XformComponent::Data& xform_data =
			static_cast< const XformComponent::Data& >(
				_entity_system.GetComponentData( *e_iter, COMPONENT_XFORM ) );

		InstanceData id;
		XMVECTOR translation = xform_data._position;
		XMVECTOR rotation    = xform_data._rotation;
		XMVECTOR scale       = xform_data._scale;
		XMVECTOR rot_origin  = XMVectorSet( 0.0f, 0.0f, 0.0f, 0.0f );
		id._xform = XMMatrixAffineTransformation(
			scale,
			rot_origin,
			rotation,
			translation );

		const RenderableComponent::Data& render_data =
			static_cast< const RenderableComponent::Data& >(
				_entity_system.GetComponentData( *e_iter, COMPONENT_RENDERABLE ) );
		id._color = render_data._color;

		id_array.push_back( id );
		++e_iter;
	}

	_instance_buffer.CopyDataToBuffer(
		_device,
		id_array,
		DATA_BUFFER_MAP_WRITE_DISCARD );
}
コード例 #9
0
ファイル: LevelParts.cpp プロジェクト: kyllindros/Gawky3
LevelParts::LevelParts() : mLevelPartsPosition(0.0f, 0.0f, 0.0f), mLevelPartsScale(1.0f, 1.0f, 1.0f), mLevelPartsRotation(0.0f, 0.0f, 0.0f, 1.0f), mLevelPartsRotationQuad(0.0f, 0.0f, 0.0f, 0.0f)
{



	///initialize player
	XMVECTOR S = XMLoadFloat3(&mLevelPartsScale);
	XMVECTOR P = XMLoadFloat3(&mLevelPartsPosition);
	XMVECTOR Q = XMLoadFloat4(&mLevelPartsRotationQuad);
	XMVECTOR rot = XMLoadFloat4(&mLevelPartsRotation);
	XMStoreFloat4x4(&mLevelPartsWorld, XMMatrixAffineTransformation(S, rot, Q, P));


	currCharDirection = XMVectorSet(0.0f, 3.0f, 0.0f, 0.0f);
	oldCharDirection = XMVectorSet(0.0f, 3.0f, 0.0f, 0.0f);
	charPosition = XMVectorSet(0.0f, 3.0f, 0.0f, 0.0f);
	LevelPartsForward = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);
	LevelPartsRight = XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f);


	direction = XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);


}
コード例 #10
0
ファイル: Matrix.hpp プロジェクト: ChaosOptima/XnaMathWrapper
		static Matrix affine_transformation(const Vector3& translation, const Quaternion& rotation, const Vector3& scale, const Vector3& rotation_centre = Vector3::ZERO)
		{
			return static_cast<Matrix>(XMMatrixAffineTransformation(scale, rotation_centre, rotation, translation));
		}
コード例 #11
0
ファイル: Matrix.hpp プロジェクト: ChaosOptima/XnaMathWrapper
		static Matrix affine_transformation(const Vector3& translation, const Quaternion& rotation)
		{
			return static_cast<Matrix>(XMMatrixAffineTransformation(XMVectorSplatOne(), XMVectorZero(), rotation, translation));
		}
コード例 #12
0
	void XM_CALLCONV PrimitveDrawer::DrawCone(FXMVECTOR Position, FXMVECTOR YDirection, float height, float radius, FXMVECTOR Color)
	{
		XMVECTOR rot = XMQuaternionRotationVectorToVector(g_XMIdentityR1, YDirection);
		XMMATRIX world = XMMatrixAffineTransformation(XMVectorSet(radius, height, radius, 1), g_XMZero, rot, Position);
		m_pCone->Draw(world, ViewMatrix, ProjectionMatrix, Color);
	}
コード例 #13
0
	void XM_CALLCONV PrimitveDrawer::DrawCube(FXMVECTOR Position, FXMVECTOR HalfExtend, FXMVECTOR Orientation, GXMVECTOR Color)
	{
		XMMATRIX world = XMMatrixAffineTransformation(HalfExtend, g_XMZero, Orientation, Position);
		m_pCube->Draw(world, ViewMatrix, ProjectionMatrix, Color);
	}