Пример #1
0
        void renderTargetUserControl1_MouseMove(object sender, MouseEventArgs e)
        {
            //free camera rotating
            if (Map.Instance != null && freeCameraEnabled && freeCameraMouseRotating)
            {
                Vec2 mouse = renderTargetUserControl1.GetMouseRelativeModeOffset().ToVec2() /
                             renderTargetUserControl1.Viewport.DimensionsInPixels.Size.ToVec2();

                SphereDir dir = freeCameraDirection;
                dir.Horizontal -= mouse.X;
                dir.Vertical   -= mouse.Y;

                dir.Horizontal = MathFunctions.RadiansNormalize360(dir.Horizontal);

                const float vlimit = MathFunctions.PI / 2 - .01f;
                if (dir.Vertical > vlimit)
                {
                    dir.Vertical = vlimit;
                }
                if (dir.Vertical < -vlimit)
                {
                    dir.Vertical = -vlimit;
                }

                freeCameraDirection = dir;
            }
        }
        protected override void OnControlledObjectChange(Unit oldObject)
        {
            base.OnControlledObjectChange(oldObject);

            //update look direction
            if (ControlledObject != null)
            {
                lookDirection = SphereDir.FromVector(ControlledObject.Rotation * new Vec3(1, 0, 0));
            }

            //TankGame specific
            {
                //set small damage for player tank
                Tank oldTank = oldObject as Tank;
                if (oldTank != null)
                {
                    oldTank.ReceiveDamageCoefficient = 1;
                }
                Tank tank = ControlledObject as Tank;
                if (tank != null)
                {
                    tank.ReceiveDamageCoefficient = .1f;
                }
            }
        }
Пример #3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //NeoAxis initialization
            if (!WPFAppWorld.Init(new ExampleEngineApp(EngineApp.ApplicationTypes.Simulation), this,
                                  "user:Logs/WPFAppExample.log", true, null, null, null, null))
            {
                Close();
                return;
            }

            UpdateVolume();

            renderTargetUserControl1.AutomaticUpdateFPS = 60;
            renderTargetUserControl1.KeyDown           += renderTargetUserControl1_KeyDown;
            renderTargetUserControl1.KeyUp     += renderTargetUserControl1_KeyUp;
            renderTargetUserControl1.MouseDown += renderTargetUserControl1_MouseDown;
            renderTargetUserControl1.MouseUp   += renderTargetUserControl1_MouseUp;
            renderTargetUserControl1.MouseMove += renderTargetUserControl1_MouseMove;
            renderTargetUserControl1.Tick      += renderTargetUserControl1_Tick;
            renderTargetUserControl1.Render    += renderTargetUserControl1_Render;
            renderTargetUserControl1.RenderUI  += renderTargetUserControl1_RenderUI;

            const string startMapName = "Maps\\MainMenu\\Map.map";

            //generate map list
            {
                string[] mapList = VirtualDirectory.GetFiles("", "*.map", SearchOption.AllDirectories);
                foreach (string mapName in mapList)
                {
                    comboBoxMaps.Items.Add(mapName);
                    if (mapName == startMapName)
                    {
                        comboBoxMaps.SelectedIndex = comboBoxMaps.Items.Count - 1;
                    }
                }
            }

            //load map
            WPFAppWorld.MapLoad(startMapName, true);

            //set camera position
            if (Map.Instance != null)
            {
                MapCamera mapCamera = FindFirstMapCamera();
                if (mapCamera != null)
                {
                    freeCameraPosition  = mapCamera.Position;
                    freeCameraDirection = SphereDir.FromVector(mapCamera.Rotation.GetForward());
                }
                else
                {
                    freeCameraPosition  = Map.Instance.EditorCameraPosition;
                    freeCameraDirection = Map.Instance.EditorCameraDirection;
                }
            }
        }
Пример #4
0
        private void TickLadder()
        {
            //!!!!!â òèï?
            const float ladderClimbingSpeedWalk = 1.5f;
            const float ladderClimbingSpeedRun  = 3;

            SphereDir lookDirection = SphereDir.Zero;
            {
                PlayerIntellect playerIntellect = Intellect as PlayerIntellect;
                if (playerIntellect != null)
                {
                    lookDirection = playerIntellect.LookDirection;
                }
            }

            bool wantMove =
                Intellect.IsControlKeyPressed(GameControlKeys.Forward) ||
                Intellect.IsControlKeyPressed(GameControlKeys.Backward) ||
                Intellect.IsControlKeyPressed(GameControlKeys.Left) ||
                Intellect.IsControlKeyPressed(GameControlKeys.Right);

            Ladder ladder = FindLadder(currentLadder != null, wantMove, lookDirection);

            if (ladder != currentLadder)
            {
                SetCurrentLadder(ladder);
            }

            if (currentLadder != null)
            {
                Line line = currentLadder.GetClimbingLine();

                Vec3 projected = MathUtils.ProjectPointToLine(line.Start, line.End, Position);

                Vec3 newPosition = projected;

                float climbingSpeed = IsNeedRun() ? ladderClimbingSpeedRun : ladderClimbingSpeedWalk;

                Vec3 moveVector = Vec3.Zero;

                float lookingSide = new Radian(lookDirection.Vertical).InDegrees() > -20 ? 1 : -1;
                moveVector.Z += Intellect.GetControlKeyStrength(GameControlKeys.Forward) * lookingSide;
                moveVector.Z -= Intellect.GetControlKeyStrength(GameControlKeys.Backward) * lookingSide;

                newPosition += moveVector * (TickDelta * climbingSpeed);

                Position = newPosition;

                if (mainBody != null)
                {
                    mainBody.LinearVelocity  = Vec3.Zero;
                    mainBody.AngularVelocity = Vec3.Zero;
                }
            }
        }
Пример #5
0
        void renderTargetUserControl1_Tick(RenderTargetUserControl sender, float delta)
        {
            //update network status
            NetworkConnectionStatuses status = NetworkConnectionStatuses.Disconnected;

            if (GameNetworkClient.Instance != null)
            {
                status = GameNetworkClient.Instance.Status;
            }
            labelNetworkStatus.Content = status.ToString();

            //moving free camera by keys
            if (Map.Instance != null && freeCameraEnabled)
            {
                float cameraVelocity = 20;

                Vec3      pos = freeCameraPosition;
                SphereDir dir = freeCameraDirection;

                float step = cameraVelocity * delta;

                if (renderTargetUserControl1.IsKeyPressed(Key.W) ||
                    renderTargetUserControl1.IsKeyPressed(Key.Up))
                {
                    pos += dir.GetVector() * step;
                }
                if (renderTargetUserControl1.IsKeyPressed(Key.S) ||
                    renderTargetUserControl1.IsKeyPressed(Key.Down))
                {
                    pos -= dir.GetVector() * step;
                }
                if (renderTargetUserControl1.IsKeyPressed(Key.A) ||
                    renderTargetUserControl1.IsKeyPressed(Key.Left))
                {
                    pos += new SphereDir(
                        dir.Horizontal + MathFunctions.PI / 2, 0).GetVector() * step;
                }
                if (renderTargetUserControl1.IsKeyPressed(Key.D) ||
                    renderTargetUserControl1.IsKeyPressed(Key.Right))
                {
                    pos += new SphereDir(
                        dir.Horizontal - MathFunctions.PI / 2, 0).GetVector() * step;
                }
                if (renderTargetUserControl1.IsKeyPressed(Key.Q))
                {
                    pos += new Vec3(0, 0, step);
                }
                if (renderTargetUserControl1.IsKeyPressed(Key.E))
                {
                    pos += new Vec3(0, 0, -step);
                }

                freeCameraPosition = pos;
            }
        }
Пример #6
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            //NeoAxis initialization
            if (!WinFormsAppWorld.Init(new ExampleEngineApp(EngineApp.ApplicationTypes.Simulation), this,
                "user:Logs/WinFormsAppExample.log", true, null, null, null, null))
            {
                Close();
                return;
            }

            UpdateVolume();

            renderTargetUserControl1.AutomaticUpdateFPS = 60;
            renderTargetUserControl1.KeyDown += renderTargetUserControl1_KeyDown;
            renderTargetUserControl1.KeyUp += renderTargetUserControl1_KeyUp;
            renderTargetUserControl1.MouseDown += renderTargetUserControl1_MouseDown;
            renderTargetUserControl1.MouseUp += renderTargetUserControl1_MouseUp;
            renderTargetUserControl1.MouseMove += renderTargetUserControl1_MouseMove;
            renderTargetUserControl1.Tick += renderTargetUserControl1_Tick;
            renderTargetUserControl1.Render += renderTargetUserControl1_Render;
            renderTargetUserControl1.RenderUI += renderTargetUserControl1_RenderUI;

            const string startMapName = "Maps\\MainMenu\\Map.map";

            //generate map list
            {
                string[] mapList = VirtualDirectory.GetFiles("", "*.map", SearchOption.AllDirectories);
                foreach (string mapName in mapList)
                {
                    comboBoxMaps.Items.Add(mapName);
                    if (mapName == startMapName)
                        comboBoxMaps.SelectedIndex = comboBoxMaps.Items.Count - 1;
                }
            }

            //load map
            WinFormsAppWorld.MapLoad(startMapName, true);

            //set camera position
            if (Map.Instance != null)
            {
                MapCamera mapCamera = FindFirstMapCamera();
                if (mapCamera != null)
                {
                    freeCameraPosition = mapCamera.Position;
                    freeCameraDirection = SphereDir.FromVector(mapCamera.Rotation.GetForward());
                }
                else
                {
                    freeCameraPosition = Map.Instance.EditorCameraPosition;
                    freeCameraDirection = Map.Instance.EditorCameraDirection;
                }
            }
        }
