Exemple #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            frame += 1;
            graphics.Clear(Color.White);
            //Sphere.Rotate(new _Point(0, 1, 0), 5);
            //Sphere.SetPosition(VectMath.Add(Sphere.Position, VectMath.Scale(new _Point(0, 1, 0), .02*Math.Sin(frame*.1))));
            //DrawMesh(Sphere);
            Cubes[0].Rotate(Axes.Y, 6);
            Cubes[1].Rotate(Axes.X, 6);
            Cubes[2].Rotate(Axes.Z, 6);


            foreach (Mesh cube in Cubes)
            {
                if (cube.Position.z > 1)
                {
                    cube.SetPosition(VectMath.Add(cube.Position, new _Point(0, 0, -.1 * Math.Sqrt(Math.Pow(cube.Position.x, 2) + Math.Pow(cube.Position.y, 2)))));
                }
                else
                {
                    cube.SetPosition(new _Point(8 * Globals.rnd.NextDouble() - 4, 8 * Globals.rnd.NextDouble() - 4, 15));
                }
                DrawMesh(cube);
            }
        }
Exemple #2
0
 public void Rotate(_Point axis, double deg)
 {
     for (int i = 0; i < Points.Count; i++)
     {
         Points[i] = VectMath.Add(VectMath.RotateByAngle(VectMath.Subtract(Points[i], Position), axis, deg), Position);
     }
     Normal = CalculateNormal();
 }
Exemple #3
0
    public void SetPosition(_Point p)
    {
        _Point MoveVector = VectMath.Subtract(p, Position);

        foreach (Plane plane in Planes)
        {
            plane.SetPosition(VectMath.Add(plane.Position, MoveVector));
        }
        Position = p;
    }
Exemple #4
0
    public void SetPosition(_Point p)
    {
        //IO.Point(Position);
        _Point DiffVector = VectMath.Subtract(p, Position);

        for (int i = 0; i < Points.Count; i++)
        {
            Points[i] = VectMath.Add(Points[i], DiffVector);
        }
        Position = p;
        Normal   = CalculateNormal();
    }
Exemple #5
0
    public static _Point RotateByAngle(_Point pnt, _Point Axis, double Angle)
    {
        if (VectMath.IsParallel(pnt, Axis) == true)
        {
            return(pnt);
        }
        Angle = (Angle * Math.PI) / 180;
        _Point Avector     = VectMath.Subtract(pnt, VectMath.Project(pnt, Axis));
        double MagAvector  = VectMath.Magnitude(Avector);
        _Point V1          = VectMath.Unit(VectMath.Cross(Axis, Avector));
        _Point V2          = (VectMath.Negate(Avector));
        _Point TransVector = VectMath.Add(VectMath.Scale(V1, MagAvector * Math.Sin(Angle)), VectMath.Scale(V2, (-1 * Math.Cos(Angle) + 1)));

        return(VectMath.Add(TransVector, pnt));
    }
Exemple #6
0
 public void Rotate(_Point axis, double angle)
 {
     foreach (Plane plane in Planes)
     {
         for (int i = 0; i < plane.Points.Count; i++)
         {
             _Point p = plane.Points[i];
             //IO.Point(p);
             plane.Points[i] = VectMath.Add(VectMath.RotateByAngle(VectMath.Subtract(p, this.Position), axis, angle), this.Position);
             //IO.Point(plane.Points[i]);
         }
         plane.Position = VectMath.CenterofPoints(plane.Points);
         plane.Normal   = plane.CalculateNormal();
     }
 }
Exemple #7
0
 public void Iterrate()
 {
     foreach (Particle particle in Particles)
     {
         particle.force = new _Point(0, 0, 0);
         foreach (Particle p in Particles)
         {
             particle.force = VectMath.Add(ForceOn(particle, p), particle.force);
         }
         particle.velocity = VectMath.Add(particle.velocity, (VectMath.Scale(VectMath.Scale(particle.force, 1 / particle.Mass), TimeInterval)));
         //MessageBox.Show(VectMath.Magnitude(particle.force).ToString());
     }
     foreach (Particle particle in Particles)
     {
         particle.Position = VectMath.Add(particle.Position, VectMath.Scale(particle.velocity, TimeInterval));
     }
 }
Exemple #8
0
 public void Move(_Point point)
 {
     SetPosition(VectMath.Add(Position, point));
 }