Page 1 of 1

[shame on me]Box dimensions update

Posted: Wed Jul 25, 2012 3:59 pm
by fredlllll
yeah shame on me for this thread:
i have an entites.prefarbs.box and i change width, height and length, but it doesnt change anything in the simulation. it just remains its normal size (1,1,1) but when i read the values, they are that what i put in. and i searched for a method to date this up, but didnt found anything.
am i blind or dumb or both? ._.

Re: [shame on me]Box dimensions update

Posted: Wed Jul 25, 2012 4:10 pm
by Norbo
Is the graphic just not being updated?

The physics engine has no concept of graphics, so a change to the simulation does not automatically tell the graphics system to update.

Re: [shame on me]Box dimensions update

Posted: Wed Jul 25, 2012 4:25 pm
by fredlllll
no. the simulation object doesnt seem to update. i do the drawing myself. and the graphic is updated(i use the box.width... for drawing). but when i throw something at it, it still collides with the 1x1x1 box (i do not remove it from the space an readd it. i just change the dimensions)

Re: [shame on me]Box dimensions update

Posted: Wed Jul 25, 2012 4:42 pm
by Norbo
Setting the width, height, or length of a Box changes the BoxShape's dimensions. The BoxShape dimensions are used directly in collision detection. So, there are likely some shenanigans afoot. Could you post a simplified demo showing the issue?

Re: [shame on me]Box dimensions update

Posted: Wed Jul 25, 2012 4:47 pm
by fredlllll
well here is some code of the class

i use the getters and setters to set the stuff.

and in the drawcall i use them to scale my 1x1x1 box, so it fits the box in the simulation.
so the graphics changes when i do something, but the simulation of the box doesnt.

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ZipperEngine
{
    public class StaticCollideBox : Entity, StaticCollide
    {
        public BEPUphysics.Entities.Prefabs.Box box;
        public StaticCollideBox(float width, float height, float length)
            : base(Global.editor, Global.editor)//will not be selected
        {
            box = new BEPUphysics.Entities.Prefabs.Box(Vector3.Zero, width, height, length);
        }

        //here i set the dimensions
        public float DimX { get { return box.Width; } set { box.Width = value; } }
        public float DimY { get { return box.Height; } set { box.Height = value; } }
        public float DimZ { get { return box.Length; } set { box.Length = value; } }

        public override Microsoft.Xna.Framework.Vector3 Position
        {
            get
            {
                return box.Position;
            }
            set
            {
                box.Position = value;
//snip
            }
        }

        public override Microsoft.Xna.Framework.Quaternion Orientation
        {
            get
            {
                return box.Orientation;
            }
            set
            {
                box.Orientation = value;
//snip
            }
        }

        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime, int method)
        {
            if (Global.showCollisionShapes)
            {
                //draw collison shape
                //little bit transparent
                //or own entity for selection?
                if (DynamicCollideBox.be == null)
                {
                    DynamicCollideBox.be = new BasicEffect(worldSpace.Device);
                }
                //and here i use the dimensions for the drawing scale matrix. and the graphics shows correct
                DynamicCollideBox.be.World = Matrix.CreateTranslation(box.Position) * Matrix.CreateFromQuaternion(Orientation) * Matrix.CreateScale(new Vector3(box.Width, box.Height, box.Length));
                DynamicCollideBox.be.View = worldSpace.currentCamera.ViewMatrix;
                DynamicCollideBox.be.Projection = worldSpace.currentCamera.ProjectionMatrix;

                switch (method)
                {
                    //snip
                }
                RasterizerState rs = new RasterizerState();
                rs.FillMode = FillMode.Solid;
                worldSpace.Device.RasterizerState = rs;
            }
        }

        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            //snip
        }

        public override void AddToSpace(Worldspace space)
        {
            space.PhysicSpace.Add(box);
        }

        public override void RemoveFromSpace(Worldspace space)
        {
            space.PhysicSpace.Remove(box);
        }
    }
}
the methods add and remove from space are called by my own worldspace class when i add this entity(my own entity class). here it just adds and removes the box.

Re: [shame on me]Box dimensions update

Posted: Wed Jul 25, 2012 4:50 pm
by Norbo
Could you create a runnable demo in the BEPUphysicsDemos that reproduces the issue so that I can look at it directly?

Re: [shame on me]Box dimensions update

Posted: Wed Jul 25, 2012 6:01 pm
by fredlllll
well i tried to... and i failed. in the demo it just works as intended(although the graphics dont change to the new dimension)[when i change all 3 parameters at once, but when i only change height, the sphere falls right through it]
but what i noticed is, when i change the dimensions in my game, at first nothing happens, then i change the position of the box, and suddenly it accepts the changes of the dimensions o.O

i dont know whats happening =/

but i disccovered some other anomaly in the demo. when changing only the height, the sphere just falls through the box...

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BEPUphysics.Entities.Prefabs;
using Microsoft.Xna.Framework;

namespace BEPUphysicsDemos.Demos
{
    public class BoxUpdateBugDemo : StandardDemo
    {
        public override string Name
        {
            get { return "BoxUpdateBug"; }
        }

        System.Timers.Timer t = new System.Timers.Timer(4000);

        Box box;

        Sphere sphere;
        public BoxUpdateBugDemo(DemosGame game)
            : base(game)
        {
            box = new Box(Vector3.Zero, 1, 1, 1);//box which should be modified
            box.Material.Bounciness = 1;
            Space.Add(box);

            sphere = new Sphere(new Vector3(0, 10, 0), 1,1);//then i drop a sphere on it
            sphere.Material.Bounciness = 1;
            Space.Add(sphere);

            t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);
            t.Start();
        }

        void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            sphere.Position = new Vector3(0, 10, 0);//redrop yay
            sphere.LinearVelocity = Vector3.Zero;
            sphere.AngularVelocity = Vector3.Zero;
            if (box.Height == 1)//change the height of the box
            {
                //box.Width = 5;
                box.Height = 5;
                //box.Width = 5;
            }
            else
            {
                //box.Width = 1;
                box.Height = 1;
                //box.Length = 1;
            }
        }
    }
}

Re: [shame on me]Box dimensions update

Posted: Wed Jul 25, 2012 6:15 pm
by Norbo
Call box.ActivityInformation.Activate() when changing a sleeping object's shape. Changing the dimensions of the object is not a typical physical operation, so it doesn't automatically wake the object up to update.

While this behavior was intended, I went ahead and automated it a little more in the development version. Changing the shape will now automatically wake up the entity.

Re: [shame on me]Box dimensions update

Posted: Wed Jul 25, 2012 6:26 pm
by fredlllll
yay it works!! :D
this also fixes the fall through bug in the demo.
for now ill stick to the official 1.2 as the changing of dimensions is just relevant for my editor(so i dont care if later releases do the activate twice)

will you change this for the other primitives like radius of a sphere?

Re: [shame on me]Box dimensions update

Posted: Wed Jul 25, 2012 6:32 pm
by Norbo
It works for all shapes that can notify the Entity of a change, including spheres.