Пример #7
0
        public void ReceiveObject(MapObject obj, Teleporter source)
        {
            if (!string.IsNullOrEmpty(Type.ReceiveParticleName))
            {
                Map.Instance.CreateAutoDeleteParticleSystem(Type.ReceiveParticleName, Position);
            }

            if (source == null)
            {
                float offset = obj.Position.Z - obj.PhysicsModel.GetGlobalBounds().Minimum.Z;
                obj.Position = Position + new Vec3(0, 0, offset);
                obj.Rotation = Rotation;
                obj.SetOldTransform(obj.Position, obj.Rotation, obj.Scale);
            }
            else
            {
                Quat destRotation = Rotation * Mat3.FromRotateByZ(new Degree(180).InRadians()).ToQuat();

                foreach (Body body in obj.PhysicsModel.Bodies)
                {
                    body.Rotation = body.Rotation * source.Rotation.GetInverse() * destRotation;
                    Vec3 localPosOffset = (body.Position - source.Position) * source.Rotation.GetInverse();
                    body.Position    = Position + localPosOffset * destRotation;
                    body.OldPosition = body.Position;
                    body.OldRotation = body.Rotation;

                    body.LinearVelocity  = body.LinearVelocity * source.Rotation.GetInverse() * destRotation;
                    body.AngularVelocity = body.AngularVelocity * source.Rotation.GetInverse() * destRotation;
                }

                obj.UpdatePositionAndRotationByPhysics(true);
                obj.SetOldTransform(obj.Position, obj.Rotation, obj.Scale);

                Unit unit = obj as Unit;
                if (unit != null)
                {
                    PlayerIntellect playerIntellect = unit.Intellect as PlayerIntellect;
                    if (playerIntellect != null)
                    {
                        Vec3 vec = playerIntellect.LookDirection.GetVector();
                        Vec3 v   = vec * source.Rotation.GetInverse() * destRotation;
                        playerIntellect.LookDirection = SphereDir.FromVector(v);
                    }
                }
            }

            //add object to the list of processed objects. object can't activate teleportation.
            processedObjectsInActiveArea.AddWithCheckAlreadyContained(obj);

            //skip ticks to wait for update physics body of transfered object after teleportation.
            skipTicks += 2;
        }
Пример #8
0
        protected override void OnAttach()
        {
            base.OnAttach();
            instance = this;

            freeCameraPosition = Map.Instance.EditorCameraPosition;
            freeCameraDirection = Map.Instance.EditorCameraDirection;

            EngineApp.Instance.Config.RegisterClassParameters( GetType() );

            if( EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle() )
                EntitySystemWorld.Instance.Simulation = true;
        }
Пример #9
0
        protected override void OnAttach()
        {
            base.OnAttach();
            instance = this;

            freeCameraPosition  = Map.Instance.EditorCameraPosition;
            freeCameraDirection = Map.Instance.EditorCameraDirection;

            EngineApp.Instance.Config.RegisterClassParameters(GetType());

            if (EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle())
            {
                EntitySystemWorld.Instance.Simulation = true;
            }
        }
Пример #10
0
        void renderTargetUserControl1_Tick(RenderTargetUserControl sender, float delta)
        {
            RenderTargetUserControl control = sender;

            //moving free camera by keys
            if (Map.Instance != null && freeCameraEnabled)
            {
                float cameraVelocity = 20;

                Vec3      pos = freeCameraPosition;
                SphereDir dir = freeCameraDirection;

                float step = cameraVelocity * delta;

                if (control.IsKeyPressed(Keys.W) ||
                    control.IsKeyPressed(Keys.Up))
                {
                    pos += dir.GetVector() * step;
                }
                if (control.IsKeyPressed(Keys.S) ||
                    control.IsKeyPressed(Keys.Down))
                {
                    pos -= dir.GetVector() * step;
                }
                if (control.IsKeyPressed(Keys.A) ||
                    control.IsKeyPressed(Keys.Left))
                {
                    pos += new SphereDir(
                        dir.Horizontal + MathFunctions.PI / 2, 0).GetVector() * step;
                }
                if (control.IsKeyPressed(Keys.D) ||
                    control.IsKeyPressed(Keys.Right))
                {
                    pos += new SphereDir(
                        dir.Horizontal - MathFunctions.PI / 2, 0).GetVector() * step;
                }
                if (control.IsKeyPressed(Keys.Q))
                {
                    pos += new Vec3(0, 0, step);
                }
                if (control.IsKeyPressed(Keys.E))
                {
                    pos += new Vec3(0, 0, -step);
                }

                freeCameraPosition = pos;
            }
        }
Пример #11
0
        protected override bool OnMouseMove()
        {
            bool ret = base.OnMouseMove();

            //If atop openly any window to not process
            if (Controls.Count != 1)
            {
                return(ret);
            }

            //free camera rotating
            if (FreeCameraEnabled && freeCameraMouseRotating)
            {
                if (!EngineApp.Instance.MouseRelativeMode)
                {
                    Vec2 diffPixels = (MousePosition - freeCameraRotatingStartPos) *
                                      new Vec2(EngineApp.Instance.VideoMode.X, EngineApp.Instance.VideoMode.Y);
                    if (Math.Abs(diffPixels.X) >= 3 || Math.Abs(diffPixels.Y) >= 3)
                    {
                        EngineApp.Instance.MouseRelativeMode = true;
                    }
                }
                else
                {
                    SphereDir dir = freeCameraDirection;
                    dir.Horizontal -= MousePosition.X;                  // *cameraRotateSensitivity;
                    dir.Vertical   -= MousePosition.Y;                  // *cameraRotateSensitivity;

                    dir.Horizontal = MathFunctions.RadiansNormalize360(dir.Horizontal);

                    const float vlimit = MathFunctions.PI / 2 - .01f;
                    if (dir.Vertical > vlimit)
                    {
                        dir.Vertical = vlimit;
                    }
                    if (dir.Vertical < -vlimit)
                    {
                        dir.Vertical = -vlimit;
                    }

                    freeCameraDirection = dir;
                }
            }

            return(ret);
        }
        private void GetFireParameters(out Vec3 pos, out Quat rot, out float speed)
        {
            Camera camera = RendererWorld.Instance.DefaultCamera;

            pos = catapult.Position + new Vec3(0, 0, .7f);

            Radian verticalAngle = new Degree(30).InRadians();

            rot   = Quat.Identity;
            speed = 0;

            if (catapultFiring)
            {
                Ray startRay = camera.GetCameraToViewportRay(catapultFiringMouseStartPosition);
                Ray ray      = camera.GetCameraToViewportRay(MousePosition);

                Plane plane = Plane.FromPointAndNormal(pos, Vec3.ZAxis);

                Vec3 startRayPos;
                if (!plane.RayIntersection(startRay, out startRayPos))
                {
                    //must never happen
                }

                Vec3 rayPos;
                if (!plane.RayIntersection(ray, out rayPos))
                {
                    //must never happen
                }

                Vec2 diff = rayPos.ToVec2() - startRayPos.ToVec2();

                Radian horizonalAngle = MathFunctions.ATan(diff.Y, diff.X) + MathFunctions.PI;

                SphereDir dir = new SphereDir(horizonalAngle, verticalAngle);
                rot = Quat.FromDirectionZAxisUp(dir.GetVector());

                float distance = diff.Length();

                //3 meters clamp
                MathFunctions.Clamp(ref distance, .001f, 3);

                speed = distance * 10;
            }
        }
Пример #13
0
        void TickIntellect()
        {
            //horizontalMotor
            {
                float throttle = 0;
                throttle += Intellect.GetControlKeyStrength(GameControlKeys.Left);
                throttle -= Intellect.GetControlKeyStrength(GameControlKeys.Right);

                GearedMotor motor = PhysicsModel.GetMotor("horizontalMotor") as GearedMotor;
                if (motor != null)
                {
                    motor.Throttle = throttle;
                }
            }

            //gibbetMotor
            {
                ServoMotor motor = PhysicsModel.GetMotor("gibbetMotor") as ServoMotor;
                if (motor != null)
                {
                    Radian needAngle = motor.DesiredAngle;

                    needAngle += Intellect.GetControlKeyStrength(GameControlKeys.Forward) * .004f;
                    needAngle -= Intellect.GetControlKeyStrength(GameControlKeys.Backward) * .004f;

                    MathFunctions.Clamp(ref needAngle,
                                        new Degree(-20.0f).InRadians(), new Degree(40.0f).InRadians());

                    motor.DesiredAngle = needAngle;
                }
            }

            //Change player LookDirection at rotation
            PlayerIntellect intellect = Intellect as PlayerIntellect;

            if (intellect != null)
            {
                Vec3 lookVector = intellect.LookDirection.GetVector();
                lookVector *= OldRotation.GetInverse();
                lookVector *= Rotation;
                intellect.LookDirection = SphereDir.FromVector(lookVector);
            }
        }
Пример #14
0
        private void buttonLoadMap_Click(object sender, EventArgs e)
        {
            if (comboBoxMaps.SelectedIndex == -1)
            {
                return;
            }

            string mapName = (string)comboBoxMaps.SelectedItem;

            if (GameNetworkClient.Instance != null)
            {
                //network mode.
                //send request message "Example_MapLoad" to the server.
                GameNetworkClient.Instance.CustomMessagesService.SendToServer("Example_MapLoad", mapName);
            }
            else
            {
                //load map in single mode.

                WinFormsAppWorld.MapLoad(mapName, true);

                //set camera position
                if (Map.Instance != null)
                {
                    MapCamera mapCamera = FindFirstMapCamera();
                    if (mapCamera != null)
                    {
                        freeCameraPosition  = mapCamera.Position;
                        freeCameraDirection = SphereDir.FromVector(mapCamera.Rotation.GetForward());
                    }
                    else
                    {
                        freeCameraPosition  = Map.Instance.EditorCameraPosition;
                        freeCameraDirection = Map.Instance.EditorCameraDirection;
                    }
                }
            }
        }
