private void InitMotioObject()
        {
            if (_motioObject == null)
            {
                PtrClass a = ((IVdsGroupInterface)_currentView.GameLayer).GetObjectByID(ActorBindingID.Value);
                if (a == null)
                {
                    return;
                }
                _motioObject = a as VdsActor;
                VdsVec3d   tRotate = TargetPose;
                VdsVec3d   oRotate = _motioObject.ActorRotation;
                VdsMatrixd oMt     = new VdsMatrixd();
                VdsMatrixd.HprToMatrix(ref oMt, tRotate);
                _targetPose = oMt.GetRotate();
                VdsMatrixd tMt = new VdsMatrixd();
                VdsMatrixd.HprToMatrix(ref tMt, oRotate);
                _originPose = tMt.GetRotate();
                _originPos  = _motioObject.ActorTranslation;
            }
            if (_relevanceObject == null && ActorRelevanceID.Value != "" && (RelevanceRotation.Value || RelevancePosition.Value))
            {
                PtrClass a = ((IVdsGroupInterface)_currentView.GameLayer).GetObjectByID(ActorRelevanceID.Value);
                if (a != null)
                {
                    _relevanceObject = a as VdsActor;
                    if (RelevancePosition.Value || RelevanceRotation.Value)
                    {
                        StaticMethod.ComputeCoordinateFrame(_relevanceObject, ref _relevanceMatrixd);
                        StaticMethod.ComputeCoordinateFrame(_motioObject.ParentObject as VdsActor, ref _parentLocalToWorld);
                        VdsMatrixd worldToRelevance = _relevanceMatrixd.Inverse(_relevanceMatrixd);
                        VdsMatrixd originPoseMt     = new VdsMatrixd();
                        originPoseMt.MakeRotate(_originPose);
                        originPoseMt.PreMult(_parentLocalToWorld);
                        originPoseMt.PreMult(worldToRelevance);
                        _originPose = originPoseMt.GetRotate();

                        VdsMatrixd targetPoseMt = new VdsMatrixd();
                        targetPoseMt.MakeRotate(_targetPose);
                        targetPoseMt.PreMult(_parentLocalToWorld);
                        targetPoseMt.PreMult(worldToRelevance);
                        _originPose = targetPoseMt.GetRotate();

                        _originPos = _parentLocalToWorld.PreMult(_originPos);
                        _originPos = worldToRelevance.PreMult(_originPos);
                    }
                }
            }
        }
        public override void UpdateStep(object param)
        {
            if (param == null)
            {
                return;
            }
            double?t = param as double?;

            if (t == null)
            {
                return;
            }
            _curTime = (double)t;
            if (_curTime < 0)
            {
                return;
            }
            InitMotioObject();
            VdsPlotEvent pEvent = ParentActor as VdsPlotEvent;

            if (_curTime > pEvent.EventStartTime && _curTime < pEvent.EventStartTime + pEvent.EventDurationTime)
            {
                if (_motioObject != null)
                {
                    VdsVec3d pos = _originPos;
                    double   interpolationValue = (_curTime - pEvent.EventStartTime) / pEvent.EventDurationTime;
                    VdsQuat  quat = VdsQuat.Slerp(interpolationValue, _originPose, _targetPose);
                    SetActorStatus(_motioObject, ActorStatus.Value, true);
                    VdsMatrixd rotateMt = new VdsMatrixd();
                    rotateMt.MakeRotate(quat);
                    if (_relevanceObject != null)
                    {
                        VdsMatrixd nowMt        = new VdsMatrixd();
                        VdsMatrixd localToWorld = new VdsMatrixd();
                        StaticMethod.ComputeCoordinateFrame(_relevanceObject, ref nowMt);
                        StaticMethod.ComputeCoordinateFrame(_motioObject.ParentObject as VdsActor, ref localToWorld);
                        VdsMatrixd worldToLocal = localToWorld.Inverse(localToWorld);
                        if (RelevancePosition.Value && !RelevanceRotation.Value)
                        {
                            nowMt.MakeTranslate(nowMt.GetTrans());
                            pos = nowMt.PreMult(pos);
                            pos = worldToLocal.PreMult(pos);
                            rotateMt.PreMult(nowMt);
                            rotateMt.PreMult(worldToLocal);
                        }
                        else if (!RelevancePosition.Value && RelevanceRotation.Value)
                        {
                            nowMt.MakeRotate(nowMt.GetRotate());
                            pos = _relevanceMatrixd.PreMult(pos);
                            pos = worldToLocal.PreMult(pos);
                            rotateMt.PreMult(nowMt);
                            rotateMt.PreMult(worldToLocal);
                        }
                        else if (RelevancePosition.Value && RelevanceRotation.Value)
                        {
                            rotateMt.PreMult(nowMt);
                            rotateMt.PreMult(worldToLocal);
                            pos = nowMt.PreMult(pos);
                            pos = worldToLocal.PreMult(pos);
                        }
                    }
                    VdsVec3d zr = new VdsVec3d();
                    VdsMatrixd.MatrixToHpr(ref zr, rotateMt);
                    VdsVec3d rotation = new VdsVec3d(0, 0, zr.Z);
                    _motioObject.ActorRotation    = rotation;
                    _motioObject.ActorTranslation = pos;
                }
            }
            else if (_motioObject != null)
            {
                SetActorStatus(_motioObject, "DefaultStatus", false);
            }
        }
