Exemplo n.º 1
0
 /** Cross Product
  * @param v
  * @return vettore ortogonale a v e this
  */
 public Vec3 Cross(Vec3 v)
 {
     return new Vec3(
             Y * v.Z - Z * v.Y,  //x
             Z * v.X - X * v.Z,  //y
             X * v.Y - Y * v.X   //z
      );
 }
Exemplo n.º 2
0
        public void Add(Vec3 p)
        {
            if(IsEmpty){
                max = new Vec3(p.X,p.Y,p.Z);
                min =new Vec3(p.X,p.Y,p.Z);
            }

            else{
                if(p.X < min.X) min.X=p.X;
                if(p.Y < min.Y) min.Y=p.Y;
                if(p.Z < min.Z) min.Z=p.Z;

                if(p.X > max.X) max.X=p.X;
                if(p.Y > max.Y) max.Y=p.Y;
                if(p.Z > max.Z) max.Z=p.Z;
            }
            IsEmpty = false;
        }
Exemplo n.º 3
0
 private void UpdateAABB()
 {
     aabb.Clear();
     for(int i=0; i<VertexList.Count; i++){
         Vec3 p = new Vec3(VertexList[i].X,VertexList[i].Y,VertexList[i].Z);
         aabb.Add(p);
     }
 }
Exemplo n.º 4
0
 void InitCloth()
 {
     clothForce = new Vec3(0,0,+1).Mult(5.0f);
     cloth = new VerletMesh (Mesh.CreatePlane (clothWidth=50,clothHeight=50, 20, 20));
     if (clothConstraints == null) {
         cloth.GenerateVertexConstraintsFromFaces ();
         clothConstraints = cloth.VertexConstraints;
     } else
         cloth.VertexConstraints = clothConstraints;
     cloth.Mass= (0.05f);
     cloth.Model =  IMatrix.Translation (0, 10.0f, 0.0f).Dot (IMatrix.RotationX (-90)).Dot (IMatrix.Translation (-clothWidth/2, -clothHeight/2, 0.0f));
 }
Exemplo n.º 5
0
 void DrawLine(Vec3 pointA, Vec3 pointB)
 {
     GL.Begin (BeginMode.Lines);
         GL.Vertex3 (pointA.X, pointA.Y, pointA.Z);
         GL.Vertex3 (pointB.X, pointB.Y, pointB.Z);
         GL.End ();
 }
        public void UpdatePosition(float dt)
        {
            Vec3 acc = new Vec3 (Force.X, Force.Y, Force.Z);
            acc.Normalize();
            acc = acc.Mult(Force.W);
            acc = new Vec3(acc.Mult (Mass));

            var pNext = new List<Vec3> ();
            for (var i = 0; i<VertexNow.Count; i++) {
                var pNow = VertexNow [i];
                var pOld = VertexOld [i];
                pNext.Add (pNow * 2 - pOld + acc * dt*dt);
            }
            VertexOld = VertexNow;
            VertexNow = pNext;
        }
        public void FixCollisionWithSphere(Vec3 sphereCenter, float sphereRadius)
        {
            for (var i = 0; i<VertexList.Count; i++) {
                var v = VertexList [i];
                var diff = (v - sphereCenter);
                var distance = diff.Norm();
                if (distance > sphereRadius)
                    continue;

                VertexList [i] = v+diff;
            }
        }
Exemplo n.º 8
0
 public Vec3 Sub(Vec3 v2)
 {
     Vec4 v = base.Sub(v2);
     return new Vec3(v.X, v.Y, v.Z);
 }
Exemplo n.º 9
0
 public Vec3 Add(Vec3 v2)
 {
     Vec4 v = base.Add(v2);
     return new Vec3(v.X, v.Y, v.Z);
 }
Exemplo n.º 10
0
 public Vec3(Vec3 v)
     : base(v)
 {
 }
Exemplo n.º 11
0
 void init()
 {
     VertexConstraints = new List<VertexConstraint> ();
     VertexOld = new List<Vec3> ();
     Force = new Vec3 (0, 0, 0);
     Mass = 0;
     Model = IMatrix.Identity ();
     foreach (var v in VertexNow)
         VertexOld.Add (v * 1);
 }
Exemplo n.º 12
0
        public void FixCollisionWithSphere(Vec3 sphereCenter, float sphereRadius)
        {
            var offset = 0.5f;
            var sc = Model.Inverse.Dot (sphereCenter);
            for (var i = 0; i<VertexList.Count; i++) {

                var v = VertexList [i];
                var diff = (v - sc);
                var distance = diff.Norm();
                if (distance > sphereRadius+offset) {
                    VertexList [i].IsColliding |= false;
                    continue;
                }
                v = new Vec3(sc+(diff.Normalized () * (sphereRadius+offset)));
                VertexList[i] = v;
                VertexList [i].IsColliding = true;
            }
        }
Exemplo n.º 13
0
        public void FixCollisionWithCapsule(Vec3 pointA, Vec3 pointB, float radius)
        {
            var a = new Vec3(Model.Inverse.Dot (pointA));
            var b = new Vec3(Model.Inverse.Dot (pointB));
            var abNormalized = (b-a).Normalized ();
            var abNorm = (b-a).Norm ();

            for (var i = 0; i<VertexList.Count; i++) {
                var v = VertexList [i];
                var p = a + abNormalized.Mult((v - a).Dot (abNormalized));

                if ((v - p).Norm () > radius)
                    continue;

                if ((p - a).Norm () > abNorm + radius || (p - b).Norm () > abNorm + radius)
                    continue;
                VertexList [i] = p+(v - p).Normalized () * radius;
                VertexList [i].IsColliding |= true;

            }
        }
Exemplo n.º 14
0
 public void ApplyForce(Vec3 force)
 {
     Force = Force + force;
 }