示例#1
0
        public ObiConstraints(ObiActor actor = null, ObiConstraints <T> source = null)
        {
            this.actor  = actor;
            this.source = source;

            if (source != null)
            {
                foreach (T batch in source.batches)
                {
                    AddBatch(batch.Clone(this) as T);
                }
            }
        }
示例#2
0
        public bool AddToSolver(object info)
        {
            if (inSolver || actor == null || !actor.InSolver)
            {
                return(false);
            }

            // Calculate our constraint offset:
            constraintOffset = 0;
            for (int i = 0; i < actor.actorID; i++)
            {
                ObiConstraints c = actor.Solver.actors[i].GetComponent(GetType()) as ObiConstraints;
                if (c != null)
                {
                    constraintOffset += c.ConstraintCount;
                }
            }

            // custom addition code:
            OnAddToSolver(info);

            inSolver = true;

            // push data to solver:
            PushDataToSolver(GetParticleDataFlags());

            // update constraints if enabled, deactivate all constraints otherwise.
            if (enabled)
            {
                UpdateConstraintActiveStatus();
            }
            else
            {
                Oni.DeactivateConstraints(actor.Solver.OniSolver,
                                          (int)GetConstraintType(),
                                          Enumerable.Range(constraintOffset, constraintOffset + ConstraintCount).ToArray(),
                                          ConstraintCount);
            }

            return(true);
        }
示例#3
0
        public bool RemoveFromSolver(object info)
        {
            if (!inSolver || actor == null || !actor.InSolver)
            {
                return(false);
            }

            // Update other actor's constraint offset:
            for (int i = actor.actorID + 1; i < actor.Solver.actors.Count; i++)
            {
                ObiConstraints c = actor.Solver.actors[i].GetComponent(GetType()) as ObiConstraints;
                if (c != null)
                {
                    c.constraintOffset -= ConstraintCount;
                }
            }

            Oni.RemoveConstraints(actor.Solver.OniSolver, (int)GetConstraintType(), ConstraintCount, constraintOffset);

            inSolver = false;

            return(true);
        }