Beispiel #1
0
        private void GetTranslationAndRotation(VdsActor actor, double timeOffset, out VdsVec3d translation, out VdsVec3d direction)
        {
            direction = _motionObjectOriginDirection;
            if (_motionSpeed == 0)
            {
                translation = _motionObjectOriginPos;
                return;
            }
            double timeTotal = 0;

            for (int i = 0; i < ActorMotionKeyPoints.ValueList.Count - 1; ++i)
            {
                double eLength = (ActorMotionKeyPoints.ValueList[i] - ActorMotionKeyPoints.ValueList[i + 1]).Length();
                timeTotal += eLength / _motionSpeed;
                if (timeTotal >= timeOffset)
                {
                    if (MotionAutoAhead.Value)
                    {
                        direction = ActorMotionKeyPoints.ValueList[i + 1] - ActorMotionKeyPoints.ValueList[i];
                        direction.Normalize();
                    }
                    translation = ActorMotionKeyPoints.ValueList[i + 1] - direction * (timeTotal - timeOffset) * _motionSpeed;
                    return;
                }
            }
            if (MotionAutoAhead.Value)
            {
                direction = ActorMotionKeyPoints.ValueList[ActorMotionKeyPoints.ValueList.Count - 1] - ActorMotionKeyPoints.ValueList[ActorMotionKeyPoints.ValueList.Count - 2];
                direction.Normalize();
            }
            translation = ActorMotionKeyPoints.ValueList[ActorMotionKeyPoints.ValueList.Count - 1];
        }
Beispiel #2
0
        public static List <VdsVec3d> ConstructCatmullRomSplinePoint(List <VdsVec3d> controlPoints, int seg)
        {
            List <VdsVec3d> vList = new List <VdsVec3d>();

            VdsVec3d[] dList = new VdsVec3d[controlPoints.Count + 2];
            controlPoints.CopyTo(0, dList, 1, controlPoints.Count);
            VdsVec3d p0 = controlPoints[0] * 2 - controlPoints[1];

            dList[0] = p0;
            VdsVec3d pn = controlPoints[controlPoints.Count - 1] * 2 - controlPoints[controlPoints.Count - 2];

            dList[dList.Length - 1] = pn;
            List <VdsVec3d> subConctrl = new List <VdsVec3d>(4);

            for (int i = 0; i < dList.Length; ++i)
            {
                if (i < dList.Length - 3)
                {
                    subConctrl[0] = dList[i];
                    subConctrl[1] = dList[i + 1];
                    subConctrl[2] = dList[i + 2];
                    subConctrl[3] = dList[i + 3];
                    double deltaU = 1.0 / (double)seg;
                    for (int j = 0; j < seg; ++j)
                    {
                        double   uu    = j * deltaU;
                        VdsVec3d tempp = DoCatmullRom(uu, subConctrl);
                        vList.Add(tempp);
                    }
                }
            }
            return(vList);
        }
Beispiel #3
0
        public virtual void UpdateTrigger()
        {
            if (IsTimeOut())
            {
                return;
            }
            if (IsDynamic)
            {
                TriggerPosition = (ParentActor as VdsGameActor).ActorTranslation;
            }
            if (_triggerTimes >= TriggerMaxTimes)
            {
                SetTimeOut(true);
                return;
            }
            long curTicks = DateTime.Now.Ticks;

            if (_startTicks == 0)
            {
                _startTicks = curTicks;
            }
            SetTimeTicks(curTicks);
            double t = (GetTimeTicks() - _startTicks) / TimeSpan.TicksPerMillisecond / 1000.0;

            if (LifeTimeSecond > 0 && t >= LifeTimeSecond)
            {
                SetTimeOut(true);
            }
        }
Beispiel #4
0
 public void MakeTranslate(VdsVec3d t)
 {
     SetRow(0, 1, 0, 0, 0);
     SetRow(1, 0, 1, 0, 0);
     SetRow(2, 0, 0, 1, 0);
     SetRow(3, t.X, t.Y, t.Z, 1);
 }
