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

📄 mgcikcontroller.cpp

📁 3D Game Engine Design Source Code非常棒
💻 CPP
字号:
// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement.  The various license agreements may be found at
// the Magic Software web site.  This file is subject to the license
//
// RESTRICTED USE SOURCE CODE
// http://www.magic-software.com/License/restricted.pdf

#include "MgcIKController.h"
#include "MgcIKJoint.h"
#include "MgcNode.h"

MgcImplementRTTI(MgcIKController,MgcController);
MgcImplementStream(MgcIKController);

//----------------------------------------------------------------------------
MgcIKController::MgcIKController (MgcSpatial* pkObject)
{
    MgcController::SetObject(pkObject);

    m_uiJointQuantity = 0;
    m_apkJoint = 0;
    m_uiGoalQuantity = 0;
    m_apkGoal = 0;
    m_uiIterations = 16;
}
//----------------------------------------------------------------------------
MgcIKController::~MgcIKController ()
{
    delete[] m_apkJoint;
    delete[] m_apkGoal;
}
//----------------------------------------------------------------------------
void MgcIKController::Initialize ()
{
}
//----------------------------------------------------------------------------
bool MgcIKController::Converged ()
{
    return false;
}
//----------------------------------------------------------------------------
bool MgcIKController::Update (MgcReal fAppTime)
{
    if ( !Active() )
    {
        // controller does not compute world transform
        return false;
    }

    // Make sure effectors are all current in world space.  It is assumed
    // that the joints form a chain, so the world transforms of joint I
    // are the parent transforms for the joint I+1.
    unsigned int uiJ;
    for (uiJ = 0; uiJ < m_uiJointQuantity; uiJ++)
        m_apkJoint[uiJ]->UpdateTransforms();

    // Update joints one-at-a-time to meet goals.  As each joint is updated,
    // the effectors occurring in the chain after that joint must be made
    // current in world space.
    Initialize();
    for (unsigned int uiI = 0; uiI < m_uiIterations && !Converged(); uiI++)
    {
        for (uiJ = 0; uiJ < m_uiJointQuantity; uiJ++)
        {
            m_apkJoint[uiJ]->Update(m_uiGoalQuantity,m_apkGoal);
            for (unsigned int uiK = uiJ; uiK < m_uiJointQuantity; uiK++)
                m_apkJoint[uiK]->UpdateTransforms();
        }
    }

    // controller does not compute world transform
    return false;
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// streaming
//----------------------------------------------------------------------------
MgcObject* MgcIKController::Factory (MgcStream& rkStream)
{
    MgcIKController* pkObject = new MgcIKController;
    MgcStream::Link* pkLink = new MgcStream::Link(pkObject);
    pkObject->Load(rkStream,pkLink);
    return pkObject;
}
//----------------------------------------------------------------------------
void MgcIKController::Load (MgcStream& rkStream, MgcStream::Link* pkLink)
{
    MgcController::Load(rkStream,pkLink);
}
//----------------------------------------------------------------------------
void MgcIKController::Link (MgcStream& rkStream, MgcStream::Link* pkLink)
{
    MgcController::Link(rkStream,pkLink);
}
//----------------------------------------------------------------------------
bool MgcIKController::Register (MgcStream& rkStream)
{
    return MgcController::Register(rkStream);
}
//----------------------------------------------------------------------------
void MgcIKController::Save (MgcStream& rkStream)
{
    MgcController::Save(rkStream);
}
//----------------------------------------------------------------------------

⌨️ 快捷键说明

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