Example #1
0
// ------------------------------------------------------------------------------------------------
// Calculates the node transformations for the scene. 
void SceneAnimator::Calculate( double pTime)
{
	// invalid anim
	if( !mAnimEvaluator)
		return;

	// calculate current local transformations
	mAnimEvaluator->Evaluate( pTime);

	// and update all node transformations with the results
	UpdateTransforms( mRootNode, mAnimEvaluator->GetTransformations());
}
Example #2
0
 void DiInstancedModel::SetScale( const DiVec3& scale, bool doUpdate /*= true*/ )
 {
     mScale = scale; 
     mMaxScaleLocal = DiMath::Max(DiMath::Max(
         DiMath::Abs(mScale.x), DiMath::Abs(mScale.y)), DiMath::Abs(mScale.z)); 
     mUseLocalTransform = true;
     MarkTransformDirty();
     if (doUpdate) 
     {
         UpdateTransforms();
     }
 }
Example #3
0
void DiSkeleton::GetBoneMatrices( DiMat4* pMatrices, bool updateTransform )
{
    if (updateTransform)
    {
        UpdateTransforms();
    }

    for (auto i = mBoneList.begin(); i != mBoneList.end(); ++i)
    {
        DiBone* pBone = *i;
        pBone->GetOffsetTransform(*pMatrices);
        pMatrices++;
    }
}
Example #4
0
 void DiAttachSet::GetAttachMatrices(Demi::DiMat4 * pMatrices,size_t unArrayLen)
 {
     UpdateTransforms();
     
     size_t unCount = 0;
     for (auto itAttach = mMapAttachNodes.begin(); itAttach != mMapAttachNodes.end()
          && unCount < unArrayLen; ++ itAttach)
     {
         DiAttachNode * pkAttach = itAttach->second;
         pkAttach->GetOffsetTransform(* pMatrices);
         ++pMatrices;
         ++unCount;
     }
 }
Example #5
0
void Scene::Update() {

	input::Update();
	
	MoveAddedObjectsToScene();
	_sceneGraph.Rebuild();
	UpdateTransforms();
	physics::Update();
	
	std::for_each(_gameObjects.begin(), _gameObjects.end(), ProcessPreUpdate);
	std::for_each(_gameObjects.begin(), _gameObjects.end(), ProcessUpdate);
	std::for_each(_gameObjects.begin(), _gameObjects.end(), ProcessPreRender);

	utils::Update();
//	input::PrintTouchesCount();
}
// ------------------------------------------------------------------------------------------------
// Recursively updates the internal node transformations from the given matrix array
void SceneAnimator::UpdateTransforms(SceneAnimNode* pNode, const std::vector<aiMatrix4x4>& pTransforms)
{
	// update node local transform
	if (pNode->mChannelIndex != -1)
	{
		ai_assert(pNode->mChannelIndex < pTransforms.size());
		pNode->mLocalTransform = pTransforms[pNode->mChannelIndex];
	}

	// update global transform as well
	CalculateGlobalTransform(pNode);

	// continue for all children
	for (std::vector<SceneAnimNode*>::iterator it = pNode->mChildren.begin(); it != pNode->mChildren.end(); ++it)
		UpdateTransforms(*it, pTransforms);
}
Example #7
0
void MassSprings3DWindow::OnIdle()
{
    mTimer.Measure();

    mCameraRig.Move();
    UpdateTransforms();
    UpdateMassSpringSystem();

    mEngine->ClearBuffers();
    for (int i = 0; i < 6; ++i)
    {
        mEngine->Draw(mBoxFace[i]);
    }
    mEngine->Draw(8, mYSize - 8, { 0.0f, 0.0f, 0.0f, 1.0f }, mTimer.GetFPS());
    mEngine->DisplayColorBuffer(0);

    mTimer.UpdateFrameCount();
}
void Skeleton::UpdateTransforms( Bone* bone ) {
	XMMATRIX localTransform = XMLoadFloat4x4( &(bone->localTransform) );
	XMMATRIX offset = XMLoadFloat4x4( &(bone->offset) );
	XMMATRIX finalTransform;
	if( bone->parentIdx == -1 ) {
		// The root bone
		XMMATRIX xmRootCorrection = XMLoadFloat4x4( &rootCorrection );
		XMStoreFloat4x4( &(toRoot[bone->idx]), xmRootCorrection*localTransform );
		finalTransform = offset*localTransform;
	} else {
		XMMATRIX parentToRoot = XMLoadFloat4x4( &(toRoot[bone->parentIdx]) );
		XMMATRIX boneToRoot = localTransform*parentToRoot;
		XMStoreFloat4x4( &(toRoot[bone->idx]), boneToRoot );
		finalTransform = offset*boneToRoot;
	}
	XMStoreFloat4x4( &(finalTransformData[bone->idx]), finalTransform );
	if( bone->children.size()==0 ) { return; }
	for( Bone* childBone:bone->children ) {
		UpdateTransforms( childBone );
	}
}
Example #9
0
    DiInstancedModel::DiInstancedModel( DiInstanceBatch *batchOwner, 
        uint32 instanceID, DiInstancedModel* sharedTransformEntity /*= NULL*/ )
        :DiTransformUnit(),
        mInstanceId( instanceID ),
        mInUse( false ),
        mBatchOwner( batchOwner ),
        mClipSet( NULL ),
        mSkeletonInstance( NULL ),
        mBoneMatrices( NULL ),
        mBoneWorldMatrices( NULL ),
        mFrameAnimationLastUpdated(std::numeric_limits<ULONG>::max() - 1),
        mSharedTransformModel( NULL ),
        mTransformLookupNumber(instanceID),
        mPosition(DiVec3::ZERO),
        mDerivedLocalPosition(DiVec3::ZERO),
        mOrientation(DiQuat::IDENTITY),
        mScale(DiVec3::UNIT_SCALE),
        mMaxScaleLocal(1),
        mNeedTransformUpdate(true),
        mNeedAnimTransformUpdate(true),
        mUseLocalTransform(false),
        mSpeed(1),
        mAutoUpdateAnims(false)
    {
        static int count = 0;
        DiString s;
        s.SetInt(count++);
        mName = batchOwner->GetName() + "_InsMdl_";
        mName += s;

        if (sharedTransformEntity)
        {
            sharedTransformEntity->ShareTransformWith(this);
        }
        else
        {
            CreateSkeletonInstance();
        }
        UpdateTransforms();
    }