Пример #15
0
        bool MapLoad(string virtualFileName)
        {
            if (!WinFormsAppWorld.MapLoad(virtualFileName, true))
            {
                return(false);
            }

            //set camera position
            MapCamera mapCamera = FindFirstMapCamera();

            if (mapCamera != null)
            {
                freeCameraPosition  = mapCamera.Position;
                freeCameraDirection = SphereDir.FromVector(mapCamera.Rotation.GetForward());
            }
            else
            {
                freeCameraPosition  = Map.Instance.EditorCameraPosition;
                freeCameraDirection = Map.Instance.EditorCameraDirection;
            }

            return(true);
        }
Пример #16
0
 void Client_ReceiveTowerLocalDirection( RemoteEntityWorld sender, ReceiveDataReader reader )
 {
     SphereDir value = reader.ReadSphereDir();
     if( !reader.Complete() )
         return;
     towerLocalDirection = value;
 }
Пример #17
0
		bool MapLoad( string virtualFileName )
		{
			if( !WinFormsAppWorld.MapLoad( virtualFileName, true ) )
				return false;

			//set camera position
			MapCamera mapCamera = FindFirstMapCamera();
			if( mapCamera != null )
			{
				freeCameraPosition = mapCamera.Position;
				freeCameraDirection = SphereDir.FromVector( mapCamera.Rotation.GetForward() );
			}
			else
			{
				freeCameraPosition = Map.Instance.EditorCameraPosition;
				freeCameraDirection = Map.Instance.EditorCameraDirection;
			}

			return true;
		}
Пример #18
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //D3DImage support
            //D3DImage feature is a new level of interoperability between WPF and DirectX by allowing a custom Direct3D (D3D)
            //surface to be blended with WPF's native D3D surface.
            {
                string[] args = Environment.GetCommandLineArgs();
                for (int n = 1; n < args.Length; n++)
                {
                    string arg = args[n];

                    if (arg.ToLower() == "/d3dimage")
                    {
                        RendererWorld.InitializationOptions.AllowDirectX9Ex = true;
                    }
                }
            }

            //NeoAxis initialization
            if (!WPFAppWorld.Init(new ExampleEngineApp(EngineApp.ApplicationTypes.Simulation), this,
                                  "user:Logs/WPFAppExample.log", true, null, null, null, null))
            {
                Close();
                return;
            }

            UpdateVolume();

            renderTargetUserControl1.AutomaticUpdateFPS = 60;
            renderTargetUserControl1.KeyDown           += renderTargetUserControl1_KeyDown;
            renderTargetUserControl1.KeyUp     += renderTargetUserControl1_KeyUp;
            renderTargetUserControl1.MouseDown += renderTargetUserControl1_MouseDown;
            renderTargetUserControl1.MouseUp   += renderTargetUserControl1_MouseUp;
            renderTargetUserControl1.MouseMove += renderTargetUserControl1_MouseMove;
            renderTargetUserControl1.Tick      += renderTargetUserControl1_Tick;
            renderTargetUserControl1.Render    += renderTargetUserControl1_Render;
            renderTargetUserControl1.RenderUI  += renderTargetUserControl1_RenderUI;

            const string startMapName = "Maps\\MainMenu\\Map.map";

            //generate map list
            {
                string[] mapList = VirtualDirectory.GetFiles("", "*.map", SearchOption.AllDirectories);
                foreach (string mapName in mapList)
                {
                    comboBoxMaps.Items.Add(mapName);
                    if (mapName == startMapName)
                    {
                        comboBoxMaps.SelectedIndex = comboBoxMaps.Items.Count - 1;
                    }
                }
            }

            //load map
            WPFAppWorld.MapLoad(startMapName, true);

            //set camera position
            if (Map.Instance != null)
            {
                MapCamera mapCamera = FindFirstMapCamera();
                if (mapCamera != null)
                {
                    freeCameraPosition  = mapCamera.Position;
                    freeCameraDirection = SphereDir.FromVector(mapCamera.Rotation.GetForward());
                }
                else
                {
                    freeCameraPosition  = Map.Instance.EditorCameraPosition;
                    freeCameraDirection = Map.Instance.EditorCameraDirection;
                }
            }

            if (!RendererWorld.InitializationOptions.AllowDirectX9Ex)
            {
                //checkBoxUseD3DImage.IsEnabled = false;
                checkBoxUseD3DImage.IsChecked = false;
            }

            initialized = true;
        }
Пример #19
0
        //
        protected override void OnAttach()
        {
            base.OnAttach();

            EngineApp.Instance.KeysAndMouseButtonUpAll();

            //hudControl
            hudControl = ControlDeclarationManager.Instance.CreateControl( "Gui\\RTSHUD.gui" );
            Controls.Add( hudControl );

            ( (EButton)hudControl.Controls[ "Menu" ] ).Click += delegate( EButton sender )
            {
                Controls.Add( new MenuWindow() );
            };

            ( (EButton)hudControl.Controls[ "Exit" ] ).Click += delegate( EButton sender )
            {
                string mapName = "Maps\\Vietheroes\\Map.map";
                string spawnPointName = "SpawnPoint_FromRTSDemo";
                GameWorld.Instance.SetShouldChangeMap( mapName, spawnPointName, null );
            };

            ( (EButton)hudControl.Controls[ "Help" ] ).Click += delegate( EButton sender )
            {
                hudControl.Controls[ "HelpWindow" ].Visible = !hudControl.Controls[ "HelpWindow" ].Visible;
            };

            ( (EButton)hudControl.Controls[ "HelpWindow" ].Controls[ "Close" ] ).Click += delegate( EButton sender )
            {
                hudControl.Controls[ "HelpWindow" ].Visible = false;
            };

            ( (EButton)hudControl.Controls[ "DebugPath" ] ).Click += delegate( EButton sender )
            {
                mapDrawPathMotionMap = !mapDrawPathMotionMap;
            };

            InitControlPanelButtons();
            UpdateControlPanel();

            //set playerFaction
            if( RTSFactionManager.Instance != null && RTSFactionManager.Instance.Factions.Count != 0 )
                playerFaction = RTSFactionManager.Instance.Factions[ 0 ].FactionType;

            //minimap
            minimapControl = hudControl.Controls[ "Minimap" ];
            string textureName = Map.Instance.GetSourceMapVirtualFileDirectory() + "\\Minimap\\Minimap";
            Texture minimapTexture = TextureManager.Instance.Load( textureName, Texture.Type.Type2D, 0 );
            minimapControl.BackTexture = minimapTexture;
            minimapControl.RenderUI += new RenderUIDelegate( Minimap_RenderUI );

            //set camera position
            foreach( Entity entity in Map.Instance.Children )
            {
                SpawnPoint spawnPoint = entity as SpawnPoint;
                if( spawnPoint == null )
                    continue;
                cameraPosition = spawnPoint.Position.ToVec2();
                break;
            }

            //World serialized data
            if( World.Instance.GetCustomSerializationValue( "cameraDistance" ) != null )
                cameraDistance = (float)World.Instance.GetCustomSerializationValue( "cameraDistance" );
            if( World.Instance.GetCustomSerializationValue( "cameraDirection" ) != null )
                cameraDirection = (SphereDir)World.Instance.GetCustomSerializationValue( "cameraDirection" );
            if( World.Instance.GetCustomSerializationValue( "cameraPosition" ) != null )
                cameraPosition = (Vec2)World.Instance.GetCustomSerializationValue( "cameraPosition" );
            for( int n = 0; ; n++ )
            {
                Unit unit = World.Instance.GetCustomSerializationValue(
                    "selectedUnit" + n.ToString() ) as Unit;
                if( unit == null )
                    break;
                SetEntitySelected( unit, true );
            }

            ResetTime();
        }
Пример #20
0
		void renderTargetUserControl1_MouseMove( object sender, MouseEventArgs e )
		{
			RenderTargetUserControl control = (RenderTargetUserControl)sender;

			//free camera rotating
			if( Map.Instance != null && freeCameraEnabled && freeCameraMouseRotating )
			{
				Vec2 mouse = control.GetMouseRelativeModeOffset().ToVec2() /
					control.Viewport.DimensionsInPixels.Size.ToVec2();

				SphereDir dir = freeCameraDirection;
				dir.Horizontal -= mouse.X;
				dir.Vertical -= mouse.Y;

				dir.Horizontal = MathFunctions.RadiansNormalize360( dir.Horizontal );

				const float vlimit = MathFunctions.PI / 2 - .01f;
				if( dir.Vertical > vlimit ) dir.Vertical = vlimit;
				if( dir.Vertical < -vlimit ) dir.Vertical = -vlimit;

				freeCameraDirection = dir;
			}
		}
Пример #21
0
        protected override void OnControlledObjectChange( Unit oldObject )
        {
            base.OnControlledObjectChange( oldObject );

            //update look direction
            if( ControlledObject != null )
                lookDirection = SphereDir.FromVector( ControlledObject.Rotation * new Vec3( 1, 0, 0 ) );
        }
