Просмотр исходного кода

Added a way to disable slider handles
Added bound calculations for lights

BearishSun 10 лет назад
Родитель
Сommit
c622d4cbfb

+ 50 - 76
BansheeEditor/Include/BsHandleSlider.h

@@ -8,17 +8,14 @@
 namespace BansheeEngine
 {
 	/**
-	 * @brief	Base class for all handle sliders. A handle slider is geometry that the user
-	 *			can interact with by selecting or dragging (i.e. sliding) it. Sliders generally
-	 *			output a one- or multi-dimensional delta value that signals the drag amount 
-	 *			(and/or direction).
+	 * Base class for all handle sliders. A handle slider is geometry that the user can interact with by selecting or 
+	 * dragging (i.e. sliding) it. Sliders generally output a one- or multi-dimensional delta value that signals the drag 
+	 * amount (and/or direction).
 	 */
 	class BS_ED_EXPORT HandleSlider
 	{
 	public:
-		/**
-		 * @brief	Possible states the slider can be in.
-		 */
+		/** Possible states the slider can be in. */
 		enum class State
 		{
 			Inactive, /**< Slider is not being interacted with. */
@@ -27,140 +24,116 @@ namespace BansheeEngine
 		};
 
 		/**
-		 * @brief	Constructs a new handle slider.
+		 * Constructs a new handle slider.
 		 *
-		 * @param	fixedScale	If true the handle slider will always try to maintain the same visible
-		 *						area in the viewport regardless of distance from camera. 
-		 * @param	layer		Layer that allows filtering of which sliders are interacted with from a specific camera.
+		 * @param[in]	fixedScale	If true the handle slider will always try to maintain the same visible area in the 
+		 *							viewport regardless of distance from camera. 
+		 * @param[in]	layer		Layer that allows filtering of which sliders are interacted with from a specific camera.
 		 */
 		HandleSlider(bool fixedScale, UINT64 layer);
 		virtual ~HandleSlider() { }
 
 		/**
-		 * @brief	Attempts to find an intersection between the provided ray and the slider geometry.
-		 *
-		 * @param	ray	Ray in world space to try to interect with geometry.
-		 * @param	t	Position of the intersection along the ray. Only if intersection happened.
+		 * Attempts to find an intersection between the provided ray and the slider geometry.
 		 *
-		 * @return	Whether an intersection was detected.
+		 * @param[in]	ray	Ray in world space to try to interect with geometry.
+		 * @param[in]	t	Position of the intersection along the ray. Only if intersection happened.
+		 * @return			Whether an intersection was detected.
 		 */
 		virtual bool intersects(const Ray& ray, float& t) const = 0;
 
 		/**
-		 * @brief	Updates a slider that is currently active (being dragged).
+		 * Updates a slider that is currently active (being dragged).
 		 *
-		 * @param	camera		Camera through which we're interacting with the slider.
-		 * @param	inputDelta	Pointer movement since the last time this method was called.
+		 * @param[in]	camera		Camera through which we're interacting with the slider.
+		 * @param[in]	inputDelta	Pointer movement since the last time this method was called.
 		 */
 		virtual void handleInput(const CameraPtr& camera, const Vector2I& inputDelta) = 0;
 
 		/**
-		 * @brief	Updates the state of the slider. Must be called every frame.
+		 * Updates the state of the slider. Must be called every frame.
 		 *
-		 * @param	camera	Camera through which we're interacting with the slider.
+		 * @param[in]	camera	Camera through which we're interacting with the slider.
 		 */
 		void update(const CameraPtr& camera);
 
-		/**
-		 * @brief	Returns the state the slider is currently in.
-		 */
+		/** Returns the state the slider is currently in. */
 		State getState() const { return mState; }
 		
 		/**
-		 * @brief	Returns if fixed scale is enabled. If enabled the handle slider will 
-		 *			always try to maintain the same visible area in the viewport regardless 
-		 *			of distance from camera.
+		 * Returns if fixed scale is enabled. If enabled the handle slider will always try to maintain the same visible 
+		 * area in the viewport regardless of distance from camera.
 		 */
 		bool getFixedScale() const { return mFixedScale; }
 
 		/** Returns a layer that determines which sliders are interacted with from a specific camera. */
 		UINT64 getLayer() const { return mLayer; }
 
-		/**
-		 * @brief	Sets the world position of the slider.
-		 */
+		/**	Sets the world position of the slider. */
 		void setPosition(const Vector3& position);
 
-		/**
-		 * @brief	Sets the world rotation of the slider.
-		 */
+		/**	Sets the world rotation of the slider. */
 		void setRotation(const Quaternion& rotation);
 
-		/**
-		 * @brief	Sets the scale of the slider.
-		 */
+		/**	Sets the scale of the slider. */
 		void setScale(const Vector3& scale);
 
-		/**
-		 * @brief	Gets the world position of the slider.
-		 */
+		/**	Enables or disabled the slider, making it interactable or not. */
+		void setEnabled(bool enabled);
+
+		/**	Gets the world position of the slider. */
 		const Vector3& getPosition() const { return mPosition; }
 
-		/**
-		 * @brief	Gets the world rotation of the slider.
-		 */
+		/**	Gets the world rotation of the slider. */
 		const Quaternion& getRotation() const { return mRotation; }
 
-		/**
-		 * @brief	Gets the scale of the slider.
-		 */
+		/**	Gets the scale of the slider. */
 		const Vector3& getScale() const { return mScale; }
 
+		/**	Checks whether the slider can be interacted with or not. */
+		bool getEnabled() const { return mEnabled; }
+
 	protected:
 		friend class HandleSliderManager;
 
-		/**
-		 * @brief	Toggles the slider state to inactive.
-		 */
+		/**	Toggles the slider state to inactive. */
 		void setInactive();
 
 		/**
-		 * @brief	Toggles the slider state to active.
+		 * Toggles the slider state to active.
 		 *
-		 * @param	camera		Camera through which the slider was activated.
-		 * @param	pointerPos	Position of the pointer when the slider was activated.
+		 * @param[in]	camera		Camera through which the slider was activated.
+		 * @param[in]	pointerPos	Position of the pointer when the slider was activated.
 		 */
 		void setActive(const CameraPtr& camera, const Vector2I& pointerPos);
 
-		/**
-		 * @brief	Toggles the slider state to hovered.
-		 */
+		/**	Toggles the slider state to hovered. */
 		void setHover();
 
-		/**
-		 * @brief	Gets the slider transform depending on set position, rotation and scale values.
-		 */
+		/**	Gets the slider transform depending on set position, rotation and scale values. */
 		const Matrix4& getTransform() const;
 
-		/**
-		 * @brief	Gets the inverse of the slider transform depending on 
-		 *			set position, rotation and scale values.
-		 */
+		/**	Gets the inverse of the slider transform depending on set position, rotation and scale values. */
 		const Matrix4& getTransformInv() const;
 
-		/**
-		 * @brief	Triggered when the slider state is changed to active.
-		 */
+		/** Triggered when the slider state is changed to active. */
 		virtual void activate(const CameraPtr& camera, const Vector2I& pointerPos) { }
 
-		/**
-		 * @brief	Triggered when the slider state is changed from active to some other state.
-		 */
+		/**	Triggered when the slider state is changed from active to some other state. */
 		virtual void reset() { }
 
-		/**
-		 * @brief	Updates the internal transform from the stored position, rotation and scale values.
-		 */
+		/**	Updates the internal transform from the stored position, rotation and scale values. */
 		void updateCachedTransform() const;
 
 		/**
-		 * @brief	Calculates amount of movement along the provided ray depending on pointer movement.
+		 * Calculates amount of movement along the provided ray depending on pointer movement.
 		 *
-		 * @param	camera			Camera on which the pointer movement is occurring.
-		 * @param	position		Position of the ray to calculate movement on.
-		 * @param	direction		Direction of the ray to calculate movement on. Must be normalized.
-		 * @param	pointerStart	Starting position of the pointer when movement started, in pixels relative to provided camera.
-		 * @param	pointerEnd		Current position of the pointer, in pixels relative to provided camera.
+		 * @param[in]	camera			Camera on which the pointer movement is occurring.
+		 * @param[in]	position		Position of the ray to calculate movement on.
+		 * @param[in]	direction		Direction of the ray to calculate movement on. Must be normalized.
+		 * @param[in]	pointerStart	Starting position of the pointer when movement started, in pixels relative to 
+		 *								provided camera.
+		 * @param[in]	pointerEnd		Current position of the pointer, in pixels relative to provided camera.
 		 */
 		float calcDelta(const CameraPtr& camera, const Vector3& position, const Vector3& direction,
 			const Vector2I& pointerStart, const Vector2I& pointerEnd);
@@ -176,6 +149,7 @@ namespace BansheeEngine
 		Vector2I mStartPointerPos;
 		Vector2I mCurrentPointerPos;
 		State mState;
+		bool mEnabled;
 
 		mutable bool mTransformDirty;
 		mutable Matrix4 mTransform;

+ 6 - 1
BansheeEditor/Source/BsHandleSlider.cpp

@@ -7,7 +7,7 @@ namespace BansheeEngine
 {
 	HandleSlider::HandleSlider(bool fixedScale, UINT64 layer)
 		:mFixedScale(fixedScale), mScale(Vector3::ONE), mTransformDirty(true),
-		mDistanceScale(1.0f), mLayer(layer)
+		mDistanceScale(1.0f), mLayer(layer), mEnabled(true)
 	{
 
 	}
@@ -39,6 +39,11 @@ namespace BansheeEngine
 		mTransformDirty = true;
 	}
 
+	void HandleSlider::setEnabled(bool enabled)
+	{
+		mEnabled = enabled;
+	}
+
 	const Matrix4& HandleSlider::getTransform() const
 	{
 		if (mTransformDirty)

+ 3 - 0
BansheeEditor/Source/BsHandleSliderManager.cpp

@@ -101,6 +101,9 @@ namespace BansheeEngine
 		
 		for (auto& slider : mSliders)
 		{
+			if (!slider->getEnabled())
+				continue;
+
 			bool layerMatches = (camera->getLayers() & slider->getLayer()) != 0;
 
 			float t;

+ 15 - 0
MBansheeEditor/Scene/HandleSlider.cs

@@ -101,6 +101,15 @@ namespace BansheeEditor
             }
         }
 
+        /// <summary>
+        /// Determines can the slider be interacted with.
+        /// </summary>
+        public bool Enabled
+        {
+            get { return Internal_GetEnabled(mCachedPtr); }
+            set { Internal_SetEnabled(mCachedPtr, value); }
+        }
+
         /// <summary>
         /// Destroys the slider, removing it from the scene.
         /// </summary>
@@ -130,6 +139,12 @@ namespace BansheeEditor
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetScale(IntPtr nativeInstance, ref Vector3 value);
 
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern bool Internal_GetEnabled(IntPtr nativeInstance);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetEnabled(IntPtr nativeInstance, bool value);
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_GetState(IntPtr nativeInstance, out StateType value);
     }

+ 10 - 0
MBansheeEditor/Scene/SceneAxesHandle.cs

@@ -15,6 +15,7 @@ namespace BansheeEditor
         private const float CONE_HEIGHT = 0.25f;
         private const float CONE_RADIUS = 0.175f;
         private const float BOX_EXTENT = 0.2f;
+        private const float DISABLE_THRESHOLD = 0.9f;
 
         private HandleSliderLine xAxis;
         private HandleSliderLine yAxis;
@@ -71,6 +72,15 @@ namespace BansheeEditor
             yNegAxis.Rotation = rotation;
             zNegAxis.Rotation = rotation;
 
+            Vector3 cameraForward = cam.SceneObject.Forward;
+            xAxis.Enabled = MathEx.Abs(Vector3.Dot(cameraForward, Vector3.XAxis)) < DISABLE_THRESHOLD;
+            yAxis.Enabled = MathEx.Abs(Vector3.Dot(cameraForward, Vector3.YAxis)) < DISABLE_THRESHOLD;
+            zAxis.Enabled = MathEx.Abs(Vector3.Dot(cameraForward, Vector3.ZAxis)) < DISABLE_THRESHOLD;
+
+            xNegAxis.Enabled = MathEx.Abs(Vector3.Dot(cameraForward, Vector3.XAxis)) < DISABLE_THRESHOLD;
+            xNegAxis.Enabled = MathEx.Abs(Vector3.Dot(cameraForward, Vector3.YAxis)) < DISABLE_THRESHOLD;
+            xNegAxis.Enabled = MathEx.Abs(Vector3.Dot(cameraForward, Vector3.ZAxis)) < DISABLE_THRESHOLD;
+
             Vector3 freeAxisOffset = new Vector3(-BOX_EXTENT, -BOX_EXTENT, 0.2f);
             projTypePlane.Rotation = Quaternion.Identity;
             projTypePlane.Position = position + freeAxisOffset;

+ 11 - 0
MBansheeEngine/Light.cs

@@ -124,6 +124,17 @@ namespace BansheeEngine
             _nativeLight.OnDestroy();
         }
 
