2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 #include <dali/internal/event/dynamics/dynamics-universal-joint-impl.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/internal/event/common/stage-impl.h>
25 #include <dali/internal/event/dynamics/dynamics-body-impl.h>
26 #include <dali/internal/event/dynamics/dynamics-world-impl.h>
27 #include <dali/internal/update/dynamics/scene-graph-dynamics-universal-joint.h>
28 #include <dali/public-api/math/vector3.h>
36 DynamicsUniversalJoint::DynamicsUniversalJoint(DynamicsWorldPtr world,
37 DynamicsBodyPtr bodyA, DynamicsBodyPtr bodyB,
38 const Vector3& pointA, const Quaternion& orientationA,
39 const Vector3& pointB, const Quaternion& orientationB )
40 : DynamicsJoint(Dali::DynamicsJoint::UNIVERSAL),
41 mTranslationLowerLimit(Vector3::ZERO),
42 mTranslationUpperLimit(Vector3::ZERO),
43 mRotationLowerLimit(Vector3::ONE),
44 mRotationUpperLimit(-Vector3::ONE)
46 DALI_LOG_INFO(Debug::Filter::gDynamics, Debug::Verbose, "%s\n", __PRETTY_FUNCTION__);
48 SceneGraph::DynamicsUniversalJoint* univeralJoint( new SceneGraph::DynamicsUniversalJoint(*(world->GetSceneObject())) );
49 mDynamicsJoint = univeralJoint;
51 Stage::GetCurrent().QueueMessage( InitializeDynamicsUniversalJointMessage(*univeralJoint,
52 *(bodyA->GetSceneObject()), *(bodyB->GetSceneObject()),
53 pointA, orientationA, pointB, orientationB) );
56 DynamicsUniversalJoint::~DynamicsUniversalJoint()
58 DALI_LOG_INFO(Debug::Filter::gDynamics, Debug::Verbose, "%s\n", __PRETTY_FUNCTION__);
61 Vector3 DynamicsUniversalJoint::GetTranslationLowerLimit() const
63 return mTranslationLowerLimit;
66 void DynamicsUniversalJoint::SetTranslationLowerLimit( const Vector3& limit )
68 if( mTranslationLowerLimit != limit )
70 mTranslationLowerLimit = limit;
72 Stage::GetCurrent().QueueMessage( SetTranslationLowerLimitMessage( *(GetSceneObject()), limit ) );
76 Vector3 DynamicsUniversalJoint::GetTranslationUpperLimit() const
78 return mTranslationUpperLimit;
81 void DynamicsUniversalJoint::SetTranslationUpperLimit( const Vector3& limit )
83 if( mTranslationUpperLimit != limit )
85 mTranslationUpperLimit = limit;
87 Stage::GetCurrent().QueueMessage( SetTranslationUpperLimitMessage( *(GetSceneObject()), limit ) );
91 Vector3 DynamicsUniversalJoint::GetRotationLowerLimit() const
93 return mRotationLowerLimit;
96 void DynamicsUniversalJoint::SetRotationLowerLimit( const Vector3& limit )
98 if( mRotationLowerLimit != limit )
100 mRotationLowerLimit = limit;
102 Stage::GetCurrent().QueueMessage( SetRotationLowerLimitMessage( *(GetSceneObject()), limit ) );
106 Vector3 DynamicsUniversalJoint::GetRotationUpperLimit() const
108 return mRotationUpperLimit;
111 void DynamicsUniversalJoint::SetRotationUpperLimit( const Vector3& limit )
113 if( mRotationUpperLimit != limit )
115 mRotationUpperLimit = limit;
117 Stage::GetCurrent().QueueMessage( SetRotationUpperLimitMessage( *(GetSceneObject()), limit ) );
121 void DynamicsJoint::EnableSpring(const int index, const bool flag)
125 void DynamicsJoint::SetStiffness(const int index, const float stiffness)
129 void DynamicsJoint::SetCenterPoint(const int index, const float ratio)
133 void EnableMotor(const int index, const bool flag)
137 void SetMotorVelocity(const int index, const float velocity)
141 void SetMotorForce(const int index, const float force)
146 SceneGraph::DynamicsUniversalJoint* DynamicsUniversalJoint::GetSceneObject() const
148 return static_cast<SceneGraph::DynamicsUniversalJoint*>(DynamicsJoint::GetSceneObject());
153 } // namespace Internal