Ejemplo n.º 1
0
        public unsafe void LerpPoseFromState([Editor.DisplayParamName("粒子对象(CGfxParticle)")] ref CGfxParticle p, [Editor.DisplayParamName("粒子对象中状态对象1(int)")] int stateindex1, [Editor.DisplayParamName("粒子对象中状态对象2(int)")] int stateindex2, [Editor.DisplayParamName("过度系数(OnGetFactorDelegate)")] OnGetFactorDelegate GetFactor)
        {
            var   ps0    = p.GetState(stateindex1);
            var   ps1    = p.GetState(stateindex2);
            float factor = GetFactor == null ? 0 : GetFactor(p.mLife, p.mLifeTick);

            factor = (float)Math.Max(0.0, Math.Min(1.0, factor));
            CGfxParticlePose.Lerp(ref p.FinalPose, ref ps0->mPose, ref ps1->mPose, factor);
        }
Ejemplo n.º 2
0
 public static void Set(ref CGfxParticlePose l, ref CGfxParticlePose r)
 {
     //r = lh * (1-v) + rh * v;
     l.mPosition = r.mPosition;
     l.mVelocity = r.mVelocity;
     l.mColor    = r.mColor;
     l.mScale    = r.mScale;
     l.mRotation = r.mRotation;
     l.mAngle    = r.mAngle;
 }
Ejemplo n.º 3
0
 public static void SubFunc(ref CGfxParticlePose r, ref CGfxParticlePose lh, ref CGfxParticlePose rh)
 {
     //r = lh * (1-v) + rh * v;
     r.mPosition = lh.mPosition - rh.mPosition;
     r.mVelocity = lh.mVelocity - rh.mVelocity;
     //r.mAcceleration = lh.mAcceleration - rh.mAcceleration;
     r.mColor    = UInt32_4.Lerp(ref lh.mColor, ref rh.mColor, 0.5f);
     r.mScale    = lh.mScale - rh.mScale;
     r.mRotation = Quaternion.Lerp(lh.mRotation, rh.mRotation, 0.5f);
     r.mAngle    = lh.mAngle - rh.mAngle;
 }
Ejemplo n.º 4
0
        public static void Lerp(ref CGfxParticlePose r, ref CGfxParticlePose lh, ref CGfxParticlePose rh, float v)
        {
            //r = lh * (1-v) + rh * v;
            float fa = 1 - v;

            r.mPosition = lh.mPosition * fa + rh.mPosition * v;
            r.mVelocity = lh.mVelocity * fa + rh.mVelocity * v;
            //r.mAcceleration = lh.mAcceleration * fa + rh.mAcceleration * v;
            r.mColor    = UInt32_4.Lerp(ref lh.mColor, ref rh.mColor, v);
            r.mScale    = lh.mScale * fa + rh.mScale * v;
            r.mRotation = Quaternion.Lerp(lh.mRotation, rh.mRotation, v);
            r.mAngle    = lh.mAngle * fa + rh.mAngle * v;
        }
Ejemplo n.º 5
0
 public static void Face2Cameral(ref CGfxParticlePose pose, Graphics.CGfxCamera camera)
 {
 }
