コード例 #1
0
ファイル: PhysicsComponent.cs プロジェクト: dzamkov/Driftoid
 public MotionState(Vector Position, Vector Velocity, double Angle, double AngularVelocity)
 {
     this.Position = Position;
     this.Velocity = Velocity;
     this.Angle = Angle;
     this.AngularVelocity = AngularVelocity;
 }
コード例 #2
0
ファイル: PhysicsComponent.cs プロジェクト: dzamkov/Driftoid
 public MotionState(Vector Position, double Angle)
 {
     this.Position = Position;
     this.Angle = Angle;
     this.AngularVelocity = 0.0;
     this.Velocity = new Vector();
 }
コード例 #3
0
ファイル: PhysicsComponent.cs プロジェクト: dzamkov/Driftoid
 /// <summary>
 /// Updates the motion state.
 /// </summary>
 /// <param name="Time">Time in seconds to update.</param>
 /// <param name="LinearFriction">Factor between 0.0 and 1.0 that indicates how much velocity
 /// remains over a second.</param>
 /// <param name="AngularFriction">Factor between 0.0 and 1.0 that indicates how much angular velocity
 /// remains over a second.</param>
 public void Update(double Time, double LinearFriction, double AngularFriction)
 {
     this.Position += this.Velocity * Time;
     this.Angle += this.AngularVelocity * Time;
     this.Velocity *= Math.Pow(LinearFriction, Time);
     this.AngularVelocity *= Math.Pow(AngularFriction, Time);
 }
コード例 #4
0
ファイル: Visual.cs プロジェクト: dzamkov/Driftoid
 public SimpleVisual(int TextureID, Vector Center, double Size, double Angle)
 {
     this._ID = TextureID;
     this._Center = Center;
     this._Size = Size;
     this._Angle = Angle;
 }
コード例 #5
0
ファイル: Drawer.cs プロジェクト: dzamkov/Driftoid
 public override Color AtPoint(Vector Point)
 {
     Color col = new Color();
     double totalint = 0.0;
     foreach (Sample samp in this._Samples)
     {
         Color sampcol = this._Source.AtPoint(Point + samp.Offset);
         col.A += sampcol.A * samp.Intensity;
         col.R += sampcol.R * samp.Intensity;
         col.G += sampcol.G * samp.Intensity;
         col.B += sampcol.B * samp.Intensity;
         totalint += samp.Intensity;
     }
     double itotalint = 1.0 / totalint;
     col.A *= itotalint;
     col.R *= itotalint;
     col.G *= itotalint;
     col.B *= itotalint;
     return col;
 }
コード例 #6
0
ファイル: Drawer.cs プロジェクト: dzamkov/Driftoid
 public AntiAliasingDrawer(Drawer Source, double Size, int Quality)
 {
     this._Samples = new List<Sample>(Quality * Quality);
     double delta = 1.0 / (double)Quality;
     double inital = -0.5 + delta * 0.5;
     double totalintensity = 0.0;
     for (int x = 0; x < Quality; x++)
     {
         for (int y = 0; y < Quality; y++)
         {
             Vector point = new Vector((double)x * delta + inital, (double)y * delta + inital);
             double intensity = IntensityAtDistance(point.Length * 2.0);
             totalintensity += intensity;
             this._Samples.Add(new Sample()
             {
                 Offset = point * Size,
                 Intensity = intensity
             });
         }
     }
     this._Source = Source;
 }
コード例 #7
0
ファイル: Visual.cs プロジェクト: dzamkov/Driftoid
 public override Color AtPoint(Vector Point)
 {
     double dis = (Point - new Vector(0.5, 0.5)).Length;
     double trans = 0.5 - BorderSize;
     if (dis > 0.5)
     {
         return Color.Transparent;
     }
     if (dis > trans)
     {
         return this.BorderColor;
     }
     return this.InteriorColor;
 }
コード例 #8
0
ファイル: Visual.cs プロジェクト: dzamkov/Driftoid
 /// <summary>
 /// Draws a texture relative to this driftoid.
 /// </summary>
 public static void DrawTexture(int ID, Vector Center, double Size, double Angle)
 {
     Texture.Bind2D(ID);
     GL.PushMatrix();
     GL.Translate(Center.X, Center.Y, 0.0);
     GL.Scale(Size, Size, 1.0);
     GL.Rotate(Angle, 0.0, 0.0, 1.0);
     GL.Begin(BeginMode.Quads);
     GL.Vertex2(-1.0f, -1.0f); GL.TexCoord2(0f, 0f);
     GL.Vertex2(-1.0f, 1.0f); GL.TexCoord2(1f, 0f);
     GL.Vertex2(1.0f, 1.0f); GL.TexCoord2(1f, 1f);
     GL.Vertex2(1.0f, -1.0f); GL.TexCoord2(0f, 1f);
     GL.End();
     GL.PopMatrix();
 }
