Example #1
0
        private void MoveShip1(GraphicsDevice graphicsDevice)
        {
            double rotationAccel = 0;
            double accel         = AccelWithKeys();

            Keyboard.GetState().AffectNumber(ref rotationAccel, Keys.Left, Keys.Right, Keys.A, Keys.D, 0.01);
            rotationSpeed  = Math.Max(Math.Min(rotationSpeed + rotationAccel, 0.1), -0.1);
            rotationSpeed *= 0.9;
            // apply rotation

            SphereVector right = new SphereVector(forward.Cross(position).Normalized());

            forward = forward.WalkTowards(right, rotationSpeed);

            // move forwards
            velocity += forward * accel * Math.Pow(0.5, zoom) * 20;
            position  = new SphereVector((position + velocity).Normalized());
            // flatten our forward/velocity against current position
            forward = new SphereVector(forward.Cross(position).Cross(-position).Normalized());
            if (velocity.Length() > 0.0000000001)
            {
                double currentSpeed = velocity.Length();
                //if (rotationSpeed != 0) currentSpeed *= velocity.Normalized().Dot(forward);
                double max = Math.Pow(0.5, zoom) * 0.2;
                double min = Math.Pow(0.5, zoom) * 0;
                currentSpeed = Math.Max(Math.Min(currentSpeed, max), min);
                velocity     = (velocity.Cross(position).Cross(-position).Normalized() * 0.8 + forward * 0.2).Normalized() * currentSpeed;
            }
            else
            {
                velocity = velocity.Cross(position).Cross(-position);
            }
            // now update altitude
            ControlZoomWithKeys();
            SphereVector unitPosition2 = new SphereVector(position.Normalized());

            camera.cameraRotX = unitPosition2.ToLongLat().X;
            camera.cameraRotY = unitPosition2.ToLongLat().Y;
            camera.UpdateCamera(graphicsDevice);
        }
Example #2
0
        // have the mouse control everything
        private void MoveShip2(GraphicsDevice graphicsDevice)
        {
            double accel = AccelerateWithMouse(graphicsDevice);

            //double accel = AccelWithKeys();
            rotationSpeed = RotateWithMouse(graphicsDevice);
            SphereVector right = new SphereVector(forward.Cross(position).Normalized());

            forward = forward.WalkTowards(right, rotationSpeed);

            // move forwards
            velocity += forward * accel * Math.Pow(0.5, zoom) * 20;
            position  = new SphereVector((position + velocity).Normalized());
            // flatten our forward/velocity against current position
            forward = new SphereVector(forward.Cross(position).Cross(-position).Normalized());
            if (velocity.Length() > 0.0000000001)
            {
                double currentSpeed = velocity.Length();
                //if (rotationSpeed != 0) currentSpeed *= velocity.Normalized().Dot(forward);
                double max = Math.Pow(0.5, zoom) * 0.2;
                double min = Math.Pow(0.5, zoom) * 0;
                currentSpeed = Math.Max(Math.Min(currentSpeed, max), min);
                velocity     = (velocity.Cross(position).Cross(-position).Normalized() * 0.8 + forward * 0.2).Normalized() * currentSpeed;
            }
            else
            {
                velocity = velocity.Cross(position).Cross(-position);
            }
            // now update altitude
            SphereVector unitPosition2 = new SphereVector(position.Normalized());

            camera.cameraRotX = unitPosition2.ToLongLat().X;
            camera.cameraRotY = unitPosition2.ToLongLat().Y;
            BaseZoomOnSpeed();
            //ControlZoomWithKeys();
            camera.UpdateCamera(graphicsDevice);
        }