Beispiel #1
0
        /// <summary>
        /// private method for selection object that creates a box from the SelectionRectangle, stop variable is passed in
        /// </summary>
        /// <param name="first">Vector2</param>
        /// <param name="second">Vector2</param>
        private void PerformSelectionWithSelectionBox(Math.Vector2 first, Math.Vector2 second)
        {
            Log("MouseSelector: " + this._name + " performing selection.");

            float left = first.x, right = second.x, top = first.y, bottom = second.y;

            if (left > right)
            {
                Utility.Swap(ref left, ref right);
            }

            if (top > bottom)
            {
                Utility.Swap(ref top, ref bottom);
            }

            if ((right - left) * (bottom - top) < 0.0001)
            {
                return;
            }

            Ray topLeft     = this._Camera.GetCameraToViewportRay(left, top);
            Ray topRight    = this._Camera.GetCameraToViewportRay(right, top);
            Ray bottomLeft  = this._Camera.GetCameraToViewportRay(left, bottom);
            Ray bottomRight = this._Camera.GetCameraToViewportRay(right, bottom);

            var vol = new PlaneBoundedVolume();

            vol.planes.Add(new Math.Plane(topLeft.GetPoint(3), topRight.GetPoint(3), bottomRight.GetPoint(3)));
            // front plane
            vol.planes.Add(new Math.Plane(topLeft.Origin, topLeft.GetPoint(100), topRight.GetPoint(100))); // top plane
            vol.planes.Add(new Math.Plane(topLeft.Origin, bottomLeft.GetPoint(100), topLeft.GetPoint(100)));
            // left plane
            vol.planes.Add(new Math.Plane(bottomLeft.Origin, bottomRight.GetPoint(100), bottomLeft.GetPoint(100)));
            // bottom plane
            vol.planes.Add(new Math.Plane(topRight.Origin, topRight.GetPoint(100), bottomRight.GetPoint(100)));
            // right plane

            var volList = new PlaneBoundedVolumeList();

            volList.Add(vol);

            PlaneBoundedVolumeListSceneQuery volQuery;

            volQuery         = Root.Instance.SceneManager.CreatePlaneBoundedVolumeQuery(new PlaneBoundedVolumeList());
            volQuery.Volumes = volList;
            SceneQueryResult result = volQuery.Execute();

            foreach (MovableObject obj in result.objects)
            {
                SelectObject(obj);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Casts the plane selection and selects all objects inside the SelectionRectangle.
        /// Hitted objects sends to the GameObjectManager (OnLeftClick).
        /// </summary>
        /// <param name="first">The firts corner.</param>
        /// <param name="second">The second corner.</param>
        private void PerformSelection(Vector2 first, Vector2 second)
        {
            float left = first.x, right = second.x,
                  top = first.y, bottom = second.y;

            if (left > right)
            {
                Swap(ref left, ref right);
            }
            if (top > bottom)
            {
                Swap(ref top, ref bottom);
            }

            if ((right - left) * (bottom - top) < 0.0001)
            {
                return;
            }

            Camera c           = Game.SceneManager.GetCamera("myCam");
            Ray    topLeft     = c.GetCameraToViewportRay(left, top);
            Ray    topRight    = c.GetCameraToViewportRay(right, top);
            Ray    bottomLeft  = c.GetCameraToViewportRay(left, bottom);
            Ray    bottomRight = c.GetCameraToViewportRay(right, bottom);

            PlaneBoundedVolume vol = new PlaneBoundedVolume();

            vol.planes.Add(new Plane(topLeft.GetPoint(3), topRight.GetPoint(3), bottomRight.GetPoint(3)));                // Front plane
            vol.planes.Add(new Plane(topLeft.Origin, topLeft.GetPoint(100), topRight.GetPoint(100)));                     // Top plane
            vol.planes.Add(new Plane(topLeft.Origin, bottomLeft.GetPoint(100), topLeft.GetPoint(100)));                   // Left plane
            vol.planes.Add(new Plane(bottomLeft.Origin, bottomRight.GetPoint(100), bottomLeft.GetPoint(100)));            // Bottom plane
            vol.planes.Add(new Plane(topRight.Origin, topRight.GetPoint(100), bottomRight.GetPoint(100)));                // Right plane

            PlaneBoundedVolumeList volList = new PlaneBoundedVolumeList();

            volList.Add(vol);
            PlaneBoundedVolumeListSceneQuery volQuery = Game.SceneManager.CreatePlaneBoundedVolumeQuery(volList);
            SceneQueryResult result = volQuery.Execute();

            List <MovableObject> list = new List <MovableObject>(result.movables);

            GameObjectManager.GetInstance().OnLeftClick(list);

            Game.SceneManager.DestroyQuery(volQuery);
        }
Beispiel #3
0
        public void performSelection(Vector2 first, Vector2 second)
        {
            float left = first.x, right = second.x,
            top = first.y, bottom = second.y;

            if (left > right) swap(ref left, ref right);
            if (top > bottom) swap(ref top, ref bottom);

            if ((right - left) * (bottom - top) < 0.0001)
            {
                Program.PerformSingleSelection();
                return;
            }

            Ray topLeft = _camera.GetCameraToViewportRay(left, top);
            Ray topRight = _camera.GetCameraToViewportRay(right, top);
            Ray bottomLeft = _camera.GetCameraToViewportRay(left, bottom);
            Ray bottomRight = _camera.GetCameraToViewportRay(right, bottom);

            PlaneBoundedVolume vol = new PlaneBoundedVolume();
            vol.planes.Add(new Plane(topLeft.GetPoint(3), topRight.GetPoint(3), bottomRight.GetPoint(3)));    // front plane
            vol.planes.Add(new Plane(topLeft.Origin, topLeft.GetPoint(100), topRight.GetPoint(100)));         // top plane
            vol.planes.Add(new Plane(topLeft.Origin, bottomLeft.GetPoint(100), topLeft.GetPoint(100)));       // left plane
            vol.planes.Add(new Plane(bottomLeft.Origin, bottomRight.GetPoint(100), bottomLeft.GetPoint(100)));// bottom plane
            vol.planes.Add(new Plane(topRight.Origin, topRight.GetPoint(100), bottomRight.GetPoint(100)));    // right plane

            PlaneBoundedVolumeList volList = new PlaneBoundedVolumeList();
            volList.Add(vol);
            PlaneBoundedVolumeListSceneQuery volQuery = Program.GetSceneManager().CreatePlaneBoundedVolumeQuery(volList);
            SceneQueryResult result = volQuery.Execute();

            foreach (var obj in result.movables)
            {
                if (obj.MovableType == "Entity")
                Program.selectUnit(obj);
            }

            Program.GetSceneManager().DestroyQuery(volQuery);
        }
Beispiel #4
0
			/// <summary>
			///		Prepare the listener for use with a set of parameters.
			/// </summary>
			/// <param name="lightInFrustum"></param>
			/// <param name="lightClipVolumes"></param>
			/// <param name="light"></param>
			/// <param name="camera"></param>
			/// <param name="shadowCasterList"></param>
			/// <param name="farDistSquared"></param>
			public void Prepare( bool lightInFrustum,
								 PlaneBoundedVolumeList lightClipVolumes,
								 Light light,
								 Camera camera,
								 List<ShadowCaster> shadowCasterList,
								 float farDistSquared )
			{
				this.casterList = shadowCasterList;
				this.isLightInFrustum = lightInFrustum;
				this.lightClipVolumeList = lightClipVolumes;
				this.camera = camera;
				this.light = light;
				this.farDistSquared = farDistSquared;
			}
Beispiel #5
0
		/// <summary>
		///		Creates a <see cref="PlaneBoundedVolumeListSceneQuery"/> for this scene manager.
		/// </summary>
		/// <remarks>
		///		This method creates a new instance of a query object for this scene manager,
		///		for querying for objects within a PlaneBoundedVolumes region.
		/// </remarks>
		/// <param name="volumes">PlaneBoundedVolumeList to use for the region query.</param>
		/// <param name="mask">Custom user defined flags to use for the query.</param>
		/// <returns>A specialized implementation of PlaneBoundedVolumeListSceneQuery for this scene manager.</returns>
		public virtual PlaneBoundedVolumeListSceneQuery CreatePlaneBoundedVolumeQuery( PlaneBoundedVolumeList volumes,
																					   uint mask )
		{
			DefaultPlaneBoundedVolumeListSceneQuery query = new DefaultPlaneBoundedVolumeListSceneQuery( this );
			query.Volumes = volumes;
			query.QueryMask = mask;

			return query;
		}
Beispiel #6
0
		/// <summary>
		///		Creates a <see cref="PlaneBoundedVolumeListSceneQuery"/> for this scene manager.
		/// </summary>
		/// <remarks>
		///		This method creates a new instance of a query object for this scene manager,
		///		for querying for objects within a PlaneBoundedVolumes region.
		/// </remarks>
		/// <param name="volumes">PlaneBoundedVolumeList to use for the region query.</param>
		/// <returns>A specialized implementation of PlaneBoundedVolumeListSceneQuery for this scene manager.</returns>
		public PlaneBoundedVolumeListSceneQuery CreatePlaneBoundedVolumeQuery( PlaneBoundedVolumeList volumes )
		{
			return this.CreatePlaneBoundedVolumeQuery( volumes, 0xffffffff );
		}
Beispiel #7
0
		/// <summary>
		/// private method for selection object that creates a box from the SelectionRectangle, stop variable is passed in
		/// </summary>
		/// <param name="first">Vector2</param>
		/// <param name="second">Vector2</param>
		private void PerformSelectionWithSelectionBox( Math.Vector2 first, Math.Vector2 second )
		{
			Log( "MouseSelector: " + _name + " performing selection." );

			float left = first.x, right = second.x,
			top = first.y, bottom = second.y;

			if ( left > right )
				Utility.Swap( ref left, ref right );

			if ( top > bottom )
				Utility.Swap( ref top, ref bottom );

			if ( ( right - left ) * ( bottom - top ) < 0.0001 )
				return;

			Ray topLeft = _Camera.GetCameraToViewportRay( left, top );
			Ray topRight = _Camera.GetCameraToViewportRay( right, top );
			Ray bottomLeft = _Camera.GetCameraToViewportRay( left, bottom );
			Ray bottomRight = _Camera.GetCameraToViewportRay( right, bottom );

			Math.PlaneBoundedVolume vol = new PlaneBoundedVolume();
			vol.planes.Add( new Math.Plane( topLeft.GetPoint( 3 ), topRight.GetPoint( 3 ), bottomRight.GetPoint( 3 ) ) );         // front plane
			vol.planes.Add( new Math.Plane( topLeft.Origin, topLeft.GetPoint( 100 ), topRight.GetPoint( 100 ) ) );         // top plane
			vol.planes.Add( new Math.Plane( topLeft.Origin, bottomLeft.GetPoint( 100 ), topLeft.GetPoint( 100 ) ) );       // left plane
			vol.planes.Add( new Math.Plane( bottomLeft.Origin, bottomRight.GetPoint( 100 ), bottomLeft.GetPoint( 100 ) ) );   // bottom plane
			vol.planes.Add( new Math.Plane( topRight.Origin, topRight.GetPoint( 100 ), bottomRight.GetPoint( 100 ) ) );     // right plane

			PlaneBoundedVolumeList volList = new PlaneBoundedVolumeList();
			volList.Add( vol );

			PlaneBoundedVolumeListSceneQuery volQuery;

			volQuery = Root.Instance.SceneManager.CreatePlaneBoundedVolumeQuery( new PlaneBoundedVolumeList() );
			volQuery.Volumes = volList;
			SceneQueryResult result = volQuery.Execute();

			foreach ( MovableObject obj in result.objects )
			{
				SelectObject( obj );
			}
		}
Beispiel #8
0
		//---------------------------------------------------------------------
		public override PlaneBoundedVolumeListSceneQuery CreatePlaneBoundedVolumeQuery( PlaneBoundedVolumeList volumes,
		                                                                                uint mask )
		{
			var q = new PCZPlaneBoundedVolumeListSceneQuery( this );
			q.Volumes = volumes;
			q.QueryMask = mask;
			return q;
		}
Beispiel #9
0
        /// <summary>
        /// Casts the plane selection and selects all objects inside the SelectionRectangle. 
        /// Hitted objects sends to the GameObjectManager (OnLeftClick).
        /// </summary>
        /// <param name="first">The firts corner.</param>
        /// <param name="second">The second corner.</param>
        private void PerformSelection(Vector2 first, Vector2 second)
        {
            float left = first.x, right = second.x,
            top = first.y, bottom = second.y;

            if (left > right) Swap(ref left, ref right);
            if (top > bottom) Swap(ref top, ref bottom);

            if ((right - left) * (bottom - top) < 0.0001) return;

            Camera c = Game.SceneManager.GetCamera("myCam");
            Ray topLeft = c.GetCameraToViewportRay(left, top);
            Ray topRight = c.GetCameraToViewportRay(right, top);
            Ray bottomLeft = c.GetCameraToViewportRay(left, bottom);
            Ray bottomRight = c.GetCameraToViewportRay(right, bottom);

            PlaneBoundedVolume vol = new PlaneBoundedVolume();
            vol.planes.Add(new Plane(topLeft.GetPoint(3), topRight.GetPoint(3), bottomRight.GetPoint(3)));    // Front plane
            vol.planes.Add(new Plane(topLeft.Origin, topLeft.GetPoint(100), topRight.GetPoint(100)));         // Top plane
            vol.planes.Add(new Plane(topLeft.Origin, bottomLeft.GetPoint(100), topLeft.GetPoint(100)));       // Left plane
            vol.planes.Add(new Plane(bottomLeft.Origin, bottomRight.GetPoint(100), bottomLeft.GetPoint(100)));// Bottom plane
            vol.planes.Add(new Plane(topRight.Origin, topRight.GetPoint(100), bottomRight.GetPoint(100)));    // Right plane

            PlaneBoundedVolumeList volList = new PlaneBoundedVolumeList();
            volList.Add(vol);
            PlaneBoundedVolumeListSceneQuery volQuery = Game.SceneManager.CreatePlaneBoundedVolumeQuery(volList);
            SceneQueryResult result = volQuery.Execute();

            List<MovableObject> list = new List<MovableObject>(result.movables);

            GameObjectManager.GetInstance().OnLeftClick(list);

            Game.SceneManager.DestroyQuery(volQuery);
        }