+        /// <inheritdoc/>
+        protected internal override bool CalculateBounds(out AABox box, out Sphere sphere)
+        {
+            sphere = Bounds;
+
+            Vector3 extents = new Vector3(sphere.Radius, sphere.Radius, sphere.Radius);
+            box = new AABox(sphere.Center - extents, sphere.Center + extents);
+
+            return true;
+        }
+
         /// <summary>
         /// Holds all data the light component needs to persist through serialization.
         /// </summary>

+ 2 - 0
SBansheeEditor/Include/BsScriptHandleSlider.h

@@ -59,6 +59,8 @@ namespace BansheeEngine
 		static void internal_SetRotation(ScriptHandleSliderBase* nativeInstance, Quaternion* value);
 		static void internal_GetScale(ScriptHandleSliderBase* nativeInstance, Vector3* value);
 		static void internal_SetScale(ScriptHandleSliderBase* nativeInstance, Vector3* value);
+		static bool internal_GetEnabled(ScriptHandleSliderBase* nativeInstance);
+		static void internal_SetEnabled(ScriptHandleSliderBase* nativeInstance, bool value);
 		static void internal_GetState(ScriptHandleSliderBase* nativeInstance, HandleSlider::State* value);
 	};
 }

+ 12 - 0
SBansheeEditor/Source/BsScriptHandleSlider.cpp

