0

オブジェクトが他のオブジェクトと衝突したときにオブジェクトを停止しようとしています。つまり、ユーザーが他のオブジェクトにスライドさせようとすると、オブジェクトをスライドさせて、今のところ移動しないようにしたいということです。Xnaと長方形の衝突機能を使用しています。

 public void Update(GameTime gametime)
        {
            Currentposition = Station.Position;
            Station.Update();
            coli = IsHit(ListObs[16].ShapeO, Station.Shape);
         }

public void Draw(SpriteBatch spritebatch)
{
            if (coli == true)
            {
                Station.Position = Currentposition;
                Station.Draw(spritebatch);
            }
            else
            {
                Station.Draw(spritebatch);
            }
}

現時点では機能していません。Farseer または bOx2DX を使用することもできますが、深すぎると思います (重力は必要ありません)。

 public bool IsHit(Rectangle r1, Rectangle r2)
        {
            if (((r1.X + r1.Width >= r2.X) && (r1.X <= r2.X + r2.Width)) && ((r1.Y + r1.Height >= r2.Y) && (r1.Y <= r2.Y + r2.Height)))
                return true;
            else
                return false;
        }
4

2 に答える 2

0

all you will normally have to know is:

 mesh.BoundingSphere

I could better explain it to you, by an example... For example:

We do have a cube...

If you know the distance to the wall , you can even create a bounding box:

float d / / middle distance <- > wall
Vector3 center = mesh.BoundingSphere.Center ;
var box = new BoundingBox (new Vector3 ( Center.X - d Center.Y - d Center.Z - d) , new Vector3 ( Center.X + d + d Center.Y , Center.Z + d) ) ;

Now you have the bounding box that includes your cube ( the bounding rich Vector3 2 : minimum and maximum) . Ideally , we can calculate them only once (possibly at the start of the program) .

Now that were the basics...


When you have improved you prgramming skills you should finally add rotations,trannformation and whatever you want...

But if your cube have to rotate , it is already complicated. Instead , the bounding box each time that you re berechnest when the cube rotates , it uses matrices. A problem that occurs when you see the bounding box always recalculate want is that the dice will no longer be the bounding box corresponds to , but at worst the corners of the cube are all right in the middle of the walls of the bounding box and you thus much " air " have in your bounding box , which is considered a collision , although there was no collision. For a bounding box is always oriented to the axes , while your cube is then just rotated. To circumvent this problem, one uses matrices to bring the cube back axes oriented in a room if you want to test on a collision ( by its rotation with a matrix inverse reverses for the collision test).

If you understood this and was able to use it, you will be able to let the objects move like wherever and how you want ;)


I hope you understood it what I've tried to explain ;)

于 2013-10-25T12:47:26.480 に答える