Пример #22
0
        internal void DoActionsAfterMapCreated()
        {
            if (EntitySystemWorld.Instance.IsSingle())
            {
                if (GameMap.Instance.GameType == GameMap.GameTypes.Action ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TPSArcade ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TurretDemo)
                {
                    string playerName = "__SinglePlayer__";

                    //create Player
                    PlayerManager.ServerOrSingle_Player player = PlayerManager.Instance.
                                                                 ServerOrSingle_GetPlayer(playerName);
                    if (player == null)
                    {
                        player = PlayerManager.Instance.Single_AddSinglePlayer(playerName);
                    }

                    //create PlayerIntellect
                    PlayerIntellect intellect = null;
                    {
                        //find already created PlayerIntellect
                        foreach (Entity entity in World.Instance.Children)
                        {
                            intellect = entity as PlayerIntellect;
                            if (intellect != null)
                            {
                                break;
                            }
                        }

                        if (intellect == null)
                        {
                            intellect = (PlayerIntellect)Entities.Instance.Create("PlayerIntellect",
                                                                                  World.Instance);
                            intellect.PostCreate();

                            player.Intellect = intellect;
                        }

                        //set instance
                        if (PlayerIntellect.Instance == null)
                        {
                            PlayerIntellect.SetInstance(intellect);
                        }
                    }

                    //create unit
                    if (intellect.ControlledObject == null)
                    {
                        SpawnPoint spawnPoint = null;
                        if (shouldChangeMapSpawnPointName != null)
                        {
                            spawnPoint = Entities.Instance.GetByName(shouldChangeMapSpawnPointName)
                                         as SpawnPoint;
                            if (spawnPoint == null)
                            {
                                Log.Error("GameWorld: SpawnPoint with name \"{0}\" is not defined.",
                                          shouldChangeMapSpawnPointName);
                            }
                        }

                        Unit unit;
                        if (spawnPoint != null)
                        {
                            unit = ServerOrSingle_CreatePlayerUnit(player, spawnPoint);
                        }
                        else
                        {
                            unit = ServerOrSingle_CreatePlayerUnit(player);
                        }

                        if (shouldChangeMapPlayerCharacterInformation != null)
                        {
                            PlayerCharacter playerCharacter = (PlayerCharacter)unit;
                            playerCharacter.ApplyChangeMapInformation(
                                shouldChangeMapPlayerCharacterInformation, spawnPoint);
                        }
                        else
                        {
                            if (unit != null)
                            {
                                intellect.LookDirection = SphereDir.FromVector(
                                    unit.Rotation.GetForward());
                            }
                        }
                    }
                }
            }

            shouldChangeMapName                       = null;
            shouldChangeMapSpawnPointName             = null;
            shouldChangeMapPlayerCharacterInformation = null;
        }
Пример #23
0
        private void buttonLoadMap_Click( object sender, RoutedEventArgs e )
        {
            if( comboBoxMaps.SelectedIndex == -1 )
                return;

            string mapName = (string)comboBoxMaps.SelectedItem;

            if( GameNetworkClient.Instance != null )
            {
                //network mode.
                //send request message "Example_MapLoad" to the server.
                GameNetworkClient.Instance.CustomMessagesService.SendToServer( "Example_MapLoad", mapName );
            }
            else
            {
                //load map in single mode.
                WPFAppWorld.MapLoad( mapName, true );

                //set camera position
                if( Map.Instance != null )
                {
                    MapCamera mapCamera = FindFirstMapCamera();
                    if( mapCamera != null )
                    {
                        freeCameraPosition = mapCamera.Position;
                        freeCameraDirection = SphereDir.FromVector( mapCamera.Rotation.GetForward() );
                    }
                    else
                    {
                        freeCameraPosition = Map.Instance.EditorCameraPosition;
                        freeCameraDirection = Map.Instance.EditorCameraDirection;
                    }
                }

            }
        }
Пример #24
0
        private void Window_Loaded( object sender, RoutedEventArgs e )
        {
            //D3DImage support
            //D3DImage feature is a new level of interoperability between WPF and DirectX by allowing a custom Direct3D (D3D)
            //surface to be blended with WPF's native D3D surface.
            {
                string[] args = Environment.GetCommandLineArgs();
                for( int n = 1; n < args.Length; n++ )
                {
                    string arg = args[ n ];

                    if( arg.ToLower() == "/d3dimage" )
                        RendererWorld.InitializationOptions.AllowDirectX9Ex = true;
                }
            }

            //NeoAxis initialization
            if( !WPFAppWorld.Init( new ExampleEngineApp( EngineApp.ApplicationTypes.Simulation ), this,
                "user:Logs/WPFAppExample.log", true, null, null, null, null ) )
            {
                Close();
                return;
            }

            UpdateVolume();

            renderTargetUserControl1.AutomaticUpdateFPS = 60;
            renderTargetUserControl1.KeyDown += renderTargetUserControl1_KeyDown;
            renderTargetUserControl1.KeyUp += renderTargetUserControl1_KeyUp;
            renderTargetUserControl1.MouseDown += renderTargetUserControl1_MouseDown;
            renderTargetUserControl1.MouseUp += renderTargetUserControl1_MouseUp;
            renderTargetUserControl1.MouseMove += renderTargetUserControl1_MouseMove;
            renderTargetUserControl1.Tick += renderTargetUserControl1_Tick;
            renderTargetUserControl1.Render += renderTargetUserControl1_Render;
            renderTargetUserControl1.RenderUI += renderTargetUserControl1_RenderUI;

            const string startMapName = "Maps\\MainMenu\\Map.map";

            //generate map list
            {
                string[] mapList = VirtualDirectory.GetFiles( "", "*.map", SearchOption.AllDirectories );
                foreach( string mapName in mapList )
                {
                    comboBoxMaps.Items.Add( mapName );
                    if( mapName == startMapName )
                        comboBoxMaps.SelectedIndex = comboBoxMaps.Items.Count - 1;
                }
            }

            //load map
            WPFAppWorld.MapLoad( startMapName, true );

            //set camera position
            if( Map.Instance != null )
            {
                MapCamera mapCamera = FindFirstMapCamera();
                if( mapCamera != null )
                {
                    freeCameraPosition = mapCamera.Position;
                    freeCameraDirection = SphereDir.FromVector( mapCamera.Rotation.GetForward() );
                }
                else
                {
                    freeCameraPosition = Map.Instance.EditorCameraPosition;
                    freeCameraDirection = Map.Instance.EditorCameraDirection;
                }
            }

            if( !RendererWorld.InitializationOptions.AllowDirectX9Ex )
            {
                //checkBoxUseD3DImage.IsEnabled = false;
                checkBoxUseD3DImage.IsChecked = false;
            }

            initialized = true;
        }
Пример #25
0
        public void SetNeedTurnToPosition( Vec3 pos )
        {
            if( towerBody == null )
                return;

            if( Type.TowerTurnSpeed != 0 )
            {
                Vec3 direction = pos - towerBody.Position;
                needTowerLocalDirection = SphereDir.FromVector( Rotation.GetInverse() * direction );
            }
            else
                SetMomentaryTurnToPosition( pos );
        }
Пример #26
0
        public void SetMomentaryTurnToPosition( Vec3 pos )
        {
            if( towerBody == null )
                return;

            Vec3 direction = pos - towerBody.Position;
            towerLocalDirection = SphereDir.FromVector( Rotation.GetInverse() * direction );
            needTowerLocalDirection = towerLocalDirection;
        }
Пример #27
0
        //

        protected override void OnAttach()
        {
            base.OnAttach();

            EngineApp.Instance.KeysAndMouseButtonUpAll();

            //hudControl
            hudControl = ControlDeclarationManager.Instance.CreateControl("Maps\\RTSDemo\\Gui\\HUD.gui");
            Controls.Add(hudControl);

            ((Button)hudControl.Controls["Menu"]).Click += delegate(Button sender)
            {
                Controls.Add(new MenuWindow());
            };

            ((Button)hudControl.Controls["Exit"]).Click += delegate(Button sender)
            {
                GameWorld.Instance.NeedChangeMap("Maps\\MainDemo\\Map.map", "Teleporter_Maps", null);
            };

            ((Button)hudControl.Controls["Help"]).Click += delegate(Button sender)
            {
                hudControl.Controls["HelpWindow"].Visible = !hudControl.Controls["HelpWindow"].Visible;
            };

            ((Button)hudControl.Controls["HelpWindow"].Controls["Close"]).Click += delegate(Button sender)
            {
                hudControl.Controls["HelpWindow"].Visible = false;
            };

            ((Button)hudControl.Controls["DebugPath"]).Click += delegate(Button sender)
            {
                mapDrawPathMotionMap = !mapDrawPathMotionMap;
            };

            cameraDistanceScrollBar = hudControl.Controls["CameraDistance"] as ScrollBar;
            if (cameraDistanceScrollBar != null)
            {
                cameraDistanceScrollBar.ValueRange = cameraDistanceRange;
                cameraDistanceScrollBar.ValueChange += cameraDistanceScrollBar_ValueChange;
            }

            cameraHeightScrollBar = hudControl.Controls["CameraHeight"] as ScrollBar;
            if (cameraHeightScrollBar != null)
            {
                cameraHeightScrollBar.ValueRange = cameraAngleRange;
                cameraHeightScrollBar.ValueChange += cameraHeightScrollBar_ValueChange;
            }

            InitControlPanelButtons();
            UpdateControlPanel();

            //set playerFaction
            if (RTSFactionManager.Instance != null && RTSFactionManager.Instance.Factions.Count != 0)
                playerFaction = RTSFactionManager.Instance.Factions[0].FactionType;

            //minimap
            minimapControl = hudControl.Controls["Minimap"];
            string textureName = Map.Instance.GetSourceMapVirtualFileDirectory() + "\\Minimap\\Minimap";
            Texture minimapTexture = TextureManager.Instance.Load(textureName, Texture.Type.Type2D, 0);
            minimapControl.BackTexture = minimapTexture;
            minimapControl.RenderUI += new RenderUIDelegate(Minimap_RenderUI);

            //set camera position
            foreach (Entity entity in Map.Instance.Children)
            {
                SpawnPoint spawnPoint = entity as SpawnPoint;
                if (spawnPoint == null)
                    continue;
                cameraPosition = spawnPoint.Position.ToVec2();
                break;
            }

            //World serialized data
            if (World.Instance.GetCustomSerializationValue("cameraDistance") != null)
                cameraDistance = (float)World.Instance.GetCustomSerializationValue("cameraDistance");
            if (World.Instance.GetCustomSerializationValue("cameraDirection") != null)
                cameraDirection = (SphereDir)World.Instance.GetCustomSerializationValue("cameraDirection");
            if (World.Instance.GetCustomSerializationValue("cameraPosition") != null)
                cameraPosition = (Vec2)World.Instance.GetCustomSerializationValue("cameraPosition");
            for (int n = 0; ; n++)
            {
                Unit unit = World.Instance.GetCustomSerializationValue(
                    "selectedUnit" + n.ToString()) as Unit;
                if (unit == null)
                    break;
                SetEntitySelected(unit, true);
            }

            ResetTime();

            //render scene for loading resources
            EngineApp.Instance.RenderScene();

            EngineApp.Instance.MousePosition = new Vec2(.5f, .5f);

            UpdateCameraScrollBars();
        }
