Water Physics

Post and discuss features you'd like to see in the BEPUphysics library.

Water Physics

Postby Maniak11 » Wed Feb 06, 2008 12:49 pm

Don't really have enough skill in lolXNA to be useful in any development or testing or anything, but do you have any plans for water physics?
Maniak11
 
Posts: 43
Joined: Sun Jul 16, 2006 9:51 pm

Re: Water Physics

Postby Norbo » Wed Feb 06, 2008 2:44 pm

I plan on adding simple buoyancy into v0.5.0, but full dynamic water will come much later, probably after v1.0.0 (which should be the name of what would otherwise be called "v0.6.0").

Basically, once the fundamentals are all there, I'll start branching out into fun stuff.
Norbo
Site Admin
 
Posts: 1207
Joined: Mon Jul 03, 2006 10:45 pm

Re: Water Physics

Postby Zukarakox » Wed Feb 06, 2008 4:41 pm

And by 'fun stuff' you mean the stuff with math that would make heads explode, rite?
i has multiple toes
User avatar
Zukarakox
Not a Site Admin
 
Posts: 416
Joined: Sun Jul 09, 2006 10:28 pm

Re: Water Physics

Postby Fe_Yoshi » Wed Feb 06, 2008 8:56 pm

Just say "See Crysis". 'Nuff said.

o and btw BEPU gonna expire if you don't log on narbo o.O
It's simple, just take the hydraulic phase ship emulator and attach it to the photon particle emitter, BAM, new tower!
Fe_Yoshi
 
Posts: 335
Joined: Tue Jul 04, 2006 11:05 am
Location: New Tower!

Re: Water Physics

Postby JHOW » Fri Nov 20, 2009 1:09 pm

Not perfect but it works quite well. To use it Just type Water water = new Water(space);
Also you will need Constraint drawing enabled.

Add these 2 classes to the BEPUphysicsDemos on this site.

Water Class
Code: Select all
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using BEPUphysics;
using System.Diagnostics;
using System.Threading;
using BEPUphysics.BroadPhases;
using BEPUphysics.Entities;
using BEPUphysics.Constraints;
using BEPUphysics.ForceFields;
using BEPUphysics.DataStructures;
using System.Collections;

namespace BEPUphysicsDemos
{
    public class Water
    {
        public List<Spring> surfaceTensionSprings;
        public List<Spring> densitySprings;
        public float surfaceTension = 0.6f;
        public float density = 0.6f;
        public List<Entity> waterTris;
        public List<WaterVertex> waterVertices;
                 
        public int wLength = 40;
        public int wWidth = 40;
        float radius = 0.0001f;
        float waterDensity = 5;
        float strength = float.MaxValue;
        Spring spring;
        Sphere sphere;
       
        Space space;

        public Water(Space space)
        {   
            this.space = space;
            BuildWater();
        }

        public void BuildWater()
        {
           
            waterVertices = new List<WaterVertex>();
            waterTris = new List<Entity>();
            surfaceTensionSprings = new List<Spring>();
            densitySprings = new List<Spring>();

            generateWaterGrid();
            setupSprings();
        }
       
