柚子快报邀请码778899分享:基于VR

http://yzkb.51969.com/

一、主体思路

VR_FORCES仿真引擎仿真反舰DD攻击舰船想定,通过VRLink取出反舰DD和舰船的坐标,通过设置坐标和姿态转换,结合FCL使用盒子碰撞检测与距离测算,验证DIS标准的VRLink姿态转换和FCL库碰撞检测的准确性

二、开发工具

VR_FORCES 4.6.1 VS2015版

VRLINK5.4  VS2015版

FCL库(The Flexible Collision Library)(前期已编译好)

VS2015(FCL的库必须使用2015及以上)

三、VRLINK 工程设置

测试使用了VRLINK 中listen这个例子,以下为项目的设置:

输出目录C:\MAK\vrlink5.4\bin64 该目录下拷贝编译好的ccd.dll

工作目录C:\MAK\vrlink5.4\bin64

附加包含目录

F:\FCL\project\fcl-master\include\

F:\FCL\project\libccd-master\src\

F:\FCL\project\eigen-3.4.0

附加库目录

F:\FCL\project\libccd-master\bulid\src\Debug

F:\FCL\project\fcl-master\build\lib\Debug

F:\FCL\project\octomap-devel\lib

附加依赖项

fcl.lib

ccd.lib

octomap.lib

octomath.lib

dynamicedt3d.lib

X64编译

四、listen代码部分

listen.cxx引用的头文件

#include

#include "Eigen/Core"

#define FCL_EXPORT

#include "fcl/fcl.h"

#include "fcl/narrowphase/collision.h"

#include

#include

using namespace std;

using namespace   fcl;

while (forever)之前加入以下代码

      shared_ptr box1 = make_shared(156, 17.3, 35);//DDG 尺寸 对应vrf实体编辑器的长宽高

      shared_ptr box2 = make_shared(11.6,2.2,  0.7);//鱼叉尺寸

      // 创建对应的碰撞对象和碰撞组

      CollisionObjectd obj1(box1);

      CollisionObjectd obj2(box2);

      CollisionRequestd request;

      CollisionResultd result;

      request.gjk_solver_type = fcl::GJKSolverType::GST_LIBCCD;

         // Process any incoming messages.

exConn.drainInput();这句代码以下加入以下代码,将原来的打印第一个实体的代码屏蔽

     // Loop through the entities in the rel

         for (DtReflectedEntity* entity = rel.first();      entity;            entity = entity->next())

         {

             printf("  实体名字 %s   实体地心坐标  x %f y%f z%f\n", entity->esr()->markingText(),

                 entity->esr()->location().x(),

             entity->esr()->location().y(),

             entity->esr()->location().z()

                 );

             printf("  实体名字 %s   实体地心姿态  psi %f theta%f phi%f\n", entity->esr()->markingText(),

                 entity->esr()->orientation().psi(),

                 entity->esr()->orientation().theta(),

                 entity->esr()->orientation().phi()

                 );

             printf("  实体名字 %s   实体地心姿态  psi %f theta%f phi%f   度\n", entity->esr()->markingText(),

                RAD_TO_DEG( entity->esr()->orientation().psi()),

                 RAD_TO_DEG(entity->esr()->orientation().theta()),

                RAD_TO_DEG(entity->esr()->orientation().phi())

                 );

             fcl::Transform3 rotz = fcl::Transform3{ fcl::AngleAxis(entity->esr()->orientation().psi(), fcl::Vector3::UnitZ()) };

              fcl::Transform3 roty = fcl::Transform3{ fcl::AngleAxis(entity->esr()->orientation().theta(), fcl::Vector3::UnitY()) };

             fcl::Transform3 rotx = fcl::Transform3{ fcl::AngleAxis(entity->esr()->orientation().phi(), fcl::Vector3::UnitX()) };

            const  char* str1 = "DDG 1";

            const  char* str2 = "AM39 1";          

                 if(strcmp(entity->esr()->markingText() ,str1)==0)

             {

                  obj1.setTransform(rotz*roty*rotx);            

                 obj1.setTranslation(Vector3d(entity->esr()->location().x(),

                                                                 entity->esr()->location().y(),

                                                                 entity->esr()->location().z()

                                                 ));

             }

                 if (strcmp(entity->esr()->markingText(), str2) == 0)

             {

                 obj2.setTransform(rotz*roty*rotx);            

                 obj2.setTranslation(Vector3d(entity->esr()->location().x(),

                     entity->esr()->location().y(),

                     entity->esr()->location().z()                 

                    ) );     

             }

            

             // 进行碰撞检测

             collide(&obj1, &obj2, request, result);             

             // 输出碰撞结果

             if (result.isCollision()) {

                 cout << "Collision detected!" << endl;

             }

             else {

                 cout << "No collision detected." << endl;

             }

             

             //距离检测

             DistanceRequestd requestd;

             DistanceResultd resultd;

             distance(&obj1, &obj2, requestd, resultd);

             cout << "min_distance:" << resultd.min_distance << endl;

            //结果及时清除,不然不会自动更新

             result.clear();

         }

五、VRForces想定与运行测试效果

用VRForces的MAKLand地形建立想定,创建实体SU-37和一艘DDG舰船

为SU37设置发射攻击任务

以上为鱼叉和DDG两者距离2.36米左右的,此时两者包围盒未碰撞。

在上述时刻暂停想定,将船旋转一个度数,使鱼叉刚好进入包围盒,可以看见代码运行提示发生了碰撞

最终碰撞结果和vrf中观察基本一致,比较准确。

QQ515826628 技术交流

柚子快报邀请码778899分享:基于VR

http://yzkb.51969.com/

精彩文章

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: 


大家都在找:

vr:vr全景