PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: SNPhysicsMouseInteraction.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLENGINE_CONTROLLER_SNPHYSICSMOUSEINTERACTION_H__ 00024 #define __PLENGINE_CONTROLLER_SNPHYSICSMOUSEINTERACTION_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLMath/Vector2i.h> 00032 #include <PLScene/Scene/SceneNodeHandler.h> 00033 #include "PLEngine/PLEngine.h" 00034 00035 00036 //[-------------------------------------------------------] 00037 //[ Forward declarations ] 00038 //[-------------------------------------------------------] 00039 namespace PLPhysics { 00040 class Body; 00041 } 00042 namespace PLEngine { 00043 class PhysicsMouseInteraction; 00044 } 00045 00046 00047 //[-------------------------------------------------------] 00048 //[ Namespace ] 00049 //[-------------------------------------------------------] 00050 namespace PLEngine { 00051 00052 00053 //[-------------------------------------------------------] 00054 //[ Classes ] 00055 //[-------------------------------------------------------] 00056 /** 00057 * @brief 00058 * Mouse physics interaction scene node 00059 * 00060 * @remarks 00061 * When using the unchanged virtual standard controller: 00062 * - Hold the third mouse button over an physics object to pick it, use the mouse wheel 00063 * to pull/push the object towards/away 00064 * - While picking, hold shift/strg-key to increase/decrease the picking force, hit the 00065 * t-key to 'throw away' the picked object 00066 * 00067 * @note 00068 * - Primary intended for rapid prototyping 00069 * - If there's a scene node for instance named 'PhysicsForceLine' (default value of the variable 'ForceLineName') 00070 * within the same scene container, it's variables 'StartPosition' and 'EndPosition' will be manipulated so you can see 00071 * the applied 'picking force' 00072 * - Please note that this scene node will be removed in the future 00073 */ 00074 class SNPhysicsMouseInteraction : public PLScene::SceneNode { 00075 00076 00077 //[-------------------------------------------------------] 00078 //[ RTTI interface ] 00079 //[-------------------------------------------------------] 00080 pl_class(PL_RTTI_EXPORT, SNPhysicsMouseInteraction, "PLEngine", PLScene::SceneNode, "Mouse physics interaction scene node") 00081 // Attributes 00082 pl_attribute(InputSemantic, PLCore::String, "", ReadWrite, DirectValue, "Semantic of this input controller (e.g. \"Camera\")", "") 00083 pl_attribute(MaxPickingRange, float, 0.0f, ReadWrite, DirectValue, "Maximum picking range, if 0.0, there's no range limit (physics container space)", "Min='0.0'") 00084 pl_attribute(ThrowForce, float, 2.0f, ReadWrite, DirectValue, "Throw force", "Min='0.0'") 00085 pl_attribute(ForceLineName, PLCore::String, "PhysicsForceLine", ReadWrite, GetSet, "Name of the force visualization line node", "") 00086 // Overwritten PLScene::SceneNode attributes 00087 pl_attribute(Flags, pl_flag_type(EFlags), NoCulling, ReadWrite, GetSet, "Flags", "") 00088 // Constructors 00089 pl_constructor_0(DefaultConstructor, "Default constructor", "") 00090 pl_class_end 00091 00092 00093 //[-------------------------------------------------------] 00094 //[ Public RTTI get/set functions ] 00095 //[-------------------------------------------------------] 00096 public: 00097 PL_API PLCore::String GetForceLineName() const; 00098 PL_API void SetForceLineName(const PLCore::String &sValue); 00099 00100 00101 //[-------------------------------------------------------] 00102 //[ Public functions ] 00103 //[-------------------------------------------------------] 00104 public: 00105 /** 00106 * @brief 00107 * Default constructor 00108 */ 00109 PL_API SNPhysicsMouseInteraction(); 00110 00111 /** 00112 * @brief 00113 * Destructor 00114 */ 00115 PL_API virtual ~SNPhysicsMouseInteraction(); 00116 00117 /** 00118 * @brief 00119 * Returns whether or not picking is currently performed 00120 * 00121 * @param[out] pvMousePos 00122 * If picking is currently performed and pvMousePos is not a null pointer, it will receive the current mouse position used for picking 00123 * 00124 * @return 00125 * 'true' if picking is currently performed, else 'false' 00126 */ 00127 PL_API bool IsPicking(PLMath::Vector2i *pvMousePos = nullptr) const; 00128 00129 00130 //[-------------------------------------------------------] 00131 //[ Public virtual PLScene::SceneNode functions ] 00132 //[-------------------------------------------------------] 00133 public: 00134 PL_API virtual PLInput::Controller *GetInputController() const override; 00135 00136 00137 //[-------------------------------------------------------] 00138 //[ Protected virtual PLScene::SceneNode functions ] 00139 //[-------------------------------------------------------] 00140 protected: 00141 PL_API virtual void InitFunction() override; 00142 PL_API virtual void OnActivate(bool bActivate) override; 00143 00144 00145 //[-------------------------------------------------------] 00146 //[ Private functions ] 00147 //[-------------------------------------------------------] 00148 private: 00149 /** 00150 * @brief 00151 * Called when the scene node modifier needs to be updated 00152 */ 00153 void OnUpdate(); 00154 00155 00156 //[-------------------------------------------------------] 00157 //[ Private event handlers ] 00158 //[-------------------------------------------------------] 00159 private: 00160 PLCore::EventHandler<> EventHandlerUpdate; 00161 00162 00163 //[-------------------------------------------------------] 00164 //[ Private data ] 00165 //[-------------------------------------------------------] 00166 private: 00167 PLCore::String m_sForceLineName; /**< Name of the force visualization line node */ 00168 bool m_bPicking; /**< Are we currently picking? */ 00169 PLMath::Vector2i m_vPickingMousePos; /**< Mouse position used for picking */ 00170 PLPhysics::Body *m_pPickedPhysicsBody; /**< The currently picked physics body, can be a null pointer */ 00171 float m_fPickedDistance; /**< Picking distance */ 00172 PLMath::Vector3 m_vAttachmentPoint; /**< Picking attachment point */ 00173 PLScene::SceneNodeHandler m_cForceLineHandler; /**< Scene handler for the physics force line */ 00174 PhysicsMouseInteraction *m_pController; /**< Physics mouse interaction input controller instance, always valid! */ 00175 00176 00177 }; 00178 00179 00180 //[-------------------------------------------------------] 00181 //[ Namespace ] 00182 //[-------------------------------------------------------] 00183 } // PLEngine 00184 00185 00186 #endif // __PLENGINE_CONTROLLER_SNPHYSICSMOUSEINTERACTION_H__
|