Beispiel #5
0
 public void FromString(string str)
 {
     char[] c = new char[1] {
         ','
     };
     string[] vList = str.Split(c, StringSplitOptions.RemoveEmptyEntries);
     if (vList.Length > 0)
     {
         VdsVec3d v = new VdsVec3d();
         v.FromString(vList[0]);
         Eye = v;
     }
     if (vList.Length > 1)
     {
         VdsVec3d v = new VdsVec3d();
         v.FromString(vList[1]);
         Center = v;
     }
     if (vList.Length > 2)
     {
         VdsVec3d v = new VdsVec3d();
         v.FromString(vList[2]);
         Up = v;
     }
 }
Beispiel #6
0
 public void MakeScale(VdsVec3d s)
 {
     SetRow(0, s.X, 0, 0, 0);
     SetRow(1, 0, s.Y, 0, 0);
     SetRow(2, 0, 0, s.Z, 0);
     SetRow(3, 0, 0, 0, 1);
 }
Beispiel #7
0
        public VdsVec3d PostMult(VdsVec3d v)
        {
            double d = 1.0f / (_mat[3, 0] * v.X + _mat[3, 1] * v.Y + _mat[3, 2] * v.Z + _mat[3, 3]);

            return(new VdsVec3d((_mat[0, 0] * v.X + _mat[0, 1] * v.Y + _mat[0, 2] * v.Z + _mat[0, 3]) * d,
                                (_mat[1, 0] * v.X + _mat[1, 1] * v.Y + _mat[1, 2] * v.Z + _mat[1, 3]) * d,
                                (_mat[2, 0] * v.X + _mat[2, 1] * v.Y + _mat[2, 2] * v.Z + _mat[2, 3]) * d));
        }
Beispiel #8
0
        public void MakeRotate(double angle, VdsVec3d axis)
        {
            MakeIdentity();
            VdsQuat quat = new VdsQuat();

            quat.MakeRotate(angle, axis);
            MakeRotate(quat);
        }
Beispiel #9
0
        public void MakeRotate(VdsVec3d from, VdsVec3d to)
        {
            MakeIdentity();
            VdsQuat quat = new VdsQuat();

            quat.MakeRotate(from, to);
            MakeRotate(quat);
        }
Beispiel #10
0
        public VdsVec3d getScale()
        {
            VdsVec3d x_vec = new VdsVec3d(_mat[0, 0], _mat[1, 0], _mat[2, 0]);
            VdsVec3d y_vec = new VdsVec3d(_mat[0, 1], _mat[1, 1], _mat[2, 1]);
            VdsVec3d z_vec = new VdsVec3d(_mat[0, 2], _mat[1, 2], _mat[2, 2]);

            return(new VdsVec3d(x_vec.Length(), y_vec.Length(), z_vec.Length()));
        }
Beispiel #11
0
 public PlotEventActorCreate()
 {
     ActorBindingID = new StringProperty();
     ActorResource  = new FilePathProperty();
     ActorStatus    = new StringProperty();
     ActorPosition  = new VdsVec3d();
     ActorRotation  = new VdsVec3d();
 }
 public PlotEventActorRotaryMotion()
 {
     ActorBindingID          = new StringProperty();
     ActorRelevanceID        = new StringProperty();
     ActorStatus             = new StringProperty();
     TargetPose              = new VdsVec3d();
     RelevancePosition       = new BoolProperty();
     RelevancePosition.Value = true;
     RelevanceRotation       = new BoolProperty();
     RelevanceRotation.Value = true;
 }
Beispiel #13
0
        public static VdsVec3d operator *(VdsQuat q, VdsVec3d v)
        {
            VdsVec3d uv, uuv;
            VdsVec3d qvec = new VdsVec3d(q._v[0], q._v[1], q._v[2]);

            uv   = qvec ^ v;
            uuv  = qvec ^ uv;
            uv  *= (2.0f * q._v[3]);
            uuv *= 2.0f;
            return(v + uv + uuv);
        }
