public override void Tick(float dTime)
        {
            base.Tick(dTime);

            Sync += dTime;

            Mars.Orientation = QuaternionExtensions.FromAxisAngle(Vector3.UnitY, 15.0f / 180.0f * (float)Math.PI * Sync);
        }
Beispiel #2
0
        public void UpdateDirection(Vector3 lookat, float dtime)
        {
            //left vector projected on plane
            Vector3 left = TargetActor.Left;

            left.Y = 0;
            left.Normalize();

            //forward vector projected on plane
            Vector3 forward = TargetActor.Direction;

            forward.Y = 0;
            forward.Normalize();

            //wanted direction vector
            Vector3 want;

            try
            {
                want = lookat - TargetActor.Position;
                want.Normalize();
            }
            catch (DivideByZeroException)
            {
                System.Console.WriteLine("divide bug./%&$");
                want = Vector3.UnitX;
            }

            float cos = Vector3.Dot(left, want);

            if (cos <= 1 && cos >= -1)
            {
                //float a = (float)Math.Acos((double)cos) * 180.0f / (float)Math.PI;
                //float a = -2 * cos;
                RotationSpeed = -2 * (float)Math.Sign(cos) * (float)Math.Sqrt(Math.Abs(cos));

                Rotation += RotationSpeed * dtime;
                Roll      = cos;// -RotationSpeed / 2;
            }
            else
            {
                RotationSpeed = 0;
                Roll          = 0;
            }

            Quaternion q1 = QuaternionExtensions.FromAxisAngle(0, 1, 0, Rotation);

            TargetActor.Orientation = q1;
            Quaternion q2 = QuaternionExtensions.FromAxisAngle(TargetActor.Direction, Roll);

            TargetActor.Orientation = q1 * q2;

            Vector3 tmp = TargetActor.Position;

            tmp.Y = 0;
            TargetActor.Position = tmp;
        }
Beispiel #3
0
        /*
         * public override void Tick(float dtime)
         * {
         *  MathUtil.Check(position.Original);
         *  MathUtil.Check(orientation);
         *  Matrix4 m = Matrix4.Rotate(orientation);
         *  position.Tick(dtime, SmoothTime);
         *  speed.Tick(dtime, SmoothTime);
         *  position.Original += speed.Original * dtime;
         *  position.Original += Vector3.Transform(localspeed,m) * dtime;
         *
         *  MathUtil.Check(position.Original);
         *  MathUtil.Check(orientation);
         *
         *  orientation.Tick(dtime, SmoothTime);
         *  Quaternion qx = QuaternionExtensions.FromAxisAngle(1, 0, 0, rotationspeed.X * dtime);
         *  Quaternion qy = QuaternionExtensions.FromAxisAngle(0, 1, 0, rotationspeed.Y * dtime);
         *  Quaternion qz = QuaternionExtensions.FromAxisAngle(0, 0, 1, rotationspeed.Z * dtime);
         *  Quaternion q = qx * qy * qz;
         *
         *  //q=Quaternion.Identity*Quaternion.Identity;
         *  orientation.Original = q * orientation.Original;
         *  //HACK
         *  if (orientation.Original.W < -1.0f)
         *  {
         *      orientation.Original.W = -1.0f;
         *  }
         *  MathUtil.Check(position.Original);
         *  MathUtil.Check(orientation);
         *
         *  age += dtime;
         *
         *  if (Attach != null && Attach.Kill)
         *      Attach = null;
         *
         *  if (Draw != null)
         *      foreach (object o in Draw)
         *      {
         *          if (o is ITickable)
         *          {
         *              ((ITickable)o).Tick(dtime);
         *          }
         *      }
         *  MathUtil.Check(position.Original);
         *  MathUtil.Check(orientation);
         * }*/
        public override void Tick(float dtime)
        {
            position.Original    = Position;
            orientation.Original = Orientation;
            orientation.Tick(dtime, SmoothTime);
            position.Tick(dtime);
            age += dtime;

            Quaternion qx = QuaternionExtensions.FromAxisAngle(1, 0, 0, rotationspeed.X * dtime);
            Quaternion qy = QuaternionExtensions.FromAxisAngle(0, 1, 0, rotationspeed.Y * dtime);
            Quaternion qz = QuaternionExtensions.FromAxisAngle(0, 0, 1, rotationspeed.Z * dtime);
            Quaternion q  = qx * qy * qz;

            orientation.Original = q * orientation.Original;
            //HACK
            if (orientation.Original.W < -1.0f)
            {
                orientation.Original.W = -1.0f;
            }

            Orientation = orientation.Original;

            if (Attach != null && Attach.Kill)
            {
                Attach = null;
            }

            if (Draw != null)
            {
                foreach (object o in Draw)
                {
                    if (o is ITickable)
                    {
                        ((ITickable)o).Tick(dtime);
                    }
                }
            }
        }
