/** * @function createDartNode */ dynamics::BodyNode* DartLoader::createDartNode(const urdf::Link* _lk, std::string _rootToSkelPath) { dynamics::BodyNode* node = new dynamics::BodyNode(_lk->name); // Mesh Loading //FIXME: Shouldn't mass and inertia default to 0? double mass = 0.1; Eigen::Matrix3d inertia = Eigen::MatrixXd::Identity(3,3); inertia *= 0.1; // Load Inertial information if(_lk->inertial) { node->setLocalCOM(toEigen(_lk->inertial->origin.position)); node->setMass(_lk->inertial->mass); node->setInertia(_lk->inertial->ixx, _lk->inertial->iyy, _lk->inertial->izz, _lk->inertial->ixy, _lk->inertial->ixz, _lk->inertial->iyz); } // Set visual information for(unsigned int i = 0; i < _lk->visual_array.size(); i++) { if(dynamics::Shape* shape = createShape(_lk->visual_array[i].get(), _rootToSkelPath)) { node->addVisualizationShape(shape); } } // Set collision information for(unsigned int i = 0; i < _lk->collision_array.size(); i++) { if(dynamics::Shape* shape = createShape(_lk->collision_array[i].get(), _rootToSkelPath)) { node->addCollisionShape(shape); } } return node; }
/** * @function createDartNode */ bool DartLoader::createDartNodeProperties( const urdf::Link* _lk, dynamics::BodyNode::Properties &node, const common::Uri& _baseUri, const common::ResourceRetrieverPtr& _resourceRetriever) { node.mName = _lk->name; // Load Inertial information if(_lk->inertial) { urdf::Pose origin = _lk->inertial->origin; node.mInertia.setLocalCOM(toEigen(origin.position)); node.mInertia.setMass(_lk->inertial->mass); Eigen::Matrix3d J; J << _lk->inertial->ixx, _lk->inertial->ixy, _lk->inertial->ixz, _lk->inertial->ixy, _lk->inertial->iyy, _lk->inertial->iyz, _lk->inertial->ixz, _lk->inertial->iyz, _lk->inertial->izz; Eigen::Matrix3d R(Eigen::Quaterniond(origin.rotation.w, origin.rotation.x, origin.rotation.y, origin.rotation.z)); J = R * J * R.transpose(); node.mInertia.setMoment(J(0,0), J(1,1), J(2,2), J(0,1), J(0,2), J(1,2)); } // Set visual information for(size_t i = 0; i < _lk->visual_array.size(); i++) { dynamics::ShapePtr shape = createShape( _lk->visual_array[i].get(), _baseUri, _resourceRetriever); if(shape) node.mVizShapes.push_back(shape); else return false; } // Set collision information for(size_t i = 0; i < _lk->collision_array.size(); i++) { dynamics::ShapePtr shape = createShape( _lk->collision_array[i].get(), _baseUri, _resourceRetriever); if (shape) node.mColShapes.push_back(shape); else return false; } return true; }
void Entity::init(const ShapeList & list, const MassProperties mass, const Transform t){ std::vector< ::std::pair<size_t, Transform> > shapes; size_t compound; //Create the shapes for_each(list.begin(), list.end(), [&](const ShapeList::value_type & shape){ switch(shape.first.type){ case E_CAPSULE: case E_SPHERE: case E_BOX: case E_PLANE: { size_t s = createShape( shape.first.type, Math::Vec4ToVec3(shape.first.data), Math::VecLast(shape.first.data) ); Transform t = shape.second; ::std::pair<size_t, Transform> p(s,t); shapes.push_back(p); } break; case E_MESH: { size_t s = createShape( shape.first.type, shape.first.rawMesh ); Transform t = shape.second; ::std::pair<size_t, Transform> p(s,t); shapes.push_back(p); } break; default: { throw "Not valid shape type!"; } } }); //Got a list of shapes, make the compound shape compound = _world->compoundShapes(shapes); //Put it back on with the compound object first _shape_index.push_back(compound); for_each(shapes.begin(),shapes.end(),[&](decltype(shapes)::value_type s){ _shape_index.push_back(s.first); }); //create body makeBody(t, mass); }
void Kolf::Shape::setTraits(Kolf::Shape::Traits traits) { if (m_traits == traits) return; m_traits = traits; updateFixture(createShape()); }
// ============================================================================ /// Gemnerates random terrain using provided description void Ground::random( QList<Section> seed ) { _heightmap = generate( seed ); setLayers( 0xffff ); //all! // create ground b2BodyDef groundBodyDef; groundBodyDef.position.SetZero(); _pGround = new Body("Ground"); _pGround->create( groundBodyDef, world() ); QList<b2PolygonDef*> shapes = createShape(); foreach( b2PolygonDef* pShape, shapes ) { /* qDebug("Creating triangle: %.2f,%.2f %.2f,%.2f %.2f,%.2f" , pShape->vertices[0].x, pShape->vertices[0].y , pShape->vertices[1].x, pShape->vertices[1].y , pShape->vertices[2].x, pShape->vertices[2].y ); */ _pGround->addShape( pShape ); delete pShape; }
void autoMoveDown() { backupGrid(); cleanShape(g_CUR_CUBE); g_CUR_CUBE->moveDown(); if(isValidShapePos(g_CUR_CUBE) == false) { // move back && setShape g_CUR_CUBE->moveUp(); setShape(g_CUR_CUBE); // get next cube && draw it g_CUR_CUBE = g_NEXT_CUBE; if(isValidShapePos(g_CUR_CUBE) == false) { gameOver(); } Shape *s = createShape(); COORD ref_coord = {4, 2}; g_NEXT_CUBE = new Cube(ref_coord, s->shape, s->types); cleanNEXT(g_CUR_CUBE); drawNEXT(g_NEXT_CUBE); checkGrid(); } else { ; // do nothing } setShape(g_CUR_CUBE); drawGrid(); }
BowlingBall::BowlingBall(const vec3& position) { //Setting up renderer KMTexture tex("ball_diffuse.png"); auto ballVertices = KMVertex::loadFromObj("ball.obj"); auto mat = std::make_shared<KMMaterialTextureDiffuse>(tex); _renderer = std::make_shared<KMRendererMesh>(mat, ballVertices); //Setting up physics body btCollisionShape* shape = createShape(); btScalar bodyMass = 10.0f; btVector3 bodyInertia; shape->calculateLocalInertia(bodyMass, bodyInertia); btTransform trasn; trasn.setIdentity(); trasn.setOrigin(btVector3(position.x, position.y, position.z)); btDefaultMotionState *motionState = new btDefaultMotionState(trasn); btRigidBody::btRigidBodyConstructionInfo bodyCI = btRigidBody::btRigidBodyConstructionInfo(bodyMass, motionState, shape, bodyInertia); _physicsBody = std::unique_ptr<btRigidBody>(new btRigidBody(bodyCI)); _physicsBody->setUserPointer(this); _physicsBody->setRestitution(0.6f); _physicsBody->setFriction(.1f); // _physicsBody->setRollingFriction(.2f); // _physicsBody->setAnisotropicFriction(shape->getAnisotropicRollingFrictionDirection(),btCollisionObject::CF_ANISOTROPIC_ROLLING_FRICTION); }
BowlingPin::BowlingPin(const vec3& position) { //Setting up renderer KMTexture tex("pin_diffuse.png"); auto pinVertices = cachedVertices(); auto mat = std::make_shared<KMMaterialTextureDiffuse>(tex); _renderer = std::make_shared<KMRendererMesh>(mat, pinVertices); //Setting up physics body btCollisionShape* shape = createShape(pinVertices); btScalar bodyMass = 1.6f; btVector3 bodyInertia(0,0,0); shape->calculateLocalInertia(bodyMass, bodyInertia); btTransform trasn; trasn.setIdentity(); trasn.setOrigin(btVector3(position.x, position.y, position.z)); btDefaultMotionState *motionState = new btDefaultMotionState(trasn); btRigidBody::btRigidBodyConstructionInfo bodyCI = btRigidBody::btRigidBodyConstructionInfo(bodyMass, motionState, shape, bodyInertia); bodyCI.m_restitution = 0.7f; bodyCI.m_friction = 0.9f; _physicsBody = std::unique_ptr<btRigidBody>(new btRigidBody(bodyCI)); _physicsBody->setUserPointer(this); //_physicsBody->setDeactivationTime(0.0f); //_physicsBody->setDamping(0.1f, 0.2f); //_physicsBody->setAnisotropicFriction(shape->getAnisotropicRollingFrictionDirection(),btCollisionObject::CF_ANISOTROPIC_ROLLING_FRICTION); }
void gkGhost::create(void) { if (m_collisionObject) return; GK_ASSERT(m_object && m_object->isInstanced() && m_object->isInActiveLayer()); // use the most up to date transform. const gkTransformState& trans = m_object->getTransformState(); createShape(); if (!m_shape) return; m_collisionObject = new btPairCachingGhostObject(); m_collisionObject->setUserPointer(this); m_collisionObject->setCollisionFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE); m_collisionObject->setCollisionShape(m_shape); m_collisionObject->setWorldTransform(trans.toTransform()); btDynamicsWorld* dyn = getOwner(); dyn->addCollisionObject(m_collisionObject); dyn->getBroadphase()->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback()); }
ftCollider *ftPhysicsSystem::createCollider(ftBody *body, ftShape *shape, const ftVector2 &position, real orientation) { ftAssert(body != nullptr, ""); ftAssert(shape != nullptr, ""); ftCollider *collider = new ftCollider; collider->transform = ftTransform(position, orientation); collider->body = body; collider->shape = createShape(shape); collider->collisionHandle = m_collisionSystem.addShape(body->transform * collider->transform, collider->shape, collider); collider->next = body->colliders; body->colliders = collider; return collider; }
void updateRandering() { if ((options[OPT_SHADER_GEN_SHAPE] == TRUE && options[OPT_SHADING_TOGG] == TRUE) || (options[OPT_SHADER_BUMPMAP] == TRUE) || (options[OPT_SHADER_DISPMAP] == TRUE)) { uGpuGenShape = true; createShape(currentShape); } else { createShape(currentShape); uGpuGenShape = false; } updateBuffer = TRUE; }
bool Kolf::Shape::attach(CanvasItem* item) { if (m_citem) return false; m_citem = item; m_body = item->m_body; updateFixture(createShape()); return true; }
cpSpace* cpSpaceSerializer::load(cpSpace *space, const char* filename) { if (!_doc.LoadFile(filename)) return space; //Grab our space TiXmlElement *root = _doc.FirstChildElement("space"); if (!root) return space; _space = space; //Initialize _bodyMap.clear(); _shapeMap.clear(); //A body id of zero is the space's static body _bodyMap[0] = space->staticBody; space->iterations = createValue<int>("iterations", root); space->gravity = createPoint("gravity", root); space->damping = createValue<cpFloat>("damping", root); TiXmlElement *child = root->FirstChildElement("shape"); //Read Shapes while (child) { //attempt a shape cpShape *shape = createShape(child); if (shape) { //This should not happen like this, need to reflect reality -rkb if (shape->body->m != INFINITY && !cpSpaceContainsBody(space, shape->body)) cpSpaceAddBody(space, shape->body); cpSpaceAddShape(space, shape); } //Next! child = child->NextSiblingElement("shape"); } //Read Constraints child = root->FirstChildElement("constraint"); while (child) { //else attempt a constraint cpConstraint *constraint = createConstraint(child); if (constraint) cpSpaceAddConstraint(space, constraint); child = child->NextSiblingElement("constraint"); } return space; }
osg::Node* soundPistol() { osg::Node* testPistol = createShape( osg::Vec3(10,10,0), SHAPE_SPHERE ); CSulAudioSource* source = new CSulAudioSource( audioManager->getBuffer( "pistol" ), listener ); source->init(); source->setLooping( false ); source->play(); testPistol->addUpdateCallback( source ); return testPistol; }
void create( const osg::Vec3& pos ) { osg::Node* testPistol = createShape( pos, SHAPE_SPHERE ); CSulAudioSource* audioSource = new CSulAudioSource( audioManager->getBuffer( "pistol" ), listener ); audioSource->init(); audioSource->setLooping( false ); audioSource->setUseSoundInAir( true ); audioSource->play(); testPistol->addUpdateCallback( audioSource ); m_group->addChild( testPistol ); }
void Kolf::Shape::update() { updateFixture(createShape()); m_interactionOutline = m_activationOutline = QPainterPath(); createOutlines(m_activationOutline, m_interactionOutline); //propagate update to overlays if (m_citem) { Kolf::Overlay* overlay = m_citem->overlay(false); if (overlay) //may be 0 if the overlay has not yet been instantiated overlay->update(); } }
void Box2DFixture::createFixture(b2Body *body) { b2Shape *shape = createShape(); if (!shape) return; mFixtureDef.shape = shape; mFixture = body->CreateFixture(&mFixtureDef); mFixture->SetUserData(this); delete shape; }
Cube *ctrl_down(Cube *cube) { // cleanShape(cube); // if(cube->getBottom() + 1 < GRID_HEIGHT) { // if(g_GRID[cube->getX()][cube->getBottom() + 1].show == YES) { // setShape(cube); // free(cube); // COORD ref_coord = {4, 0}; // cube = new Cube(ref_coord, (COORD *)SHAPE_I_2); // setShape(cube); // return cube; // } // else { // cube->setCoord(cube->getX(), cube->getY() + 1); // } // } // setShape(cube); cleanShape(cube); COORD c; for(int i = 0; i < 4; i++) { c.X = cube->getCoord().X + cube->getShapes()[cube->cur_type][i].X; c.Y = cube->getCoord().Y + cube->getShapes()[cube->cur_type][i].Y + 1; if( // if reach blocks isInCube(c, cube) == false && g_GRID[cube->getCoord().X + cube->getShapes()[cube->cur_type][i].X][cube->getCoord().Y + 1 + cube->getShapes()[cube->cur_type][i].Y].show == 1 // if reach bottom || cube->getCoord().Y + 1 + cube->getShapes()[cube->cur_type][i].Y >= GRID_HEIGHT) { setShape(cube); // free(cube); COORD ref_coord = {4, 2}; // cube = new Cube(ref_coord, SHAPE_T.shape, SHAPE_T.types); cube = g_NEXT_CUBE; if(isValidShapePos(cube) == false) { gameOver(); } Shape *s = createShape(); g_NEXT_CUBE = new Cube(ref_coord, s->shape, s->types); // g_NEXT_CUBE = new Cube(ref_coord, SHAPE_T.shape, SHAPE_T.types); // int index = random(0, g_CubeGenerator->getLength()); // g_NEXT_CUBE = new Cube(ref_coord, g_CubeGenerator->getShapeList()[index].shape, g_CubeGenerator->getShapeList()[index].types); checkGrid(); setShape(cube); return cube; } } cube->setCoord(cube->getX(), cube->getY() + 1); checkGrid(); cube = ctrl_down(cube); setShape(cube); return cube; }
bool MgCommandDraw::_initialize(MgShape* (*creator)(), const MgMotion* sender) { if (!m_shape) { m_shape = creator ? creator() : createShape(sender->view->getShapeFactory()); if (!m_shape || !m_shape->shape()) return false; m_shape->setParent(sender->view->shapes(), 0); } sender->view->setNewShapeID(0); m_step = 0; m_needClear = false; m_shape->shape()->clear(); *m_shape->context() = *sender->view->context(); return true; }
void PhysicalItem::createBody() { if (body_ != nullptr) throw new std::logic_error("A body has already been created."); b2BodyDef bodyDef; defineBody(bodyDef); bodyDef.type = b2_dynamicBody; bodyDef.userData = reinterpret_cast<void*>(this); // For CollisionCallback bodyDef.position = gameScene()->mapToWorld(scenePos()); this->body_ = gameScene()->world()->CreateBody(&bodyDef); // Copies content of bodyDef b2FixtureDef fixtureDef; defineFixture(fixtureDef); fixtureDef.shape = createShape(); body_->CreateFixture(&fixtureDef); // Deep copies fixtureDef. delete fixtureDef.shape; }
/*! * \internal * * The objects created as children of \p parent will \em not be rotated or * translated correctly. Instead the required transformations are stored and * provided to the user, see \ref Loader3ds::getTransformationNodes */ bool Loader3dsInternal::loadNode(dcollide::World* world, dcollide::Proxy* parent, Lib3dsNode* node, Lib3dsMatrix* parentTranslateRotateMatrix) { if (!parent || !node) { return false; } if (node->type != LIB3DS_OBJECT_NODE) { return false; } Lib3dsObjectData* data = &node->data.object; Lib3dsMatrix translateRotateMatrix; lib3ds_matrix_copy(translateRotateMatrix, *parentTranslateRotateMatrix); lib3ds_matrix_translate(translateRotateMatrix, data->pos); lib3ds_matrix_rotate(translateRotateMatrix, data->rot); dcollide::Shape* shape = createShape(node, &translateRotateMatrix); dcollide::Proxy* object = world->createProxy(shape); mData->mProxy2TextureInformation.insert(std::make_pair(object, loadTextureInformation(node))); dcollide::Vector3 scale(data->scl[0], data->scl[1], data->scl[2]); dcollide::Vector3 translation(data->pos[0], data->pos[1], data->pos[2]); Lib3dsMatrix lib3dsRotationMatrix; lib3ds_matrix_identity(lib3dsRotationMatrix); lib3ds_matrix_rotate(lib3dsRotationMatrix, data->rot); dcollide::Matrix rotation(&lib3dsRotationMatrix[0][0]); Loader3ds::TransformationNode transformation; transformation.translation = translation; transformation.rotation = rotation; mData->mProxy2Transformation.insert(std::make_pair(object, transformation)); for (Lib3dsNode* n = node->childs; n; n = n->next) { if (!loadNode(world, object, n, &translateRotateMatrix)) { std::cerr << "Failed loading node " << n->name << std::endl; // TODO: delete object->getProxy() ? delete object; return false; } } parent->addChild(object); return true; }
void updateCache() { if (!dirty) return; dirty = false; if (node->style()->shape() != shape->type()) { delete shape; shape = createShape(node->style()->shape(), q); } shapePath = shape->shape(); outlinePath = shape->outline(); q->setRotation(node->style()->rotation()); q->update(); }
void MScene::prepareCollisionShape(MOEntity * entity) { MPhysicsContext * physics = MEngine::getInstance()->getPhysicsContext(); MPhysicsProperties * phyProps = entity->getPhysicsProperties(); if(! phyProps) return; unsigned int shapeId = 0; if(createShape(entity, phyProps, &shapeId)) { // has physics child bool hasPhysicsChild = false; unsigned int o; unsigned int oSize = entity->getChildsNumber(); for(o=0; o<oSize; o++) { MObject3d * childObject = entity->getChild(o); if(childObject->getType() == M_OBJECT3D_ENTITY) { MOEntity * childEntity = (MOEntity*)childObject; MPhysicsProperties * childPhyProps = childEntity->getPhysicsProperties(); if(childPhyProps) { if(! childPhyProps->isGhost()) { hasPhysicsChild = true; break; } } } } // create multi shape if(hasPhysicsChild) { unsigned int subShapeId = shapeId; physics->createMultiShape(&shapeId); physics->addChildShape(shapeId, subShapeId, MVector3(), MQuaternion()); } phyProps->setShapeId(shapeId); } }
void neb::phx::core::shape::base::create_physics() { printf("%s\n", __PRETTY_FUNCTION__); printv_func(DEBUG); //NEBULA_DEBUG_0_FUNCTION; if(!hasParent()) { printf("%s\n", __PRETTY_FUNCTION__); return; } auto fnd_shape = neb::could_be<parent_t, neb::fnd::core::shape::base>(getParent()); assert(fnd_shape); auto fnd_actor = fnd_shape->getParent()->is_fnd_actor_base(); assert(fnd_actor); auto actor = std::dynamic_pointer_cast<neb::phx::core::actor::base>(fnd_actor->P::get_object()); assert(actor); if(!actor) return; auto rigidactor = actor->isPxActorRigidActorBase();//std::dynamic_pointer_cast<neb::fnd::actor::Rigid_Actor>(parent_.lock()); assert(rigidactor); if(!rigidactor) return; physx::PxActor* const & px_actor = rigidactor->px_actor_; assert(px_actor); if(!px_actor) return; auto px_rigidactor = rigidactor->px_actor_->isRigidActor(); assert(px_rigidactor); auto fnd_app = get_fnd_app(); auto app = dynamic_cast<neb::phx::app::base*>(fnd_app->P::get_object().get()); assert(app); physx::PxMaterial* px_mat = app->px_physics_->createMaterial(1,1,1); px_shape_ = px_rigidactor->createShape( *(to_geo()), *px_mat ); }
void AnnotationRenderer::update() { // ObjectRenderer::update(); // No need to call it if (m_movingAction == MOVING_NONE) m_endPos = getPosition() + m_annotation->getDeltaToEnd(); m_textArea = Rect::fromSize(getPosition(), m_textSize); m_textArea.translate(0, -m_textSize.y); m_textArea.adjust(3, -13, 13, -3); m_annotation->cleanDirty(); m_selectionArea = m_visualArea = m_textArea; if(m_annotation->m_type.getValue() != Annotation::ANNOTATION_TEXT) m_visualArea |= Rect(getPosition(), m_endPos).canonicalized(); createShape(); }
void RenderSVGShape::layout() { LayoutRepainter repainter(*this, checkForRepaintDuringLayout() && selfNeedsLayout()); SVGStyledTransformableElement* element = static_cast<SVGStyledTransformableElement*>(node()); bool updateCachedBoundariesInParents = false; bool needsShapeUpdate = m_needsShapeUpdate; if (needsShapeUpdate || m_needsBoundariesUpdate) { setIsPaintingFallback(false); m_path.clear(); createShape(); m_needsShapeUpdate = false; updateCachedBoundariesInParents = true; } if (m_needsTransformUpdate) { m_localTransform = element->animatedLocalTransform(); m_needsTransformUpdate = false; updateCachedBoundariesInParents = true; } // Invalidate all resources of this client if our layout changed. if (everHadLayout() && selfNeedsLayout()) { SVGResourcesCache::clientLayoutChanged(this); m_markerLayoutInfo.clear(); } // At this point LayoutRepainter already grabbed the old bounds, // recalculate them now so repaintAfterLayout() uses the new bounds. if (needsShapeUpdate || m_needsBoundariesUpdate) { updateCachedBoundaries(); m_needsBoundariesUpdate = false; } // If our bounds changed, notify the parents. if (updateCachedBoundariesInParents) RenderSVGModelObject::setNeedsBoundariesUpdate(); repainter.repaintAfterLayout(); setNeedsLayout(false); }
bool handleButtons(float x, float y) { if(translateButton.contains(x,y)) transM = TRANS_TRANSLATION; else if(rotateButton.contains(x,y)) transM = TRANS_ROTATION; else if(scaleButton.contains(x,y)) transM = TRANS_SCALE; else if(XButton.contains(x,y)) axisM = X_AXIS; else if(YButton.contains(x,y)) axisM = Y_AXIS; else if(ZButton.contains(x,y)) axisM = Z_AXIS; else if(tetraButton.contains(x,y)) createShape(SHAPE_TETRAHEDRON); else if(cubeButton.contains(x,y)) createShape(SHAPE_CUBE); else if(octButton.contains(x,y)) createShape(SHAPE_OCTAHEDRON); else if(sphereButton.contains(x,y)) createShape(SHAPE_SPHERE); else if(cylinderButton.contains(x,y)) createShape(SHAPE_CYLINDER); else if(planeButton.contains(x,y)) createShape(SHAPE_PLANE); else if(deleteButton.contains(x,y)) deleteShape(); else if(RButton.contains(x,y)) colorM = COLOR_R; else if(GButton.contains(x,y)) colorM = COLOR_G; else if(BButton.contains(x,y)) colorM = COLOR_B; else if(loadButton.contains(x,y)) { idCounter = load("default.mcg", &listOfShapes); if(idCounter <= 0) { idCounter = 1; listOfShapes.clear(); } } else if(saveButton.contains(x,y)) save("default", listOfShapes); else return false; buttonCheck(); return true; }
void init() { glClearColor(0.0, 0.0, 0.0, 0.0); memset(options, 0, sizeof(bool) * OPTSIZE); options[OPT_STDOUT_TEXT] = TRUE; options[OPT_OSP_SHORT_LONG] = TRUE; uTessellation = WELL_FORM_TESS; /* set starting default setting */ currentShape = SHAPE_GRID; sprintf(tessString, "Tessellation: %d x %d",uTessellation,uTessellation); sprintf(bumpSizeString,"Number Of Bumps: %d x %d",uNumOfBumps,uNumOfBumps); strcpy(localViewString,"LocalView: Off "); strcpy(infoString, "Shader: Fixed pipeline"); strcpy(drawMethodString,currentDrawingMethod[currentShape][0]); createShape(currentShape); generateBuffers(); enableVertexArrays(); generateBuffers(); bufferData(); }
void THIS::create_physics() { printv_func(DEBUG); auto fnd_app = get_fnd_app(); if(!fnd_app->is_valid()) return; auto actor = neb::could_be<parent_t, neb::phx::core::actor::base>(getParent()); assert(actor); if(px_shape_) return; if(actor) { auto rigidactor = actor->isPxActorRigidActorBase();//std::dynamic_pointer_cast<neb::fnd::actor::Rigid_Actor>(parent_.lock()); assert(rigidactor); if(rigidactor) { if(!rigidactor->px_actor_) rigidactor->create_physics(); assert(rigidactor->px_actor_); auto px_rigidactor = rigidactor->px_actor_->isRigidActor(); assert(px_rigidactor); physx::PxMaterial* px_mat[2]; auto app = dynamic_cast<neb::phx::app::base*>(get_fnd_app()); assert(app); px_mat[0] = app->px_physics_->createMaterial(1,1,1); px_mat[1] = app->px_physics_->createMaterial(1,1,1); px_shape_ = px_rigidactor->createShape(*(to_geo()), px_mat, 2); } } }
NxActor* MxActor::createNxActor() { if (m_bulletBody) { MaxMsgBox(NULL, _T("Error: body was already added to the dynamics world"), _T("Error"), MB_OK); return 0; } // find proxy node m_proxyNode = NULL; TSTR str = MxUserPropUtils::GetUserPropStr(m_node, "Proxy_Geometry"); char* proxyName = str.data(); if(proxyName && strlen(proxyName) > 0 && (stricmp(proxyName, "<None>") != 0)) { m_proxyNode = GetCOREInterface()->GetINodeByName(proxyName); } // ccMaxNode* pActorNode = ccMaxWorld::FindNode(m_node); assert(pActorNode); maxNodeActor = pActorNode; maxNodeProxy = NULL; if(m_proxyNode) { maxNodeProxy = ccMaxWorld::FindNode(m_proxyNode); assert(maxNodeProxy); //Point3 p1 = maxNodeActor->PhysicsNodePoseTM.GetRow(3), p2 = maxNodeProxy->PhysicsNodePoseTM.GetRow(3); Point3 p1 = maxNodeActor->NodePosInPhysics, p2 = maxNodeProxy->NodePosInPhysics; ProxyDistance = p1 - p2; } NxActorDesc& actorDesc = m_desc; NxBodyDesc& bodyDesc = m_bodyDesc; //LoadParameters(actorDesc, bodyDesc); actorDesc.globalPose = pActorNode->PhysicsNodePoseTM;//MxMathUtils::MaxMatrixToNx(pActorNode->PhysicsNodePoseTM); SaveLastPose(pActorNode->PhysicsNodePoseTM); //m_bodydesc.solverIterationCount = (NxU32)mSetting_solveriterationcount; // support it in future? std::vector<INode*> stack; std::vector<INode*> shapes; //Check if the object is using a proxy, in that case only those shapes should be added INode* current = m_node; if(m_proxyNode) current = m_proxyNode; stack.push_back(current); //DEBUG_S("List collision shapes"); while (stack.size() > 0) { current = stack[0]; if(stack.size() > 1) { stack[0] = stack.back(); } stack.pop_back(); if(current->EvalWorldState(0).obj->SuperClassID()==GEOMOBJECT_CLASS_ID) { shapes.push_back(current); } //go through grouped objects for(int i = 0; i < current->NumberOfChildren(); i++) { INode *c = current->GetChildNode(i); if (c->IsGroupMember()) { stack.push_back(c); } } } if (shapes.size() == 0) { if (gCurrentstream) gCurrentstream->printf("Unable to add %s as an actor, it has no shapes.\n", m_node->GetName()); return 0; } ccMaxNode* baseNode = pActorNode; if(maxNodeProxy) { baseNode = maxNodeProxy; } btAlignedObjectArray<btCollisionShape*> collisionShapes; btAlignedObjectArray<btTransform> localTransforms; for (int i = 0; i < shapes.size(); i++) { INode* current = shapes[i]; //DEBUG_F(" Debug adding shape node: %s\n", current->GetName()); ccMaxNode* pn = ccMaxWorld::FindNode(current); assert(pn); btCollisionShape* collisionShape = createShape(actorDesc, pn, pActorNode); collisionShapes.push_back(collisionShape); btTransform localTrans; max2Bullet(actorDesc.localPose,localTrans); localTransforms.push_back(localTrans); } //create a rigid body and add it to the world if (collisionShapes.size()) { btCollisionShape* collisionShape = 0; if (collisionShapes.size()==1) { collisionShape = collisionShapes[0]; } else { btCompoundShape* compound = new btCompoundShape(); for (int i=0;i<collisionShapes.size();i++) { compound->addChildShape(localTransforms[i],collisionShapes[i]); } //clear local pose actorDesc.localPose.IdentityMatrix(); collisionShape = compound; } if (collisionShape) { btVector3 localInertia(0,0,0); if (actorDesc.mass) { collisionShape->calculateLocalInertia(actorDesc.mass,localInertia); } m_bulletBody = new btRigidBody(actorDesc.mass,0,collisionShape,localInertia); m_bulletBody->setUserPointer(this); btScalar restitution; if (MxUserPropUtils::GetUserPropFloat(m_node, "Restitution", restitution)) { m_bulletBody->setRestitution(restitution); } btScalar staticFriction = 0.f; //take the maximum for now MxUserPropUtils::GetUserPropFloat(m_node, "StaticFriction", staticFriction); btScalar friction = 0.f; if (MxUserPropUtils::GetUserPropFloat(m_node, "Friction", friction)) { if (staticFriction>friction) friction = staticFriction; m_bulletBody->setFriction(friction); } // char bla[1024]; // sprintf(bla,"restitution=%f",restitution); // MaxMsgBox(NULL, _T(bla), _T("Error"), MB_OK); syncGlobalPose(); gDynamicsWorld->addRigidBody(m_bulletBody); // MaxMsgBox(NULL, _T("adding rigid body"), _T("Error"), MB_OK); } } bool isvalid = actorDesc.isValid(); actorDesc.name = m_node->GetName(); //NxMat34 pose0 = actorDesc.globalPose; //m_actor = gPluginData->getScene()->createActor(actorDesc); //if(! m_actor) return 0; //NxMat34 pose1 = m_actor->getGlobalPose(); // sometimes pose1 != pose0; it is strange //m_actor->userData = this; if(MxUserPropUtils::GetUserPropBool(m_node, "PutToSleep", false)) { //m_actor->putToSleep(); } // for collision force when contact happens /* NxU32 num = m_actor->getNbShapes(); NxShape*const* ps = m_actor->getShapes(); for(NxU32 i = 0; i < num; ++i) { NxShape* nxShape = ps[i]; nxShape->setFlag(NX_SF_POINT_CONTACT_FORCE, true); } */ //save last pose Matrix3 poseTM = maxNodeActor->GetCurrentTM(); SaveLastPose(poseTM); //return m_actor; return 0; }