void CRaycastTankExample::createTerrain()
{
    // TERRAIN
	IMeshSceneNode *Node = device->getSceneManager()->addMeshSceneNode(device->getSceneManager()->getMesh("terrainMain.b3d")->getMesh(0));
	Node->setPosition(vector3df(0,0,0));
	Node->setMaterialFlag(video::EMF_LIGHTING, false);

    // For the terrain, instead of adding a cube or sphere shape, we are going to
    // add a BvhTriangleMeshShape. This is the standard trimesh shape
    // for static objects. The first parameter is of course the node to control,
    // the second parameter is the collision mesh, incase you want a low-poly collision mesh,
    // and the third parameter is the mass.
	ICollisionShape *shape = new IGImpactMeshShape(Node, device->getSceneManager()->getMesh("terrainMain.b3d"), 0.0);

	shape->setMargin(0.07);

    // The rigid body will be placed at the origin of the node that the collision shape is controlling,
    // so we do not need to set the position after positioning the node.
	IRigidBody *terrain = world->addRigidBody(shape);


    shape->setLocalScaling(vector3df(4,4,4), ESP_BOTH);

	// When setting a rigid body to a static object, please be sure that you have
	// that object's mass set to 0.0. Otherwise, undesired results will occur.
	terrain->setCollisionFlags(ECF_STATIC_OBJECT);
}
예제 #2
0
int main()
{
	int rows = 10, colums = 10;
	printf("Number of stack rows: ");
	cin >> rows;
	printf("\nNumber of stack colums: ");
	cin >> colums;
	CReceiver receiver;
	IrrlichtDevice *device = createDevice(EDT_DIRECT3D9, dimension2d<u32>(640, 480), 16, false, false, false, &receiver);
	IVideoDriver *driver = device->getVideoDriver();
	ISceneManager *smgr = device->getSceneManager();
	IGUIEnvironment *guienv = device->getGUIEnvironment();
	device->setWindowCaption(L"HelloWorld");
	irrBulletWorld * world = createIrrBulletWorld(device, true, true);
	world->setDebugMode(EPDM_DrawAabb | EPDM_DrawContactPoints);
	world->setGravity(core::vector3df(0, -10, 0));
	createWorld(rows, colums, device, world);
	scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
	camera->setPosition(core::vector3df(50, 15, 200));
	u32 then = device->getTimer()->getTime();
	while (device->run())
	{
		const u32 now = device->getTimer()->getTime();
		const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // в секундах
		then = now;
		if (receiver.isMouseDown(EMIE_RMOUSE_PRESSED_DOWN))
		{
			core::vector3df pos(camera->getPosition().X, camera->getPosition().Y, camera->getPosition().Z);
			scene::ISceneNode *Node = smgr->addCubeSceneNode();
			Node->setScale(core::vector3df(0.2, 0.2, 0.2));
			Node->setPosition(pos);
			Node->setMaterialFlag(video::EMF_LIGHTING, false);
			Node->setMaterialTexture(0, driver->getTexture("../rockwall.jpg"));
			ICollisionShape *shape = new IBoxShape(Node, 1, true);
			IRigidBody *body = world->addRigidBody(shape);
			body->setDamping(0.2, 0.2);
			body->setFriction(0.4f);
			body->setGravity(core::vector3df(0, -10, 0));
			core::vector3df rot = camera->getRotation();
			core::matrix4 mat;
			mat.setRotationDegrees(rot);
			core::vector3df forwardDir(core::vector3df(mat[8], mat[9], mat[10]) * 120);
			body->setLinearVelocity(forwardDir);
		}

		driver->beginScene(true, true, video::SColor(255, 100, 101, 140));
		world->stepSimulation(frameDeltaTime, 120);
		world->debugDrawWorld(true);
		world->debugDrawProperties(true);
		smgr->drawAll();
		guienv->drawAll();
		driver->endScene();

		if (world) delete world;
		device->drop();
		return 0;
	}
}
예제 #3
0
bool CLiquidbodyExample::OnEvent(const SEvent& event)
{
	if (!device)
		return false;

    switch(event.EventType)
    {
        case EET_MOUSE_INPUT_EVENT:
        {
            if(event.MouseInput.Event==EMIE_LMOUSE_PRESSED_DOWN)
            {
                IRigidBody* body = shootCube(vector3df(10,10,10), 2, "crate.jpg");

                irr::f32 t = 0.5f;
                irr::f32 buoyancy = 0.8f;

                irr::core::array<SBuoyancyPoint> points;
                //points.push_back(SBuoyancyPoint(irr::core::vector3df(0,0,0), 180.0f));
                points.push_back(SBuoyancyPoint(irr::core::vector3df(t,t,t), buoyancy));
                points.push_back(SBuoyancyPoint(irr::core::vector3df(-t,t,t), buoyancy));
                points.push_back(SBuoyancyPoint(irr::core::vector3df(-t,t,-t), buoyancy));
                points.push_back(SBuoyancyPoint(irr::core::vector3df(t,t,-t), buoyancy));

                points.push_back(SBuoyancyPoint(irr::core::vector3df(-t,-t,t), buoyancy));
                points.push_back(SBuoyancyPoint(irr::core::vector3df(t,-t,t), buoyancy));
                points.push_back(SBuoyancyPoint(irr::core::vector3df(-t,-t,-t), buoyancy));
                points.push_back(SBuoyancyPoint(irr::core::vector3df(t,-t,-t), buoyancy));


                body->setBuoyancyPoints(points);
                return true;
            }

            else
            if(event.MouseInput.Event==EMIE_RMOUSE_PRESSED_DOWN)
            {
                IRigidBody* body = shootSphere(vector3df(0.2,0.2,0.2), 0.2);

                body->getBuoyancyPointByIndex(0).buoyancy = 0.0f;
                return true;
            }
        }
        break;

        case EET_KEY_INPUT_EVENT:
        {
            if(event.KeyInput.Key == KEY_KEY_P && event.KeyInput.PressedDown == false)
            {
                world->pauseSimulation(!world->simulationPaused());
                return true;
            }
        }
        break;
        default:
            break;
    }
    return false;
}
예제 #4
0
IRigidBody* irrBulletWorld::addRigidBody(ICollisionShape *shape, s32 group, s32 mask)
{
    IRigidBody* b = new IRigidBody(this, shape);
    collisionObjects.push_back(b);
    getPointer()->addRigidBody(b->getPointer(), group, mask);

    CollisionObjectCount++;

    return b;
}
예제 #5
0
void GameScene::onLoad(){
  
  character = new Character(world, device, smgr->getMesh("obj/character.x"));
  character2 = new Character(world, device, smgr->getMesh("obj/character.x"));
  
  character2->setPos(core::vector3df(0.0f,40.0f,0.0f));
  irr::scene::ISceneNode *Cube = device->getSceneManager()->addCubeSceneNode(1.0f);
	Cube->setScale(core::vector3df(1.0f,1.0f,1.0f));
	Cube->setPosition(core::vector3df(0.0f,40.0f, 0.0f));
	Cube->setMaterialFlag(irr::video::EMF_LIGHTING, true);
	Cube->setMaterialFlag(irr::video::EMF_NORMALIZE_NORMALS, true);

	ICollisionShape *cshape = new IBoxShape(Cube, 1.0f, false);

	//shape->setMargin(0.01);

	IRigidBody *body;
	body = world->getIrrBulletWorld()->addRigidBody(cshape);
    
    //adding terrain
    // TERRAIN
	scene::IMeshSceneNode *Node = device->getSceneManager()->addMeshSceneNode(device->getSceneManager()->getMesh("../media/terrainMain.b3d"),
                                        0, 1 | TERRAINID, core::vector3df(0.0f,0.0f,0.0f), core::vector3df(0.0f,0.0f,0.0f), core::vector3df(1.0f,1.0f,1.0f));
  
	Node->setPosition(core::vector3df(0,0,0));
	Node->setMaterialFlag(video::EMF_LIGHTING, false);
    
    //change texturemapping of terrain
    core::matrix4 m;
    
    m = Node->getMaterial(0).getTextureMatrix(0);
    m.setTextureScale(10.0f,10.0f);
    Node->getMaterial(0).setTextureMatrix(0, m);
    
    scene::ITriangleSelector* selector = 0;


    // Now create a triangle selector for it.  The selector will know that it
    // is associated with an animated node, and will update itself as necessary.
    selector = device->getSceneManager()->createTriangleSelector(Node->getMesh(), Node);
    Node->setTriangleSelector(selector);
    selector->drop(); // We're done with this selector, so drop it now.
    
    // For the terrain, instead of adding a cube or sphere shape, we are going to
    // add a BvhTriangleMeshShape. This is the standard trimesh shape
    // for static objects. The first parameter is of course the node to control,
    // the second parameter is the collision mesh, incase you want a low-poly collision mesh,
    // and the third parameter is the mass.
	ICollisionShape *shape = new IBvhTriangleMeshShape(Node, Node->getMesh(), 0.0);

	shape->setMargin(0.07);

    // The rigid body will be placed at the origin of the node that the collision shape is controlling,
    // so we do not need to set the position after positioning the node.
	IRigidBody *terrain = world->getIrrBulletWorld()->addRigidBody(shape);


    shape->setLocalScaling(core::vector3df(4,4,4), ESP_BOTH);

	// When setting a rigid body to a static object, please be sure that you have
	// that object's mass set to 0.0. Otherwise, undesired results will occur.
	terrain->setCollisionFlags(ECF_STATIC_OBJECT);
  //
    
  ///////////////////////////////////////////////
  //create Selected Position animation
  selectedPos = smgr->addVolumeLightSceneNode(0, -1,
                                32,                              // Subdivisions on U axis
                                32,                              // Subdivisions on V axis
                                video::SColor(0, 255, 255, 255), // foot color
                                video::SColor(0, 0, 0, 0));      // tail color

  if (selectedPos)
  {
          selectedPos->setScale(core::vector3df(10.0f, 10.0f, 10.0f));
          selectedPos->setPosition(core::vector3df(-120,50,40));

          // load textures for animation
          core::array<video::ITexture*> textures;
          for (s32 g=7; g > 0; --g)
          {
                  core::stringc tmp;
                  
                  tmp = "obj/img/portal";
                  tmp += g;
                  tmp += ".bmp";
                  video::ITexture* t = driver->getTexture( tmp.c_str() );
                  textures.push_back(t);
          }

          // create texture animator
          scene::ISceneNodeAnimator* glow = smgr->createTextureAnimator(textures, 150);

          // add the animator
          selectedPos->addAnimator(glow);

          // drop the animator because it was created with a create() function
          glow->drop();
  }
  
  ///////////////////////////////////////////////////
  
  //add lightning
  smgr->addLightSceneNode(0, core::vector3df(20, 40, -50), video::SColorf(1.0f, 1.0f, 1.0f), 4000.0f);
  smgr->addLightSceneNode(0, core::vector3df(20, -40, -50), video::SColorf(1.0f, 1.0f, 1.0f), 4000.0f);
  //
  
  //add debug camera
  camera = smgr->addCameraSceneNode();
  camera->setPosition(core::vector3df(12.0f,50.0f,30.0f));
  camera->setTarget(core::vector3df(0.0f,0.0f,0.0f));
  //
        
  collMan = smgr->getSceneCollisionManager();
}
예제 #6
0
void CLiquidbodyExample::runExample()
{
    debugDraw = true;
    drawProperties = true;
    drawWireFrame = false;

    int rows=2, columns=2;

    device =
        createDevice( video::EDT_OPENGL, dimension2d<u32>(640, 480), 16,
            false, false, false, this);

    printf("Please enter the number of rows and columns of floating objects to create: \n");

    cin >> rows;
    cin >> columns;


    device->setWindowCaption(L"irrBullet Liquidbody Example - Josiah Hartzell");

    device->getFileSystem()->addFolderFileArchive("../../media/");


    ILightSceneNode* light = device->getSceneManager()->addLightSceneNode(0, vector3df(20, 40, -50), SColorf(1.0f, 1.0f, 1.0f), 4000.0f);
    light->setLightType(ELT_DIRECTIONAL);
    light->setRotation(vector3df(0,200,30));

    device->getSceneManager()->setAmbientLight(SColor(100,100,100,100));

    camera = device->getSceneManager()->addCameraSceneNodeFPS();
	camera->setPosition(vector3df(50,15,4));
	camera->setTarget(vector3df(0,0,0));


    ////////////////////////////
    // Create irrBullet World //
    ////////////////////////////
    world = createIrrBulletWorld(device, true, debugDraw);

    world->setDebugMode(EPDM_DrawAabb |
            EPDM_DrawContactPoints);

    world->setGravity(vector3df(0,-10,0));

    ILiquidBody* water = world->addLiquidBody(vector3df(-5000,0,5000),irr::core::aabbox3df(0, -10000, 0, 10000, 0, 10000), 500.0f, 200.0f);
    water->setCurrentDirection(vector3df(0,0,0));
    water->setGlobalWaveChangeIncrement(0.01f);
    water->setGlobalWaveUpdateFrequency(1.0f);
    water->setMaxGlobalWaveHeight(4.0f);
    water->setMinGlobalWaveHeight(-1.0f);
    water->setLocalWaveValues(10,1,0.5f);
    water->setInfinite(true);
    water->setInfiniteDepth(true);
    water->setLiquidDensity(0.1f);
    //water->setDebugDrawEnabled(false);


    IAnimatedMesh* mesh = device->getSceneManager()->addHillPlaneMesh( "myHill",
		core::dimension2d<f32>(20,20),
		core::dimension2d<u32>(40,40), 0, 0,
		core::dimension2d<f32>(0,0),
		core::dimension2d<f32>(1000,1000));

	ISceneNode* node = device->getSceneManager()->addWaterSurfaceSceneNode(mesh->getMesh(0), 0.0f, 300.0f, 30.0f);
	node->setPosition(core::vector3df(0,5,0));

	node->setMaterialTexture(0, device->getVideoDriver()->getTexture("water.jpg"));
	node->setScale(vector3df(1000,1,1000));

	node->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
	node->setMaterialFlag(EMF_BACK_FACE_CULLING, false);


	for(u32 i=0; i < rows; i++)
	{
	    for(u32 j=0; j < columns; j++)
        {
            IRigidBody* body = addCube(vector3df(i*15,0,j*15), vector3df(10,10,10), 1, "crate.jpg");

            irr::f32 t = 0.5f;
            irr::f32 buoyancy = 0.2f;

            irr::core::array<SBuoyancyPoint> points;
            //points.push_back(SBuoyancyPoint(irr::core::vector3df(0,0,0), 180.0f));
            points.push_back(SBuoyancyPoint(irr::core::vector3df(t,t,t), buoyancy));
            points.push_back(SBuoyancyPoint(irr::core::vector3df(-t,t,t), buoyancy));
            points.push_back(SBuoyancyPoint(irr::core::vector3df(-t,t,-t), buoyancy));
            points.push_back(SBuoyancyPoint(irr::core::vector3df(t,t,-t), buoyancy));

            points.push_back(SBuoyancyPoint(irr::core::vector3df(-t,-t,t), buoyancy));
            points.push_back(SBuoyancyPoint(irr::core::vector3df(t,-t,t), buoyancy));
            points.push_back(SBuoyancyPoint(irr::core::vector3df(-t,-t,-t), buoyancy));
            points.push_back(SBuoyancyPoint(irr::core::vector3df(t,-t,-t), buoyancy));


            /*ICollisionObjectAffectorBuoyancy* affector = new ICollisionObjectAffectorBuoyancy(points,
                irr::core::aabbox3df(0, -100, 0, 10000, 0, 10000), 1);
            affector->setDebugDrawing(true);
            body->addAffector(affector);*/
            body->setBuoyancyPoints(points);

            //body->setActivationState(EAS_DISABLE_DEACTIVATION);
        }
	}

    // Set our delta time and time stamp
    u32 TimeStamp = device->getTimer()->getTime();
    u32 DeltaTime = 0;
    while(device->run())
    {
        device->getVideoDriver()->beginScene(true, true, SColor(255,100,101,140));

        DeltaTime = device->getTimer()->getTime() - TimeStamp;
		TimeStamp = device->getTimer()->getTime();

		// Step the simulation with our delta time
        world->stepSimulation(DeltaTime*0.001f, 120);
        //static_cast<ISoftBody*>(world->getCollisionObjectByName("SOFTBODY1"))->addForce(vector3df(-2,0,0));


        //world->debugDrawWorld(debugDraw);
        // This call will draw the technical properties of the physics simulation
        // to the GUI environment.
        world->debugDrawProperties(drawProperties);


        device->getSceneManager()->drawAll();
        device->getGUIEnvironment()->drawAll();

        device->getVideoDriver()->endScene();
    }
    //delete Liquid;

    // We're done with the IrrBullet world, so we free the memory that it takes up.
    if(world)
        delete world;

    if(device)
        device->drop();
}