Example #10
0
// calculates the node transformations for the scene
// returns false of the animation is completed or if there is no animation
bool Animator::UpdateAnimation(float time, bool loop)
{
    if (currentAnimation && currentAnimation->mDuration > 0.0 && CurAnimation != NULL)
    {
        // map into animation's duration
        double timeInTicks = 0.0f;
        
        float dur = (CurAnimation->endFrame - CurAnimation->startFrame)/FPS;
        
        if(time == 0)
        {
            timeInTicks = 0;
        }
        else if (dur > 0.0)
        {
            timeInTicks = (CurAnimation->startFrame/FPS) + fmod(time-(1/FPS), dur);
        }
        else
        {
            timeInTicks = CurAnimation->startFrame/FPS;
        }
        
        if (boneTransforms.size() != currentAnimation->mNumChannels)
        {
            boneTransforms.resize(currentAnimation->mNumChannels);
        }
        
        //calculate the transformations for each animation channel
        for (unsigned int i = 0; i < currentAnimation->mNumChannels; i++)
        {
            const aiNodeAnim* channel = currentAnimation->mChannels[i];
            
            //******** Position *****
            aiVector3D currentPosition(0, 0, 0);
            
            if (channel->mNumPositionKeys > 0)
            {
                // Look for present frame number. Search from last position if time is after the last time, else from beginning
                unsigned int frame = (timeInTicks >= lastTime) ? lastFramePosition[i].x : 0;
                
                while (frame < channel->mNumPositionKeys - 1)
                {
                    if (timeInTicks < channel->mPositionKeys[frame + 1].mTime)
                    {
                        break;
                    }
                    
                    frame++;
                }
                
                // interpolate between this frame's value and next frame's value
                unsigned int nextFrame = (frame + 1) % channel->mNumPositionKeys;
                const aiVectorKey& key = channel->mPositionKeys[frame];
                const aiVectorKey& nextKey = channel->mPositionKeys[nextFrame];
                double dt = nextKey.mTime - key.mTime;
                
                if (dt < 0.0)
                {
                    dt += dur;
                }
                
                if (dt > 0)
                {
                    float interpolationFactor = (float) ((timeInTicks - key.mTime) / dt);
                    currentPosition = key.mValue + (nextKey.mValue - key.mValue) * interpolationFactor;
                }
                else
                {
                    currentPosition = key.mValue;
                }
                
                lastFramePosition[i].x = frame;
            }
            
            //******** Rotation *********
            aiQuaternion currentRotation(1, 0, 0, 0);
            
            if (channel->mNumRotationKeys > 0)
            {
                unsigned int frame = (timeInTicks >= lastTime) ? lastFramePosition[i].y : 0;
                
                while (frame < channel->mNumRotationKeys - 1)
                {
                    if (timeInTicks < channel->mRotationKeys[frame + 1].mTime)
                    {
                        break;
                    }
                    
                    frame++;
                }
                
                // interpolate between this frame's value and next frame's value
                unsigned int nextFrame = (frame + 1) % channel->mNumRotationKeys;
                const aiQuatKey& key = channel->mRotationKeys[frame];
                const aiQuatKey& nextKey = channel->mRotationKeys[nextFrame];
                double dt = nextKey.mTime - key.mTime;
                
                if (dt < 0.0)
                {
                    dt += dur;
                }
                
                if (dt > 0)
                {
                    float interpolationFactor = (float) ((timeInTicks - key.mTime) / dt);
                    aiQuaternion::Interpolate(currentRotation, key.mValue, nextKey.mValue, interpolationFactor);
                }
                else
                {
                    currentRotation = key.mValue;
                }
                
                lastFramePosition[i].y = frame;
            }
            
            //******** Scaling **********
            aiVector3D currentScaling(1, 1, 1);
            
            if (channel->mNumScalingKeys > 0)
            {
                unsigned int frame = (timeInTicks >= lastTime) ? lastFramePosition[i].z : 0;
                
                while (frame < channel->mNumScalingKeys - 1)
                {
                    if (timeInTicks < channel->mScalingKeys[frame + 1].mTime)
                    {
                        break;
                    }
                    
                    frame++;
                }
                
                currentScaling = channel->mScalingKeys[frame].mValue;
                lastFramePosition[i].z = frame;
            }
            
            // build a transformation matrix from the current position, rotation, and scale
            aiMatrix4x4& transformation = boneTransforms[i];
            transformation = aiMatrix4x4(currentRotation.GetMatrix());
            
            transformation.a1 *= currentScaling.x;
            transformation.b1 *= currentScaling.x;
            transformation.c1 *= currentScaling.x;
            
            transformation.a2 *= currentScaling.y;
            transformation.b2 *= currentScaling.y;
            transformation.c2 *= currentScaling.y;
            
            transformation.a3 *= currentScaling.z;
            transformation.b3 *= currentScaling.z;
            transformation.c3 *= currentScaling.z;
            
            transformation.a4 = currentPosition.x;
            transformation.b4 = currentPosition.y;
            transformation.c4 = currentPosition.z;
        }
        
        lastTime = timeInTicks;
        
        // update all node transformations with the results
        UpdateTransforms(rootNode, boneTransforms);
        
        if(time <= dur || loop)
        {
            if(CurAnimation != NULL) CurAnimation->isPlaying = true;
            return true;
        }
    }
    
    if(CurAnimation != NULL) CurAnimation->isPlaying = false;
    return false;
}
Example #11
0
//-------------------------------------------------------------------------------------
HRESULT CDXUTEffectMap::SetViewMatrix( D3DXMATRIXA16* pViewMatrix, const WCHAR* strUnits )
{
    m_matView = *pViewMatrix;
    return UpdateTransforms( DXUT_View );
}
Example #12
0
void Camera::VUpdate(unsigned int elapsedMs)
{
	m_pitch = Math::Clamp(static_cast<float>(m_pitch), static_cast<float>(PI * (-0.25)),
		static_cast<float>(PI * 0.25));
	UpdateTransforms();
}
Example #13
0
 void DiInstancedModel::NotifyAttached( DiNode* parent )
 {
     MarkTransformDirty();
     DiTransformUnit::NotifyAttached( parent );
     UpdateTransforms();
 }