コード例 #9
0
ファイル: Area.cs プロジェクト: dzamkov/Driftoid
 /// <summary>
 /// Gets the driftoid at the specified position. Returns null if the point is unoccupied.
 /// </summary>
 public LinkedDriftoid Pick(Vector Position)
 {
     foreach (LinkedDriftoid dr in this._Driftoids)
     {
         double radius = dr.Radius;
         if ((dr.MotionState.Position - Position).SquareLength <= radius * radius)
         {
             return dr;
         }
     }
     return null;
 }
コード例 #10
0
ファイル: PhysicsComponent.cs プロジェクト: dzamkov/Driftoid
 /// <summary>
 /// Applies a force, in units/second^2.
 /// </summary>
 public void ApplyForce(double Time, Vector Force)
 {
     this.Velocity += Force * Time;
 }
コード例 #11
0
ファイル: Nucleus.cs プロジェクト: dzamkov/Driftoid
        internal void _Pull(double Time, Driftoid Driftoid, Driftoid Target, Vector Position)
        {
            double dis = (Target.Position - Driftoid.Position).Length;
            if (dis < this.MaxDistance)
            {
                Vector vel = Target.MotionState.Velocity;
                double vellen = vel.Length;
                vel = vel * vellen;

                Vector gpos = Target.Position + vel * (Target.Mass / this.MaxForce);
                Vector vec = (Position - gpos);
                double mdis = vec.Length;
                Vector nvec = vec * (1.0 / mdis);
                vec = nvec * this.MaxForce;
                Target._ApplyForce(Time, vec);
                Driftoid._ApplyForce(Time, -vec);
            }
        }
コード例 #12
0
ファイル: Nucleus.cs プロジェクト: dzamkov/Driftoid
        private static int _CreateTexture(Player Player)
        {
            Color primary = Player.FadedColor;
            Color secondary = Player.SecondaryColor;
            int texsize = 256;
            float actualsize = (float)texsize;
            using (Bitmap bm = new Bitmap(texsize, texsize))
            {
                Driftoid.DrawSolid(bm, 0.15, primary, secondary);
                using (Graphics g = Graphics.FromImage(bm))
                {
                    int dashamount = 9;
                    double dashdelta = Math.PI * 2.0 / (double)dashamount;
                    Vector center = new Vector(actualsize / 2.0f, actualsize / 2.0f);
                    using (Pen p = new Pen(primary, actualsize * 0.05f))
                    {
                        for (int t = 0; t < dashamount; t++)
                        {
                            double dashangle = dashdelta * (double)t;
                            Vector dashunit = Vector.Unit(dashangle) * (double)actualsize * 0.5;

                            g.DrawLine(p, dashunit * 0.3 + center, dashunit * 0.6 + center);
                        }
                    }
                }
                return Texture.Create(bm);
            }
        }
コード例 #13
0
ファイル: PhysicsComponent.cs プロジェクト: dzamkov/Driftoid
 /// <summary>
 /// Directly applies a velocity.
 /// </summary>
 internal void _ApplyImpulse(Vector Impulse)
 {
     this._MotionState.Velocity += Impulse * (1.0 / this._Mass);
 }
コード例 #14
0
ファイル: Vector.cs プロジェクト: dzamkov/Driftoid
 /// <summary>
 /// Gets the dot product of two vectors.
 /// </summary>
 public static double Dot(Vector A, Vector B)
 {
     return A.X * B.X + A.Y * B.Y;
 }
コード例 #15
0
ファイル: LinkedDriftoid.cs プロジェクト: dzamkov/Driftoid
 /// <summary>
 /// Corrects (repositions participants) the link between a parent and child driftoid.
 /// </summary>
 internal static void _CorrectLink(LinkedDriftoid Parent, LinkedDriftoid Child, int Iter, Vector Difference, double Distance)
 {
     // Is there a problem
     if (Math.Abs(Distance - Parent.Radius - Child.Radius) > 0.001)
     {
         // Equivalent to another problem...
         Driftoid._CollisionResponse(Parent, Child, Difference, Distance, 1.0);
     }
 }
コード例 #16
0
ファイル: Visual.cs プロジェクト: dzamkov/Driftoid
 public override Color AtPoint(Vector Point)
 {
     double dis = (Point - new Vector(0.5, 0.5)).Length;
     if (dis <= 0.5)
     {
         return Color.RGB(1.0, 1.0, 1.0);
     }
     return Color.RGBA(1.0, 1.0, 1.0, 0.0);
 }
コード例 #17
0
ファイル: Drawer.cs プロジェクト: dzamkov/Driftoid
 public override Color AtPoint(Vector Point)
 {
     return this.Handler(Point);
 }
コード例 #18
0
ファイル: Drawer.cs プロジェクト: dzamkov/Driftoid
 /// <summary>
 /// Draws to bitmap data.
 /// </summary>
 public unsafe void Draw(BitmapData Data, int Width, int Height)
 {
     Vector delta = new Vector(1.0 / (double)Width, 1.0 / (double)Height);
     Vector initial = delta * 0.5;
     byte* dataloc = (byte*)Data.Scan0.ToPointer();
     for (int y = 0; y < Width; y++)
     {
         for (int x = 0; x < Height; x++)
         {
             Vector point = initial + new Vector((double)x * delta.X, (double)y * delta.Y);
             Color col = this.AtPoint(point);
             dataloc[3] = (byte)(col.A * 255.0);
             dataloc[2] = (byte)(col.R * 255.0);
             dataloc[1] = (byte)(col.G * 255.0);
             dataloc[0] = (byte)(col.B * 255.0);
             dataloc += 4;
         }
     }
 }