Beispiel #14
0
        public void MakeRotate(double angle1, VdsVec3d axis1,
                               double angle2, VdsVec3d axis2,
                               double angle3, VdsVec3d axis3)
        {
            MakeIdentity();
            VdsQuat quat = new VdsQuat();

            quat.MakeRotate(angle1, axis1,
                            angle2, axis2,
                            angle3, axis3);
            MakeRotate(quat);
        }
Beispiel #15
0
        public static void HprToMatrix(ref VdsMatrixd rotation, VdsVec3d hpr)
        {
            double tmp = hpr.X;

            hpr.X = hpr.Z;
            hpr.Z = hpr.Y;
            hpr.Y = tmp;
            double ch, sh, cp, sp, cr, sr, srsp, crsp, srcp;
            double magicEpsilon = 0.00001;

            if (StaticMethod.Equivalent(hpr.X, 0.0, magicEpsilon))
            {
                ch = 1.0;
                sh = 0.0;
            }
            else
            {
                sh = Math.Sin(StaticMethod.DegreesToRadians(hpr.X));
                ch = Math.Cos(StaticMethod.DegreesToRadians(hpr.X));
            }
            if (StaticMethod.Equivalent(hpr.Y, 0.0, magicEpsilon))
            {
                cp = 1.0;
                sp = 0.0;
            }
            else
            {
                sp = Math.Sin(StaticMethod.DegreesToRadians(hpr.Y));
                cp = Math.Cos(StaticMethod.DegreesToRadians(hpr.Y));
            }
            if (StaticMethod.Equivalent(hpr.Z, 0.0, magicEpsilon))
            {
                cr   = 1.0;
                sr   = 0.0;
                srsp = 0.0;
                srcp = 0.0;
                crsp = sp;
            }
            else
            {
                sr   = Math.Sin(StaticMethod.DegreesToRadians(hpr.Z));
                cr   = Math.Cos(StaticMethod.DegreesToRadians(hpr.Z));
                srsp = sr * sp;
                crsp = cr * sp;
                srcp = sr * cp;
            }
            rotation.SetMatrixd(ch * cr - sh * srsp, cr * sh + srsp * ch, -srcp, 0.0,
                                -sh * cp, ch * cp, sp, 0.0,
                                sr * ch + sh * crsp, sr * sh - crsp * ch, cr * cp, 0.0,
                                0.0, 0.0, 0.0, 1.0);
        }
Beispiel #16
0
        private void InitMotioObject()
        {
            if (_motioObject == null)
            {
                PtrClass a = ((IVdsGroupInterface)_currentView.GameLayer).GetObjectByID(ActorBindingID.Value);
                if (a == null)
                {
                    return;
                }
                _motioObject           = a as VdsActor;
                _motionObjectOriginPos = _motioObject.ActorTranslation;
                VdsVec3d   direction = new VdsVec3d(1, 0, 0);
                VdsMatrixd rMt       = new VdsMatrixd();
                VdsMatrixd.HprToMatrix(ref rMt, _motioObject.ActorRotation);
                direction = rMt.PreMult(direction);
                _motionObjectOriginDirection = direction;
            }
            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)
                    {
                        VdsMatrixd localToWorld = new VdsMatrixd();
                        StaticMethod.ComputeCoordinateFrame(_motioObject.ParentObject as VdsActor, ref localToWorld);
                        StaticMethod.ComputeCoordinateFrame(_relevanceObject, ref _relevanceMatrixd);
                        VdsMatrixd worldToRelevance = _relevanceMatrixd.Inverse(_relevanceMatrixd);

                        _motionObjectOriginDirection = localToWorld.PreMult(_motionObjectOriginDirection);
                        _motionObjectOriginDirection = worldToRelevance.PreMult(_motionObjectOriginDirection);
                        VdsVec3d zPos = new VdsVec3d();
                        zPos = localToWorld.PreMult(zPos);
                        zPos = worldToRelevance.PreMult(zPos);
                        _motionObjectOriginDirection = _motionObjectOriginDirection - zPos;
                        _motionObjectOriginDirection.Normalize();
                        _motionObjectOriginPos = localToWorld.PreMult(_motionObjectOriginPos);
                        _motionObjectOriginPos = worldToRelevance.PreMult(_motionObjectOriginPos);
                        List <VdsVec3d> newKeyPointsList = new List <VdsVec3d>(ActorMotionKeyPoints.ValueList.Count);
                        foreach (VdsVec3d v in ActorMotionKeyPoints.ValueList)
                        {
                            VdsVec3d newV = localToWorld.PreMult(v);
                            newV = worldToRelevance.PreMult(newV);
                            newKeyPointsList.Add(newV);
                        }
                        ActorMotionKeyPoints.ValueList = newKeyPointsList;
                    }
                }
            }
        }
        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);
                    }
                }
            }
        }
