예제 #1
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);
            }
        }
예제 #2
0
 //计算最终粒子姿态
 public unsafe void OnParticleCompose(CGfxParticleSystem sys, CGfxParticle **ppParticles, int num, float elaspe)
 {
     DoParticleCollectCompose(sys, ppParticles, num, sys.SubStates.Length, elaspe);
 }