2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiEffects_PeRodSurface.cpp
20 * @brief This file contains an implementation of RodSurface class methods
24 #include <FUiEffects_PeRodSurface.h>
26 using namespace Tizen::Ui::Effects::_Runtime;
27 using namespace Tizen::Ui::Effects::_Utils;
29 namespace Tizen { namespace Ui { namespace Effects { namespace _PhysicsEngine
32 RodSurface::RodSurface(
35 PointSurface* pPoint1,
36 PointSurface* pPoint2,
39 : ElementSurface(objId),
40 __stiffnessInit(stiffness)
42 this->_pPoint1 = pPoint1;
43 this->_pPoint2 = pPoint2;
44 this->_pPoint3 = pPoint3;
50 RodSurface::~RodSurface(void)
56 RodSurface::GetType(void) const
58 return ESURFACE_ROD_SURFACE;
62 RodSurface::Initialize(void)
69 RodSurface::Calculate(float timeStep)
71 UseUnbendModel(timeStep);
76 RodSurface::GetProperty(ElementProperty property) const
82 result.type = PropertyCast::NUMBER;
83 result.value.numberValue = __stiffness;
86 result = ElementSurface::GetProperty(property);
93 RodSurface::SetProperty(ElementProperty property, bool boolValue)
95 return ElementSurface::SetProperty(property, boolValue);
99 RodSurface::SetProperty(ElementProperty property, LUA_NUMBER numericValue)
101 bool result = true; // for successful set
104 // coefficient of rigidity
106 __stiffness = numericValue;
109 result = ElementSurface::SetProperty(property, numericValue);
116 RodSurface::SetProperty(ElementProperty property, const Vec3f& vectorValue)
118 return ElementSurface::SetProperty(property, vectorValue);
122 RodSurface::InitRod(void)
124 this->_deformationAngle = 0.f;
125 this->__stiffness = __stiffnessInit;
129 // old rod model, currently not used
131 RodSurface::UseStretchModel(float timeStep)
134 direction31 = _pPoint3->GetPosition() - _pPoint1->GetPosition(),
135 direction21 = _pPoint2->GetPosition() - _pPoint1->GetPosition(),
138 direction31.normalize();
139 direction21.normalize();
141 // |[AxB]| = |A||B|sin(alpha) (angle between A and B)
142 // |A| = |B| = 1, so fDeformArc is equal to angle sine
143 _deformationAngle = direction21.getCrossed(direction31).length();
144 float rodForceValue = __stiffness * _deformationAngle;
146 rodForce = direction31 * rodForceValue;
148 _pPoint3->AddForce( rodForce);
149 _pPoint1->AddForce(-rodForce);
153 // new rod model, now in use
155 RodSurface::UseUnbendModel(float timeStep)
158 direction21 = _pPoint1->GetPosition() - _pPoint2->GetPosition(),
159 direction23 = _pPoint3->GetPosition() - _pPoint2->GetPosition();
161 direction21.normalize();
162 direction23.normalize();
164 Vec3f rodNormal = direction23.getCrossed(direction21);
165 float deformation = rodNormal.length(),
166 forceValue = __stiffness * deformation;
168 Vec3f forceDirection;
169 // force for central point
170 forceDirection = direction21 + direction23;
171 _pPoint2->AddForce( forceDirection.normalize() * forceValue );
173 // forces for edge points
175 _pPoint1->AddForce( rodNormal.getCrossed(direction21).normalize() * forceValue );
176 _pPoint3->AddForce( direction23.getCrossed(rodNormal).normalize() * forceValue );
180 } } } } // Tizen::Ui::Effects::_PhysicsEngine