예제 #1
0
void ActionMoveToPoint::Update(unsigned int Delta)
{
	if (owner)
	{
		Transform *t = owner->GetTransform();

		Vector3 ownerPos = t->Position();
		Vector3 targetPos = targetPoint->Position();

		if (Vector3::Distance(Vector3(ownerPos.x, 0, ownerPos.z), Vector3(targetPos.x, 0, targetPos.z)) < moveSpeed * 2.0f)	//ignore Y for gravity, temp fix
		{
			t->SetPosition(targetPos);
			owner->SetVelocity(Vector3(0, owner->Velocity().y, 0));
			owner->SetActionState(NULL);
			return;
		}


		float rad = atan2(ownerPos.x - targetPos.x, ownerPos.z - targetPos.z);

		Vector3 orientation = t->Orientation();
		orientation.y = rad;

		t->SetOrientation(orientation);

		Vector3 velocity = owner->Velocity();
		Vector3 nVelocity = t->GetMatrix().Forward() * moveSpeed;
		nVelocity.y = velocity.y;

		owner->SetVelocity(nVelocity);
	}
};
예제 #2
0
파일: tgf.cpp 프로젝트: iat-cener/tonatiuh
SbMatrix tgf::MatrixFromTransform( const Transform& transform )
{
	Ptr<Matrix4x4> transformMatrix = transform.GetMatrix()->Transpose();
	float m00 = float ( transformMatrix->m[0][0] );
	float m01 = float ( transformMatrix->m[0][1] );
	float m02 = float ( transformMatrix->m[0][2] );
	float m03 = float ( transformMatrix->m[0][3] );
	float m10 = float ( transformMatrix->m[1][0] );
	float m11 = float ( transformMatrix->m[1][1] );
	float m12 = float ( transformMatrix->m[1][2] );
	float m13 = float ( transformMatrix->m[1][3] );
	float m20 = float ( transformMatrix->m[2][0] );
	float m21 = float ( transformMatrix->m[2][1] );
	float m22 = float ( transformMatrix->m[2][2] );
	float m23 = float ( transformMatrix->m[2][3] );
	float m30 = float ( transformMatrix->m[3][0] );
	float m31 = float ( transformMatrix->m[3][1] );
	float m32 = float ( transformMatrix->m[3][2] );
	float m33 = float ( transformMatrix->m[3][3] );

	SbVec3f axis1( m00, m10, m20 );
	SbVec3f axis2( m01, m11, m21 );
	//axis2.normalize();

	SbVec3f axis3( m02, m12, m22 );
	//axis3.normalize();

	return SbMatrix( axis1[0], axis2[0], axis3[0], m03,
			axis1[1], axis2[1], axis3[1], m13,
			axis1[2], axis2[2], axis3[2], m23,
			m30, m31, m32, m33 );

}
예제 #3
0
void Manipulator::RenderSphere(LPD3DXEFFECT effect,
    const Matrix& projection, const Matrix& view,
    const D3DXVECTOR3& color, const Transform& world)
{
    D3DXMATRIX wvp = world.GetMatrix() * view.GetMatrix() * projection.GetMatrix();
    effect->SetMatrix(DxConstant::WordViewProjection, &wvp);
    effect->SetFloatArray(DxConstant::VertexColor, &color.x, 3);

    UINT nPasses = 0;
    effect->Begin(&nPasses, 0);
    for(UINT iPass = 0; iPass < nPasses; iPass++)
    {
        effect->BeginPass(iPass);
        m_sphere->DrawSubset(0);
        effect->EndPass();
    }
    effect->End();
}
예제 #4
0
Transform operator*(Transform const& A, Transform const& B)
{
    if (A.IsIdentity())
    {
        return B;
    }

    if (B.IsIdentity())
    {
        return A;
    }

    Transform product;

    if (A.IsRSMatrix() && B.IsRSMatrix())
    {
#if defined(GTE_USE_MAT_VEC)
        if (A.IsUniformScale())
        {
            product.SetRotation(A.GetRotation() * B.GetRotation());

            product.SetTranslation(A.GetUniformScale()*(
                A.GetRotation() * B.GetTranslationW0()) +
                A.GetTranslationW1());

            if (B.IsUniformScale())
            {
                product.SetUniformScale(
                    A.GetUniformScale() * B.GetUniformScale());
            }
            else
            {
                product.SetScale(A.GetUniformScale() * B.GetScale());
            }

            return product;
        }
#else
        if (B.IsUniformScale())
        {
            product.SetRotation(A.GetRotation() * B.GetRotation());

            product.SetTranslation(B.GetUniformScale()*(
                A.GetTranslationW0() * B.GetRotation()) + B.GetTranslationW1());

            if (A.IsUniformScale())
            {
                product.SetUniformScale(
                    A.GetUniformScale() * B.GetUniformScale());
            }
            else
            {
                product.SetScale(A.GetScale() * B.GetUniformScale());
            }

            return product;
        }
#endif
    }

    // In all remaining cases, the matrix cannot be written as R*S*X+T.
    Matrix4x4<float> matMA;
    if (A.IsRSMatrix())
    {
#if defined(GTE_USE_MAT_VEC)
        matMA = MultiplyMD(A.GetRotation(), A.GetScaleW1());
#else
        matMA = MultiplyDM(A.GetScaleW1(), A.GetRotation());
#endif
    }
    else
    {
        matMA = A.GetMatrix();
    }

    Matrix4x4<float> matMB;
    if (B.IsRSMatrix())
    {
#if defined(GTE_USE_MAT_VEC)
        matMB = MultiplyMD(B.GetRotation(), B.GetScaleW1());
#else
        matMB = MultiplyDM(B.GetScaleW1(), B.GetRotation());
#endif
    }
    else
    {
        matMB = B.GetMatrix();
    }

    product.SetMatrix(matMA * matMB);
#if defined(GTE_USE_MAT_VEC)
    product.SetTranslation(matMA * B.GetTranslationW0() +
        A.GetTranslationW1());
#else
    product.SetTranslation(A.GetTranslationW0() * matMB +
        B.GetTranslationW1());
#endif
    return product;
}