Esempio n. 1
0
	void PlaypenApp::createWall(unsigned int length, unsigned height, 
		const opal::Vec3r& boxDim, const opal::Matrix44r& baseTransform, 
		const std::string& material)
	{
		for (unsigned int l=0; l<length; ++l)
		{
			for (unsigned int h=0; h<height; ++h)
			{
				opal::real offset = 0;
				if (h % 2 == 0)
				{
					offset = (opal::real)0.5 * boxDim[0];
				}

				opal::Matrix44r blockTransform = baseTransform;
				blockTransform.translate(l * boxDim[0] + 
					0.5 * boxDim[0] - 0.5 * length * boxDim[0] + 
					offset, h * boxDim[1] + 0.5 * boxDim[1], 0);

				opal::Solid* s = mSimulator->createSolid();
				s->setTransform(blockTransform);
				//s->setSleeping(true);
				opal::BoxShapeData boxData;
				boxData.dimensions = boxDim;
				boxData.material.density = 6;
				boxData.material.hardness = 0.4;
				s->addShape(boxData);
				Ogre::Vector3 boxDimensions(boxDim[0], boxDim[1], boxDim[2]);
				createPhysicalEntityBox("", material, boxDimensions, s);
			}
		}
	}
Esempio n. 2
0
void UIBox::resize(int width, int height) {
    //Renderable *renderable;
    float ratio = (width / (float)height);

    int bWidth  = (int)(_uiBorder * width),
        bHeight = (int)(_uiBorder * height * ratio);

    UIElement::resize(width, height);

    clearRenderables();

    // Add the center box
    Vec2f boxPosition(0, 0);
    Vec2f boxDimensions((float)_dimensions.x, (float)_dimensions.y);
    if(_uiBorder > 0) {
        // Subtract space for the border if there is a border that protrudes inwards
        boxPosition += Vec2f((float)bWidth, (float)bHeight);
        boxDimensions -= Vec2f(bWidth * 2.0f, bHeight * 2.0f);
    }
    addRenderable(Renderable::OrthoBox(boxPosition, boxDimensions, false, false, _material));

    if(_uiBorder != 0) {
        int bXOffset = 0, bYOffset = 0;
        if(_uiBorder < 0) {
            bXOffset = bWidth;
            bYOffset = bHeight;
        }
        
        // Top border
        addRenderable(Renderable::OrthoBox(Vec2f((float)bWidth, (float)_dimensions.h), Vec2f((float)(_dimensions.w - (bWidth * 2)), (float)-bHeight), false, false, _borderMaterial));

        // Bottom border
        addRenderable(Renderable::OrthoBox(Vec2f((float)bWidth, 0.0f), Vec2f((float)(_dimensions.w - (bWidth * 2)), (float)bHeight), false, false, _borderMaterial));
        
        // Left border
        addRenderable(Renderable::OrthoBox(Vec2f((float)bWidth, 0.0f), Vec2f((float)-bWidth, (float)_dimensions.y), false, false, _borderMaterial));

        // Right border
        addRenderable(Renderable::OrthoBox(Vec2f((float)_dimensions.w, 0.0f), Vec2f((float)-bWidth, (float)_dimensions.y), false, false, _borderMaterial));
    }
}
Esempio n. 3
0
void CState::fillBoxes()
{
    cout << "CState::fillBoxes()" << endl;

    vec3 atomPosition;
    ivec3 boxIndex;
    CAtom* atomptr;

    for (int i = 0; i < nAtoms; i++)
    {
        atomptr = atoms[i];
        atomPosition = atomptr->getPosition();
        for (int j = 0; j < 3; j++)
        {
            boxIndex(j) = int(floor(atomPosition(j)/boxDimensions(j)));
        }
        boxes[calculate_box_number(boxIndex, NBoxes)]->addAtom(atomptr);
    }

    cout << "Exiting CState::fillBoxes()" << endl << endl;
}
Esempio n. 4
0
    void WorldTest::simulationTestUncached() {
        World* world = new World(Vector3(200000, 200000, 200000));
        world->setUseCollisionCaching(false);
        Vector3 boxDimensions(10, 10, 10);
        Proxy* box1 = world->createProxy(new Box(boxDimensions));
        //Proxy* childBox = world->createProxy(new Box(boxDimensions));
        //childBox->translate(5, 5, 5);
        //box->addChild(childBox);

        world->addProxy(box1);

        Proxy* box2 = world->createProxy(new Box(boxDimensions));
        box2->translate(0, -20, 0);
        world->addProxy(box2);

        Proxy* box3 = world->createProxy(new Box(boxDimensions)); //always colliding with box2
        box3->translate(5, -25, 0);
        world->addProxy(box3);

        
        Proxy* moveBox = world->createProxy(new Box(Vector3(10, 50, 10)));
        moveBox->translate(20, -25, 0); //starting in no-collision state
        world->addProxy(moveBox);

        //WorldCollisions coll;
        
        world->prepareSimulation();
//std::cout << "-----------Starting simulation test-----------"<<std::endl;
//std::cout << "doing pre-move collisionCheck"<<std::endl;
        //test and ensure 1 BPC and rigid C
        WorldCollisions coll0 = world->calculateAllCollisions();
        CPPUNIT_ASSERT_EQUAL(1,
                (int)coll0.getBroadPhaseCollisions()->getResults().size());
        CPPUNIT_ASSERT_EQUAL(1, (int)coll0.getRigidBoundingVolumeCollisions().size());

        //Step 1 -> move moveBox to collidy with box3
//std::cout <<std::endl<< "doing step 1 - move in to collide with box3"<<std::endl;
        moveBox->translate(-6, 0, 0);

        //ensure 2 BPC/RC
        WorldCollisions coll1  = world->calculateAllCollisions();
        CPPUNIT_ASSERT_EQUAL(2,
                (int)coll1.getBroadPhaseCollisions()->getResults().size());
        CPPUNIT_ASSERT_EQUAL(2, (int)coll1.getRigidBoundingVolumeCollisions().size());

        //Step 2-> move to collide with all boxes
//std::cout <<std::endl<<"doing step 2 - move further to collide with all"<<std::endl;
        moveBox->translate(-5, 0, 0);
        //ensure 4 collisions
        WorldCollisions coll2  = world->calculateAllCollisions();
        CPPUNIT_ASSERT_EQUAL(4,
                (int)coll2.getBroadPhaseCollisions()->getResults().size());
        CPPUNIT_ASSERT_EQUAL(4, (int)coll2.getRigidBoundingVolumeCollisions().size());

        //Step 3-> move out again
//std::cout << std::endl<<"doing step 3 - moving out"<<std::endl;
        moveBox->translate(11, 0, 0);
        //ensure 1 collisions
        WorldCollisions coll3  = world->calculateAllCollisions();
        CPPUNIT_ASSERT_EQUAL(1,
                (int)coll3.getBroadPhaseCollisions()->getResults().size());
        CPPUNIT_ASSERT_EQUAL(1, (int)coll3.getRigidBoundingVolumeCollisions().size());

        //Step 4-> move in again
//std::cout << std::endl<<"doing step 4 - moving back in"<<std::endl;
        moveBox->translate(-11, 0, 0);
        //ensure 4 collisions
        WorldCollisions coll4  = world->calculateAllCollisions();
        CPPUNIT_ASSERT_EQUAL(4,
                (int)coll4.getBroadPhaseCollisions()->getResults().size());
        CPPUNIT_ASSERT_EQUAL(4, (int)coll4.getRigidBoundingVolumeCollisions().size());

        delete world;
    }