        public void generateWaterGrid()
        {
            for (int i = 0; i < wWidth; i+= Convert.ToInt32(0.6f))
            {
                for (int j = 0; j < wLength; j += Convert.ToInt32(0.6f))
                {
                    sphere = new Sphere(new Vector3(i, 0, j), radius,waterDensity);
                    sphere.allowedPenetration = 1000;
                    WaterVertex vertex = new WaterVertex(sphere);
                   
                    space.add(sphere);
                    waterVertices.Add(vertex);
                }

            }
        }
        public void setupSprings()
        {
            int counter = 0;
            for (int i = 0; i < wWidth; i++)
            {
                for (int j = 0; j < wLength; j++)
                {


                    if (j != 0 && j < wLength - 1)
                    {
                        spring = new Spring(waterVertices[counter].sphere, waterVertices[counter - 1].sphere,
                        new Vector3(waterVertices[counter].sphere.worldTransform.M41, waterVertices[counter].sphere.worldTransform.M42, waterVertices[counter].sphere.worldTransform.M43),
                        new Vector3(waterVertices[counter - 1].sphere.worldTransform.M41, waterVertices[counter - 1].sphere.worldTransform.M42, waterVertices[counter - 1].sphere.worldTransform.M43),
                        5000, surfaceTension, strength, strength, strength);

                        space.add(spring);

                        surfaceTensionSprings.Add(spring);
                    }

                    if (j < wLength - 1)
                    {
                        spring = new Spring(waterVertices[counter].sphere, waterVertices[counter + 1].sphere,
                        new Vector3(waterVertices[counter].sphere.worldTransform.M41, waterVertices[counter].sphere.worldTransform.M42, waterVertices[counter].sphere.worldTransform.M43),
                        new Vector3(waterVertices[counter + 1].sphere.worldTransform.M41, waterVertices[counter + 1].sphere.worldTransform.M42, waterVertices[counter + 1].sphere.worldTransform.M43),
                        5000, surfaceTension, strength, strength, strength);

                        space.add(spring);

                        surfaceTensionSprings.Add(spring);
                    }

                    if ((counter + wLength) <  waterVertices.Count)
                    {
                        spring = new Spring(waterVertices[counter].sphere, waterVertices[counter + wLength].sphere,
                        new Vector3(waterVertices[counter].sphere.worldTransform.M41, waterVertices[counter].sphere.worldTransform.M42, waterVertices[counter].sphere.worldTransform.M43),
                        new Vector3(waterVertices[counter + wLength].sphere.worldTransform.M41, waterVertices[counter + wLength].sphere.worldTransform.M42, waterVertices[counter + wLength].sphere.worldTransform.M43),
                        5000, surfaceTension, strength, strength, strength);

                        space.add(spring);
                   

                        surfaceTensionSprings.Add(spring);
                    }

                    spring = new Spring(null, waterVertices[counter].sphere,
                        new Vector3(waterVertices[counter].sphere.worldTransform.M41, waterVertices[counter].sphere.worldTransform.M42, waterVertices[counter].sphere.worldTransform.M43),
                        new Vector3(waterVertices[counter].sphere.worldTransform.M41, waterVertices[counter].sphere.worldTransform.M42, waterVertices[counter].sphere.worldTransform.M43),
                        160, density, strength, strength, strength);
                    space.add(spring);
                    densitySprings.Add(spring);
                    /*
                    if ((counter + wLength) <  waterVertices.Count && j != 0 && j < wLength - 1)
                    {
                        tri = new Triangle(new Vector3( waterVertices[counter].worldTransform.M41,  waterVertices[counter].worldTransform.M42,  waterVertices[counter].worldTransform.M43),
                            new Vector3( waterVertices[counter + 1].worldTransform.M41,  waterVertices[counter + 1].worldTransform.M42,  waterVertices[counter + 1].worldTransform.M43),
                            new Vector3( waterVertices[counter + wLength].worldTransform.M41,  waterVertices[counter + wLength].worldTransform.M42,  waterVertices[counter + wLength].worldTransform.M43),10);
                        space.add(tri);
                        waterTris.Add(tri);
                    }
                    */
                    counter++;
                }

            }
        }
    }
}


Water Vertex Class
Made as a helper for rendering the water.

Code: Select all
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using BEPUphysics;
using System.Diagnostics;
using System.Threading;
using BEPUphysics.BroadPhases;
using BEPUphysics.Entities;
using BEPUphysics.Constraints;
using BEPUphysics.ForceFields;
using BEPUphysics.DataStructures;
using System.Collections;

namespace BEPUphysicsDemos
{
    public class WaterVertex
    {
        //public Vector3 position;
        public Sphere sphere;

        public WaterVertex(Sphere sphere)
        {
            this.sphere = sphere;
        }
        public Vector3 GetPosition()
        {
            return new Vector3(sphere.worldTransform.M41, sphere.worldTransform.M42, sphere.worldTransform.M43);
        }
    }
}
JHOW
 
Posts: 9
Joined: Sun Oct 25, 2009 6:52 pm


Return to Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest

cron