Example #3
0
        public override void UpdateStep(object param)
        {
            if (param == null)
            {
                return;
            }
            double?t = param as double?;

            if (t == null)
            {
                return;
            }
            _curTime = (double)t;
            if (_curTime < 0)
            {
                return;
            }
            InitMotioObject();
            VdsPlotEvent pEvent = ParentActor as VdsPlotEvent;

            if (_curTime > pEvent.EventStartTime && _curTime < pEvent.EventStartTime + pEvent.EventDurationTime)
            {
                if (_motioObject != null)
                {
                    VdsVec3d pos       = new VdsVec3d();
                    VdsVec3d direction = new VdsVec3d();
                    GetTranslationAndRotation(_motioObject, _curTime - pEvent.EventStartTime, out pos, out direction);
                    SetActorStatus(_motioObject, ActorStatus.Value, true);
                    if (_relevanceObject != null)
                    {
                        VdsMatrixd nowMt        = new VdsMatrixd();
                        VdsMatrixd localToWorld = new VdsMatrixd();
                        StaticMethod.ComputeCoordinateFrame(_relevanceObject, ref nowMt);
                        StaticMethod.ComputeCoordinateFrame(_motioObject.ParentObject as VdsActor, ref localToWorld);
                        VdsMatrixd worldToLocal = localToWorld.Inverse(localToWorld);
                        if (RelevancePosition.Value && !RelevanceRotation.Value)
                        {
                            nowMt.MakeTranslate(nowMt.GetTrans());
                            pos = nowMt.PreMult(pos);
                            pos = worldToLocal.PreMult(pos);
                        }
                        else if (!RelevancePosition.Value && RelevanceRotation.Value)
                        {
                            nowMt.MakeRotate(nowMt.GetRotate());
                            direction = nowMt.PreMult(direction);
                            direction = worldToLocal.PreMult(direction);
                            VdsVec3d zPos = new VdsVec3d();
                            zPos      = nowMt.PreMult(zPos);
                            zPos      = worldToLocal.PreMult(zPos);
                            direction = direction - zPos;

                            pos = _relevanceMatrixd.PreMult(pos);
                            pos = worldToLocal.PreMult(pos);
                        }
                        else if (RelevancePosition.Value && RelevanceRotation.Value)
                        {
                            direction = nowMt.PreMult(direction);
                            direction = worldToLocal.PreMult(direction);
                            VdsVec3d zPos = new VdsVec3d();
                            zPos      = nowMt.PreMult(zPos);
                            zPos      = worldToLocal.PreMult(zPos);
                            direction = direction - zPos;

                            pos = nowMt.PreMult(pos);
                            pos = worldToLocal.PreMult(pos);
                        }
                    }
                    direction.Normalize();
                    VdsVec3d   zr  = new VdsVec3d();
                    VdsMatrixd rMt = new VdsMatrixd();
                    rMt.MakeRotate(new VdsVec3d(1, 0, 0), direction);
                    VdsMatrixd.MatrixToHpr(ref zr, rMt);
                    VdsVec3d rotation = new VdsVec3d(0, 0, zr.Z);
                    _motioObject.ActorRotation    = rotation;
                    _motioObject.ActorTranslation = pos;
                }
            }
            else if (_motioObject != null)
            {
                SetActorStatus(_motioObject, "DefaultStatus", false);
            }
        }