示例#1
0
    //-------------------------------------
    // Collision Methods - Single Particle Colliders
    //-------------------------------------
    /// <summary>
    /// Separate 2 objects where at least one is a SingleParticle object (SphereCollider).
    /// </summary>
    private void SeparateParticleObjectWithSingleParticles(BaseCollider bc, SphereCollider sp, Vector3 currPoint, Vector3 projPoint, ColliderTypes collTypes)
    {
        if (collTypes == ColliderTypes.FirstRigidBody_SecondSingleParticle)
        {
            //ParticleObject po = bc.GetParticleObject();
            //float[] c1 = this.ComputeParticlesCoefficients(po, currPoint);
            //float lambda1 = this.ComputeLambda(c1);
            Logger.Instance.DebugInfo("Updating FirstRigidBody_SecondSingleParticle object", "COLLISION");

            // Update the dynamic object
            //for (int i = 0; i < 4; i++)
            //{
            //    po.particles[i].position = po.particles[i].position + (lambda1 * c1[i] * (projPoint - currPoint) * 0.5f) * po.particles[i].invMass;
            //}

            // Update also the single particle
            Vector3 newPos = sp.GetSingleParticlePosition() - ((projPoint - currPoint)) * 0.5f * sp.GetSingleParticleInvMass();
            sp.ChangeSingleParticlePosition(newPos);
        }
        // if both are single particle objects
        else if (collTypes == ColliderTypes.BothSingleParticles)
        {
            // TODO: test
            SphereCollider sp1 = (SphereCollider)bc;

            Vector3 newPosSp1 = sp1.GetSingleParticlePosition() + ((projPoint - currPoint)) * sp1.GetSingleParticleInvMass();
            sp1.ChangeSingleParticlePosition(newPosSp1);

            Vector3 newPosSp2 = sp.GetSingleParticlePosition() - ((projPoint - currPoint)) * sp.GetSingleParticleInvMass();
            sp.ChangeSingleParticlePosition(newPosSp2);
        }
    }
示例#2
0
    public void AddCollider(BaseCollider Collider)
    {
        if (Colliders == null)
        {
            Colliders = new List <BaseCollider>();
        }
        Colliders.Add(Collider);

        Logger.Instance.DebugInfo("Added Collider " + Collider.Id + " to CollisionManager!");
    }
示例#3
0
    private void Start()
    {
        // Instantiate debugging arrows
        if (this.ShowVelocityArrows)
        {
            this.VelocityArrows_DB = new GameObject[particles.Length];
            for (int i = 0; i < particles.Length; i++)
            {
                this.VelocityArrows_DB[i] = (GameObject)Instantiate(Resources.Load("VelocityArrow"));
                this.VelocityArrows_DB[i].SetActive(false);
            }
        }

        // Check if there is a collider
        if (this.gameObject.GetComponent <BaseCollider>() != null)
        {
            this.Collider = this.gameObject.GetComponent <BaseCollider>();
            this.Collider.AssignParticleObject(this);
        }

        // Initialize prev pos as current one and invmass
        foreach (Particle p in particles)
        {
            p.position     = this.transform.TransformPoint(p.position);
            p.prevPosition = p.position - velocity / 10f;
        }
        // For visualizer
        E_pointsTransformedInLocalSpace = true;

        // Add Tetrahederon and Bounding constraints
        constraints = new List <Constraint>();
        constraints.Add(new DistanceConstraint(particles, distTuples));
        constraints.Add(new PointConstraint(particles, pointTuples));
        //constraints.Add(new BoundConstraint(particles, new Vector3(10, 5, 10)));

        // Initialize center position
        this.centerOfMass = this.ComputeCenterOfMass();
        this.SetOrientationAxis();

        // Add object to simulation
        VerletSimulation.Instance.AddParticleObject(this);

        // Initialize acceleration
        gravityAcceleraiton = new Vector3(0, -9.81f, 0);
        if (this.UseGravity)
        {
            acceleration += gravityAcceleraiton;
        }
    }
示例#4
0
    public void AddCollider(BaseCollider Collider, bool isSingleParticle = false)
    {
        if (Colliders == null)
        {
            this.Colliders = new List <BaseCollider>();
            this.SingleParticleColliders = new List <SphereCollider>();
        }

        if (!isSingleParticle)
        {
            this.Colliders.Add(Collider);
        }
        else
        {
            this.SingleParticleColliders.Add((SphereCollider)Collider);
        }

        Logger.Instance.DebugInfo("Added Collider " + Collider.Id + " to CollisionManager!");
    }
示例#5
0
文件: Octree.cs 项目: lanicon/Flowmo
    /// <summary>
    /// Check where this vertex should be allocated.
    /// </summary>
    public void UpdateNodePosition(Vector3 vertexPosition, BaseCollider baseCollider)
    {
        //node.
        //node.s
        //node.node

        // (1) Get node where it should be stored
        OctreeNode <TType> itNode = GetRoot();

        for (int i = 0; i <= depth; i++)
        {
            int occupiedNodeIdx = GetIndexOfPosition(vertexPosition, itNode.Position);
            //itNode = itNode.Nodes[occupiedNodeIdx];
        }

        // (2) Once the Node is found
        // (2.1) Check where this basecollider was stored previously
        // (2.2) if it isn't stored in the current node add the BaseCollider to its IList

        // PROBLEM: an object (cube/sphere) can be inside multiple nodes
        //          checking only the extents isn't enough, because it might extend
        //          through multiple nodes (should use ray coverage?)
    }
示例#6
0
 public MapCollider(BaseCollider collider)
 {
     m_baseCollider = collider;
 }