Example #1
0
        public bool update(GameWorld gameWorld)
        {
            spd.Z -= 0.5;

            GamePoint3D sz3_ = new GamePoint3D(size.X, size.X, -size.Y);
            GamePoint3D d1   = pos + new GamePoint2D(-size.X, -size.X),
                        d2   = pos + new GamePoint3D(size.X, size.X, size.Y);

            if (spd.X != 0d)
            {
                GamePoint3D t_ = new GamePoint3D(spd.X, 0d, 0d);
                while (gameWorld.checkCollision(d1 + t_, d2 + t_))
                {
                    if (Math.Abs(spd.X) > precision)
                    {
                        spd.X = 0;
                        break;
                    }
                    spd.X -= precision * Math.Sign(spd.X);
                    t_.X   = spd.X;
                }
            }
            if (spd.Y != 0d)
            {
                GamePoint3D t_ = new GamePoint3D(0d, spd.Y, 0d);
                while (gameWorld.checkCollision(d1 + t_, d2 + t_))
                {
                    if (Math.Abs(spd.Y) > precision)
                    {
                        spd.Y = 0;
                        break;
                    }
                    spd.Y -= precision * Math.Sign(spd.Y);
                    t_.Y   = spd.Y;
                }
            }
            if (spd.Z != 0d)
            {
                GamePoint3D t_ = new GamePoint3D(0d, 0d, spd.Z);
                while (gameWorld.checkCollision(d1 + t_, d2 + t_))
                {
                    if (Math.Abs(spd.Z) > precision)
                    {
                        spd.Z = 0;
                        break;
                    }
                    spd.Z -= precision * Math.Sign(spd.Z);
                    t_.Z   = spd.Z;
                }
            }
            if (Math.Abs(spd.X) <= spd_deadzone.X)
            {
                spd.X = 0;
            }
            if (Math.Abs(spd.Y) <= spd_deadzone.Y)
            {
                spd.Y = 0;
            }
            if (Math.Abs(spd.Z) <= spd_deadzone.Z)
            {
                spd.Z = 0;
            }

            pos      += spd;
            spd       = spd.Divide(frc);
            direction = direction % 360f;
            pitch     = GameGeometry.clamp(pitch, -89f, 89f);
            bool updateSelf = false;

            if (pos != previous_pos || previous_direction != direction || previous_pitch != pitch)
            {
                updateSelf = true;
            }

            previous_pos = pos;

            return(updateSelf);
        }
Example #2
0
 public static GamePoint3D operator /(GamePoint3D left, GamePoint2D right)
 {
     return(GamePoint3D.Divide(left, right));
 }