Пример #28
0
        void region_ObjectIn(Entity entity, MapObject obj)
        {
            if (!active || destination == null)
            {
                return;
            }
            if (obj == this)
            {
                return;
            }

            Vec3 localOldPosOffset = (obj.OldPosition - Position) * Rotation.GetInverse();

            if (localOldPosOffset.X < -.3f)
            {
                return;
            }

            foreach (Body body in obj.PhysicsModel.Bodies)
            {
                body.Rotation    = body.Rotation * Rotation.GetInverse() * destination.Rotation;
                body.OldRotation = body.Rotation;

                Vec3 localPosOffset = (body.Position - Position) * Rotation.GetInverse();
                localPosOffset.Y = -localPosOffset.Y;
                localPosOffset.X = .3f;

                body.Position    = destination.Position + localPosOffset * destination.Rotation;
                body.OldPosition = body.Position;

                Vec3 vel = body.LinearVelocity * Rotation.GetInverse();
                vel.X = -vel.X;
                vel.Y = -vel.Y;
                vel  *= destination.Rotation;
                body.LinearVelocity = vel;

                vel   = body.AngularVelocity * Rotation.GetInverse();
                vel.X = -vel.X;
                vel.Y = -vel.Y;
                vel  *= destination.Rotation;
                body.AngularVelocity = vel;
            }

            Unit unit = obj as Unit;

            if (unit != null)
            {
                PlayerIntellect playerIntellect = unit.Intellect as PlayerIntellect;
                if (playerIntellect != null)
                {
                    Vec3 vec = playerIntellect.LookDirection.GetVector();

                    Vec3 v = vec * Rotation.GetInverse();
                    v.X = -v.X;
                    v.Y = -v.Y;
                    v  *= destination.Rotation;
                    playerIntellect.LookDirection = SphereDir.FromVector(v);
                }
            }

            //!!!!!!need check telefrag
        }
Пример #29
0
        void CalculateMainBodyGroundDistanceAndGroundBody( out Vec3 addForceOnBigSlope )
        {
            addForceOnBigSlope = Vec3.Zero;

            float height;
            float walkUpHeight;
            float fromPositionToFloorDistance;
            Type.GetBodyFormInfo( crouching, out height, out walkUpHeight, out fromPositionToFloorDistance );

            Capsule[] volumeCapsules = GetVolumeCapsules();
            //make radius smaller
            for( int n = 0; n < volumeCapsules.Length; n++ )
            {
                Capsule capsule = volumeCapsules[ n ];
                capsule.Radius *= .99f;
                volumeCapsules[ n ] = capsule;
            }

            mainBodyGroundDistance = 1000;
            groundBody = null;

            //1. get collision bodies
            List<Body> collisionBodies;
            float collisionOffset = 0;
            {
                Vec3 destVector = new Vec3( 0, 0, -height * 1.5f );
                float step = Type.Radius / 2;
                float collisionDistance;
                bool collisionOnFirstCheck;
                VolumeCheckGetFirstNotFreePlace( volumeCapsules, destVector, true, step, out collisionBodies, out collisionDistance,
                    out collisionOnFirstCheck );

                collisionOffset = collisionDistance;

                //for( float offset = 0; offset < height * 1.5f; offset += step )
                //{
                //   foreach( Capsule sourceVolumeCapsule in volumeCapsules )
                //   {
                //      Capsule checkCapsule = CapsuleAddOffset( sourceVolumeCapsule, new Vec3( 0, 0, -offset ) );

                //      Body[] bodies = PhysicsWorld.Instance.VolumeCast( checkCapsule, (int)ContactGroup.CastOnlyContact );
                //      foreach( Body body in bodies )
                //      {
                //         if( body == mainBody || body == fixRotationJointBody )
                //            continue;
                //         collisionBodies.Add( body );
                //      }
                //   }

                //   if( collisionBodies.Count != 0 )
                //   {
                //      collisionOffset = offset;
                //      break;
                //   }

                //   firstCheck = false;
                //}
            }

            //2. check slope angle
            if( collisionBodies.Count != 0 )
            {
                Capsule capsule = volumeCapsules[ volumeCapsules.Length - 1 ];
                Vec3 rayCenter = capsule.Point1 - new Vec3( 0, 0, collisionOffset );

                Body foundBodyWithGoodAngle = null;
                Vec3 bigSlopeVector = Vec3.Zero;

                const int horizontalStepCount = 16;
                const int verticalStepCount = 8;

                for( int verticalStep = 0; verticalStep < verticalStepCount; verticalStep++ )
                {
                    //.8f - to disable checking by horizontal rays
                    float verticalAngle = MathFunctions.PI / 2 -
                        ( (float)verticalStep / (float)verticalStepCount ) * MathFunctions.PI / 2 * .8f;

                    for( int horizontalStep = 0; horizontalStep < horizontalStepCount; horizontalStep++ )
                    {
                        //skip same rays on direct vertical ray
                        if( verticalStep == 0 && horizontalStep != 0 )
                            continue;

                        float horizontalAngle = ( (float)horizontalStep / (float)horizontalStepCount ) * MathFunctions.PI * 2;

                        SphereDir sphereDir = new SphereDir( horizontalAngle, -verticalAngle );
                        Ray ray = new Ray( rayCenter, sphereDir.GetVector() * Type.Radius * 1.3f );
                        //Ray ray = new Ray( rayCenter, sphereDir.GetVector() * Type.Radius * 1.1f );
                        RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing( ray,
                            (int)ContactGroup.CastOnlyContact );

                        //{
                        //   DebugGeometry debugGeometry = RendererWorld.Instance.DefaultCamera.DebugGeometry;
                        //   debugGeometry.Color = new ColorValue( 1, 0, 0 );
                        //   debugGeometry.AddLine( ray.Origin, ray.Origin + ray.Direction );
                        //}

                        if( piercingResult.Length != 0 )
                        {
                            foreach( RayCastResult result in piercingResult )
                            {
                                if( result.Shape.Body != mainBody && result.Shape.Body != fixRotationJointBody )
                                {
                                    //Log.Info( result.Normal.ToString() + " " +
                                    //   MathUtils.GetVectorsAngle( result.Normal, Vec3.ZAxis ).ToString() + " " +
                                    //   Type.MaxSlopeAngle.InRadians() );

                                    //{
                                    //   DebugGeometry debugGeometry = RendererWorld.Instance.DefaultCamera.DebugGeometry;
                                    //   debugGeometry.Color = new ColorValue( 1, 1, 0 );
                                    //   debugGeometry.AddLine( ray.Origin, ray.Origin + ray.Direction );
                                    //}
                                    //{
                                    //   DebugGeometry debugGeometry = RendererWorld.Instance.DefaultCamera.DebugGeometry;
                                    //   debugGeometry.Color = new ColorValue( 0, 0, 1 );
                                    //   debugGeometry.AddLine( result.Position, result.Position + result.Normal );
                                    //}

                                    //check slope angle
                                    if( MathUtils.GetVectorsAngle( result.Normal, Vec3.ZAxis ) < Type.MaxSlopeAngle.InRadians() )
                                    {
                                        foundBodyWithGoodAngle = result.Shape.Body;
                                        break;
                                    }
                                    else
                                    {
                                        Vec3 vector = new Vec3( result.Normal.X, result.Normal.Y, 0 );
                                        if( vector != Vec3.Zero )
                                            bigSlopeVector += vector;
                                    }
                                }
                            }

                            if( foundBodyWithGoodAngle != null )
                                break;
                        }
                    }
                    if( foundBodyWithGoodAngle != null )
                        break;
                }

                if( foundBodyWithGoodAngle != null )
                {
                    groundBody = foundBodyWithGoodAngle;
                    mainBodyGroundDistance = fromPositionToFloorDistance + collisionOffset;
                }
                else
                {
                    if( bigSlopeVector != Vec3.Zero )
                    {
                        //add force
                        bigSlopeVector.Normalize();
                        bigSlopeVector *= mainBody.Mass * 2;
                        addForceOnBigSlope = bigSlopeVector;
                    }
                }
            }
        }