Beispiel #18
0
        public void FromString(string str)
        {
            char[] c = new char[1] {
                ','
            };
            string[]        vList      = str.Split(c, StringSplitOptions.RemoveEmptyEntries);
            List <VdsVec3d> resultList = new List <VdsVec3d>(vList.Length);

            for (int i = 0; i < vList.Length; ++i)
            {
                VdsVec3d v = new VdsVec3d();
                v.FromString(vList[i]);
                resultList.Add(v);
            }
            ValueList = resultList;
        }
 public override void End()
 {
     if (_currentView != null && _motioObject != null)
     {
         _motioObject = null;
     }
     _relevanceObject    = null;
     _relevanceMatrixd   = null;
     _parentLocalToWorld = null;
     _behaviourIsWorking = false;
     _originPose         = null;
     _originPos          = null;
     _targetPose         = null;
     _currentView        = null;
     base.End();
 }
Beispiel #20
0
        public void MakeRotate(double angle1, VdsVec3d axis1,
                               double angle2, VdsVec3d axis2,
                               double angle3, VdsVec3d axis3)
        {
            VdsQuat q1 = new VdsQuat();

            q1.MakeRotate(angle1, axis1);
            VdsQuat q2 = new VdsQuat();

            q2.MakeRotate(angle2, axis2);
            VdsQuat q3 = new VdsQuat();

            q3.MakeRotate(angle3, axis3);
            VdsQuat q = q1 * q2 * q3;

            SetQuat(q);
        }
Beispiel #21
0
 public CameraPoseProperty()
 {
     Eye    = new VdsVec3d(50, 50, 50);
     Center = new VdsVec3d();
     Up     = new VdsVec3d(0, 0, 1);
 }
Beispiel #22
0
 public VdsVec3d(VdsVec3d v)
 {
     X = v.X;
     Y = v.Y;
     Z = v.Z;
 }
