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 <dali-physics/public-api/physics-adaptor.h>
19 #include <dali-physics/public-api/physics-actor.h>
21 #include <dali-physics/integration-api/integ-physics-adaptor.h>
23 #include <btBulletDynamicsCommon.h>
26 #include <dali-csharp-binder/common/common.h>
32 using Dali::Toolkit::Physics::PhysicsActor;
33 using Dali::Toolkit::Physics::PhysicsAdaptor;
35 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_new_PhysicsAdaptor__SWIG_0()
38 PhysicsAdaptor* result = 0;
43 result = (PhysicsAdaptor*)new PhysicsAdaptor();
45 CALL_CATCH_EXCEPTION(0);
48 jresult = (void*)result;
52 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_New(void* csMatrix, void* csSize)
55 PhysicsAdaptor result;
57 Dali::Matrix *matrixPtr = (Dali::Matrix*)csMatrix;
60 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Matrix const & type is null", 0);
63 Dali::Vector2 *sizePtr = (Dali::Vector2*)csSize;
66 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Vector2 const & type is null", 0);
73 Dali::Uint16Pair size(uint16_t(sizePtr->x), uint16_t(sizePtr->y));
74 // Stack allocate a handle
75 result = PhysicsAdaptor::New(*matrixPtr, size);
77 CALL_CATCH_EXCEPTION(0);
80 // Heap allocate a handle using copy constructor
81 jresult = new PhysicsAdaptor((const PhysicsAdaptor&)result);
85 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_DownCast(void* csHandle)
87 Dali::BaseHandle* handle = (Dali::BaseHandle*)csHandle;
88 PhysicsAdaptor result;
92 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null Dali::BaseHandle", 0);
98 result = PhysicsAdaptor::DownCast(*handle);
100 CALL_CATCH_EXCEPTION(0);
102 return new PhysicsAdaptor((const PhysicsAdaptor&)result);
105 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_delete_PhysicsAdaptor(void* csPhysicsAdaptor)
107 PhysicsAdaptor* physicsAdaptor = (PhysicsAdaptor*)csPhysicsAdaptor;
111 delete physicsAdaptor;
113 CALL_CATCH_EXCEPTION();
117 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_new_PhysicsAdaptor__SWIG_1(void* csPhysicsAdaptor)
119 PhysicsAdaptor* physicsAdaptor = (PhysicsAdaptor*)csPhysicsAdaptor;
120 PhysicsAdaptor* result = 0;
124 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
130 result = (PhysicsAdaptor*)new PhysicsAdaptor((PhysicsAdaptor const&)*physicsAdaptor);
132 CALL_CATCH_EXCEPTION(0);
135 return (void*)result;
138 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_Assign(void* csDest, void* csSrc)
140 PhysicsAdaptor* dest = (PhysicsAdaptor*)csDest;
141 PhysicsAdaptor* src = (PhysicsAdaptor*)csSrc;
142 PhysicsAdaptor* result = 0;
146 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
152 result = (PhysicsAdaptor*)&(dest)->operator=((PhysicsAdaptor const&)*src);
154 CALL_CATCH_EXCEPTION(0);
157 return (void*)result;
163 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_SetTimestep(void* csAdaptor, float timestep)
165 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
168 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
174 adaptor->SetTimestep(timestep);
176 CALL_CATCH_EXCEPTION();
180 SWIGEXPORT float SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_GetTimestep(void* csAdaptor)
182 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
186 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
193 result = adaptor->GetTimestep();
195 CALL_CATCH_EXCEPTION(0.0f);
200 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_CreateDebugLayer(void* csAdaptor, void* csWindow)
202 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
206 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
209 Dali::Window* window = (Dali::Window*)csWindow;
212 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Window const & type is null", 0);
218 result = adaptor->CreateDebugLayer(*window);
220 CALL_CATCH_EXCEPTION(0);
222 return new Dali::Layer((const Dali::Layer&)result);
225 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_TranslateToPhysicsSpace_1(void* csAdaptor, Dali::Vector3* csPosition)
227 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
228 Dali::Vector3 result;
231 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
236 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Vector3 const & type is null", 0);
242 result = adaptor->TranslateToPhysicsSpace(*csPosition);
244 CALL_CATCH_EXCEPTION(0);
246 return new Dali::Vector3((const Dali::Vector3&)result);
249 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_TranslateToPhysicsSpace_2(void* csAdaptor, Dali::Quaternion* csRotation)
251 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
252 Dali::Quaternion result;
255 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
260 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Quaternion const & type is null", 0);
266 result = adaptor->TranslateToPhysicsSpace(*csRotation);
268 CALL_CATCH_EXCEPTION(0);
270 return new Dali::Quaternion((const Dali::Quaternion&)result);
273 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_TranslateFromPhysicsSpace_1(void* csAdaptor, Dali::Vector3* csPosition)
275 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
276 Dali::Vector3 result;
279 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
284 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Vector3 const & type is null", 0);
290 result = adaptor->TranslateFromPhysicsSpace(*csPosition);
292 CALL_CATCH_EXCEPTION(0);
294 return new Dali::Vector3((const Dali::Vector3&)result);
297 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_TranslateFromPhysicsSpace_2(void* csAdaptor, Dali::Quaternion* csRotation)
299 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
300 Dali::Quaternion result;
303 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
308 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Quaternion const & type is null", 0);
314 result = adaptor->TranslateFromPhysicsSpace(*csRotation);
316 CALL_CATCH_EXCEPTION(0);
318 return new Dali::Quaternion((const Dali::Quaternion&)result);
322 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_ConvertVectorToPhysicsSpace(void* csAdaptor, Dali::Vector3* csVector)
324 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
325 Dali::Vector3 result;
328 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
333 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Vector3 const & type is null", 0);
339 result = adaptor->ConvertVectorToPhysicsSpace(*csVector);
341 CALL_CATCH_EXCEPTION(0);
343 return new Dali::Vector3((const Dali::Vector3&)result);
346 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_ConvertVectorFromPhysicsSpace(void* csAdaptor, Dali::Vector3* csVector)
348 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
349 Dali::Vector3 result;
352 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
357 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Vector3 const & type is null", 0);
363 result = adaptor->ConvertVectorFromPhysicsSpace(*csVector);
365 CALL_CATCH_EXCEPTION(0);
367 return new Dali::Vector3((const Dali::Vector3&)result);
371 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_SetTransformAndSize(void* csAdaptor, void* csTransform, void* csSize)
373 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
376 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
381 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Matrix const & type is null", 0);
384 Dali::Vector2 *sizePtr = (Dali::Vector2*)csSize;
387 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Vector2 const & type is null", 0);
394 Dali::Uint16Pair size(uint16_t(sizePtr->x), uint16_t(sizePtr->y));
395 adaptor->SetTransformAndSize((const Dali::Matrix&)(*(Dali::Matrix*)csTransform), size);
397 CALL_CATCH_EXCEPTION();
401 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_SetIntegrationState(void* csAdaptor, int csIntegrationState)
403 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
406 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
412 adaptor->SetIntegrationState(PhysicsAdaptor::IntegrationState(csIntegrationState));
414 CALL_CATCH_EXCEPTION();
418 SWIGEXPORT int SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_GetIntegrationState(void* csAdaptor)
420 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
421 PhysicsAdaptor::IntegrationState result;
424 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
430 result = adaptor->GetIntegrationState();
432 CALL_CATCH_EXCEPTION(0);
438 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_SetDebugState(void* csAdaptor, int csDebugState)
440 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
443 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
449 adaptor->SetDebugState(PhysicsAdaptor::DebugState(csDebugState));
451 CALL_CATCH_EXCEPTION();
455 SWIGEXPORT int SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_GetDebugState(void* csAdaptor)
457 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
458 PhysicsAdaptor::DebugState result;
461 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
467 result = adaptor->GetDebugState();
469 CALL_CATCH_EXCEPTION(0);
474 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_AddActorBody(void* csAdaptor, void* csActor, void* csBody)
476 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
479 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
484 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Actor const & type is null", 0);
489 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "btRigidBody ptr is null", 0);
493 PhysicsActor physicsActor;
497 physicsActor = adaptor->AddActorBody((const Dali::Actor&)*(Dali::Actor*)csActor, Dali::Any((btRigidBody*)csBody));
499 CALL_CATCH_EXCEPTION(0);
501 return new PhysicsActor((const PhysicsActor&)physicsActor);
504 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_RemoveActorBody(void* csAdaptor, void* csPhysicsActor)
506 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
509 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
514 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsActor const & type is null", 0);
521 adaptor->RemoveActorBody((const PhysicsActor&)*(PhysicsActor*)csPhysicsActor);
523 CALL_CATCH_EXCEPTION();
528 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_GetPhysicsActor(void* csAdaptor, void* csBody)
530 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
533 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
538 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "btRigidBody ptr type is null", 0);
542 PhysicsActor physicsActor;
546 physicsActor = adaptor->GetPhysicsActor((Dali::Any((btRigidBody*)csBody)));
548 CALL_CATCH_EXCEPTION(0);
550 return new PhysicsActor((const PhysicsActor&)physicsActor);
554 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_GetRootActor(void* csAdaptor)
556 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
559 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
567 actor = adaptor->GetRootActor();
569 CALL_CATCH_EXCEPTION(0);
571 return new Dali::Actor((const Dali::Actor&)actor);
574 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_BuildPickingRay(void* csAdaptor,
577 void* csRayFromWorld,
580 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
583 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
588 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Vector3 const & type is null", 0);
593 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Vector3 const & type is null", 0);
598 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Vector3 const & type is null", 0);
603 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Vector3 const & type is null", 0);
609 adaptor->BuildPickingRay(*(Dali::Vector3*)(csOrigin),
610 *(Dali::Vector3*)(csDirection),
611 *(Dali::Vector3*)(csRayFromWorld),
612 *(Dali::Vector3*)(csRayToWorld));
614 CALL_CATCH_EXCEPTION();
617 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_ProjectPoint(void* csAdaptor,
622 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
625 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
630 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Vector3 const & type is null", 0);
635 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Dali::Vector3 const & type is null", 0);
641 point = adaptor->ProjectPoint(*(Dali::Vector3*)(csOrigin),
642 *(Dali::Vector3*)(csDirection),
646 CALL_CATCH_EXCEPTION(0);
647 return new Dali::Vector3((const Dali::Vector3&)point);
650 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_CreateSyncPoint(void* csAdaptor)
652 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
655 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
661 adaptor->CreateSyncPoint();
663 CALL_CATCH_EXCEPTION();
667 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsAdaptor_GetPhysicsWorld(void* csAdaptor)
669 PhysicsAdaptor* adaptor = (PhysicsAdaptor*)csAdaptor;
672 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsAdaptor const & type is null", 0);
676 Dali::Toolkit::Physics::Integration::PhysicsWorld result{nullptr};
681 result = Dali::Toolkit::Physics::Integration::GetPhysicsWorld(*adaptor);
683 CALL_CATCH_EXCEPTION(0);
685 return result.GetImpl();
689 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_PhysicsWorld_Lock(void* csWorld)
693 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsWorld const ref type is null",0);
699 Dali::Toolkit::Physics::Integration::PhysicsWorld world(static_cast<Dali::Toolkit::Physics::Internal::PhysicsWorld*>(csWorld));
702 CALL_CATCH_EXCEPTION();
706 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_PhysicsWorld_Unlock(void* csWorld)
710 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsWorld const ref type is null",0);
716 Dali::Toolkit::Physics::Integration::PhysicsWorld world(static_cast<Dali::Toolkit::Physics::Internal::PhysicsWorld*>(csWorld));
719 CALL_CATCH_EXCEPTION();
724 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsWorld_GetNative(void* csWorld)
728 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsWorld const ref type is null",0);
731 Dali::Any physicsWorld;
735 Dali::Toolkit::Physics::Integration::PhysicsWorld world(static_cast<Dali::Toolkit::Physics::Internal::PhysicsWorld*>(csWorld));
736 physicsWorld = world.GetNative();
738 CALL_CATCH_EXCEPTION(0);
740 if(!physicsWorld.Empty())
742 return physicsWorld.Get<btDiscreteDynamicsWorld*>();
747 SWIGEXPORT void* SWIGSTDCALL CSharp_Dali_PhysicsWorld_HitTest(void* csWorld, Dali::Vector3* rayFromWorld, Dali::Vector3* rayToWorld, void* localPivot, void* distanceFromCamera)
751 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "PhysicsWorld const ref type is null",0);
756 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Vector3 const ref type is null",0);
761 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Vector3 const ref type is null",0);
766 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Vector3 ref type is null",0);
769 if(!distanceFromCamera)
771 SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "float ref type is null",0);
775 Dali::Vector3 myLocalPivot;
776 float myDistanceFromCamera;
781 Dali::Any shapeFilter;
783 Dali::Toolkit::Physics::Integration::PhysicsWorld world(static_cast<Dali::Toolkit::Physics::Internal::PhysicsWorld*>(csWorld));
784 result = world.HitTest(*rayFromWorld, *rayToWorld, shapeFilter, myLocalPivot, myDistanceFromCamera);
786 CALL_CATCH_EXCEPTION(0);
791 if(localPivot != nullptr)
793 *(static_cast<Dali::Vector3*>(localPivot)) = myLocalPivot;
795 if(distanceFromCamera != nullptr)
797 *(static_cast<float*>(distanceFromCamera)) = myDistanceFromCamera;
799 return result.Get<btRigidBody*>();
807 //void Queue(std::function<void(void)> function);