Пример #30
0
        void renderTargetUserControl1_Tick( RenderTargetUserControl sender, float delta )
        {
            //update network status
            NetworkConnectionStatuses status = NetworkConnectionStatuses.Disconnected;
            if( GameNetworkClient.Instance != null )
                status = GameNetworkClient.Instance.Status;
            labelNetworkStatus.Content = status.ToString();

            //moving free camera by keys
            if( Map.Instance != null && freeCameraEnabled )
            {
                float cameraVelocity = 20;

                Vec3 pos = freeCameraPosition;
                SphereDir dir = freeCameraDirection;

                float step = cameraVelocity * delta;

                if( renderTargetUserControl1.IsKeyPressed( Key.W ) ||
                    renderTargetUserControl1.IsKeyPressed( Key.Up ) )
                {
                    pos += dir.GetVector() * step;
                }
                if( renderTargetUserControl1.IsKeyPressed( Key.S ) ||
                    renderTargetUserControl1.IsKeyPressed( Key.Down ) )
                {
                    pos -= dir.GetVector() * step;
                }
                if( renderTargetUserControl1.IsKeyPressed( Key.A ) ||
                    renderTargetUserControl1.IsKeyPressed( Key.Left ) )
                {
                    pos += new SphereDir(
                        dir.Horizontal + MathFunctions.PI / 2, 0 ).GetVector() * step;
                }
                if( renderTargetUserControl1.IsKeyPressed( Key.D ) ||
                    renderTargetUserControl1.IsKeyPressed( Key.Right ) )
                {
                    pos += new SphereDir(
                        dir.Horizontal - MathFunctions.PI / 2, 0 ).GetVector() * step;
                }
                if( renderTargetUserControl1.IsKeyPressed( Key.Q ) )
                    pos += new Vec3( 0, 0, step );
                if( renderTargetUserControl1.IsKeyPressed( Key.E ) )
                    pos += new Vec3( 0, 0, -step );

                freeCameraPosition = pos;
            }
        }
Пример #31
0
		private Ladder FindLadder( bool alreadyAttachedToSomeLadder, bool wantMove, SphereDir lookDirection )
		{
			float fromPositionToFloorDistance = ( Type.Height - Type.WalkUpHeight ) * .5f + Type.WalkUpHeight;

			Ladder result = null;

			Bounds bounds = MapBounds;
			bounds.Expand( 1 );

			Map.Instance.GetObjects( bounds, delegate( MapObject mapObject )
			{
				if( result != null )
					return;

				Ladder ladder = mapObject as Ladder;
				if( ladder == null )
					return;
				// if (ladder.IsInvalidOrientation())
				// return;

				Line line = ladder.GetClimbingLine();

				Vec3 projected = MathUtils.ProjectPointToLine( line.Start, line.End, Position );

				//check by distance
				float distanceToLine = ( projected - Position ).Length();
				if( distanceToLine > .5f )
					return;

				//check by up and down limits
				if( alreadyAttachedToSomeLadder )
				{
					if( projected.Z > line.End.Z + fromPositionToFloorDistance )
						return;
				}
				else
				{
					if( projected.Z > line.End.Z + fromPositionToFloorDistance * .5f )
						return;
				}
				if( projected.Z < line.Start.Z )
					return;

				//check by direction
				bool isHorizontallyOrientedToLadder;
				{
					Vec2 ladderDirection2 = ladder.Rotation.GetForward().ToVec2();
					Vec2 direction2 = Rotation.GetForward().ToVec2();
					Radian angle = MathUtils.GetVectorsAngle( ladderDirection2, direction2 );
					isHorizontallyOrientedToLadder = angle.InDegrees() < 70;
				}

				if( Math.Abs( new Radian( lookDirection.Vertical ).InDegrees() ) < 45 &&
					!isHorizontallyOrientedToLadder )
				{
					if( alreadyAttachedToSomeLadder )
					{
						if( wantMove )
							return;
					}
					else
						return;
				}

				//got ladder
				result = ladder;
			} );

			return result;
		}
