2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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 "physics-actor.h"
19 #include "physics-impl.h"
20 #include <dali/public-api/common/constants.h>
21 #include <dali/public-api/math/vector3.h>
22 #include <dali/public-api/math/quaternion.h>
25 using Dali::Quaternion;
28 void PhysicsActor::ClearForces()
30 printf("Not Implemented\n");
31 //mBody->clearForces();
35 Dali::Vector3 PhysicsActor::GetPhysicsPosition()
37 cpVect cpPosition = cpBodyGetPosition(mBody);
38 return Vector3(cpPosition.x, cpPosition.y, 0.0f);
41 void PhysicsActor::SetPhysicsPosition(Dali::Vector3 actorPosition)
43 Dali::Mutex::ScopedLock lock(mImpl->mMutex);
44 Vector3 physicsPosition = mImpl->TranslateToPhysicsSpace(actorPosition);
45 cpBodySetPosition(mBody, cpv(physicsPosition.x, physicsPosition.y));
48 void PhysicsActor::SetPhysicsVelocity(Dali::Vector3 actorVelocity)
50 Dali::Mutex::ScopedLock lock(mImpl->mMutex);
51 Vector3 physicsVelocity = mImpl->ConvertVectorToPhysicsSpace(actorVelocity);
52 cpBodySetVelocity(mBody, cpv(physicsVelocity.x, physicsVelocity.y));
55 void PhysicsActor::SetPhysicsAngularVelocity(Dali::Vector3 velocity)
57 Dali::Mutex::ScopedLock lock(mImpl->mMutex);
58 printf("Not Implemented\n");
59 //mBody->setAngularVelocity(btVector3(velocity.x, velocity.y, velocity.z));
62 Quaternion PhysicsActor::GetPhysicsRotation()
67 void PhysicsActor::SetPhysicsRotation(Dali::Quaternion rotation)
69 Dali::Mutex::ScopedLock lock(mImpl->mMutex);
73 rotation.ToAxisAngle(axis, angle);
75 //btQuaternion orn = btQuaternion(btVector3(axis.x, -axis.y, axis.z), btScalar(float(-angle)));
76 //btTransform& transform = mBody->getWorldTransform();
77 //transform.setRotation(orn);
78 printf("Not Implemented\n");
82 Vector3 PhysicsActor::GetActorPosition()
84 cpVect cpPosition = cpBodyGetPosition(mBody);
85 return mImpl->TranslateFromPhysicsSpace(Vector3(cpPosition.x, cpPosition.y, 0.0f));
88 Vector3 PhysicsActor::GetActorVelocity()
90 cpVect cpVelocity = cpBodyGetVelocity(mBody);
91 return mImpl->ConvertVectorFromPhysicsSpace(Vector3(cpVelocity.x, cpVelocity.y, 0.0f));
94 Quaternion PhysicsActor::GetActorRotation()
96 cpFloat angle = cpBodyGetAngle(mBody);
97 return Quaternion(Radian(angle), -Vector3::ZAXIS);