unigine 自定义形状 rigidbody创建

Vec3 min (100000, 100000, 100000);
    Vec3 max(-100000, -100000, -100000);
    for (int i = 0; i < RIGIDTESTCOUNT; i++)//
    {
        //MeshPtr mesh = Mesh::create();
        //Primitives::createBox(vec3(4.0,4.0,4.0))->getMesh(mesh);
        //m_boundMeshs[i] = ObjectMeshStatic::create(mesh);
        //m_boundMeshs[i]->setMaterial("mesh_base", "*");
        NodeReferencePtr noderef = NodeReference::create("data/nodes/DYBZC1.node");
        NodePtr node;
        ObjectPtr obj;
        
        m_boundMeshs[i] = ObjectMeshStatic::cast(noderef->detachReference());
        m_boundMeshs[i]->release();
        m_boundMeshs[i]->setCastShadow(0, 0);
        m_boundMeshs[i]->setCastWorldShadow(0, 0);

        vec3 boxSize = m_boundMeshs[i]->getBoundBox().getMax() - m_boundMeshs[i]->getBoundBox().getMin();
        

        //Primitives::createBox(boxSize)->getMesh(mesh);
        //m_boundMeshs[i] = ObjectMeshStatic::create(mesh);
        //m_boundMeshs[i]->setWorldTransform(node->getWorldTransform());
        //BoundBox box = m_boundMeshs[i]->getBoundBox();

        ShapeBoxPtr shape = ShapeBox::create(boxSize);//创建自定义形状
        BodyRigidPtr rigid = BodyRigid::create();
        rigid->addShape(shape->getShape(), mat4(translate(Vec3(0, 0, -boxSize.z / 2))*m_boundMeshs[i]->getWorldTransform()));//初始化rigidbody
        m_boundMeshs[i]->setBody(rigid->getBody());//给mesh设置rigidbody

        //m_boundMeshs[i]->addChild(node); 
        //node->setPosition(node->getPosition() - Vec3(0,0,boxSize.z/2));
        //m_boundMeshs[i]->setMaterial("mesh_base_0", "*");
        Vec3 outpos;
        vec3 dir;
        float randx = Game::get()->getRandomFloat(-1, 1)*0.005;
        float randy = Game::get()->getRandomFloat(-1, 1)*0.005;
        GlobalPivot::get()->getIntersectionByGeoPos(Vec3(31.2162919999999993+ randx, 121.3660770000000042 +randy, 10), outpos, dir);
        //Log::message("%d:%f,%f,%f\n",i, outpos.x, outpos.y, outpos.z);
        
        //node->setWorldPosition(outpos );//+ Vec3(0, 0, boxSize.z / 2)
        m_boundMeshs[i]->setWorldPosition(outpos + Vec3(0, 0, boxSize.z/2));
        //m_boundMeshs[0]->setCollider(0);

        if (outpos.x < min.x) min.x = outpos.x;
        if (outpos.y < min.y) min.y = outpos.y;
        if (outpos.z < min.z) min.z = outpos.z;
        if (outpos.x > max.x) max.x = outpos.x;
        if (outpos.y > max.y) max.y = outpos.y;
        if (outpos.z > max.z) max.z = outpos.z;
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值