Ejemplo n.º 1
0
 Field(const FieldGeometry *f)
     : ground_ci{{0, 0, 1}, 0.0}, ceil_ci{{0, 0, -1}, -10.0},
       left_wall_ci{{1, 0, 0}, -field_limit_x(f)},
       right_wall_ci{{-1, 0, 0}, -field_limit_x(f)},
       top_wall_ci{{0, 1, 0}, -field_limit_y(f)},
       bottom_wall_ci{{0, -1, 0}, -field_limit_y(f)},
       goal_ci{f->goal_width, f->goal_depth, f->goal_height,
               f->goal_wall_width},
       ground_body{ground_ci}, ceil_body{ceil_ci},
       left_wall_body{left_wall_ci}, right_wall_body{right_wall_ci},
       top_wall_body{top_wall_ci}, bottom_wall_body{bottom_wall_ci},
       left_goal_body{goal_ci}, right_goal_body{goal_ci} {
   auto trans1 = btTransform({0, 0, 0, 1}, {-f->field_length / 2, 0, 0});
   left_goal_body.setWorldTransform(trans1);
   auto trans2 = btTransform({0, 0, 1, 0}, {f->field_length / 2, 0, 0});
   right_goal_body.setWorldTransform(trans2);
 }
Ejemplo n.º 2
0
        virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
        {
            btScalar m[16];

            btDefaultMotionState* myMotionState = (btDefaultMotionState*) _body->getMotionState();
            myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(m);

            osg::Matrixf mat(m);

            
            // to move our ShapeNode according to gravity, we do something like this?:
            
            osg::Matrixf diff = osg::Matrix::inverse(previousMatrix_) * mat;
            spin::ShapeNode *shp = dynamic_cast<spin::ShapeNode*>(node);
            /*
            if (shp)
            {
                //osg::Vec3 t = diff.getTrans() - osg::Vec3(2,0,0);
                //shp->translate(t.x(),t.y(),t.z());
                shp->setTranslation(mat.getTrans().x(),mat.getTrans().y(),mat.getTrans().z());
            }
            else
            {
                osg::PositionAttitudeTransform *pat = dynamic_cast<osg::PositionAttitudeTransform*>(node);
                if (pat)
                {
                    pat->setPosition(mat.getTrans());
                    pat->setAttitude(mat.getRotate());

                    //std::cout << mat.getTrans().x() << ", " << mat.getTrans().y() << ", " << mat.getTrans().z() << std::endl;
                }
            }
            */
            
            //_body->getMotionState()->setWorldTransform(trans);
            _body->setWorldTransform(trans);
            
            previousMatrix_ = mat;
            
            traverse(node, nv);
        }