Example #1
0
        void avatar_Updated(object sender, UpdatedEventArgs e)
        {
            Scalar maxVelocity = 40;

            Scalar vel = 0;
            for (int index = 1; index < avatarBodies.Count; ++index)
            {
                vel = Math.Max(Math.Abs(avatarBodies[index].State.Velocity.Angular), vel);
            }

            Scalar multiply = Math.Abs((vel) / maxVelocity);
            if (vel > maxVelocity)
            {
                multiply = 1;
            }
            for (int index = 1; index < avatarBodies.Count; ++index)
            {
                avatarBodies[index].State.ForceAccumulator.Angular += (torque - torque * multiply);
            }

            // avatarBodies.State.ForceAccumulator.Linear += force;
        }
Example #2
0
 void clipper_Updated(object sender, UpdatedEventArgs e)
 {
     try
     {
         for (int index = 0; index < objects.Count; ++index)
         {
             OpenGlObject o = objects[index];
             o.shouldDraw = o.collided;
             o.collided = false;
         }
     }
     catch { }
 }
Example #3
0
 void DemoU_Body_Updated(object sender, UpdatedEventArgs e)
 {
     Body b = (Body)sender;
     if (b.State.Position.Linear.Y > 900)
     {
         b.State.Position.Linear.Y = -100;
     }
 }
Example #4
0
        void DemoI_Body_Updated(object sender, UpdatedEventArgs e)
        {
            Body b = (Body)sender;
            BoundingRectangle clip = this.clipper.Rectangle;
            BoundingRectangle mainRect =b.Rectangle;
            ContainmentType inter = clip.Contains( mainRect);
            if (inter == ContainmentType.Intersects)
            {
                Scalar yDiff = clip.Max.Y - clip.Min.Y;
                Scalar xDiff = clip.Max.X - clip.Min.X;

                int[,] has = new int[3, 3];
                bool[,] needs = new bool[3, 3];

                int[,] needsTemp = new int[3, 3];
                FillRect(needsTemp, clip, mainRect);
                for (int x = 0; x < 3; ++x)
                {
                    for (int y = 0; y < 3; ++y)
                    {
                        if (needsTemp[x, y] > 0)
                        {
                            needs[(-(x - Non) + Non), (-(y - Non) + Non)] = true;
                        }
                    }
                }



                if (mainRect.Min.X < clip.Min.X)
                {
                    needs[Max, Non] = true;
                }
                else if (mainRect.Max.X > clip.Max.X)
                {
                    needs[Min, Non] = true;
                }
                if (mainRect.Min.Y < clip.Min.Y)
                {
                    needs[Non,Max] = true;
                }
                else if (mainRect.Max.Y > clip.Max.Y)
                {
                    needs[Non, Min] = true;
                }
                FillRect(has, clip, mainRect);
                foreach (BodyProxy proxy in b.Proxies)
                {
                    BoundingRectangle rect = proxy.Body2.Rectangle;
                    FillRect(has, clip, rect);
                }
                for (int x = 0; x < 3; ++x)
                {
                    for (int y = 0; y < 3; ++y)
                    {
                        bool add = false;
                        if (x != Non || y != Non)
                        {
                            if (needs[x, y] && has[x, y] == 0)
                            {
                                add = true;
                            }
                        }
                        
                        if (add)
                        {
                            Vector2D location = b.State.Position.Linear;
                            location.X -= xDiff * (Non - x);
                            location.Y -= yDiff * (Non - y);
                            foreach (BodyProxy prox in b.Proxies)
                            {
                                if (prox.Body1.Rectangle.Contains(location) != ContainmentType.Disjoint)
                                {
                                    add = false;
                                    break;
                                }
                            }
                            if (add)
                            {
                                Body prox = b.Duplicate();
                                prox.Updated += new EventHandler<UpdatedEventArgs>(DemoI_Body_Updated);
                                prox.Collided += new EventHandler<CollisionEventArgs>(DemoI_Body_Collided);
                                prox.State.Position.Linear = location;
                                AddBody(prox);
                                engine.AddProxy(b, prox, Matrix2x2.Identity);
                            }
                        }
                    }
                }
            }
            else if (inter == ContainmentType.Disjoint)
            {
                b.Lifetime.IsExpired = true;
            }
        }
Example #5
0
        void OnWillUpdated(object sender, UpdatedEventArgs e)
        {
            if (!_isRenderingCompleted)
            {
                return;
            }

            _updatesToSkip--;

            if (_updatesToSkip < 0 )
            {
                _updatesToSkip = WILL_UPDATE_SKIPS_COUNT;

                Task.Factory.StartNew<IRenderer>(s =>
                {
                    IRenderer renderer;
                    if (_renderer.TryGetTarget(out renderer))
                    {
                        var snapshot = Will.Instance.GetWorldSnapshot();
                        renderer.RenderWorld(snapshot);
                    }
                    else
                    {
                        throw new ArgumentNullException("_renderer");
                    }

                    return renderer;
                },
                _renderingContext).ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        // Log Error call goes here
                    }

                    _isRenderingCompleted = true;
                });
            }
        }
Example #6
0
 void OnAvatarUpdated(object sender, UpdatedEventArgs e)
 {
     avatar.State.ForceAccumulator.Linear += force;
 }
Example #7
0
 void OnEngineUpdated(object sender, UpdatedEventArgs e)
 {
     if (Updated != null)
     {
         Updated(sender, e);
     }
 }