Beispiel #4
0
        /*public override void OnKill()
         * {
         *  if (IsLocal)
         *  {
         *      Explosion x = new Explosion(AbsolutePosition);
         *      Root.Instance.Scene.Spawn(x);
         *      x.Position = AbsolutePosition;
         *  }
         * }*/

        public override void Tick(float dTime)
        {
            base.Tick(dTime);

            if (Target != null)
            {
                /*UpdateDirection(Target.AbsolutePosition, dTime);
                 * Vector3 forward = Direction;
                 * forward.Y = 0;
                 * forward.Normalize();
                 * Speed = forward * 1000;
                 * return;*/

                if (first)
                {
                    first = false;
                    //rotation = (float)Math.Acos(Vector3.Dot(Direction, Vector3.ZAxis));
                    Vector3 d = Direction;
                    rotation = (float)Math.Atan2(d.X, d.Z);
                    //System.Console.WriteLine(rotation.ToString());
                    Orientation = QuaternionExtensions.FromAxisAngle(0, 1, 0, rotation);
                    //rotation = -(float)Math.Atan2(Direction.X, Direction.Z);
                    //System.Console.WriteLine(rotation.ToString());
                }


                //left vector projected on plane
                Vector3 left = Left;
                left.Y = 0;
                left.Normalize();

                //forward vector projected on plane
                Vector3 forward = Direction;
                forward.Y = 0;
                forward.Normalize();

                //wanted direction vector
                Vector3 want = Target.Position - Position;
                want.Normalize();

                float wantedrotation = (float)Math.Atan2(want.X, want.Z);


                //cos=0
                float cos = Vector3.Dot(left, want);
                float a   = (float)Math.Acos((double)cos) * 180.0f / (float)Math.PI;
                // rotationspeed = new Vector3(0, -2 * cos, 0);
                rotationspeed = 2 * cos;

                rotation += rotationspeed * dTime;
                roll      = -rotationspeed / 2;

                Quaternion q1 = QuaternionExtensions.FromAxisAngle(0, 1, 0, rotation);
                Orientation = q1;
                Quaternion q2 = QuaternionExtensions.FromAxisAngle(Direction, roll);
                Orientation = q1 * q2;

                Vector3 tmp = Position;
                tmp.Y    = 0;
                Position = tmp;



                Speed = Direction * 1000;
                //v.Normalize();
                //Speed = v * 1000;*/



                /*LookAt(Target.AbsolutePosition);
                 * Vector3 v = Target.AbsolutePosition - AbsolutePosition;
                 * v.Normalize();
                 * Speed = v * 1000;*/
            }

            Timer += dTime;
        }
        public override void Create()
        {
            Node n, n2;

            Mars = new Mars();
            //Mars.rotationspeed.Y = 15.0f / 180.0f * (float)Math.PI;
            Mars.Position = new Vector3(2000, 0, 3000);
            Spawn(Mars, true);

            Moon = new Moon();
            Moon.rotationspeed.Y = 15.0f / 180.0f * (float)Math.PI;
            Moon.Position        = new Vector3(1000, 0, 0);
            Moon.Attach          = Mars;
            Spawn(Moon, true);

            n = new Saturn();
            n.rotationspeed.Y = 10.0f / 180.0f * (float)Math.PI;
            n.Orientation     = QuaternionExtensions.FromAxisAngle(0, 1, 0, (float)Math.PI);
            n.Position        = new Vector3(-2000, 0, 3000);
            Spawn(n, true);

            DominationPoint dp = new DominationPoint();

            dp.Name          = "DomPoint 1";
            dp.Position      = new Vector3(2000, 0, 2000);
            dp.rotationspeed = new Vector3(0, 1, 0);
            Spawn(dp, false);

            CheckPoint cp = new CheckPoint();

            cp.CheckPointIndex = 0;
            cp.Position        = new Vector3(3000, 0, 2000);
            Spawn(cp, true);
            cp = new CheckPoint();
            cp.CheckPointIndex = 1;
            cp.Position        = new Vector3(4000, 0, 2000);
            Spawn(cp, true);

            VecRandom r      = new VecRandom();
            Vector3   center = new Vector3(-4000, 0, -2000);

            for (int i = 0; i < 20; ++i)
            {
                Vector3 rv = r.NextScaledVector3(3000, 300, 2000);
                n = new Phobos();
                Spawn(n, true);
                float s = 30.0f / 180.0f * (float)Math.PI;
                n.rotationspeed = r.NextScaledVector3(s, s, s);
                n.Position      = center + rv;
            }

            //if (Root.Instance is Server)
            {
                n = new SpawnPoint(typeof(Repair), 20);
                n.rotationspeed = new Vector3(0, 1, 0);
                n.Position      = new Vector3(-500, 0, 0);
                Spawn(n, true);
            }
            {
                n = new SpawnPoint(typeof(MissilePickup), 30);
                n.rotationspeed = new Vector3(0, 1, 0);
                n.Position      = new Vector3(2000, 0, -1000);
                Spawn(n, true);
            }

            {
                n = new PlayerStart();
                n.rotationspeed = new Vector3(0, 1, 0);
                n.Position      = new Vector3(4000, 0, 4000);
                Spawn(n, true);
            }
            {
                n = new PlayerStart();
                n.rotationspeed = new Vector3(0, 1, 0);
                n.Position      = new Vector3(-4000, 0, -4000);
                Spawn(n, true);
            }
            {
                n = new PlayerStart();
                n.rotationspeed = new Vector3(0, 1, 0);
                n.Position      = new Vector3(-4000, 0, 4000);
                Spawn(n, true);
            }
            {
                n = new PlayerStart();
                n.rotationspeed = new Vector3(0, 1, 0);
                n.Position      = new Vector3(4000, 0, -4000);
                Spawn(n, true);
            }

            {
                n = new Flag(1, new Vector3(4800, 0, -4800));
                Spawn(n, false);
            }
            {
                n = new Flag(0, new Vector3(4400, 0, -4400));
                Spawn(n, false);
            }

            //ParticleNebula pn = new ParticleNebula();
            n = new Nebula();
            //n.Draw.Add(pn);
            //n.Transparent = true;
            n.Position = new Vector3(0, 0, 0);
            Spawn(n, true);

            n = new Nebula();
            //n.Draw.Add(pn);
            //n.Transparent = true;
            n.Position = new Vector3(100, 0, 600);
            Spawn(n, true);

            //n = new LaserTurret();
            //n = new Nebula();
            //n.Draw.Add(pn);
            n = new PornCinema();

            //Text3D tx = new Cheetah.Text3D("abcabcabc", (MeshFont)Root.Instance.ResourceManager.Load("models/font-arial-black", typeof(MeshFont)));
            //n.Draw.Add(tx);
            n.Position    = new Vector3(300, 0, 1200);
            n.Orientation = QuaternionExtensions.FromAxisAngle(0, 1, 0, (float)Math.PI);
            Spawn(n, true);

            //n = new TestShip();
            //Root.Instance.Scene.Spawn(n);
            //n.Position = new Vector3(400, 0, 0);

            Light l = new Light();

            l.directional = true;
            l.Position    = Vector3Extensions.GetUnit(new Vector3(1, 3, 4));
            //l.directional = false;

            l.diffuse = new Color4f(0.5f, 0.8f, 1.0f, 1);
            Spawn(l, true);


            l             = new Light();
            l.Position    = new Vector3(0, 0, 0);
            l.directional = false;
            l.diffuse     = new Color4f(1, 0, 0, 1);
            Spawn(l, true);


            n = new EclipticNode();
            //n.Draw.Add(new Ecliptic(new Color3f(0, 0, 0.5f), 10000, 100));
            Spawn(n, true);

            //Spawn(new RandomSpawn(typeof(SpaceWar2006.Planets.PhobosAsteroid), 1, 1), true);
        }