예제 #1
0
 public void CreateDialog(Body body)
 {
     Reset();
     if (body as Ball != null)
         panel.AddField("Radius", ((Ball)body).radius);
     panel.AddField("Mass", body.Mass);
     if (body as Box != null)
     {
         panel.AddLabel("HalfSize", "HalfSize");
         panel.AddXYZ(((Box)body).HalfSize, "hlf");
     }
     panel.AddLabel("Position", "Position");
     panel.AddXYZ(body.Position, "pos");
     panel.AddLabel("Velocity", "Velocity");
     panel.AddXYZ(body.Velocity, "vel");
     panel.AddLabel("Acceleration", "Acceleration");
     panel.AddXYZ(body.LastFrameAcceleration, "acc");
     panel.AddOkButton();
     panel.AddCancelButton();
     panel.AddApplyButton();
     panel.Show = true;
     currentBody = body;
     previousBody = currentBody;
     BodyAdded = true;
     ((Drawable)body).ShowPanel = true;
     type = Type.Body;
 }
예제 #2
0
        /// <summary>
        /// override affect
        /// update body position and velocity
        /// </summary>
        /// <param name="body"></param>
        /// <param name="duration"></param>
        protected override void Affect(Body body)
        {
            if (!body.HasFiniteMass)
                return;

            //Vector3 velocity=Vector3.Multiply(gravity,body.Mass);
            //velocity=Vector3.Multiply(velocity,duration);
            //body.AddVelocity(velocity);
            //TODO delete above lines @Adnan

            body.AddForce(Vector3.Multiply(gravity,body.Mass));
        }
예제 #3
0
 /** Creates a new spring with the given parameters. */
 public Spring(Body first, Body other, float springConstant, float restLength, float C, 
     Vector3 ConnectionPoint = new Vector3(), Vector3 otherConnectionPoint = new Vector3())
     : base(/** The particle at the first end of the spring. */
     first,
     /** The particle at the other end of the spring. */
     other)
 {
     this.otherConnectionPoint = otherConnectionPoint;
     this.ConnectionPoint = ConnectionPoint;
     this.springConstant = springConstant;
     this.restLength = restLength;
     this.C = C;
 }
예제 #4
0
 public void CrateSpring(Body one, Body two)
 {
     AddEffect(new Spring(one, two, 5f, 6f, 0.9f));
 }
예제 #5
0
 protected abstract void Affect(Body other);
예제 #6
0
 public void RemoveBody(Body body)
 {
     bodies.Remove(body);
 }
예제 #7
0
 public void AddBody(Body body)
 {
     bodies.Add(body);
 }
예제 #8
0
 public Constraint(Body firstBody, Body SecondBody)
 {
     bodys = new Body[2];
     this.bodys[0] = firstBody;
     this.bodys[1] = SecondBody;
 }
예제 #9
0
파일: Lab.cs 프로젝트: IdeasStorm/PhysiXLab
        public void SelectedAndMoving(MouseState mouse, KeyboardState keyboard,
            Vector2 cursorPosition,Vector2 previousCursorPosition, float totalSecond)
        {
            var cursorDelta = (cursorPosition - previousCursorPosition) * totalSecond;
            var cameraDelta = (camera.cameraPosition - previousCameraPosition) * totalSecond;

            if (!bodySel)
            {
                ray = camera.GetMouseRay(cursorPosition, GraphicsDevice.Viewport);
                if (!bodyMoving) bdy = basicLab.CheckIntersect(ray);
                if (bdy != null)
                {
                    currentBody = bdy;
                    if (mouse.LeftButton == ButtonState.Pressed)
                        bodyMoving = true;
                    else
                    {
                        bodyMoving = false;
                        bdy = null;
                    }

                    if (bodyMoving)
                    {
                        Vector3 tocentre = camera.cameraPosition - bdy.Position;
                        float dest = tocentre.Length();
                        cursorDelta *= dest / 10f;
                        cameraDelta *= dest / 10f;
                        ((Drawable)bdy).Selected = true;

                        if (keyboard.IsKeyDown(Keys.LeftControl))
                        {
                            bodySel = true;
                            prevBody = bdy;
                            ((IMoveable)bdy).Translate(-camera.cameraDirection, cameraDelta.Y + cursorDelta.Y + cameraDelta.X + cursorDelta.X);
                        }
                        else
                        {
                            Vector3 moveUnit = Vector3.Cross(camera.cameraUp, camera.cameraDirection);
                            moveUnit.Normalize();
                            ((IMoveable)bdy).Translate(-moveUnit, cameraDelta.X + cursorDelta.X);
                            ((IMoveable)bdy).Translate(-camera.cameraUp, cameraDelta.Y + cursorDelta.Y);
                        }
                    }
                }
            }
            else
            {
                Vector3 tocentre = camera.cameraPosition - prevBody.Position;
                float dest = tocentre.Length();
                cursorDelta *= dest / 10f;
                cameraDelta *= dest / 10f;

                ((IMoveable)prevBody).Translate(-camera.cameraDirection, cameraDelta.Y + cursorDelta.Y);
                ((Drawable)prevBody).Selected = true;
            }
            if (keyboard.IsKeyUp(Keys.LeftControl)) bodySel = false;
        }
