void SlideJoint::onEnter() { BaseDemo::onEnter(); auto box1 = createBox(Point(400, 200), Size(100, 100)); auto box2 = createBox(Point(600, 400), Size(100, 100)); this->addChild(box1); this->addChild(box2); PhysicsJointLimit * box_joint = PhysicsJointLimit::construct(box1->getPhysicsBody(), box2->getPhysicsBody(), Point(0, 0), Point(0, 0), 120, 200); _world->addJoint(box_joint); Sprite* box = nullptr; PhysicsJointLimit* chainJoint_limit = nullptr; int chainLen = 10; Vector<Sprite*> boxes; for (int i = 0; i < chainLen; i++) { box = createBox(Point(500 + 40 * i, 600), Size(20, 10)); this->addChild(box); boxes.pushBack(box); if (i == 0) { box->getPhysicsBody()->setDynamic(false); } if(i > 0) { chainJoint_limit = PhysicsJointLimit::construct(boxes.at(i-1)->getPhysicsBody(), boxes.at(i)->getPhysicsBody(), Point(10, 0), Point(-10, 0), 10, 20); _world->addJoint(chainJoint_limit); } } }
void btWorldFactory::createPoolOfBalls(QVariantList &shapesList, double areaX, double areaZ, btVector3 pos, int nbBalls) { // walls btScalar wallsHeight = 10.0; btScalar wallsWidth = 4.0; createBox(shapesList, btVector3(areaX,wallsHeight,wallsWidth), pos + btVector3(0,wallsHeight*.5,areaZ*0.5-wallsWidth*0.5), btVector3(0,0,0), 0); createBox(shapesList, btVector3(areaX,wallsHeight,wallsWidth), pos + btVector3(0,wallsHeight*.5,-(areaZ*0.5-wallsWidth*0.5)), btVector3(0,0,0), 0); btScalar cubeSize = 20; btScalar cubeZRot = M_PI * 0.08 ; createBox(shapesList, btVector3(cubeSize,cubeSize,areaZ), pos + btVector3(areaX*0.5,-7,0), btVector3(0,0,cubeZRot), 0); createBox(shapesList, btVector3(cubeSize,cubeSize,areaZ), pos + btVector3(-areaX*0.5,-7,0), btVector3(0,0,-cubeZRot), 0); // balls // btScalar ballRadius = 1.0; // int nbx = 8; // int nby = 4; // int nbz = 14; // for(int x=0;x<nbx;x++) { // for(int y=0;y<nby;y++) { // for(int z=0;z<nbz;z++) { // createSphere(shapesList, // ballRadius,pos - btVector3(nbx*ballRadius,0,nbz*ballRadius) + btVector3(x* ballRadius*2,y* ballRadius*2+ ballRadius,z* ballRadius*2), // btVector3(0,0,0),20.0); // } // } // } }
void PivotJointScene::onEnter() { BaseDemo::onEnter(); auto visibleSize = VisibleRect::getVisibleRect().size; float pierPosY = 100.0f; Sprite* bridgePierL = createBox(Point(visibleSize.width/2 - 400, pierPosY), Size(40, 40)); Sprite* bridgePierR = createBox(Point(visibleSize.width/2 + 400, pierPosY), Size(40, 40)); bridgePierL->setRotation(0); bridgePierR->setRotation(0); bridgePierL->getPhysicsBody()->setDynamic(false); bridgePierR->getPhysicsBody()->setDynamic(false); bridgePierL->getPhysicsBody()->setTag(0); bridgePierR->getPhysicsBody()->setTag(0); this->addChild(bridgePierL); this->addChild(bridgePierR); float ballRadius = 40.0f; Sprite* fallingBall = createBall(Point(visibleSize.width/2, visibleSize.height-ballRadius), ballRadius); this->addChild(fallingBall); Vector<Sprite*> bamboos; for (int i = 0; i < BAMBOO_SEGMENTS_NUM; i++) { auto box = createBox(Point(bridgePierL->getPositionX() + BAMBOO_SEGMENT_SIZE.width * i, pierPosY), BAMBOO_SEGMENT_SIZE); box->setRotation(0); this->addChild(box); bamboos.pushBack(box); } PhysicsJointPin* pinJointL = PhysicsJointPin::construct(bridgePierL->getPhysicsBody(), bamboos.front()->getPhysicsBody(),bridgePierL->getPosition()); PhysicsJointPin* pinJointR = PhysicsJointPin::construct(bridgePierR->getPhysicsBody(), bamboos.back()->getPhysicsBody(),bridgePierR->getPosition()); pinJointL->setCollisionEnable(false); pinJointR->setCollisionEnable(false); _world->addJoint(pinJointL); _world->addJoint(pinJointR); for (int i = 0; i < BAMBOO_SEGMENTS_NUM - 1; i++) { auto body1 = bamboos.at(i)->getPhysicsBody(); auto body2 = bamboos.at(i+1)->getPhysicsBody(); PhysicsJointPin* pivotJointUp = PhysicsJointPin::construct(body1, body2, bamboos.at(i+1)->getPosition() + Point(-BAMBOO_SEGMENT_SIZE.width/2, BAMBOO_SEGMENT_SIZE.height/2)); PhysicsJointPin* pivotJointDown = PhysicsJointPin::construct(body1, body2, bamboos.at(i+1)->getPosition() + Point(-BAMBOO_SEGMENT_SIZE.width/2, -BAMBOO_SEGMENT_SIZE.height/2)); PhysicsJointRotarySpring* springJoint = PhysicsJointRotarySpring::construct(body1, body2, 2000, 0.8f); pivotJointUp->setCollisionEnable(false); pivotJointDown->setCollisionEnable(false); springJoint->setCollisionEnable(false); _world->addJoint(pivotJointUp); _world->addJoint(pivotJointDown); _world->addJoint(springJoint); } }
ClientUnit::ClientUnit( Rendering* const rendering, Wrapper* const wrapper, GameStaticData* const gameStaticData, GameDynData* const gameDynData, ClientSquad* const squad, const IntCode id, const Coord& coord, Input* const input ) : mRendering(rendering), mWrapper(wrapper), mGameStaticData(gameStaticData), mGameDynData(gameDynData), mSquad(squad), mId(id), mCoord(coord), mInput(input), mMode(MODE_PLAYER), mCtrl(MODE_PLAYER), mSpeed(100.0f, 100.0f, Math::PI/360.0f, Math::PI/360.0f), mScale(0, 0, 0, 0), mDiff(0, 0.55, 0.46, 0.45), mTarget(0), mAgressor(0), mTargetTime(TIME_TO_PEACE), mAgressorTime(TIME_TO_PEACE), mFireTime(TIME_TO_CHANGE), mMoveTime(TIME_TO_CHANGE), mInterfaceInput( squad ? new ClientInputGame(rendering, input) : 0 ), mSaladin( squad ? new Saladin(rendering, wrapper) : 0 ), mSquadData( squad ? squad->mSquadData : 0 ), mLeader( squad ? squad->mLeader : 0 ), maUnit( squad ? squad->maUnit : 0 ), maPlayerDynData( squad ? gameDynData->aPlayerDynData : 0 ), Actor(wrapper->scene) { if (squad) { for (IntVal index = 0 ; index < 5 ; ++index) { maState[index] = 0; } for (IntVal index = 0 ; index < MAX_AMMO ; ++index) { maBullet[index] = 0; } mSpeed.x *= (0.60 + (bool)mLeader*0.60); NxOgre::RigidBodyDescription description; description.mName = "Unit"; description.mMass = 24500; description.mWakeUpCounter = 1E12; description.mMassLocalPose = Vec3(0.00f, -2.18f, 0.0f); mName = description.mName; mNameHash = NxOgre::Strings::hash(mName); NxOgre::ShapeDescriptions vShapes; vShapes.push_back(createBox ( 0.00f, 0.00f, 0.00f, 4.40f, 2.50f, 7.00f)); vShapes.push_back(createBox ( 0.10f, 0.70f, 0.70f, 4.40f, 1.50f, 4.40f)); vShapes.push_back(createBox (-0.10f, 0.40f, 4.10f, 0.50f, 0.50f, 4.00f)); vShapes.push_back(createWheel(-2.30f, -2.18f, 3.54f)); vShapes.push_back(createWheel(-2.29f, -2.18f, 0.50f)); vShapes.push_back(createWheel(-2.31f, -2.18f, -3.00f)); vShapes.push_back(createWheel( 2.30f, -2.18f, 3.54f)); vShapes.push_back(createWheel( 2.29f, -2.18f, 0.50f)); vShapes.push_back(createWheel( 2.31f, -2.18f, -3.00f)); this ->createDynamic(coord, description, vShapes); mSaladin ->init(this); for (IntVal index = 0 ; index < vShapes.size() ; ++index) { delete vShapes[index]; } } }
void ComputeAABBOnBoneVisitor::computeBoundingBoxOnBones() { //Perform Updates updateBones(); updateRigGeometries(); //We have our T pose, we can compute an AABB for each bone for (BoneList::iterator bone = _bones.begin(); bone != _bones.end(); ++ bone) { osg::BoundingBox bb; //For each geometry for (RigGeometryList::iterator iterator = _rigGeometries.begin(); iterator != _rigGeometries.end(); ++ iterator) { osgAnimation::RigGeometry* rigGeometry = *iterator; if(!rigGeometry) continue; osg::Matrix mtxLocalToSkl = rigGeometry->getWorldMatrices(_root).at(0); //For each Vertex influence osgAnimation::VertexInfluenceMap * infMap = rigGeometry->getInfluenceMap(); osgAnimation::VertexInfluenceMap::iterator itMap = infMap->find((*bone)->getName()); if(itMap == infMap->end()) continue; osg::Vec3Array *vertices = dynamic_cast<osg::Vec3Array*>(rigGeometry->getVertexArray()); if(!vertices) continue; osgAnimation::VertexInfluence vxtInf = (*itMap).second; //Expand the boundingBox with each vertex for(unsigned int j = 0; j < vxtInf.size(); j++) { if(vxtInf.at(j).second < 10e-2) continue; //Skip vertex if low weight osg::Vec3 vx = vertices->at(vxtInf.at(j).first); vx = vx * mtxLocalToSkl; bb.expandBy(vx); } // Compare initial and actual boundingBox if (no change) => no box on bone if(bb == osg::BoundingBox() || (bb._min.x() == bb._max.x() && bb._min.y() == bb._max.y() && bb._min.z() == bb._max.z())) { continue; } osg::Matrix worldToBone = osg::Matrix::inverse((*bone)->getWorldMatrices(_root).at(0)); if(_createGeometry) { osg::Geode *g = new osg::Geode; g->setName("AABB_for_bone_" + (*bone)->getName()); g->addDrawable(createBox(bb, worldToBone)); (*bone)->addChild(g); } serializeBoundingBox(bb, worldToBone, *(*bone)); } } //Clear geometries for (RigGeometryList::iterator iterator = _rigGeometries.begin(); iterator != _rigGeometries.end(); ++ iterator) { osgAnimation::RigGeometry* rigGeometry = *iterator; if(rigGeometry) { rigGeometry->copyFrom(*rigGeometry->getSourceGeometry()); rigGeometry->setRigTransformImplementation(0); } } }
void initialise() { glClearColor(0.0f, 1.0f, 1.0f, 1.0f); projection = glm::perspective(glm::degrees(glm::quarter_pi<float>()), 800.0f/600.0f, 0.1f, 10000.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_VERTEX_ARRAY); shaders[0] = loadShader("ambient.vert", GL_VERTEX_SHADER); shaders[1] = loadShader("ambient.frag", GL_FRAGMENT_SHADER); if (shaders[0] && shaders[1]) { program = createProgram(shaders, 2); if (!program) exit(EXIT_FAILURE); } else exit(EXIT_FAILURE);//TODO 36 is crashing on this line, seems like it cant load shaders into program MVPuniform = glGetUniformLocation(program, "modelViewProjection"); ambientMaterialUniform = glGetUniformLocation(program, "ambientMaterial"); ambientLightUniform = glGetUniformLocation(program, "ambientLight"); object.geometry = createBox(); }
void QgsColorBox::paintEvent( QPaintEvent *event ) { Q_UNUSED( event ); QPainter painter( this ); QStyleOptionFrameV3 option; option.initFrom( this ); option.state = hasFocus() ? QStyle::State_Active : QStyle::State_None; style()->drawPrimitive( QStyle::PE_Frame, &option, &painter ); if ( mDirty ) { createBox(); } //draw background image painter.drawImage( QPoint( mMargin, mMargin ), *mBoxImage ); //draw cross lines double xPos = mMargin + ( width() - 2 * mMargin - 1 ) * ( double )xComponentValue() / ( double )valueRangeX(); double yPos = mMargin + ( height() - 2 * mMargin - 1 ) - ( height() - 2 * mMargin - 1 ) * ( double )yComponentValue() / ( double )valueRangeY(); painter.setBrush( Qt::white ); painter.setPen( Qt::NoPen ); painter.drawRect( xPos - 1, mMargin, 3, height() - 2 * mMargin - 1 ); painter.drawRect( mMargin, yPos - 1, width() - 2 * mMargin - 1, 3 ); painter.setPen( Qt::black ); painter.drawLine( xPos, mMargin, xPos, height() - mMargin - 1 ); painter.drawLine( mMargin, yPos, width() - mMargin - 1, yPos ); painter.end(); }
void PointCloudSelectionHandler::onSelect(const Picked& obj) { S_uint64::iterator it = obj.extra_handles.begin(); S_uint64::iterator end = obj.extra_handles.end(); for (; it != end; ++it) { int global_index = (*it & 0xffffffff) - 1; int index = 0; PointCloudBase::CloudInfoPtr cloud; getCloudAndLocalIndexByGlobalIndex(global_index, cloud, index); if (!cloud) { continue; } sensor_msgs::PointCloud2ConstPtr message = cloud->message_; Ogre::Vector3 pos = cloud->transform_ * pointFromCloud(message, index); float size = 0.002; if (display_->style_ != PointCloudBase::Points) { size = display_->billboard_size_ / 2.0; } Ogre::AxisAlignedBox aabb(pos - size, pos + size); createBox(std::make_pair(obj.handle, global_index), aabb, "RVIZ/Cyan"); } }
void processEvent(SDL_Event *e) override { Sample::processEvent(e); if (e->type == SDL_KEYDOWN) { if (e->key.keysym.sym == SDLK_c) { if (mCubes.size() > 500) { // delete oldest boxc mCubes.pop_front(); } String cubeName("Cube"); cubeName.append(std::to_string(mBoxCounter++)); BaseBody::Ptr box = createBox(cubeName); mCubes.push_back(box); kmVec3 pos = { static_cast<float>(rand() % 1000), static_cast<float>(rand() % 1000), static_cast<float>((rand() % 1000) + 1000) }; kmQuaternion rot = { 1.0f, 1.0f, 1.0f, (rand() % 1000)/1000.0f }; box->setPosition(pos); box->setRotation(rot); } } }
void btWorldFactory::createBoxesStairs(QVariantList &shapesList, double areaX, double areaZ, btVector3 pos, double stepWidth, double yMinStep, double yMaxStep) { // Boxes Floor double sizeX = stepWidth; double sizeZ = stepWidth; int nbBoxesX = areaX / sizeX; int nbBoxesZ = areaZ / sizeZ; double maxY = (nbBoxesX+nbBoxesZ)*Tools::random(yMinStep, yMaxStep); for(int i=0;i<nbBoxesX;++i){ for(int j=0;j<nbBoxesZ;++j){ //double sizeY = 2*maxY - sin((double)i/nbBoxesX*M_PI)*maxY - sin((double)j/nbBoxesX*M_PI)*maxY; double sizeY = qAbs(nbBoxesX/2. - i)/nbBoxesX*maxY + qAbs(nbBoxesZ/2. - j)/nbBoxesZ*maxY; createBox(shapesList, btVector3(sizeX,sizeY,sizeZ), btVector3(i*sizeX - areaX*0.5 + pos.x(),sizeY/2.0 + pos.y(),j*sizeZ - areaZ*0.5 + pos.z()), btVector3(0,0,0),0); } } }
void renderInCSGMode(void){ glLoadIdentity(); //Just to be sure glTranslatef(0.0f,0.0f,init_zoom);//Fix Zoom if(menu_open)glTranslatef(boxMatrix[0]/2.0f,0.0f,0.0f); if(rotating){ float tempc = cosf(rot_speed*2.0f*PI / 360.0f); float temps = sinf(rot_speed*2.0f*PI / 360.0f); float tempMatrix[16] = { tempc, 0.0f, -temps, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, temps, 0.0f, tempc, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; multMatrixBA4f(ThisRotMatrix, tempMatrix); } glMultMatrixf(ThisRotMatrix); glTranslatef(-(boxMatrix[0]+boxMatrix[1]+boxMatrix[2])/2.0f, -(boxMatrix[4]+boxMatrix[5])/2.0f, -boxMatrix[8]/2.0f); //Center Box if(box_display)createBox(boxMatrix); CSGrender(); glDepthFunc(GL_EQUAL); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,CrystalColors[0]); renderPrimitives(); glDepthFunc(GL_LEQUAL); if(menu_open)screenFade(); }
OpenGLWidget::OpenGLWidget(MainWindow* mainWindow) : QOpenGLWidget{mainWindow} , m_axisLegendScene{mainWindow->app()} , m_width{0} , m_height{0} , m_currentLocation{} , m_previousLocation{} { this->setFocusPolicy(Qt::StrongFocus); m_contextMenu = new QMenu(this); QMenu* createMenu = m_contextMenu->addMenu("Create"); createMenu->addAction(tr("Box"), this, SLOT(createBox())); createMenu->addAction(tr("Cylinder"), this, SLOT(createCylinder())); createMenu->addAction(tr("Cone"), this, SLOT(createCone())); createMenu->addAction(tr("Sphere"), this, SLOT(createSphere())); m_contextMenu->addAction(tr("Import Mesh"), this, SLOT(importMesh())); QSurfaceFormat format = this->format(); format.setVersion(kOpenGLMajorVersion, kOpenGLMinorVersion); format.setProfile(QSurfaceFormat::CoreProfile); format.setDepthBufferSize(32); format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); LOG(INFO) << fmt::format("Setting format with OpenGL version {}.{}", kOpenGLMajorVersion, kOpenGLMinorVersion); this->setFormat(format); }
void SelectionHandler::updateTrackedBoxes() { M_HandleToBox::iterator it = boxes_.begin(); M_HandleToBox::iterator end = boxes_.end(); for (; it != end; ++it) { V_AABB aabbs; Picked p(it->first.first); p.extra_handles.insert(it->first.second); getAABBs(Picked(it->first.first), aabbs); if (!aabbs.empty()) { Ogre::AxisAlignedBox combined; V_AABB::iterator aabb_it = aabbs.begin(); V_AABB::iterator aabb_end = aabbs.end(); for (; aabb_it != aabb_end; ++aabb_it) { combined.merge(*aabb_it); } createBox(std::make_pair(p.handle, it->first.second), combined, "RVIZ/Cyan"); } } }
BlokItem::BlokItem(float w, float h,KGLEngine * parent) :KGLPhysicsItem(parent,KGLPhysicsItem::PolygonShape) { createBox(w,h); setZIndex(LAYER_MIDDLE); m_willRemove=false; m_exploseSound=new KALSound(KGlobal::dirs()->findResourceDir("appdata", "data/sounds/") + "data/sounds/explosion.wav"); }
PropertyGroup::PropertyGroup(float min, float max, float t, QString name) { createBox(name); properties.emplace_back(new Property(min, max, t, box)); config(); }
osg::ref_ptr<osg::Camera> setupWidgets(osgViewer::Viewer* viewer) { osg::ref_ptr<osgWidget::WindowManager> wm = new osgWidget::WindowManager( viewer, 1280.0f, 1024.0f, MASK_2D, osgWidget::WindowManager::WM_PICK_DEBUG ); wm->setPointerFocusMode(osgWidget::WindowManager::PFM_SLOPPY); osgWidget::Window* box1 = createBox("HBOX", osgWidget::Box::HORIZONTAL); osgWidget::Window* box2 = createBox("VBOX", osgWidget::Box::VERTICAL); osgWidget::Window* box3 = createBox("HBOX2", osgWidget::Box::HORIZONTAL); osgWidget::Window* box4 = createBox("VBOX2", osgWidget::Box::VERTICAL); box1->getBackground()->setColor(1.0f, 0.0f, 0.0f, 0.8f); box1->attachMoveCallback(); box2->getBackground()->setColor(0.0f, 1.0f, 0.0f, 0.8f); box2->attachMoveCallback(); box3->getBackground()->setColor(0.0f, 0.0f, 1.0f, 0.8f); box3->attachMoveCallback(); wm->addChild(box1); wm->addChild(box2); wm->addChild(box3); wm->addChild(box4); box4->hide(); osg::Camera* camera = wm->createParentOrthoCamera(); viewer->addEventHandler(new osgWidget::MouseHandler(wm)); viewer->addEventHandler(new osgWidget::KeyboardHandler(wm)); viewer->addEventHandler(new osgWidget::ResizeHandler(wm, camera)); viewer->addEventHandler(new osgWidget::CameraSwitchHandler(wm, camera)); viewer->addEventHandler(new osgViewer::StatsHandler()); viewer->addEventHandler(new osgViewer::WindowSizeHandler()); wm->resizeAllWindows(); return camera; }
//-------------------------------------------------------------------------------------------------- /// Create a 3D solid box at the specified position and with the given total extents /// /// \param centerPos Position of center of box /// \param extentX Total extent of box along x-axis /// \param extentY Total extent of box along y-axis /// \param extentZ Total extent of box along z-axis /// \param builder Geometry builder to use when creating geometry //-------------------------------------------------------------------------------------------------- void GeometryUtils::createBox(const Vec3f& centerPos, float extentX, float extentY, float extentZ, GeometryBuilder* builder) { Vec3f halfExtent(extentX/2, extentY/2, extentZ/2); Vec3f min(centerPos - halfExtent); Vec3f max(centerPos + halfExtent); createBox(min, max, builder); }
void Physics::testPhysics(){ int box3 = createBox(895,95,395); int box4 = createBox(195,195,195); createJoint(box3, box4,0, 50, 50, 2, 50, 50,50, 30,30,30); /* int box = createBox(85,385,185); createJoint(box3, box, 0,50, 50, 3, 50, 50, 3, 0,0,0); int box5 = createBox(95,95,395); createJoint(box, box5, 0,50, 50,5, 50, 50, 0, 0,0,0); */ // createSensor(box2, pressure); //NN test std::vector<NeuralNode*> inputs; for(int i=0;i< (int) sensors.size();i++){ inputs.push_back(new NeuralNode(&sensors.at(i))); } inputs.push_back(new NeuralNode(1)); //index 3 inputs.push_back(new NeuralNode(-2)); //index 4 float* testPoint = new float; *testPoint = 5; inputs.push_back(new NeuralNode(testPoint)); //index 5 theNet = new NeuralNetwork(inputs); theNet->insertNode(SUM,5,3,3,1); theNet->insertNode(SIN,1,1); theNet->changeLayer(); theNet->insertNode(PRODUCT,0,1,2,2); theNet->stopBuilding(); NeuralNetwork* aNet = new NeuralNetwork(theNet->getLastLayer()); aNet->insertNode(PRODUCT,0,0,10000,10000); aNet->stopBuilding(); subnets.push_back(aNet); effectorNNindex.push_back(0); effectorNNindex.push_back(1); effectorNNindex.push_back(2); solveGroundConflicts(); }
int main(){ const int X=1; const int Y=2; const unsigned int R=3; circle myCircle=createCircle(X,Y,R); box myBox=createBox(myCircle); printBound(myBox); return 0; }
PropertyGroup::PropertyGroup(vec2 min, vec2 max, vec2 t, QString name) { createBox(name); properties.emplace_back(new Property(min.x, max.x, t.x, box)); properties.emplace_back(new Property(min.y, max.y, t.y, box)); config(); }
PropertyGroup::PropertyGroup(QVector2D min, QVector2D max, QVector2D t, QString name) { createBox(name); properties.emplace_back(new Property(min.x(), max.x(), t.x(), box)); properties.emplace_back(new Property(min.y(), max.y(), t.y(), box)); config(); }
void readGeometry(scene_data* scene, const boost::property_tree::ptree& pt) { boost::property_tree::ptree::const_iterator iter = pt.begin(); for (; iter != pt.end(); ++iter) { std::string name = iter->first; geometry* geom; if (name == "cube") geom = createBox(); else if (name == "tetrahedron") geom = createTetrahedron(); else if (name == "pyramid") geom = createPyramid(); else if (name == "disk") { int slices = iter->second.get_child("slices").get_value<int>(); geom = createDisk(slices); } else if (name == "cylinder") { int slices = iter->second.get_child("slices").get_value<int>(); int stacks = iter->second.get_child("stacks").get_value<int>(); geom = createCylinder(stacks, slices); } else if (name == "sphere") { int slices = iter->second.get_child("slices").get_value<int>(); int stacks = iter->second.get_child("stacks").get_value<int>(); geom = createSphere(stacks, slices); } else if (name == "torus") { float radius = iter->second.get_child("radius").get_value<float>(); int slices = iter->second.get_child("slices").get_value<int>(); int stacks = iter->second.get_child("stacks").get_value<int>(); geom = createTorus(radius, stacks, slices); } else if (name == "plane") { int width = iter->second.get_child("width").get_value<int>(); int depth = iter->second.get_child("depth").get_value<int>(); geom = createPlane(width, depth); } else if (name == "sierpinski") { int divisions = iter->second.get_child("divisions").get_value<int>(); geom = createSierpinski(divisions); } else { std::cerr << "Error - Geometry type not recognised: " << name << std::endl; exit(EXIT_FAILURE); } scene->geometry[name] = geom; } }
void btWorldFactory::createSlope(QVariantList &shapesList, double areaX, double areaZ, btVector3 pos, btVector3 axis, double minAngle, double maxAngle) { createBox(shapesList, btVector3(areaX,1.0,areaZ), pos, axis*Tools::random(minAngle, maxAngle),0); }
/* * copy the contents of one mailbox to another * either truncates or removes the source box if it succeeds. */ int copyBox(char *from, char *to, int doremove) { MbLock *ml; char *fimp, *timp; int ffd, tfd, ok; if(cistrcmp(from, "inbox") == 0) from = "mbox"; ml = mbLock(); if(ml == nil) return 0; ffd = openLocked(mboxDir, from, OREAD); if(ffd < 0){ mbUnlock(ml); return 0; } tfd = createBox(to, 0); if(tfd < 0){ mbUnlock(ml); close(ffd); return 0; } ok = copyData(ffd, tfd, ml); close(ffd); close(tfd); if(!ok){ mbUnlock(ml); return 0; } fimp = impName(from); timp = impName(to); if(fimp != nil && timp != nil){ ffd = cdOpen(mboxDir, fimp, OREAD); if(ffd >= 0){ tfd = cdCreate(mboxDir, timp, OWRITE, 0664); if(tfd >= 0){ copyData(ffd, tfd, ml); close(tfd); } close(ffd); } } cdRemove(mboxDir, fimp); if(doremove) cdRemove(mboxDir, from); else close(cdOpen(mboxDir, from, OWRITE|OTRUNC)); mbUnlock(ml); return 1; }
PropertyGroup::PropertyGroup(int min, int max, int t, QString name) { createBox(name); properties.emplace_back(new Property(min, max, t, box)); properties.at(0)->spinbox->setDecimals(0); properties.at(0)->spinbox->setSingleStep(1); config(); }
int main(int argc, char** argv) { osgViewer::Viewer viewer; osgWidget::WindowManager* wm = new osgWidget::WindowManager( &viewer, 1280.0f, 1024.0f, MASK_2D, osgWidget::WindowManager::WM_PICK_DEBUG ); wm->setPointerFocusMode(osgWidget::WindowManager::PFM_SLOPPY); osgWidget::Window* box1 = createBox("HBOX", osgWidget::Box::HORIZONTAL); osgWidget::Window* box2 = createBox("VBOX", osgWidget::Box::VERTICAL); osgWidget::Window* box3 = createBox("HBOX2", osgWidget::Box::HORIZONTAL); osgWidget::Window* box4 = createBox("VBOX2", osgWidget::Box::VERTICAL); box1->getBackground()->setColor(1.0f, 0.0f, 0.0f, 0.8f); box1->attachMoveCallback(); box2->getBackground()->setColor(0.0f, 1.0f, 0.0f, 0.8f); box2->attachMoveCallback(); box3->getBackground()->setColor(0.0f, 0.0f, 1.0f, 0.8f); box3->attachMoveCallback(); wm->addChild(box1); wm->addChild(box2); wm->addChild(box3); wm->addChild(box4); box4->hide(); osg::Node* model = osgDB::readNodeFile("spaceship.osgt"); model->setNodeMask(MASK_3D); return osgWidget::createExample(viewer, wm, model); }
bool SimpleShear::generate(std::string& message) { scene = shared_ptr<Scene>(new Scene); createActors(scene); // Box walls shared_ptr<Body> w1; // The left one : createBox(w1,Vector3r(-thickness/2.0,(height)/2.0,0),Vector3r(thickness/2.0,5*(height/2.0+thickness),width/2.0)); scene->bodies->insert(w1); shared_ptr<Body> w2; // The lower one : createBox(w2,Vector3r(length/2.0,-thickness/2.0,0),Vector3r(length/2.0,thickness/2.0,width/2.0)); YADE_PTR_CAST<FrictMat> (w2->material)->frictionAngle = sphereFrictionDeg * Mathr::PI/180.0; // so that we have phi(spheres-inferior wall)=phi(sphere-sphere) scene->bodies->insert(w2); shared_ptr<Body> w3; // The right one createBox(w3,Vector3r(length+thickness/2.0,height/2.0,0),Vector3r(thickness/2.0,5*(height/2.0+thickness),width/2.0)); scene->bodies->insert(w3); shared_ptr<Body> w4; // The upper one createBox(w4,Vector3r(length/2.0,height+thickness/2.0,0),Vector3r(length/2.0,thickness/2.0,width/2.0)); YADE_PTR_CAST<FrictMat> (w4->material)->frictionAngle = sphereFrictionDeg * Mathr::PI/180.0; // so that we have phi(spheres-superior wall)=phi(sphere-sphere) scene->bodies->insert(w4); // To close the front and the back of the box shared_ptr<Body> w5; // behind createBox(w5,Vector3r(length/2.0,height/2.0,-width/2.0-thickness/2.0), Vector3r(2.5*length/2.0,height/2.0+thickness,thickness/2.0)); scene->bodies->insert(w5); shared_ptr<Body> w6; // the front createBox(w6,Vector3r(length/2.0,height/2.0,width/2.0+thickness/2.0), Vector3r(2.5*length/2.0,height/2.0+thickness,thickness/2.0)); scene->bodies->insert(w6); // the list which will contain the positions of centers and the radii of the created spheres vector<BasicSphere> sphere_list; // to use the TriaxialTest method : string out=GenerateCloud(sphere_list,Vector3r(0,0,-width/2.0),Vector3r(length,height,width/2.0),1000,0.3,0.7);// tries to generate a sample of 1000 spheres, with a required porosity of 0.7 cout << out << endl; // to use a text file : // std::pair<string,bool> res=ImportCloud(sphere_list,filename); vector<BasicSphere>::iterator it = sphere_list.begin(); vector<BasicSphere>::iterator it_end = sphere_list.end(); shared_ptr<Body> body; for (;it!=it_end; ++it) { createSphere(body,it->first,it->second); scene->bodies->insert(body); } return true; }
bool SkyBox::init() { if(!initShader()) return false; if(!createBox()) return false; texture = new TextureClass(); texture->init(device, "..\\Shaders\\skybox.dds"); return true; }
void PlatformDemoState::addItems() { std::function<void(const sf::Vector2f&)> createBox = [this](const sf::Vector2f& position) { auto body = xy::Component::create<xy::Physics::RigidBody>(m_messageBus, xy::Physics::BodyType::Dynamic); xy::Physics::CollisionRectangleShape cs({ 100.f, 100.f }, { -50.f, -50.f }); cs.setDensity(11.f); cs.setFriction(0.7f); body->addCollisionShape(cs); auto model = m_meshRenderer.createModel(MeshID::Cube, m_messageBus); model->setBaseMaterial(m_meshRenderer.getMaterial(MatId::Demo)); auto ent = xy::Entity::create(m_messageBus); ent->setPosition(position); ent->addComponent(body); ent->addComponent(model); m_scene.addEntity(ent, xy::Scene::BackFront); }; std::function<void(const sf::Vector2f&)> createBall = [this](const sf::Vector2f& position) { auto body = xy::Component::create<xy::Physics::RigidBody>(m_messageBus, xy::Physics::BodyType::Dynamic); xy::Physics::CollisionCircleShape cs(34.f); cs.setDensity(4.f); cs.setFriction(0.2f); cs.setRestitution(0.8f); body->addCollisionShape(cs); auto model = m_meshRenderer.createModel(MeshID::Sphere, m_messageBus); model->setBaseMaterial(m_meshRenderer.getMaterial(MatId::SphereTest)); auto ent = xy::Entity::create(m_messageBus); ent->setPosition(position); ent->addComponent(body); ent->addComponent(model); m_scene.addEntity(ent, xy::Scene::BackFront); }; for (auto i = 0u; i < 5u; ++i) { createBox({ xy::Util::Random::value(20.f, 2500.f), 20.f }); createBall({ xy::Util::Random::value(20.f, 2500.f), 20.f }); } }
void renderShape(void){ glLoadIdentity(); //Just to be sure glTranslatef(0.0f,0.0f,init_zoom);//Fix Zoom if(menu_open)glTranslatef(boxMatrix[0]/2.0f,0.0f,0.0f); if(rotating){ float tempc = cosf(rot_speed*2.0f*PI / 360.0f); float temps = sinf(rot_speed*2.0f*PI / 360.0f); float tempMatrix[16] = { tempc, 0.0f, -temps, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, temps, 0.0f, tempc, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; multMatrixBA4f(ThisRotMatrix, tempMatrix); } glMultMatrixf(ThisRotMatrix); glTranslatef(-(boxMatrix[0]+boxMatrix[1]+boxMatrix[2])/2.0f, -(boxMatrix[4]+boxMatrix[5])/2.0f, -boxMatrix[8]/2.0f); //Center Box if(box_display)createBox(boxMatrix); for(uint i=0;i<nPart;i++){ glPushMatrix(); glTranslatef(particle[i].coords[0],particle[i].coords[1],particle[i].coords[2]); if(render_points){ glDisable(GL_LIGHTING); glBegin(GL_POINTS); glVertex3f(0.0f,0.0f,0.0f); glEnd(); glEnable(GL_LIGHTING); } else if(!particle[i].hidden){ glScalef(scale,scale,scale); glRotatef(particle[i].rotation[0],particle[i].rotation[1],particle[i].rotation[2],particle[i].rotation[3]); if(particle[i].selected){ glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,emissive); glCallList(sphereDL); glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,black);//Reset Material } else{ glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,CrystalColors[particle[i].solid]); glCallList(sphereDL); } } glPopMatrix(); } if(menu_open)screenFade(); }