Beispiel #23
0
        public void MakeRotate(VdsVec3d from, VdsVec3d to)
        {
            VdsVec3d sourceVector = new VdsVec3d(from);
            VdsVec3d targetVector = new VdsVec3d(to);
            double   fromLen2     = from.Length2();
            double   fromLen;

            if ((fromLen2 < 1.0 - 1e-7) || (fromLen2 > 1.0 + 1e-7))
            {
                fromLen       = Math.Sqrt(fromLen2);
                sourceVector /= fromLen;
            }
            else
            {
                fromLen = 1.0;
            }
            double toLen2 = to.Length2();

            if ((toLen2 < 1.0 - 1e-7) || (toLen2 > 1.0 + 1e-7))
            {
                double toLen;
                if ((toLen2 > fromLen2 - 1e-7) && (toLen2 < fromLen2 + 1e-7))
                {
                    toLen = fromLen;
                }
                else
                {
                    toLen = Math.Sqrt(toLen2);
                }
                targetVector /= toLen;
            }
            double dotProdPlus1 = 1.0 + sourceVector * targetVector;

            if (dotProdPlus1 < 1e-7)
            {
                if (Math.Abs(sourceVector.X) < 0.6)
                {
                    double norm = Math.Sqrt(1.0 - sourceVector.X * sourceVector.X);
                    _v[0] = 0.0;
                    _v[1] = sourceVector.Z / norm;
                    _v[2] = -sourceVector.Y / norm;
                    _v[3] = 0.0;
                }
                else if (Math.Abs(sourceVector.Y) < 0.6)
                {
                    double norm = Math.Sqrt(1.0 - sourceVector.Y * sourceVector.Y);
                    _v[0] = -sourceVector.Z / norm;
                    _v[1] = 0.0;
                    _v[2] = sourceVector.X / norm;
                    _v[3] = 0.0;
                }
                else
                {
                    double norm = Math.Sqrt(1.0 - sourceVector.Z * sourceVector.Z);
                    _v[0] = sourceVector.Y / norm;
                    _v[1] = -sourceVector.X / norm;
                    _v[2] = 0.0;
                    _v[3] = 0.0;
                }
            }

            else
            {
                double   s   = Math.Sqrt(0.5 * dotProdPlus1);
                VdsVec3d tmp = sourceVector ^ targetVector / (2.0 * s);
                _v[0] = tmp.X;
                _v[1] = tmp.Y;
                _v[2] = tmp.Z;
                _v[3] = s;
            }
        }
        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);
            }
        }
Beispiel #25
0
        public void UpdateGeometry()
        {
            if (VertexArray == null)
            {
                return;
            }
            int updateThreadID = GlobalEnvironment.UpdateThreadID;
            int curThreadID    = System.Threading.Thread.CurrentThread.ManagedThreadId;

            if (updateThreadID != curThreadID)
            {
                return;
            }
            VdsVec3d[] vArray = VertexArray.ToArray();
            VdsVec3d[] nArray = null;
            if (NormalArray != null)
            {
                nArray = NormalArray.ToArray();
            }
            else
            {
                nArray = new VdsVec3d[0];
            }
            VdsVec4d[] cArray = null;
            if (ColorArray != null)
            {
                cArray = ColorArray.ToArray();
            }
            else
            {
                cArray = new VdsVec4d[0];
            }
            VdsVec2d[] tArray = null;
            if (TexCoordArray != null)
            {
                tArray = TexCoordArray.ToArray();
            }
            else
            {
                tArray = new VdsVec2d[0];
            }

            VdsVec4d[] maturalArray = null;
            if (AmbientMatural == null && DiffuseMatural == null && SpecularMatural == null && EmissionMatural == null)
            {
                maturalArray = new VdsVec4d[0];
            }
            else
            {
                maturalArray = new VdsVec4d[4];
                if (AmbientMatural == null)
                {
                    maturalArray[0] = new VdsVec4d(0.8, 0.8, 0.8, 1.0);
                }
                else
                {
                    maturalArray[0] = AmbientMatural;
                }
                if (DiffuseMatural == null)
                {
                    maturalArray[1] = new VdsVec4d(0.9, 0.9, 0.9, 1.0);
                }
                else
                {
                    maturalArray[1] = DiffuseMatural;
                }
                if (SpecularMatural == null)
                {
                    maturalArray[2] = new VdsVec4d(0.95, 0.95, 0.95, 1.0);
                }
                else
                {
                    maturalArray[2] = SpecularMatural;
                }
                if (EmissionMatural == null)
                {
                    maturalArray[3] = new VdsVec4d(0.1, 0.1, 0.1, 1.0);
                }
                else
                {
                    maturalArray[3] = EmissionMatural;
                }
            }
            string tFileName = "";

            if (TextureFileName != null)
            {
                tFileName = TextureFileName;
            }
            int drawMode = 0;

            switch (DrawMode)
            {
            case GeometryDrawModel.POINTS:
                drawMode = 0;
                break;

            case GeometryDrawModel.LINES:
                drawMode = 1;
                break;

            case GeometryDrawModel.LINE_STRIP:
                drawMode = 3;
                break;

            case GeometryDrawModel.LINE_LOOP:
                drawMode = 2;
                break;

            case GeometryDrawModel.TRIANGLES:
                drawMode = 4;
                break;

            case GeometryDrawModel.TRIANGLE_STRIP:
                drawMode = 5;
                break;

            case GeometryDrawModel.TRIANGLE_FAN:
                drawMode = 6;
                break;

            case GeometryDrawModel.QUADS:
                drawMode = 7;
                break;

            case GeometryDrawModel.QUAD_STRIP:
                drawMode = 8;
                break;
            }
            IUpdateGeometry(this.NativeHandle, vArray, nArray, cArray, tArray, drawMode, (int)CullFaceMode, tFileName, maturalArray);
        }