Пример #32
0
        private Ladder FindLadder(bool alreadyAttachedToSomeLadder, bool wantMove, SphereDir lookDirection)
        {
            float fromPositionToFloorDistance = (Type.Height - Type.WalkUpHeight) * .5f + Type.WalkUpHeight;

            Ladder result = null;

            Bounds bounds = MapBounds;

            bounds.Expand(1);

            Map.Instance.GetObjects(bounds, delegate(MapObject mapObject)
            {
                if (result != null)
                {
                    return;
                }

                Ladder ladder = mapObject as Ladder;
                if (ladder == null)
                {
                    return;
                }
                //if (ladder.IsInvalidOrientation())
                //   return;

                Line line = ladder.GetClimbingLine();

                Vec3 projected = MathUtils.ProjectPointToLine(line.Start, line.End, Position);

                //check by distance
                float distanceToLine = (projected - Position).Length();
                if (distanceToLine > .5f)
                {
                    return;
                }

                //check by up and down limits
                if (alreadyAttachedToSomeLadder)
                {
                    if (projected.Z > line.End.Z + fromPositionToFloorDistance)
                    {
                        return;
                    }
                }
                else
                {
                    if (projected.Z > line.End.Z + fromPositionToFloorDistance * .5f)
                    {
                        return;
                    }
                }
                if (projected.Z < line.Start.Z)
                {
                    return;
                }

                //check by direction
                bool isHorizontallyOrientedToLadder;
                {
                    Vec2 ladderDirection2          = ladder.Rotation.GetForward().ToVec2();
                    Vec2 direction2                = Rotation.GetForward().ToVec2();
                    Radian angle                   = MathUtils.GetVectorsAngle(ladderDirection2, direction2);
                    isHorizontallyOrientedToLadder = angle.InDegrees() < 70;
                }

                if (Math.Abs(new Radian(lookDirection.Vertical).InDegrees()) < 45 &&
                    !isHorizontallyOrientedToLadder)
                {
                    if (alreadyAttachedToSomeLadder)
                    {
                        if (wantMove)
                        {
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }

                //got ladder
                result = ladder;
            });

            return(result);
        }
Пример #33
0
        void TickTowerTurn()
        {
            //update direction
            if( towerLocalDirection != needTowerLocalDirection )
            {
                Radian turnSpeed = Type.TowerTurnSpeed;

                SphereDir needDirection = needTowerLocalDirection;
                SphereDir direction = towerLocalDirection;

                //update horizontal direction
                float diffHorizontalAngle = needDirection.Horizontal - direction.Horizontal;
                while( diffHorizontalAngle < -MathFunctions.PI )
                    diffHorizontalAngle += MathFunctions.PI * 2;
                while( diffHorizontalAngle > MathFunctions.PI )
                    diffHorizontalAngle -= MathFunctions.PI * 2;

                if( diffHorizontalAngle > 0 )
                {
                    if( direction.Horizontal > needDirection.Horizontal )
                        direction.Horizontal -= MathFunctions.PI * 2;
                    direction.Horizontal += turnSpeed * TickDelta;
                    if( direction.Horizontal > needDirection.Horizontal )
                        direction.Horizontal = needDirection.Horizontal;
                }
                else
                {
                    if( direction.Horizontal < needDirection.Horizontal )
                        direction.Horizontal += MathFunctions.PI * 2;
                    direction.Horizontal -= turnSpeed * TickDelta;
                    if( direction.Horizontal < needDirection.Horizontal )
                        direction.Horizontal = needDirection.Horizontal;
                }

                //update vertical direction
                if( direction.Vertical < needDirection.Vertical )
                {
                    direction.Vertical += turnSpeed * TickDelta;
                    if( direction.Vertical > needDirection.Vertical )
                        direction.Vertical = needDirection.Vertical;
                }
                else
                {
                    direction.Vertical -= turnSpeed * TickDelta;
                    if( direction.Vertical < needDirection.Vertical )
                        direction.Vertical = needDirection.Vertical;
                }

                if( direction.Equals( needTowerLocalDirection, .001f ) )
                    towerLocalDirection = direction;

                towerLocalDirection = direction;
            }

            //update tower turn sound
            {
                bool needSound = !towerLocalDirection.Equals( needTowerLocalDirection,
                    new Degree( 2 ).InRadians() );

                if( needSound )
                {
                    if( towerTurnChannel == null && !string.IsNullOrEmpty( Type.SoundTowerTurn ) )
                    {
                        Sound sound = SoundWorld.Instance.SoundCreate(
                            RelativePathUtils.ConvertToFullPath( Path.GetDirectoryName( Type.FilePath ), Type.SoundTowerTurn ),
                            SoundMode.Mode3D | SoundMode.Loop );

                        if( sound != null )
                        {
                            towerTurnChannel = SoundWorld.Instance.SoundPlay(
                                sound, EngineApp.Instance.DefaultSoundChannelGroup, .3f, true );
                            towerTurnChannel.Position = Position;
                            switch( Type.SoundRolloffMode )
                            {
                            case DynamicType.SoundRolloffModes.Logarithmic:
                                towerTurnChannel.SetLogarithmicRolloff( Type.SoundMinDistance, Type.SoundMaxDistance,
                                    Type.SoundRolloffLogarithmicFactor );
                                break;
                            case DynamicType.SoundRolloffModes.Linear:
                                towerTurnChannel.SetLinearRolloff( Type.SoundMinDistance, Type.SoundMaxDistance );
                                break;
                            }
                            towerTurnChannel.Pause = false;
                        }
                    }

                    if( towerTurnChannel != null )
                        towerTurnChannel.Position = Position;
                }
                else
                {
                    if( towerTurnChannel != null )
                    {
                        towerTurnChannel.Stop();
                        towerTurnChannel = null;
                    }
                }
            }
        }
Пример #34
0
        /// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary>
        protected override void OnPostCreate( bool loaded )
        {
            base.OnPostCreate( loaded );

            needAngles = new SphereDir( MathFunctions.DegToRad( -Rotation.ToAngles().Yaw ), 0 );

            CreatePhysicsModel();

            Body body = PhysicsModel.CreateBody();
            mainBody = body;
            body.Name = "main";
            body.Position = Position;
            body.Rotation = Rotation;
            body.Sleepiness = 0;
            body.LinearVelocity = linearVelocityForSerialization;

            float length = Type.Height - Type.Radius * 2 - Type.WalkUpHeight;
            if( length < 0 )
            {
                Log.Error( "Length < 0" );
                return;
            }

            //create main capsule
            {
                CapsuleShape shape = body.CreateCapsuleShape();
                shape.Length = length;
                shape.Radius = Type.Radius;
                shape.ContactGroup = (int)ContactGroup.Dynamic;
                shape.StaticFriction = 0;
                shape.DynamicFriction = 0;
                shape.Bounciness = 0;
                shape.Hardness = 0;
                float r = shape.Radius;
                shape.Density = Type.Mass / ( MathFunctions.PI * r * r * shape.Length +
                    ( 4.0f / 3.0f ) * MathFunctions.PI * r * r * r );
                shape.SpecialLiquidDensity = .5f;
            }

            //create down capsule
            {
                CapsuleShape shape = body.CreateCapsuleShape();
                shape.Length = Type.Height - Type.BottomRadius * 2;
                shape.Radius = Type.BottomRadius;
                shape.Position = new Vec3( 0, 0,
                    ( Type.Height - Type.WalkUpHeight ) / 2 - Type.Height / 2 );
                shape.ContactGroup = (int)ContactGroup.Dynamic;
                shape.Bounciness = 0;
                shape.Hardness = 0;
                shape.Density = 0;
                shape.SpecialLiquidDensity = .5f;

                shape.StaticFriction = 0;
                shape.DynamicFriction = 0;
            }

            //That the body did not fall after loading a map.
            //After loading a map, the physics simulate 5 seconds, that bodies have fallen asleep.
            if( loaded && EntitySystemWorld.Instance.SerializationMode == SerializationModes.Map )
            {
                body.Static = true;
            }

            PhysicsModel.PushToWorld();

            AddTimer();
        }
Пример #35
0
        protected override void OnTick(float delta)
        {
            base.OnTick(delta);

            if (Controls.Count != 1)
            {
                return;
            }

            EntitySystemWorld.Instance.Tick();

            //Shound change map
            if (GameWorld.Instance != null && GameWorld.Instance.NeedChangeMapName != null)
            {
                GameEngineApp.Instance.ServerOrSingle_MapLoad(GameWorld.Instance.NeedChangeMapName,
                                                              EntitySystemWorld.Instance.DefaultWorldType, false);
            }

            //moving free camera by keys
            if (FreeCameraEnabled && OnFreeCameraIsAllowToMove())
            {
                float cameraVelocity;
                if (EngineApp.Instance.IsKeyPressed(EKeys.Shift))
                {
                    cameraVelocity = freeCameraSpeedFast;
                }
                else
                {
                    cameraVelocity = freeCameraSpeedNormal;
                }

                Vec3      pos = freeCameraPosition;
                SphereDir dir = freeCameraDirection;

                float step = cameraVelocity * delta;

                bool activeConsole = EngineConsole.Instance != null && EngineConsole.Instance.Active;

                if (!activeConsole)
                {
                    if (EngineApp.Instance.IsKeyPressed(EKeys.W) ||
                        EngineApp.Instance.IsKeyPressed(EKeys.Up))
                    {
                        pos += dir.GetVector() * step;
                    }
                    if (EngineApp.Instance.IsKeyPressed(EKeys.S) ||
                        EngineApp.Instance.IsKeyPressed(EKeys.Down))
                    {
                        pos -= dir.GetVector() * step;
                    }
                    if (EngineApp.Instance.IsKeyPressed(EKeys.A) ||
                        EngineApp.Instance.IsKeyPressed(EKeys.Left))
                    {
                        pos += new SphereDir(
                            dir.Horizontal + MathFunctions.PI / 2, 0).GetVector() * step;
                    }
                    if (EngineApp.Instance.IsKeyPressed(EKeys.D) ||
                        EngineApp.Instance.IsKeyPressed(EKeys.Right))
                    {
                        pos += new SphereDir(
                            dir.Horizontal - MathFunctions.PI / 2, 0).GetVector() * step;
                    }

                    if (EngineApp.Instance.IsKeyPressed(EKeys.Q))
                    {
                        pos += new SphereDir(dir.Horizontal, dir.Vertical + MathFunctions.PI / 2).GetVector() * step;
                    }
                    if (EngineApp.Instance.IsKeyPressed(EKeys.E))
                    {
                        pos += new SphereDir(dir.Horizontal, dir.Vertical - MathFunctions.PI / 2).GetVector() * step;
                    }
                }

                freeCameraPosition = pos;
            }

            if (freeCameraMouseRotating && !FreeCameraEnabled)
            {
                freeCameraMouseRotating = false;
            }
        }
Пример #36
0
        internal void DoActionsAfterMapCreated()
        {
            if (EntitySystemWorld.Instance.IsSingle())
            {
                if (GameMap.Instance.GameType == GameMap.GameTypes.Action ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TPSArcade ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TurretDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.VillageDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.PlatformerDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                {
                    string playerName = "__SinglePlayer__";

                    //create Player
                    PlayerManager.ServerOrSingle_Player player = PlayerManager.Instance.
                                                                 ServerOrSingle_GetPlayer(playerName);
                    if (player == null)
                    {
                        player = PlayerManager.Instance.Single_AddSinglePlayer(playerName);
                    }

                    //create PlayerIntellect
                    PlayerIntellect intellect = null;
                    {
                        //find already created PlayerIntellect
                        foreach (Entity entity in World.Instance.Children)
                        {
                            intellect = entity as PlayerIntellect;
                            if (intellect != null)
                            {
                                break;
                            }
                        }

                        if (intellect == null)
                        {
                            intellect = (PlayerIntellect)Entities.Instance.Create("PlayerIntellect",
                                                                                  World.Instance);
                            intellect.PostCreate();

                            player.Intellect = intellect;
                        }

                        //set instance
                        if (PlayerIntellect.Instance == null)
                        {
                            PlayerIntellect.SetInstance(intellect);
                        }
                    }

                    //create unit
                    if (intellect.ControlledObject == null)
                    {
                        MapObject spawnPoint = null;
                        if (!string.IsNullOrEmpty(needChangeMapSpawnPointName))
                        {
                            spawnPoint = Entities.Instance.GetByName(needChangeMapSpawnPointName) as MapObject;
                            if (spawnPoint == null)
                            {
                                Log.Warning("GameWorld: Object with name \"{0}\" does not exist.",
                                            needChangeMapSpawnPointName);
                            }
                        }

                        Unit unit;
                        if (spawnPoint != null)
                        {
                            unit = ServerOrSingle_CreatePlayerUnit(player, spawnPoint);
                        }
                        else
                        {
                            unit = ServerOrSingle_CreatePlayerUnit(player);
                        }

                        if (needChangeMapPlayerCharacterInformation != null)
                        {
                            PlayerCharacter playerCharacter = (PlayerCharacter)unit;
                            playerCharacter.ApplyChangeMapInformation(
                                needChangeMapPlayerCharacterInformation, spawnPoint);
                        }
                        else
                        {
                            if (unit != null)
                            {
                                intellect.LookDirection = SphereDir.FromVector(
                                    unit.Rotation.GetForward());
                            }
                        }
                    }
                }
            }

            needChangeMapName                       = null;
            needChangeMapSpawnPointName             = null;
            needChangeMapPlayerCharacterInformation = null;
        }
Пример #37
0
Файл: Tank.cs Проект: Eneth/GAO
        void TickTowerTurn()
        {
            //update direction
            if( towerLocalDirection != needTowerLocalDirection )
            {
                Radian turnSpeed = Type.TowerTurnSpeed;

                SphereDir needDirection = needTowerLocalDirection;
                SphereDir direction = towerLocalDirection;

                //update horizontal direction
                float diffHorizontalAngle = needDirection.Horizontal - direction.Horizontal;
                while( diffHorizontalAngle < -MathFunctions.PI )
                    diffHorizontalAngle += MathFunctions.PI * 2;
                while( diffHorizontalAngle > MathFunctions.PI )
                    diffHorizontalAngle -= MathFunctions.PI * 2;

                if( diffHorizontalAngle > 0 )
                {
                    if( direction.Horizontal > needDirection.Horizontal )
                        direction.Horizontal -= MathFunctions.PI * 2;
                    direction.Horizontal += turnSpeed * TickDelta;
                    if( direction.Horizontal > needDirection.Horizontal )
                        direction.Horizontal = needDirection.Horizontal;
                }
                else
                {
                    if( direction.Horizontal < needDirection.Horizontal )
                        direction.Horizontal += MathFunctions.PI * 2;
                    direction.Horizontal -= turnSpeed * TickDelta;
                    if( direction.Horizontal < needDirection.Horizontal )
                        direction.Horizontal = needDirection.Horizontal;
                }

                //update vertical direction
                if( direction.Vertical < needDirection.Vertical )
                {
                    direction.Vertical += turnSpeed * TickDelta;
                    if( direction.Vertical > needDirection.Vertical )
                        direction.Vertical = needDirection.Vertical;
                }
                else
                {
                    direction.Vertical -= turnSpeed * TickDelta;
                    if( direction.Vertical < needDirection.Vertical )
                        direction.Vertical = needDirection.Vertical;
                }

                if( direction.Equals( needTowerLocalDirection, .001f ) )
                    towerLocalDirection = direction;

                towerLocalDirection = direction;
            }

            //update tower turn sound
            {
                bool needSound = !towerLocalDirection.Equals( needTowerLocalDirection,
                    new Degree( 2 ).InRadians() );

                if( needSound )
                {
                    if( towerTurnChannel == null && !string.IsNullOrEmpty( Type.SoundTowerTurn ) )
                    {
                        Sound sound = SoundWorld.Instance.SoundCreate( Type.SoundTowerTurn,
                            SoundMode.Mode3D | SoundMode.Loop );

                        if( sound != null )
                        {
                            towerTurnChannel = SoundWorld.Instance.SoundPlay(
                                sound, EngineApp.Instance.DefaultSoundChannelGroup, .3f, true );
                            towerTurnChannel.Position = Position;
                            towerTurnChannel.Pause = false;
                        }
                    }

                    if( towerTurnChannel != null )
                        towerTurnChannel.Position = Position;
                }
                else
                {
                    if( towerTurnChannel != null )
                    {
                        towerTurnChannel.Stop();
                        towerTurnChannel = null;
                    }
                }
            }
        }
Пример #38
0
        void GetFireParameters( out Vec3 pos, out Quat rot, out float speed )
        {
            Camera camera = RendererWorld.Instance.DefaultCamera;

            pos = catapult.Position + new Vec3( 0, 0, .7f );

            Radian verticalAngle = new Degree( 30 ).InRadians();

            rot = Quat.Identity;
            speed = 0;

            if( catapultFiring )
            {
                Ray startRay = camera.GetCameraToViewportRay( catapultFiringMouseStartPosition );
                Ray ray = camera.GetCameraToViewportRay( MousePosition );

                Plane plane = Plane.FromPointAndNormal( pos, Vec3.ZAxis );

                Vec3 startRayPos;
                if( !plane.RayIntersection( startRay, out startRayPos ) )
                {
                    //must never happen
                }

                Vec3 rayPos;
                if( !plane.RayIntersection( ray, out rayPos ) )
                {
                    //must never happen
                }

                Vec2 diff = rayPos.ToVec2() - startRayPos.ToVec2();

                Radian horizonalAngle = MathFunctions.ATan( diff.Y, diff.X ) + MathFunctions.PI;

                SphereDir dir = new SphereDir( horizonalAngle, verticalAngle );
                rot = Quat.FromDirectionZAxisUp( dir.GetVector() );

                float distance = diff.Length();

                //3 meters clamp
                MathFunctions.Clamp( ref distance, .001f, 3 );

                speed = distance * 10;
            }
        }
Пример #39
0
        protected override bool OnMouseMove()
        {
            bool ret = base.OnMouseMove();

            //If atop openly any window to not process
            if( Controls.Count != 1 )
                return ret;

            //free camera rotating
            if( FreeCameraEnabled && freeCameraMouseRotating )
            {
                if( !EngineApp.Instance.MouseRelativeMode )
                {
                    Vec2 diffPixels = ( MousePosition - freeCameraRotatingStartPos ) *
                        new Vec2( EngineApp.Instance.VideoMode.X, EngineApp.Instance.VideoMode.Y );
                    if( Math.Abs( diffPixels.X ) >= 3 || Math.Abs( diffPixels.Y ) >= 3 )
                    {
                        EngineApp.Instance.MouseRelativeMode = true;
                    }
                }
                else
                {
                    SphereDir dir = freeCameraDirection;
                    dir.Horizontal -= MousePosition.X;// *cameraRotateSensitivity;
                    dir.Vertical -= MousePosition.Y;// *cameraRotateSensitivity;

                    dir.Horizontal = MathFunctions.RadiansNormalize360( dir.Horizontal );

                    const float vlimit = MathFunctions.PI / 2 - .01f;
                    if( dir.Vertical > vlimit ) dir.Vertical = vlimit;
                    if( dir.Vertical < -vlimit ) dir.Vertical = -vlimit;

                    freeCameraDirection = dir;
                }
            }

            return ret;
        }
Пример #40
0
		void renderTargetUserControl1_Tick( RenderTargetUserControl sender, float delta )
		{
			RenderTargetUserControl control = sender;

			//moving free camera by keys
			if( Map.Instance != null && freeCameraEnabled )
			{
				float cameraVelocity = 20;

				Vec3 pos = freeCameraPosition;
				SphereDir dir = freeCameraDirection;

				float step = cameraVelocity * delta;

				if( control.IsKeyPressed( Keys.W ) ||
					control.IsKeyPressed( Keys.Up ) )
				{
					pos += dir.GetVector() * step;
				}
				if( control.IsKeyPressed( Keys.S ) ||
					control.IsKeyPressed( Keys.Down ) )
				{
					pos -= dir.GetVector() * step;
				}
				if( control.IsKeyPressed( Keys.A ) ||
					control.IsKeyPressed( Keys.Left ) )
				{
					pos += new SphereDir(
						dir.Horizontal + MathFunctions.PI / 2, 0 ).GetVector() * step;
				}
				if( control.IsKeyPressed( Keys.D ) ||
					control.IsKeyPressed( Keys.Right ) )
				{
					pos += new SphereDir(
						dir.Horizontal - MathFunctions.PI / 2, 0 ).GetVector() * step;
				}
				if( control.IsKeyPressed( Keys.Q ) )
					pos += new Vec3( 0, 0, step );
				if( control.IsKeyPressed( Keys.E ) )
					pos += new Vec3( 0, 0, -step );

				freeCameraPosition = pos;
			}
		}
Пример #41
0
        protected override void OnTick( float delta )
        {
            base.OnTick( delta );

            if( Controls.Count != 1 )
                return;

            EntitySystemWorld.Instance.Tick();

            //Shound change map
            if( GameWorld.Instance != null && GameWorld.Instance.ShouldChangeMapName != null )
            {
                GameEngineApp.Instance.ServerOrSingle_MapLoad( GameWorld.Instance.ShouldChangeMapName,
                    EntitySystemWorld.Instance.DefaultWorldType, false );
            }

            //moving free camera by keys
            if( FreeCameraEnabled && OnFreeCameraIsAllowToMove() )
            {
                float cameraVelocity;
                if( EngineApp.Instance.IsKeyPressed( EKeys.Shift ) )
                    cameraVelocity = 100.0f;
                else
                    cameraVelocity = 20.0f;

                Vec3 pos = freeCameraPosition;
                SphereDir dir = freeCameraDirection;

                float step = cameraVelocity * delta;

                bool activeConsole = EngineConsole.Instance != null && EngineConsole.Instance.Active;

                if( !activeConsole )
                {
                    if( EngineApp.Instance.IsKeyPressed( EKeys.W ) ||
                        EngineApp.Instance.IsKeyPressed( EKeys.Up ) )
                    {
                        pos += dir.GetVector() * step;
                    }
                    if( EngineApp.Instance.IsKeyPressed( EKeys.S ) ||
                        EngineApp.Instance.IsKeyPressed( EKeys.Down ) )
                    {
                        pos -= dir.GetVector() * step;
                    }
                    if( EngineApp.Instance.IsKeyPressed( EKeys.A ) ||
                        EngineApp.Instance.IsKeyPressed( EKeys.Left ) )
                    {
                        pos += new SphereDir(
                            dir.Horizontal + MathFunctions.PI / 2, 0 ).GetVector() * step;
                    }
                    if( EngineApp.Instance.IsKeyPressed( EKeys.D ) ||
                        EngineApp.Instance.IsKeyPressed( EKeys.Right ) )
                    {
                        pos += new SphereDir(
                            dir.Horizontal - MathFunctions.PI / 2, 0 ).GetVector() * step;
                    }
                    if( EngineApp.Instance.IsKeyPressed( EKeys.Q ) )
                        pos += new Vec3( 0, 0, step );
                    if( EngineApp.Instance.IsKeyPressed( EKeys.E ) )
                        pos += new Vec3( 0, 0, -step );
                }

                freeCameraPosition = pos;
            }

            if( freeCameraMouseRotating && !FreeCameraEnabled )
                freeCameraMouseRotating = false;
        }
Пример #42
0
 void Server_TickSendTowerLocalDirection()
 {
     float epsilon = new Degree( .5f ).InRadians();
     if( !towerLocalDirection.Equals( server_sentTowerLocalDirection, epsilon ) )
     {
         Server_SendTowerLocalDirectionToClients( EntitySystemWorld.Instance.RemoteEntityWorlds );
         server_sentTowerLocalDirection = towerLocalDirection;
     }
 }
Пример #43
0
        protected override void OnControlledObjectChange( Unit oldObject )
        {
            base.OnControlledObjectChange( oldObject );

            //update look direction
            if( ControlledObject != null )
                lookDirection = SphereDir.FromVector( ControlledObject.Rotation * new Vec3( 1, 0, 0 ) );

            //TankGame specific
            {
                //set small damage for player tank
                Tank oldTank = oldObject as Tank;
                if( oldTank != null )
                    oldTank.ReceiveDamageCoefficient = 1;
                Tank tank = ControlledObject as Tank;
                if( tank != null )
                    tank.ReceiveDamageCoefficient = .1f;
            }
        }