Example #14
0
//-------------------------------------------------------------------------------------
HRESULT CDXUTEffectMap::SetProjectionMatrix( D3DXMATRIXA16* pProjectionMatrix )
{
    m_matProjection = *pProjectionMatrix;
    return UpdateTransforms( DXUT_Projection );
}
// ------------------------------------------------------------------------------------------------
// Calculates the node transformations for the scene. 
void SceneAnimator::Calculate(float pTime){
	if( (CurrentAnimIndex < 0) | ((size_t)CurrentAnimIndex >= Animations.size()) ) return;// invalid animation
	
	Animations[CurrentAnimIndex].Evaluate( pTime, BonesByName);
	UpdateTransforms(Skeleton);
}
// ------------------------------------------------------------------------------------------------
// Recursively updates the internal node transformations from the given matrix array
void SceneAnimator::UpdateTransforms(cBone* pNode) {
	CalculateBoneToWorldTransform( pNode);// update global transform as well
	for( std::vector<cBone*>::iterator it = pNode->Children.begin(); it != pNode->Children.end(); ++it)// continue for all children
		UpdateTransforms( *it);
}
Example #17
0
//-------------------------------------------------------------------------------------
HRESULT CDXUTEffectMap::SetWorldMatrix( D3DXMATRIXA16* pWorldMatrix, const WCHAR* strUnits )
{
    m_matWorld = *pWorldMatrix;
    return UpdateTransforms( DXUT_World );
}