예제 #10
0
파일: Lab.cs 프로젝트: IdeasStorm/PhysiXLab
 void Crate(Vector2 cursorPosition, KeyboardState keyboard, float time)
 {
     if (keyboard.IsKeyDown(Keys.B))
         bClicked = true;
     if (keyboard.IsKeyUp(Keys.B) && bClicked)
     {
         Vector3 point = new Vector3(cursorPosition, 0.9f);
         point = GraphicsDevice.Viewport.Unproject(point, camera.projection, camera.view, Matrix.Identity);
         Body body = basicLab.CreateBall(point);
         panel.CreateDialog(body);
         currentBody = body;
         bClicked = false;
     }
     if (keyboard.IsKeyDown(Keys.C))
         cClicked = true;
     if (keyboard.IsKeyUp(Keys.C) && cClicked)
     {
         Vector3 point = new Vector3(cursorPosition, 0.9f);
         point = GraphicsDevice.Viewport.Unproject(point, camera.projection, camera.view, Matrix.Identity);
         Crate crate = basicLab.CreateCrate(point);
         panel.CreateDialog(crate);
         currentBody = crate;
         cClicked = false;
     }
     if (keyboard.IsKeyDown(Keys.P))
         pClicked = true;
     if (keyboard.IsKeyUp(Keys.P) && pClicked)
     {
         Body body = basicLab.CreateBall(camera.cameraPosition);
         panel.CreateDialog(body);
         currentBody = body;
         body.AddVelocity(ray.Direction * 25);
         pClicked = false;
     }
     if (keyboard.IsKeyDown(Keys.G))
     {
         if (panel.BodyAdded)
         {
             gClicked = true;
             WaitForOther = true;
         }
     }
     if (keyboard.IsKeyUp(Keys.G) && gClicked)
     {
         panel.SpringActivated();
         gClicked = false;
     }
     if (keyboard.IsKeyDown(Keys.I))
         iClicked = true;
     if (keyboard.IsKeyUp(Keys.G) && iClicked)
     {
         panel.CreateSpringPanel();
         iClicked = false;
     }
 }
예제 #11
0
 private void PanelShow(MouseState mouse)
 {
     if (mouse.RightButton == ButtonState.Pressed)
     {
         if (currentBody != null)
         {
             if (currentBody.InverseMass != 0)
             {
                 if (((Lab)Game).WaitForOther)
                 {
                     ((Lab)Game).basicLab.CrateSpring(previousBody, currentBody);
                     ((Lab)Game).WaitForOther = false;
                     spPanel.Close();
                 }
                 else
                 {
                     if (previousBody != null)
                         ((Drawable)previousBody).ShowPanel = false;
                     Reset();
                     CreateDialog(currentBody);
                     ((Drawable)currentBody).ShowPanel = true;
                     previousBody = currentBody;
                 }
             }
         }
     }
 }
예제 #12
0
 private void CheckPanelClosed()
 {
     if (previousBody != null && !panel.Show && BodyAdded)
     {
         ApplyChanges();
         ((Drawable)previousBody).ShowPanel = false;
         BodyAdded = false;
         previousBody = null;
     }
     if (type == Type.Spring)
         ApplyChanges();
 }
예제 #13
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            MouseState mouse = Mouse.GetState();
            currentBody = ((Lab)Game).currentBody;
            PanelShow(mouse);
            if (panel.Show && !panel.Applied)
                ApplyChanges();
            UpdateFeildPanel();
            CheckPanelClosed();
            SpringPanelPanel();

            base.Update(gameTime);
        }