@@ -38,6 +38,8 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_SetRotation", &ScriptHandleSlider::internal_SetRotation);
 		metaData.scriptClass->addInternalCall("Internal_SetScale", &ScriptHandleSlider::internal_SetScale);
 		metaData.scriptClass->addInternalCall("Internal_GetScale", &ScriptHandleSlider::internal_GetScale);
+		metaData.scriptClass->addInternalCall("Internal_GetEnabled", &ScriptHandleSlider::internal_GetEnabled);
+		metaData.scriptClass->addInternalCall("Internal_SetEnabled", &ScriptHandleSlider::internal_SetEnabled);
 		metaData.scriptClass->addInternalCall("Internal_GetState", &ScriptHandleSlider::internal_GetState);
 	}
 
@@ -76,6 +78,16 @@ namespace BansheeEngine
 		nativeInstance->getSlider()->setScale(*value);
 	}
 
+	bool ScriptHandleSlider::internal_GetEnabled(ScriptHandleSliderBase* nativeInstance)
+	{
+		return nativeInstance->getSlider()->getEnabled();
+	}
+
+	void ScriptHandleSlider::internal_SetEnabled(ScriptHandleSliderBase* nativeInstance, bool value)
+	{
+		nativeInstance->getSlider()->setEnabled(value);
+	}
+
 	void ScriptHandleSlider::internal_GetState(ScriptHandleSliderBase* nativeInstance, HandleSlider::State* value)
 	{
 		*value = nativeInstance->getSlider()->getState();