Examples of FluidParticle


Examples of org.cmj.flowy.simulation.particles.FluidParticle

    public void refresh(final List<FluidParticle> particles) {
        theGrid = new ArrayList[this.theWidth][this.theHeight];
        theNeighboursIndex.clear();
        final int numOfParticles = particles.size();
        for (int i = 0; i < numOfParticles; ++i) {
            final FluidParticle thisParticle = particles.get(i);
            thisParticle.gridIndexX = GetGridIndexX(thisParticle);
            thisParticle.gridIndexY = GetGridIndexY(thisParticle);

            // Add particle to list
            if (theGrid[thisParticle.gridIndexX][thisParticle.gridIndexY] == null) {
                theGrid[thisParticle.gridIndexX][thisParticle.gridIndexY] = new ArrayList<Integer>();
            }
            theGrid[thisParticle.gridIndexX][thisParticle.gridIndexY].add(i);
        }

       
        // Build up the cache of neighbours for each fluid particle.
        for (int i = 0; i < numOfParticles; ++i) {
            final FluidParticle thisParticle = particles.get(i);
            theNeighboursIndex.put(thisParticle, getNeighbourIndexForCache(thisParticle));
        }
    }
View Full Code Here

Examples of org.cmj.flowy.simulation.particles.FluidParticle

     * @param particles The particles whose densities and pressures are to be updated.
     */
    private void updatePressureAndDensities(final List<FluidParticle> particles) {
        final Vector2 distance = new Vector2();
        for (int i = particles.size() - 1; i >= 0; --i) {
            final FluidParticle particle = particles.get(i);
            particle.density = 0.0f;
            final List<Integer> neighbours = theGrid.GetNeighbourIndex(particle);
            for (int j = neighbours.size()-1; j>=0; --j  ) {
                final int neighbourIndex = neighbours.get(j);
                final FluidParticle neighbour = particles.get(neighbourIndex);
                distance.x = particle.position.x - neighbour.position.x;
                distance.y = particle.position.y - neighbour.position.y;
                particle.density += particle.mass * this.theSKGeneral.Calculate(distance);
            }
            particle.updatePressure();
View Full Code Here

Examples of org.cmj.flowy.simulation.particles.FluidParticle

        final float massViscosityProduct = Constants.PARTICLE_MASS * theViscosity;
        final Vector2 distance = new Vector2();

        for (int i = particles.size()-1; i >= 0 ; --i) {

            final FluidParticle particle = particles.get(i);

            // Add global force to every particle
            particle.force.add(globalForce);

            // Get neighbours for each of the particles
            final List<Integer> neighbours = theGrid.GetNeighbourIndex(particle);

            for (final int neighbourIndex : neighbours) {

                // Prevent double tests
                if (neighbourIndex > i) {

                    final FluidParticle neighbour = particles.get(neighbourIndex);

                    if (neighbour.density > Constants.FLOAT_EPSILON) {

                        distance.x = particle.position.x - neighbour.position.x;
                        distance.y = particle.position.y - neighbour.position.y;
View Full Code Here

Examples of org.cmj.flowy.simulation.particles.FluidParticle

     * @param timestep The time over which hte positions and velocities should be updated.
     */
    private void updateParticles(final List<FluidParticle> particles, final float timestep) {

        for (int i=particles.size()-1; i >= 0;  --i) {
            final FluidParticle particle = particles.get(i);
            // Clip positions to domain space
            if (particle.position.x < theMinWidth) {
                particle.position.x = (theMinWidth + Constants.FLOAT_EPSILON);
            }
            else if (particle.position.x > theMaxWidth) {
                particle.position.x = (theMaxWidth - Constants.FLOAT_EPSILON);
            }
            if (particle.position.y < theMinHeight) {
                particle.position.y = (theMinHeight + Constants.FLOAT_EPSILON);
            }
            else if (particle.position.y > theMaxHeight) {
                particle.position.y = (theMaxHeight - Constants.FLOAT_EPSILON);
            }

            // Update velocity + position using forces
            particle.updatePositionAndVelocity(timestep);

            // Reset force
            particle.force.x = 0;
            particle.force.y = 0;
        }
View Full Code Here

Examples of org.cmj.flowy.simulation.particles.FluidParticle

        final Vector2 particleSeparation = new Vector2();

        for (int i = particles.size() -1; i >=0; --i) {

            final FluidParticle particle = particles.get(i);

            final List<Integer> neighbours = theGrid.GetNeighbourIndex(particle);

            for (int j=neighbours.size()-1; j>=0; --j) {
                final int neighbourIndex = neighbours.get(j);
                // Prevent double tests
                if (neighbourIndex > i) {
                    final FluidParticle neighbour = particles.get(neighbourIndex);
                    particleSeparation.x = neighbour.position.x - particle.position.x;
                    particleSeparation.y = neighbour.position.y - particle.position.y;
                    final float particleSeparationSquared = particleSeparation.getLengthSqaured();
                    if (particleSeparationSquared < minDistSq) {
                        if (particleSeparationSquared > Constants.FLOAT_EPSILON) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.