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_PePointSurface.cpp
20 * @brief This file contains an implementation of PointSurface class methods
24 #include <FBaseSysLog.h>
25 #include <FBaseErrors.h>
26 #include <FUiEffects_PePointSurface.h>
27 #include "../FUiEffects_EffectErrorMessages.h"
29 using namespace Tizen::Ui::Effects::_Runtime;
30 using namespace Tizen::Ui::Effects::_Utils;
32 namespace Tizen { namespace Ui { namespace Effects { namespace _PhysicsEngine
35 PointSurface::PointSurface(long objId, Vec3f& positionInit, float massInit, float pointEnvResist, bool fixed)
36 : ElementSurface(objId), __positionInit(positionInit), __massInit(massInit), __pointEnvResist(pointEnvResist)
38 this->__fixed = fixed;
40 // those must be initialised in PointSurface::Construct
41 this->__pEnvResist = null;
42 this->__pGravityAcc = null;
43 this->__pGroundLevel = null;
45 // initialize after creation
49 PointSurface::~PointSurface()
55 PointSurface::GetType(void) const
57 return ESURFACE_POINT_SURFACE;
61 PointSurface::Initialize(void)
68 PointSurface::Construct(const float* pEnvResist, const Vec3f* pGravAcc, const float* pGroundLevel)
70 SysAssertf(!(pEnvResist == null || pGravAcc == null || pGroundLevel == null), _UiEffectError::INTERNAL_ERROR);
72 this->__pEnvResist = pEnvResist;
73 this->__pGravityAcc = pGravAcc;
74 this->__pGroundLevel = pGroundLevel;
79 PointSurface::Calculate(float timeStep)
81 // don't move point if fixed setting is enabled
88 // add user force to total force
89 __force += __forceUser;
91 // apply gravity force (m * g)
92 __force += __mass * (*__pGravityAcc);
94 // apply environment resistance
95 __force -= __velocity * (__pointEnvResist * (*__pEnvResist));
97 __positionPrev = __position; // save current position
100 // using explicit Euler time integration
103 __velocity += __force * timeStep / __mass;
104 __position += __velocity * timeStep;
106 // GroundLevel value needs to be specified
107 if ( __position.z < *__pGroundLevel )
109 __position.z = *__pGroundLevel;
112 // reset force for next time step
113 //_vForceUser.set(0.0f);
119 PointSurface::IsFixed(void) const
125 PointSurface::GetProperty(ElementProperty property) const
130 // position coordinates
132 result.type = PropertyCast::NUMBER;
133 result.value.numberValue = __position.x;
136 result.type = PropertyCast::NUMBER;
137 result.value.numberValue = __position.y;
140 result.type = PropertyCast::NUMBER;
141 result.value.numberValue = __position.z;
143 // initial position coordinates
145 result.type = PropertyCast::NUMBER;
146 result.value.numberValue = __positionInit.x;
149 result.type = PropertyCast::NUMBER;
150 result.value.numberValue = __positionInit.y;
153 result.type = PropertyCast::NUMBER;
154 result.value.numberValue = __positionInit.z;
158 result.type = PropertyCast::VEC3;
159 result.value.vec3Value = &__position;
161 // initial velocity vector
163 result.type = PropertyCast::VEC3;
164 result.value.vec3Value = &__positionInit;
166 // user force coordinates
168 result.type = PropertyCast::NUMBER;
169 result.value.numberValue = __forceUser.x;
172 result.type = PropertyCast::NUMBER;
173 result.value.numberValue = __forceUser.y;
176 result.type = PropertyCast::NUMBER;
177 result.value.numberValue = __forceUser.z;
181 result.type = PropertyCast::VEC3;
182 result.value.vec3Value = &__forceUser;
186 result.type = PropertyCast::NUMBER;
187 result.value.numberValue = __mass;
190 case N_POINT_RESISTANCE:
191 result.type = PropertyCast::NUMBER;
192 result.value.numberValue = __pointEnvResist;
196 result.type = PropertyCast::BOOL;
197 result.value.boolValue = __fixed;
200 result = ElementSurface::GetProperty(property);
207 PointSurface::SetProperty(ElementProperty property, bool boolValue)
209 bool result = true; // for successful set
217 result = ElementSurface::SetProperty(property, boolValue);
224 PointSurface::SetProperty(ElementProperty property, LUA_NUMBER numericValue)
226 bool result = true; // for successful set
229 // position coordinates
231 __position.x = numericValue;
234 __position.y = numericValue;
237 __position.z = numericValue;
239 // user force coordinates
241 __forceUser.x = numericValue;
244 __forceUser.y = numericValue;
247 __forceUser.z = numericValue;
251 __mass = numericValue;
254 case N_POINT_RESISTANCE:
255 __pointEnvResist = numericValue;
258 result = ElementSurface::SetProperty(property, numericValue);
265 PointSurface::SetProperty(ElementProperty property, const Vec3f& vectorValue)
267 bool result = true; // for successful set
272 __position = vectorValue;
276 __forceUser = vectorValue;
279 result = ElementSurface::SetProperty(property, vectorValue);
286 PointSurface::GetPosition(void) const
292 PointSurface::GetVelocity(void) const
298 PointSurface::AddForce(Vec3f appliedForce)
300 __force += appliedForce;
305 PointSurface::AddVelocity(Vec3f newVelocity)
307 __velocity += newVelocity;
312 PointSurface::InitPoint(void)
314 // setting simulation initial position and mass
315 __position = __positionPrev = __positionInit;
318 // the point is considered still in the beginning
319 __velocity.set(0.0f);
321 __forceUser.set(0.0f);
326 } } } }//Tizen::Ui::Ext::Effects3d::_PhysicsEngine