Beispiel #26
0
 public void MakeRotate(double angle, VdsVec3d vec)
 {
     MakeRotate(angle, vec.X, vec.Y, vec.Z);
 }
Beispiel #27
0
        public static void MatrixToHpr(ref VdsVec3d hpr, VdsMatrixd rotation)
        {
            VdsMatrixd   mat          = new VdsMatrixd();
            VdsVec3d     col1         = new VdsVec3d(rotation.Mat[0, 0], rotation.Mat[0, 1], rotation.Mat[0, 2]);
            double       s            = col1.Length();
            const double magicEpsilon = 0.00001;

            if (s <= magicEpsilon)
            {
                hpr.X = 0.0;
                hpr.Y = 0.0;
                hpr.Z = 0.0;
                return;
            }
            double oneOverS = 1.0f / s;

            for (int i = 0; i < 3; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    mat.Mat[i, j] = rotation.Mat[i, j] * oneOverS;
                }
            }
            double sinPitch = StaticMethod.ClampUnity(mat.Mat[1, 2]);
            double pitch    = Math.Asin(sinPitch);

            hpr.Y = StaticMethod.RadiansToDegrees(pitch);
            double cp = Math.Cos(pitch);

            if (cp > -magicEpsilon && cp < magicEpsilon)
            {
                double cr = StaticMethod.ClampUnity(-mat.Mat[2, 1]);
                double sr = StaticMethod.ClampUnity(mat.Mat[0, 1]);
                hpr.X = 0.0f;
                hpr.Z = StaticMethod.RadiansToDegrees(Math.Atan2(sr, cr));
            }
            else
            {
                double oneOverCp = 1.0 / cp;
                double sr        = StaticMethod.ClampUnity(-mat.Mat[0, 2] * oneOverCp);
                double cr        = StaticMethod.ClampUnity(mat.Mat[2, 2] * oneOverCp);
                double sh        = StaticMethod.ClampUnity(-mat.Mat[1, 0] * oneOverCp);
                double ch        = StaticMethod.ClampUnity(mat.Mat[1, 1] * oneOverCp);
                if ((StaticMethod.Equivalent(sh, 0.0, magicEpsilon) && StaticMethod.Equivalent(ch, 0.0, magicEpsilon)) ||
                    (StaticMethod.Equivalent(sr, 0.0, magicEpsilon) && StaticMethod.Equivalent(cr, 0.0, magicEpsilon)))
                {
                    cr    = StaticMethod.ClampUnity(-mat.Mat[2, 1]);
                    sr    = StaticMethod.ClampUnity(mat.Mat[0, 1]);;
                    hpr.X = 0.0f;
                }
                else
                {
                    hpr.X = StaticMethod.RadiansToDegrees(Math.Atan2(sh, ch));
                }
                hpr.Z = StaticMethod.RadiansToDegrees(Math.Atan2(sr, cr));
            }
            double tmp = hpr.X;

            hpr.X = hpr.Y;
            hpr.Y = hpr.Z;
            hpr.Z = tmp;
        }
Beispiel #28
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);
            }
        }