Example #1
0
void dsp_quick(NSLNSLnet *net)
{ int rr,qq,pp,nn,num,parts,flds,outnum=0;
  hop_ctrl_ds *hp=nsl_drv(hop_ctrl_ds); bio_ds *np=(&hp->nio);
  float val,hamap,hamai,ham;
  flds=np->fld_siz; num=dsi(np->flda,hop_tree_ds,size.part);
  parts=flds/num;
  for(rr=0;rr<num_pats;++rr)
    {hamap=(float)0.0; hamai=(float)0.0;
     for(pp=0;pp<parts;++pp)
      {for(qq=0;qq<num;++qq)
         {nn=pp*num+qq;
          val=(float)((quant)qua(np->flda+pp,hop_tree_ds,part[qq].output))
            /((float)QSCALE);
          hamap+=diff((float)patsa[rr][nn],val);  val=(float)1.0-val;
          hamai+=diff((float)patsa[rr][nn],val);
          val=(float)((quant)qua(np->fldb+pp,hop_tree_ds,part[qq].output))
            /((float)QSCALE);
          hamap+=diff((float)patsb[rr][nn],val);  val=(float)1.0-val;
          hamai+=diff((float)patsb[rr][nn],val);
         }
      }
    if(rr==0) ham=hamap;
    if(hamap<ham) {outnum=2*rr; ham=hamap;}
    if(hamai<ham) {outnum=2*rr+1; ham=hamai;}
    }
  fprintf(bam_logfp,"%d,%.3f,%d\n",curcc,ham,outnum);
}
Example #2
0
bool DexSkinMesh::AddJointKeyFrameRotation(Joint* joint, int32 time, const DexVector3& axis, float32 radian)
{
	DEX_ENSURE_B(joint);
	DexQuaternion qua(axis, radian);
	DexMatrix4x4 matrix = qua.GetMatrix();
	joint->AddKeyFrame(time, matrix);
	return true;
}
Example #3
0
bool DexSkinMesh::AddJointKeyFrame(Joint* joint, int32 time, const DexVector3& pos, const DexVector3& scale, const DexVector3& axis, float32 radian)
{
	DEX_ENSURE_B(joint);
	DexQuaternion qua(axis, radian);
	DexMatrix4x4 rotationMatrix = qua.GetMatrix();
	DexMatrix4x4 scaleMatrix; scaleMatrix.Scale(scale);
	DexMatrix4x4 TransMatrix; TransMatrix.Translate(pos);
	DexMatrix4x4 matrix = scaleMatrix * rotationMatrix * TransMatrix;
	joint->AddKeyFrame(time, matrix);
	return true;
}
Example #4
0
void Animate3D::update(float t)
{
    if (_target)
    {
        if (_state == Animate3D::Animate3DState::FadeIn && _lastTime > 0.f)
        {
            _accTransTime += (t - _lastTime) * getDuration();
            
            _weight = _accTransTime / _transTime;
            if (_weight >= 1.0f)
            {
                _accTransTime = _transTime;
                _weight = 1.0f;
                _state = Animate3D::Animate3DState::Running;
                s_fadeInAnimates.erase(_target);
                s_runningAnimates[_target] = this;
            }
        }
        else if (_state == Animate3D::Animate3DState::FadeOut && _lastTime > 0.f)
        {
            _accTransTime += (t - _lastTime) * getDuration();
            
            _weight = 1 - _accTransTime / _transTime;
            if (_weight <= 0.0f)
            {
                _accTransTime = _transTime;
                _weight = 0.0f;
                
                s_fadeOutAnimates.erase(_target);
                _target->stopAction(this);
                return;
            }
        }
        float lastTime = _lastTime;
        _lastTime = t;
        
        if (_quality != Animate3DQuality::QUALITY_NONE)
        {
            if (_weight > 0.0f)
            {
                float transDst[3], rotDst[4], scaleDst[3];
                float* trans = nullptr, *rot = nullptr, *scale = nullptr;
                if (_playReverse){
                    t = 1 - t;
                    lastTime = 1.0f - lastTime;
                }
                
                t = _start + t * _last;
                lastTime = _start + lastTime * _last;
                
                for (const auto& it : _boneCurves) {
                    auto bone = it.first;
                    auto curve = it.second;
                    if (curve->translateCurve)
                    {
                        curve->translateCurve->evaluate(t, transDst, _translateEvaluate);
                        trans = &transDst[0];
                    }
                    if (curve->rotCurve)
                    {
                        curve->rotCurve->evaluate(t, rotDst, _roteEvaluate);
                        rot = &rotDst[0];
                    }
                    if (curve->scaleCurve)
                    {
                        curve->scaleCurve->evaluate(t, scaleDst, _scaleEvaluate);
                        scale = &scaleDst[0];
                    }
                    bone->setAnimationValue(trans, rot, scale, this, _weight);
                }
                
                for (const auto& it : _nodeCurves)
                {
                    auto node = it.first;
                    auto curve = it.second;
                    Mat4 transform;
                    if (curve->translateCurve)
                    {
                        curve->translateCurve->evaluate(t, transDst, _translateEvaluate);
                        transform.translate(transDst[0], transDst[1], transDst[2]);
                    }
                    if (curve->rotCurve)
                    {
                        curve->rotCurve->evaluate(t, rotDst, _roteEvaluate);
                        Quaternion qua(rotDst[0], rotDst[1], rotDst[2], rotDst[3]);
                        transform.rotate(qua);
                    }
                    if (curve->scaleCurve)
                    {
                        curve->scaleCurve->evaluate(t, scaleDst, _scaleEvaluate);
                        transform.scale(scaleDst[0], scaleDst[1], scaleDst[2]);
                    }
                    node->setAdditionalTransform(&transform);
                }
                if (!_keyFrameUserInfos.empty()){
                    float prekeyTime = lastTime * getDuration() * _frameRate;
                    float keyTime = t * getDuration() * _frameRate;
                    std::vector<Animate3DDisplayedEventInfo*> eventInfos;
                    for (auto keyFrame : _keyFrameUserInfos)
                    {
                        if ((!_playReverse && keyFrame.first >= prekeyTime && keyFrame.first < keyTime)
                            || (_playReverse && keyFrame.first >= keyTime && keyFrame.first < prekeyTime))
                            {
                                auto& frameEvent = _keyFrameEvent[keyFrame.first];
                                if (frameEvent == nullptr)
                                    frameEvent = new (std::nothrow) EventCustom(Animate3DDisplayedNotification);
                                auto eventInfo = &_displayedEventInfo[keyFrame.first];
                                eventInfo->target = _target;
                                eventInfo->frame = keyFrame.first;
                                eventInfo->userInfo = &_keyFrameUserInfos[keyFrame.first];
                                eventInfos.push_back(eventInfo);
                                frameEvent->setUserData((void*)eventInfo);
                            }
                    }
                    std::sort(eventInfos.begin(), eventInfos.end(), _playReverse ? cmpEventInfoDes : cmpEventInfoAsc);
                    for (auto eventInfo : eventInfos) {
                        Director::getInstance()->getEventDispatcher()->dispatchEvent(_keyFrameEvent[eventInfo->frame]);
                    }
                }
            }
        }
    }
}
Example #5
0
void Animate3D::update(float t)
{
    if (_target)
    {
        if (_state == Animate3D::Animate3DState::FadeIn && _lastTime > 0.f)
        {
            _accTransTime += (t - _lastTime) * getDuration();
            
            _weight = _accTransTime / _transTime;
            if (_weight >= 1.0f)
            {
                _accTransTime = _transTime;
                _weight = 1.0f;
                _state = Animate3D::Animate3DState::Running;
                s_fadeInAnimates.erase(_target);
                s_runningAnimates[_target] = this;
            }
        }
        else if (_state == Animate3D::Animate3DState::FadeOut && _lastTime > 0.f)
        {
            _accTransTime += (t - _lastTime) * getDuration();
            
            _weight = 1 - _accTransTime / _transTime;
            if (_weight <= 0.0f)
            {
                _accTransTime = _transTime;
                _weight = 0.0f;
                
                s_fadeOutAnimates.erase(_target);
            }
        }
        _lastTime = t;
        
        if (_weight > 0.0f)
        {
            float transDst[3], rotDst[4], scaleDst[3];
            float* trans = nullptr, *rot = nullptr, *scale = nullptr;
            if (_playReverse)
                t = 1 - t;
            
            t = _start + t * _last;
 
            for (const auto& it : _boneCurves) {
                auto bone = it.first;
                auto curve = it.second;
                if (curve->translateCurve)
                {
                    curve->translateCurve->evaluate(t, transDst, _translateEvaluate);
                    trans = &transDst[0];
                }
                if (curve->rotCurve)
                {
                    curve->rotCurve->evaluate(t, rotDst, _roteEvaluate);
                    rot = &rotDst[0];
                }
                if (curve->scaleCurve)
                {
                    curve->scaleCurve->evaluate(t, scaleDst, _scaleEvaluate);
                    scale = &scaleDst[0];
                }
                bone->setAnimationValue(trans, rot, scale, this, _weight);
            }
            
            for (const auto& it : _nodeCurves)
            {
                auto node = it.first;
                auto curve = it.second;
                Mat4 transform;
                if (curve->translateCurve)
                {
                    curve->translateCurve->evaluate(t, transDst, _translateEvaluate);
                    transform.translate(transDst[0], transDst[1], transDst[2]);
                }
                if (curve->rotCurve)
                {
                    curve->rotCurve->evaluate(t, rotDst, _roteEvaluate);
                    Quaternion qua(rotDst[0], rotDst[1], rotDst[2], rotDst[3]);
                    transform.rotate(qua);
                }
                if (curve->scaleCurve)
                {
                    curve->scaleCurve->evaluate(t, scaleDst, _scaleEvaluate);
                    transform.scale(scaleDst[0], scaleDst[1], scaleDst[2]);
                }
                node->setAdditionalTransform(&transform);
            }
        }
    }
}