コード例 #19
0
ファイル: Drawer.cs プロジェクト: dzamkov/Driftoid
 /// <summary>
 /// Gets the final color of the image at the specified point between (0.0, 0.0) and (1.0, 1.0).
 /// </summary>
 public abstract Color AtPoint(Vector Point);
コード例 #20
0
ファイル: PhysicsComponent.cs プロジェクト: dzamkov/Driftoid
        /// <summary>
        /// Responds (by correcting positions and velocities) to the collision of two driftoids.
        /// </summary>
        internal static void _CollisionResponse(PhysicsComponent A, PhysicsComponent B, Vector Difference, double Distance, double Factor)
        {
            double trad = A.Radius + B.Radius;
            Vector ncol = Difference * (1.0 / Difference.Length);
            double pen = trad - Distance;
            double ima = 1.0 / A._Mass;
            double imb = 1.0 / B._Mass;
            Vector sep = ncol * (pen / (ima + imb)) * Factor;
            A._MotionState.Position -= sep * ima;
            B._MotionState.Position += sep * imb;

            Vector vcol = B._MotionState.Velocity - A._MotionState.Velocity;
            double impact = Vector.Dot(vcol, ncol);
            if (impact < 0.0)
            {
                double cor = 0.5;
                double j = -(1.0f + cor) * (impact) / (ima + imb);
                Vector impulse = ncol * j;
                A._MotionState.Velocity -= impulse * ima;
                B._MotionState.Velocity += impulse * imb;
            }
        }
コード例 #21
0
ファイル: PhysicsComponent.cs プロジェクト: dzamkov/Driftoid
 /// <summary>
 /// Applies a force, in mass * unit/second^2, to the driftoid.
 /// </summary>
 internal void _ApplyForce(double Time, Vector Force)
 {
     this._MotionState.ApplyForce(Time, Force * (1.0 / this._Mass));
 }
コード例 #22
0
ファイル: LinkedDriftoid.cs プロジェクト: dzamkov/Driftoid
        /// <summary>
        /// Creates a linker texture for the given key.
        /// </summary>
        private static _LinkerTexture _CreateTexture(_LinkerKey Key)
        {
            double grabberwidth = Key.ChildBorderWidth;
            double handlelength = 0.4;
            double handlewidth = 0.1;
            double grabbermaxangle = Math.PI / 8;
            double partangle = grabbermaxangle / 2.0;

            double maxheight = handlewidth / 2.0;

            double innerwidth = Key.ChildRadius - grabberwidth;
            double maxgrabberwidth = Key.ChildRadius - Math.Cos(grabbermaxangle) * innerwidth;
            double posheight = Math.Sin(grabbermaxangle) * Key.ChildRadius;
            if (posheight > maxheight)
            {
                maxheight = posheight;
            }

            Vector size = new Vector(maxgrabberwidth + handlelength, maxheight * 2.0);
            double grabbercenter = -Key.ChildRadius + maxgrabberwidth;

            double midcenter = 0.5 * size.Y;
            Drawer dr = Drawer.Create(delegate(Vector Point)
            {
                Point.X *= size.X;
                Point.Y *= size.Y;

                Vector grabberdif = (Point - new Vector(grabbercenter, midcenter));
                double grabberdis = grabberdif.Length;
                double grabberang = grabberdif.Angle;

                if (grabberdis < innerwidth)
                {
                    return Color.Transparent;
                }
                if (grabberdis < Key.ChildRadius)
                {
                    double angdif = Math.Abs(grabberang);
                    if (angdif < grabbermaxangle - partangle)
                    {
                        return Color.RGBA(0.9, 0.9, 0.9, 1.0);
                    }
                    if (angdif < grabbermaxangle)
                    {
                        return Color.RGBA(0.9, 0.9, 0.9, 0.5);
                    }
                }
                if (Math.Abs(Point.Y - midcenter) < handlewidth / 2.0)
                {
                    double a = (Point.X - maxgrabberwidth) / handlelength;
                    return Color.RGBA(0.9, 0.9, 0.9, 1.0 - a * a);
                }
                return Color.Transparent;
            });
            return new _LinkerTexture()
            {
                Size = size,
                ChildCenterOffset = grabbercenter,
                Texture = Texture.Define(dr, size.X / size.Y, 0.7)
            };
        }
コード例 #23
0
ファイル: Weighted.cs プロジェクト: dzamkov/Driftoid
 public override Color AtPoint(Vector Point)
 {
     Vector dif = Point - new Vector(0.5, 0.5);
     double dis = dif.Length * 2.0;
     double ang = dif.Angle;
     if (dis > 1.0)
     {
         return Color.Transparent;
     }
     if (dis > 1.0 - UnitBorderWidth * 2.0)
     {
         return BorderColor;
     }
     if (dis < 0.2)
     {
         return BorderColor;
     }
     return InnerColor;
 }