Ejemplo n.º 6
0
        public virtual unsafe void DoParticleCollectCompose(CGfxParticleSystem sys, CGfxParticle **ppParticles, int particlenum, int substatenum, float elaspe)
        {
            bool usecompute = true;

            for (int i = 0; i < particlenum; i++)
            {
                if (sys.BillBoardType != CGfxParticleSystem.BILLBOARDTYPE.BILLBOARD_DISABLE || sys.TriggerNodes.Count > 0)
                {
                    prepos = ppParticles[i]->FinalPose.mPosition;
                }

                if (sys.ComposeNodes.Count > 0)
                {
                    usecomposenodes = false;
                    for (int ni = 0; ni < sys.ComposeNodes.Count; ni++)
                    {
                        if (sys.ComposeNodes[ni].CanUsed)
                        {
                            sys.ComposeNodes[ni].ComposeParticle(sys, ref *ppParticles[i], substatenum, elaspe, usecompute);
                            if (usecomposenodes == false)
                            {
                                (*ppParticles[i]).FinalPose = sys.ComposeNodes[ni].ResultPose;// TODO.
                            }
                            else
                            {
                                CGfxParticlePose.AddFunc(ref (*ppParticles[i]).FinalPose, ref (*ppParticles[i]).FinalPose, ref sys.ComposeNodes[ni].ResultPose);
                            }

                            usecomposenodes = true;
                        }
                    }
                }

                usecompute = false;

                if (usecomposenodes == false)
                {
                    if (sys.SubStates.Length > 0)
                    {
                        var ps = ppParticles[i]->GetState(0);
                        ppParticles[i]->FinalPose = ps->mPose;
                        CGfxParticlePose.Set(ref ppParticles[i]->FinalPose, ref ps->mPose);
                        var substate = sys.SubStates[0];
                        if (substate.TransformNode != null)
                        {
                            Quaternion.RotationYawPitchRoll(substate.TransformNode.YawPitchRoll.X, substate.TransformNode.YawPitchRoll.Y, substate.TransformNode.YawPitchRoll.Z, out substate.TransformNode.Rotation);
                            Matrix.Transformation(substate.TransformNode.Scale, substate.TransformNode.Rotation, substate.TransformNode.Translation, out matrix);

                            Vector3.Transform(ref (ppParticles[i]->FinalPose.mPosition), ref matrix, out matrixtovec4);
                            ppParticles[i]->FinalPose.mPosition.X = matrixtovec4.X;
                            ppParticles[i]->FinalPose.mPosition.Y = matrixtovec4.Y;
                            ppParticles[i]->FinalPose.mPosition.Z = matrixtovec4.Z;

                            if (substate.TransformNode.IgnoreRotation == false)
                            {
                                if (substate.RotationNodes == null || substate.RotationNodes.Count == 0)
                                {
                                    ppParticles[i]->FinalPose.mRotation = substate.TransformNode.Rotation;
                                }
                                else
                                {
                                    ppParticles[i]->FinalPose.mRotation *= substate.TransformNode.Rotation;
                                }
                            }

                            if (substate.TransformNode.IgnoreScale == false)
                            {
                                if (substate.ParticleScaleNode != null)
                                {
                                    ppParticles[i]->FinalPose.mScale *= substate.TransformNode.Scale;
                                }
                                else
                                {
                                    ppParticles[i]->FinalPose.mScale = substate.TransformNode.Scale;
                                }
                            }
                        }
                    }
                }
                //TODO..
                if (sys.TrailNode != null)
                {
                    sys.TrailNode.CreateAndUpdateTrailData(sys, ref *ppParticles[i], elaspe);
                }

                if (sys.TextureCutNode != null)
                {
                    sys.TextureCutNode.Update(elaspe, ref *ppParticles[i]);
                    ppParticles[i]->FinalPose.SetUserParamsY(1, (byte)sys.TextureCutNode.CurrentIndex);
                }


                //处理处罚结点
                if (sys.TriggerNodes.Count > 0)
                {
                    for (int j = 0; j < sys.TriggerNodes.Count; j++)
                    {
                        sys.TriggerNodes[j].RefreshUpdateEvent(ref ppParticles[i]->FinalPose, ref prepos);
                        sys.TriggerNodes[j].TriggerBornEvent(ref ppParticles[i]->FinalPose);
                        sys.TriggerNodes[j].TriggerUpdateEvent(ref ppParticles[i]->FinalPose, ref prepos);
                    }
                }

                if (sys.EnableEventReceiver)
                {
                    var tag = ppParticles[i]->Tag as ParticleTag;
                    if (tag != null)
                    {
                        if (tag.TriggerEvent != null)
                        {
                            if (tag.TriggerEvent.TriggerData.InheritPosition)
                            {
                                ppParticles[i]->FinalPose.mPosition += tag.TriggerEvent.Pose.mPosition;
                            }

                            if (tag.TriggerEvent.TriggerData.InheritScale)
                            {
                                ppParticles[i]->FinalPose.mScale *= tag.TriggerEvent.Pose.mScale;
                            }

                            if (tag.TriggerEvent.TriggerData.InheritRotation)
                            {
                                ppParticles[i]->FinalPose.mRotation *= tag.TriggerEvent.Pose.mRotation;
                            }

                            if (tag.TriggerEvent.TriggerData.InheritVelocity)//Todo
                            {
                                ppParticles[i]->FinalPose.mPosition += tag.TriggerEvent.Pose.mVelocity * elaspe;
                            }
                        }
                    }
                }

                if (sys.PointGravityNode != null)
                {
                    gravity = sys.PointGravityNode._Data.Point - ppParticles[i]->FinalPose.mPosition;
                    // var dis = gravity.Length();
                    //if (dis > 0.00001f)
                    {
                        ppParticles[i]->FinalPose.mAcceleration.X = 0.5f * sys.PointGravityNode._Data.Accelerated * ppParticles[i]->mLifeTick * ppParticles[i]->mLifeTick;

                        //if (dis < ppParticles[i]->FinalPose.mAcceleration.X)
                        //{
                        //    ppParticles[i]->FinalPose.mAcceleration.X = dis;
                        //}
                        gravity += ppParticles[i]->FinalPose.mVelocity;
                        gravity.Normalize();

                        ppParticles[i]->FinalPose.mPosition += gravity * ppParticles[i]->FinalPose.mAcceleration.X;
                    }
                }

                if (sys.BillBoardType != CGfxParticleSystem.BILLBOARDTYPE.BILLBOARD_DISABLE)
                {
                    ppParticles[i]->FacePose(sys, sys.BillBoardType, sys.CoordSpace, ref prepos);
                }

                ppParticles[i]->FinalPose.SetUserParamsX(1, 1);
            }
        }