Ejemplo n.º 1
0
 int main()
 {
    IrrlichtDevice* irrDevice   = createDevice(EDT_OPENGL,dimension2d<s32>(800,600),32,false,false,false,0);
    IVideoDriver*   irrVideo    = irrDevice->getVideoDriver();
    ISceneManager*  irrSceneMgr = irrDevice->getSceneManager();
    TMovie* movie = new TMovie(irrDevice->getTimer());
    movie->LoadMovie("Mymovie.avi");
    irrVideo->setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false);
    u32 w = movie->getMovieWidth();
    u32 h = movie->getMovieHeight();
    ITexture* movTxtr = irrVideo->addTexture(dimension2d<s32>(w<513?512:1024,h<513?512:1024),"imovie"); 
    irrSceneMgr->addCameraSceneNode(0, vector3df(0,0,-20), vector3df(0,0,0));
    CSampleSceneNode* myNode = new CSampleSceneNode(irrSceneMgr->getRootSceneNode(), irrSceneMgr, 666);
    myNode->setMaterialTexture( 0, movTxtr);
    myNode->drop();
    ISceneNodeAnimator* anim = irrSceneMgr->createRotationAnimator(vector3df(0,0.1f,0));
    myNode->addAnimator(anim);
    anim->drop();
 
    while(irrDevice->run())
     {
        irrVideo->beginScene(true, true, SColor(0,200,200,200));
                  if (movie->NextMovieFrame())
                    movie->DrawMovie(0,0,movTxtr);
                  irrSceneMgr->drawAll();
        irrVideo->endScene();
     }       
    irrDevice->drop();

    return 0;
}
Ejemplo n.º 2
0
int example_customscenenode()
{
    // create device
    IrrlichtDevice *device = startup();
    if (device == 0) return 1; // could not create selected driver.

    // create engine and camera
    EventReceiver_basic receiver(device);
    device->setEventReceiver(&receiver);

    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();

    smgr->addCameraSceneNode(0, vector3df(0, -40, 0), vector3df(0, 0, 0));

    CSampleSceneNode *myNode = new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666);

    ISceneNodeAnimator* anim = smgr->createRotationAnimator(vector3df(0.8f, 0, 0.8f));

    if (anim) {
        myNode->addAnimator(anim);
        anim->drop();
        anim = 0; // As I shouldn't refer to it again, ensure that I can't
    }

    myNode->drop();
    myNode = 0; // As I shouldn't refer to it again, ensure that I can't

    return run(device);
}
Ejemplo n.º 3
0
/*********************************************************************
 * Animates a muzzle flash billboard with firing sound and does
 * damage to borbie.  This method is only called when the soldier
 * is within range and has direct line of sight.  He has an 80%
 * chance of hitting his target.
 *********************************************************************/
void Soldier::fire(int distance){
	lastFireTime = gameInstance->getDevice()->getTimer()->getTime();
	IBillboardSceneNode * bill;
	bill = smgr->addBillboardSceneNode();
	bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
    bill->setMaterialTexture(0, driver->getTexture("assets/textures/muzFlash.png"));
	bill->setMaterialFlag(video::EMF_LIGHTING, false);
	bill->setMaterialFlag(video::EMF_ZBUFFER, false);
	float randomNum = Random::randomFloat(-10.0, 15.0);
	bill->setSize(core::dimension2d<f32>(30.0+randomNum, 30.0+randomNum));
	bill->setID(0);//not pickable by ray caster
		
	//get enemy position, adjust muzzle flash height to barrel
	vector3df start = sceneNode->getPosition();
	start.Y+=60;
	bill->setPosition(start);

    this->audioSystem->playSound3d(gameInstance->gunShot1,
	    this);
	
	const int MUZZLE_FLASH_TIME = 50;
	
	ISceneNodeAnimator* anim =
	    gameInstance->getSceneManager()->createDeleteAnimator(MUZZLE_FLASH_TIME);
	bill->addAnimator(anim);
	anim->drop();
    if (!miss(distance))
	    gameInstance->player->applyBulletDamage(BULLET_DAMAGE);
    else
        gameInstance->player->ricochet();		
}
void CRaycastTankExample::createMuzzleFlash(irr::scene::IBoneSceneNode *node)
{
    IBillboardSceneNode *muzzleFlash = device->getSceneManager()->addBillboardSceneNode(0,
        dimension2d<f32>(30.0f, 30.0f), node->getAbsoluteTransformation().getTranslation());

    muzzleFlash->setMaterialFlag(EMF_LIGHTING, false);
    muzzleFlash->setMaterialTexture(0,device->getVideoDriver()->getTexture("particlewhite.bmp"));
    muzzleFlash->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);


    ISceneNodeAnimator* deleteAnim = device->getSceneManager()->createDeleteAnimator(100);
    muzzleFlash->addAnimator(deleteAnim);
    deleteAnim->drop();
}
Ejemplo n.º 5
0
	int Java_zte_irrlib_scene_SceneNode_nativeAddDeleteAnimator(
		JNIEnv *env, jobject defaultObj, jint ms, jint id)
	{
		ISceneNode* node = smgr->getSceneNodeFromId(id);
		if (!node) 
		{
			WARN_NODE_NOT_FOUND(id, AddDeleteAnimator);
			return -1;
		}				
		ISceneNodeAnimator* anim = smgr->createDeleteAnimator(ms);
		node->addAnimator(anim);
		anim->drop();
		return 0;
	}
Ejemplo n.º 6
0
	int Java_zte_irrlib_scene_SceneNode_nativeAddRotationAnimator(
		JNIEnv*  env, jobject defaultObj, jdouble x, jdouble y, jdouble z,
		jint id)
	{
		ISceneNode* node = smgr->getSceneNodeFromId(id);
		if (!node) 
		{
			WARN_NODE_NOT_FOUND(id, AddRotationAnimator);
			return -1;
		}
		ISceneNodeAnimator* anim = smgr->createRotationAnimator(vector3df(x,y,z));
		node->addAnimator(anim);
		anim->drop();
		return 0;
	}
Ejemplo n.º 7
0
/** Tests the offset capability of the fly circle animator */
bool flyCircleAnimator(void)
{
	IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO,
										core::dimension2du(160,120), 32);
	if (!device)
		return false;

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();

	const f32 offsetDegrees[] = { 0.f, 45.f, 135.f, 270.f };

	for(u32 i = 0; i < sizeof(offsetDegrees) / sizeof(offsetDegrees[0]); ++i)
	{
		IBillboardSceneNode * node = smgr->addBillboardSceneNode();
		// Have the animator rotate around the Z axis plane, rather than the default Y axis
		ISceneNodeAnimator * animator = smgr->createFlyCircleAnimator(
				vector3df(0, 0, 0), 30.f, 0.001f,
				vector3df(0, 0, 1), (offsetDegrees[i] / 360.f));
		if(!node || !animator)
			return false;

		node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
		node->setMaterialTexture(0, driver->getTexture("../media/particle.bmp"));
		node->setMaterialFlag(video::EMF_LIGHTING, false);

		node->addAnimator(animator);
		animator->drop();
	}

	(void)smgr->addCameraSceneNode(0, vector3df(0, 0, -50), vector3df(0, 0, 0));

	bool result = false;

	// Don't do device->run() since I need the time to remain at 0.
	if (driver->beginScene(true, true, video::SColor(0, 80, 80, 80)))
	{
		smgr->drawAll();
		driver->endScene();
		result = takeScreenshotAndCompareAgainstReference(driver, "-flyCircleAnimator.png", 100);
	}

	device->closeDevice();
	device->run();
	device->drop();

	return result;
}
Ejemplo n.º 8
0
/*********************************************************************
 * Moves the soldier toward the enemy, only gets called when
 * there is a direct line of sight
 *********************************************************************/
void Soldier::moveToPlayer(){
    vector3df start = sceneNode->getPosition();
    destination = gameInstance->getCamera()->getPosition();
    destination.X = start.X + 0.2*(destination.X-start.X);
    destination.Z = start.Z + 0.2*(destination.Z-start.Z);
    destination.Y = 70;//ground height
    f32 length = (f32)ray.start.getDistanceFrom(destination);
    const int SOLDIER_MOVE_SPEED = 1.5;
    f32 time = length * SOLDIER_MOVE_SPEED;
    ISceneNodeAnimator* anim =
            gameInstance->getSceneManager()->createFlyStraightAnimator(start,
            destination, time, false);
    sceneNode->addAnimator(anim);
    anim->drop();
    moving = true;
}
Ejemplo n.º 9
0
  void Entity::addCollision(Entity coll, f32 tx, f32 ty, f32 tz,  f32 sx, f32 sy, f32 sz, f32 gx, f32 gy, f32 gz)
  {
    ITriangleSelector* selector = 0;

    if(coll.type == MESH_TYPE)
    {
      selector = Scene->createTriangleSelector(coll.tmesh, coll.sceneNode);
      coll.sceneNode->setTriangleSelector(selector);
    }
    if(coll.type == ANIM_TYPE)
    {
      selector = Scene->createTriangleSelector(coll.animNode->getMesh(), coll.animNode);
      coll.animNode->setTriangleSelector(selector);
    }
    if(coll.type == MAP_TYPE)
    {
      selector = Scene->createOctreeTriangleSelector(coll.bmesh->getMesh(0), coll.sceneNode);
      coll.sceneNode->setTriangleSelector(selector);
    }


    ISceneNodeAnimator* anim;

    if(type == MESH_TYPE)
    {
      anim = Scene->createCollisionResponseAnimator(selector, sceneNode, vector3df(sx,sy,sz), \
        vector3df(gx,gy,gz), vector3df(tx,ty,tz));
      sceneNode->addAnimator(anim);
    }
    if(type == ANIM_TYPE)
    {
      anim = Scene->createCollisionResponseAnimator(selector, animNode, vector3df(sx,sy,sz), \
        vector3df(gx,gy,gz), vector3df(tx,ty,tz));
      animNode->addAnimator(anim);
    }
    if(type == MAP_TYPE)
    {
      anim = Scene->createCollisionResponseAnimator(selector, sceneNode, vector3df(sx,sy,sz), \
        vector3df(gx,gy,gz), vector3df(tx,ty,tz));
      sceneNode->addAnimator(anim);
    }
    else
      return;

    selector->drop();
    anim->drop();
  }
Ejemplo n.º 10
0
	int Java_zte_irrlib_scene_SceneNode_nativeAddCollisionResponseAnimator(
		JNIEnv *env, jobject defaultObj, jint selId, jobject jradius, jboolean bbox, jboolean octree, jint id)
	{
		ISceneNode* selNode = smgr->getSceneNodeFromId(selId);
		if (!selNode)
		{
			WARN_NODE_NOT_FOUND(selId, AddCollisionResponseAnimator);
			return -1;
		}
		
		ISceneNode* node = smgr->getSceneNodeFromId(id);
		if (!node)
		{
			WARN_NODE_NOT_FOUND(id, AddCollisionResponseAnimator);
			return -1;
		}
		
		ITriangleSelector* selector = 0;
		if (bbox) selector = smgr->createTriangleSelectorFromBoundingBox(selNode);
		else if (!octree) selector = smgr->createTriangleSelector(((IMeshSceneNode*)selNode)->getMesh(), selNode);
		else selector = smgr->createTriangleSelector(((IMeshSceneNode*)selNode)->getMesh(), selNode);
		
		node->updateAbsolutePosition();
		const aabbox3d<f32>& box = node->getTransformedBoundingBox();
		
		vector3df radius;
		if (jradius == 0)
			radius = box.MaxEdge-box.getCenter();
		else radius = utils->createvector3dfFromVector3d(env, jradius);
		
		vector3df translation = -(box.getCenter() - node->getAbsolutePosition());
		
		//LOGD("max, %f, %f, %f", box.MaxEdge.X, box.MaxEdge.Y, box.MaxEdge.Z);
		//LOGD("min, %f, %f, %f", box.MinEdge.X, box.MinEdge.Y, box.MinEdge.Z);
		//LOGD("trans, %f, %f, %f", translation.X, translation.Y, translation.Z);
		ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(selector, node,
			radius,
			vector3df(),/*gravity*/
			translation,
			0.0005f
		);
		selector->drop();
		node->addAnimator(anim);
		anim->drop();
	}
Ejemplo n.º 11
0
//! creates a scene node animator based on its type id
ISceneNodeAnimator* CBulletAnimatorManager::createSceneNodeAnimator(ESCENE_NODE_ANIMATOR_TYPE type, ISceneNode* target)
{
  ESCENE_NODE_BULLET_ANIMATOR_TYPE animType = (ESCENE_NODE_BULLET_ANIMATOR_TYPE)type;

  ISceneNodeAnimator* anim = NULL;
  switch (animType)
  {
    case ESNAT_BULLET_WORLD:
    {
      // create bullet world animator
      //if (BulletWorldAnimator != NULL) { BulletWorldAnimator->drop(); BulletWorldAnimator = NULL; } 
      anim = createEmptyBulletWorldAnimator(sceneManager, target);
    } break;

    case ESNAT_BULLET_OBJECT:
    {
      // create object
      anim = createEmptyBulletObjectAnimator(sceneManager, target);
    } break;

	//나중에 확장을...
	case ESNAT_BULLET_OBJECT_FPS_CTRL:
    {
      // create object		
		//anim = new CBulletFpsCamAnimator();
	
		//anim = createBulletFpsCamAnimator(sceneManager, target);
    } break;
	case ESNAT_BULLET_OBJECT_CHACTER_CTRL:
    {
      // create object
		anim = new CBulletChracterAnimator();
		target->addAnimator(anim);
		anim->drop();
		//anim = createBulletCharcterAnimator(sceneManager, target,0,);
    } break;
  }

  if (anim && target)
  {
    target->addAnimator(anim);
  }

  return anim;
}
Ejemplo n.º 12
0
	int Java_zte_irrlib_scene_SceneNode_nativeAddFlyCircleAnimator(
		JNIEnv*  env, jobject defaultObj, jdouble cx, jdouble cy, jdouble cz,
		jdouble radius, jdouble speed, jdouble ax, jdouble ay, jdouble az, 
		jdouble startPosition, jdouble radiusEllipsoid, jint id)
	{
		ISceneNode* node = smgr->getSceneNodeFromId(id);
		if (!node) 
		{
			WARN_NODE_NOT_FOUND(id, AddFlyCircleAnimator);
			return -1;
		}		
		
		ISceneNodeAnimator* anim = 
			smgr->createFlyCircleAnimator(vector3df(cx,cy,cz),radius,speed,vector3df(ax, ay, az), startPosition, radiusEllipsoid);
		node->addAnimator(anim);
		anim->drop();
		return 0;
	}
Ejemplo n.º 13
0
	int Java_zte_irrlib_scene_SceneNode_nativeAddFlyStraightAnimator(
		JNIEnv*  env, jobject defaultObj, jdouble sx, jdouble sy, jdouble sz,
		jdouble dx, jdouble dy, jdouble dz, jdouble time, 
		jboolean loop, jboolean pingpong, jint id)
	{
		ISceneNode* node = smgr->getSceneNodeFromId(id);
		if (!node) 
		{
			WARN_NODE_NOT_FOUND(id, AddFlyStraightAnimator);
			return -1;
		}			
		vector3df start(sx,sy,sz);
		vector3df end(dx, dy, dz);
		
		ISceneNodeAnimator* anim = smgr->createFlyStraightAnimator (start, end, time, loop, pingpong);
		node->addAnimator(anim);
		anim->drop();
		return 0;
	}
Ejemplo n.º 14
0
void Player::SetGravity(vector3df gravityVector)
{
	//Set the new collision vector
	collisionAnimator->setGravity(gravityVector);
	//Remove the outdated response animator
	fpsCamera->GetCamera()->removeAnimator(collisionAnimator);
	//Set the new collision response animator
	fpsCamera->GetCamera()->addAnimator(collisionAnimator);

	//TODO: If player is falling, make descent slower.
	if(collisionAnimator->isFalling())
	{
		ISceneNodeAnimator* anim = smgr->createFlyStraightAnimator(fpsCamera->GetPosition(), vector3df(0,-100, 0), 1000, false);
		fpsCamera->GetCamera()->addAnimator(anim);
		
		anim->drop();

	}

}//end SetGravity()
Ejemplo n.º 15
0
void load_map() {
	IAnimatedMesh* mesh = smgr->getMesh("resources/nodes/maps/room.3ds");

	smgr->getMeshManipulator()->makePlanarTextureMapping(mesh->getMesh(0), 0.008f);
	ISceneNode* node = 0;

	node = smgr->addAnimatedMeshSceneNode(mesh);
	node->setMaterialTexture(0,	driver->getTexture("resources/textures/maps/wall.jpg"));
	node->getMaterial(0).SpecularColor.set(0,0,0,0);

	mesh = smgr->addHillPlaneMesh("myHill",
			dimension2d<f32>(20,20),
			dimension2d<u32>(40,40),
			0,
			0,
			dimension2d<f32>(0,0),
			dimension2d<f32>(10,10)
		);

	node = smgr->addWaterSurfaceSceneNode(mesh->getMesh(0), 3.0f, 300.0f, 30.0f);
	node->setPosition(vector3df(0,7,0));

	node->setMaterialTexture(0,	driver->getTexture("resources/textures/maps/stones.jpg"));
	node->setMaterialTexture(1,	driver->getTexture("resources/textures/maps/water.jpg"));

	node->setMaterialType(video::EMT_REFLECTION_2_LAYER);

	// create light
	node = smgr->addLightSceneNode(0, vector3df(0,0,0), SColorf(1.0f, 0.6f, 0.7f, 1.0f), 600.0f);
	ISceneNodeAnimator* anim = 0;
	anim = smgr->createFlyCircleAnimator (vector3df(0,150,0),250.0f);
	node->addAnimator(anim);
	anim->drop();

	// attach billboard to light
	node = smgr->addBillboardSceneNode(node, dimension2d<f32>(50, 50));
	node->setMaterialFlag(EMF_LIGHTING, false);
	node->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
	node->setMaterialTexture(0,	driver->getTexture("resources/textures/particles/particlewhite.bmp"));
}
Ejemplo n.º 16
0
//! reads animators of a node
void CSceneLoaderIrr::readAnimators(io::IXMLReader* reader, ISceneNode* node)
{
	while(reader->read())
	{
		const wchar_t* name = reader->getNodeName();

		switch(reader->getNodeType())
		{
		case io::EXN_ELEMENT_END:
			if (IRR_XML_FORMAT_ANIMATORS == name)
				return;
			break;
		case io::EXN_ELEMENT:
			if (IRR_XML_FORMAT_ATTRIBUTES == name)
			{
				// read animator data from attribute list
				io::IAttributes* attr = FileSystem->createEmptyAttributes(SceneManager->getVideoDriver());
				attr->read(reader);

				if (node)
				{
					core::stringc typeName = attr->getAttributeAsString("Type");
					ISceneNodeAnimator* anim = SceneManager->createSceneNodeAnimator(typeName.c_str(), node);

					if (anim)
					{
						anim->deserializeAttributes(attr);
						anim->drop();
					}
				}

				attr->drop();
			}
			break;
		default:
			break;
		}
	}
}
Ejemplo n.º 17
0
/*********************************************************************
 * Moves the soldier toward the Borbie over a longer distance, using
 * A* algorithm to find a shortest path using roads.
 *********************************************************************/
void Soldier::aStarToPlayer(){
    // Find shortest path using the MapSearcher from this soldier to the player
    //  using the closest available road intersection points.
    MapSearcher *searcher = this->gameInstance->getMapSearcher();
    vector3df curPosition = this->sceneNode->getPosition();
    std::vector<RoadIntersection> path = searcher->getShortestPath(
	    curPosition,
	    this->gameInstance->getCamera()->getPosition());
    
    // If path is unavailable, or already near Borbie, do nothing.
    int numPathPoints = path.size();
    if(numPathPoints == 0)
        return;
    
    // set up a list of coordinates to move through, starting with the
    //  soldier's current position.
    array<vector3df> coords;
    coords.push_back(this->sceneNode->getPosition());
    for(int i=0; i<numPathPoints; ++i){
        vector3df point;
        point.X = path[i].X;
        point.Y = curPosition.Y;
        point.Z = path[i].Y;
        coords.push_back(point);
    }
    
    // set the destination to the location of the last coordinate
    this->destination.X = path[numPathPoints-1].X;
    this->destination.Y = curPosition.Y;
    this->destination.Z = path[numPathPoints-1].Y;
    
    // create a spline animator (follows the path of coordinates) to animate
    //  the soldier to move to Borbie.
    ISceneNodeAnimator *anim = smgr->createFollowSplineAnimator(
        this->gameInstance->currentGameTime, coords, 0.1f, 0.0, false);
    sceneNode->addAnimator(anim);
    anim->drop();
    moving = true;
}
Ejemplo n.º 18
0
void Game::init()
{
#ifdef WIN32
	device = createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(640, 480));
#else
	device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480));
#endif
	
	driver = device->getVideoDriver();
	smgr = device->getSceneManager();
	guienv = device->getGUIEnvironment();
	
	device->setWindowCaption(L"Not So Much Super Offroad - By Andreas Kröhnke");
	
	IMeshSceneNode *node = smgr->addMeshSceneNode( smgr->getMesh("data/car3.3ds")->getMesh(0) );
	GameObject *car = new GameObject();
	car->setSceneNode(node);
	node->setMaterialFlag(EMF_LIGHTING, false);
	node->setScale(vector3df(0.09,0.09,0.09));
	node->setRotation(vector3df(0,0,0));
	node->setPosition(vector3df(3454,500,1256));
	//node->setDebugDataVisible(EDS_BBOX);
	object->push_back(car);
	
	ITerrainSceneNode *terrain = smgr->addTerrainSceneNode("data/level1.bmp");
	GameObject *go_terrain = new GameObject();
	go_terrain->setSceneNode(terrain);
	terrain->setMaterialFlag(EMF_LIGHTING, false);
	terrain->setScale(core::vector3df(18, 3.0f, 18));
	terrain->setMaterialFlag(video::EMF_LIGHTING, false);
	terrain->setMaterialTexture(0, driver->getTexture("data/terrain-texture.jpg"));
	terrain->setMaterialTexture(1, driver->getTexture("data/detailmap3.jpg"));
	terrain->setMaterialType(video::EMT_DETAIL_MAP);
	terrain->scaleTexture(1.0f, 20.0f);
	terrain->setDebugDataVisible(EDS_BBOX);
	object->push_back(go_terrain);
	
	// Camera
	Camera *cam = new Camera();
	cam->setSceneNode(smgr->addCameraSceneNode());
	object->push_back(cam);
	cam->followNode(car->getSceneNode());
	
	reciever = new EventReciever();
	reciever->setSteer(car->getSceneNode());
	device->setEventReceiver(reciever);
	
	// create triangle selector for the terrain	
	ITriangleSelector* selector = smgr->createTerrainTriangleSelector(terrain, 0);
	terrain->setTriangleSelector(selector);
	selector->drop();
	
	// create collision response animator and attach it to the camera
	ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(selector, car->getSceneNode(), core::vector3df(10,10,10),
																			core::vector3df(0,-5.0f,0), 
																			core::vector3df(0,0,0)
	);
	
	car->getSceneNode()->addAnimator(anim);
	anim->drop();
	
	// Skybox
	smgr->addSkyBoxSceneNode(
							 driver->getTexture("data/irrlicht2_up.jpg"),
							 driver->getTexture("data/irrlicht2_dn.jpg"),
							 driver->getTexture("data/irrlicht2_lf.jpg"),
							 driver->getTexture("data/irrlicht2_rt.jpg"),
							 driver->getTexture("data/irrlicht2_ft.jpg"),
							 driver->getTexture("data/irrlicht2_bk.jpg"));
	
	// Checkpoints
	pair<vector3df, vector3df> cp1(vector3df(3112,393,1234), vector3df(90,90,0));
	addCheckPoint(cp1.first, cp1.second);
	pair<vector3df, vector3df> cp2(vector3df(2531,281,1389), vector3df(90,120,0));
	addCheckPoint(cp2.first, cp2.second);
	addCheckPoint(vector3df(2304,160,1826), vector3df(90,140,0));
	addCheckPoint(vector3df(2132,111,2672), vector3df(90,120,0));
	addCheckPoint(vector3df(1130,415,3313), vector3df(90,75,0));
	addCheckPoint(vector3df(746,471,1753), vector3df(90,0,0));
	addCheckPoint(vector3df(1985,269,1457), vector3df(90,-120,0));
	addCheckPoint(vector3df(2475,146,2868), vector3df(90,-120,0));
	addCheckPoint(vector3df(3707,417,2915), vector3df(90,-60,0));
	
	// Arrows
	addArrow(vector3df(3012,320,1234), vector3df(100,-55,0));
	addArrow(vector3df(2531,220,1389), vector3df(100,-10,0));
	//addArrow(vector3df(2304,110,1826), vector3df(90,10,0));
	addArrow(vector3df(2232,20,2272), vector3df(90,-20,0));

	// HUD
	info = guienv->addStaticText(L"USE ARROW KEYS TO PLAY",
								 rect<int>(10,10,200,60), true);
	info->setOverrideColor(SColor(255, 255, 255, 255));

	//IGUIStaticText *quick_info = guienv->addStaticText(L"Arrow keys to play\n", rect<int>(10,50,200,50), true);
	//quick_info->setOverrideColor(SColor(255,255,255,255));
	initSound();
}
Ejemplo n.º 19
0
/** Test functionality of the ISceneNodeAnimator implementations. */
bool sceneNodeAnimator(void)
{
	IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(160, 120));
	assert_log(device);
	if(!device)
		return false;

	ISceneManager * smgr = device->getSceneManager();

	// Test the hasFinished() method.
	ISceneNodeAnimatorCollisionResponse* collisionResponseAnimator
		= smgr->createCollisionResponseAnimator(0, 0);

	ISceneNodeAnimator* deleteAnimator = smgr->createDeleteAnimator(1);

	ISceneNodeAnimator* flyCircleAnimator = smgr->createFlyCircleAnimator();

	ISceneNodeAnimator* flyStraightAnimator
		= smgr->createFlyStraightAnimator(vector3df(0, 0, 0), vector3df(0, 0, 0), 1, false);

	ISceneNodeAnimator* flyStraightAnimatorLooping
		= smgr->createFlyStraightAnimator(vector3df(0, 0, 0), vector3df(0, 0, 0), 1, true);

	ISceneNodeAnimator* rotationAnimator = smgr->createRotationAnimator(vector3df(0, 0, 0));

	array<vector3df> points;
	points.push_back(vector3df(0, 0, 0));
	points.push_back(vector3df(0, 0, 0));
	ISceneNodeAnimator* followSplineAnimator = smgr->createFollowSplineAnimator(0, points, 1000.f);

	array<video::ITexture*> textures;
	textures.push_back(0);
	textures.push_back(0);

	ISceneNodeAnimator* textureAnimator = smgr->createTextureAnimator(textures, 1, false);
	ISceneNodeAnimator* textureAnimatorLooping = smgr->createTextureAnimator(textures, 1, true);

	bool result = true;

	ISceneNode * deletedNode = smgr->addEmptySceneNode();
	deletedNode->addAnimator(deleteAnimator);

	ISceneNode * testNode = smgr->addEmptySceneNode();
	testNode->addAnimator(collisionResponseAnimator);
	testNode->addAnimator(deleteAnimator);
	testNode->addAnimator(flyCircleAnimator);
	testNode->addAnimator(flyStraightAnimator);
	testNode->addAnimator(flyStraightAnimatorLooping);
	testNode->addAnimator(rotationAnimator);
	testNode->addAnimator(followSplineAnimator);
	testNode->addAnimator(textureAnimator);
	testNode->addAnimator(textureAnimatorLooping);

	result &= !collisionResponseAnimator->hasFinished();
	result &= !deleteAnimator->hasFinished();
	result &= !flyCircleAnimator->hasFinished();
	result &= !flyStraightAnimator->hasFinished();
	result &= !flyStraightAnimatorLooping->hasFinished();
	result &= !rotationAnimator->hasFinished();
	result &= !followSplineAnimator->hasFinished();
	result &= !textureAnimator->hasFinished();
	result &= !textureAnimatorLooping->hasFinished();

	device->run();
	device->sleep(10);
	device->run();
	smgr->drawAll();

	// These animators don't have an endpoint.
	result &= !collisionResponseAnimator->hasFinished();
	result &= !flyCircleAnimator->hasFinished();
	result &= !rotationAnimator->hasFinished();
	result &= !followSplineAnimator->hasFinished();

	// These animators are looping and so can't finish.
	result &= !flyStraightAnimatorLooping->hasFinished();
	result &= !textureAnimatorLooping->hasFinished();

	// These have an endpoint and have reached it.
	result &= deleteAnimator->hasFinished();
	result &= flyStraightAnimator->hasFinished();
	result &= textureAnimator->hasFinished();

	collisionResponseAnimator->drop();
	deleteAnimator->drop();
	flyCircleAnimator->drop();
	flyStraightAnimator->drop();
	flyStraightAnimatorLooping->drop();
	rotationAnimator->drop();
	followSplineAnimator->drop();
	textureAnimator->drop();
	textureAnimatorLooping->drop();

	device->closeDevice();
	device->run();
	device->drop();

	if(!result)
	{
		logTestString("One or more animators has a bad hasFinished() state\n.");
		assert_log(false);
	}

	return result;
}
Ejemplo n.º 20
0
/******************************************************************************
 * Constructor for the gameInstance
 * Param: smgr the iSceneManager for the game
 * Param: guienv the GUI environment used by the game to draw gui's 
 * Param: driver the IVideoDriver for the game 
 * Param: device the IrrlichtDevice for the game
 * Param: audioSystm used from making both 3d and 2d sound in the game
 * Param: runMode used to determine if the debug flag has been set
 * Param: game the encompassing game object for gameInstance
 *****************************************************************************/
GameInstance::GameInstance(
    ISceneManager *smgr,
    IGUIEnvironment *guienv,
    IVideoDriver *driver,
    IrrlichtDevice *device,
    AudioSystem *audioSystem,
    unsigned int runMode,
    IEventReceiver *receiver,
    Game *game)
{

  this->game=game;


  /*** Setup Pointers and Irrlicht Objects ***/    

  // keep pointers to Irrlicht rendering pointers
  this->smgr = smgr;
  this->guienv = guienv;
  this->driver = driver;
  this->device = device;
  this->audioSystem = audioSystem;
  this->receiver = receiver;
  this->timer = device->getTimer();

  // initialize all game timers to 0
  this->currentGameTime = this->timer->getTime();
  this->nextPunchTime = 0;

  ((BorbiesEventReceiver*)(this->receiver))->setGameInstance(this);


  /*** Setup Sounds and Music ***/
  this->bgSound = audioSystem->createSound2d("assets/sounds/yumyum.ogg");
  this->bgSoundDead = audioSystem->createSound2d("assets/sounds/angryWorld.ogg");
  this->borbieDead = audioSystem->createSound2d("assets/sounds/soundEffects/wut.mp3");
  //Start the shitty music and loop! 
  audioSystem->playMusicLoop(bgSound); 
  audioSystem->setMusicVolume(0.5);
  // setup global collision meta selector
  this->metaTriSelector = smgr->createMetaTriangleSelector();

  this->burningSound =
    audioSystem->createSound3d("assets/sounds/soundEffects/burning.mp3");
  this->explosionSound1 =
    audioSystem->createSound3d("assets/sounds/soundEffects/rocketHit.wav");
  this->death1 =
    audioSystem->createSound3d("assets/sounds/soundEffects/meinLeiben.wav");
  this->gunShot1 =
    audioSystem->createSound3d("assets/sounds/soundEffects/burst.mp3");  
  this->gunShot2 =
    audioSystem->createSound3d("assets/sounds/soundEffects/bigAssGun.mp3");  

  /*** Setup Runtime Flags ***/
  float gravity = GLOBAL_GRAVITY;
  bool noVerticalMovement = true; // disabled
  float playerMoveSpeed = PLAYER_MOVEMENT_SPEED;

  // if debug mode, turn off gravity and enable vertical movement
  if(runMode & BORBIE_DEBUG_MODE){
    gravity = 0.f; // no gravity
    noVerticalMovement = false; // vertical movement enabled
    playerMoveSpeed = PLAYER_MOVEMENT_SPEED_DEBUG;
  }


  /*** create textures for in game menu ***/
  this->menu = driver->getTexture("assets/textures/deathMenu.jpg");



  /*** Setup Environment ***/

  // Add Terrain and collision
  this->terrain = new Terrain(driver, smgr, metaTriSelector);
  addCollision(this->terrain->getTriSelector());

  // add skybox
  this->skybox = new Sky(smgr, driver);

  // add lighting
  this->light = new WorldLight(smgr);

  //set shadow color: dark purplish
  smgr->setShadowColor(video::SColor(120,35,20,47));

  this->rainParticleSystem = 0;


  /*** Setup Game Objects (BUILDINGS, VEHICLES) ***/

  // Read the map file into the global static MapReader object.
  this->mapReader = new MapReader("assets/map/coords.bor");
  this->mapSearcher = this->mapReader->getMapSearcher();

  // add the buildings and generate city based on coordinate file
  this->buildings = new Buildings(metaTriSelector, this);
  this->buildings->generateObjects();

  // add the vehicles and generate initial spawns
  this->vehicles = new Vehicles(metaTriSelector, this);
  this->vehicles->generateObjects();

  // default vehicle throwing variables to nothing
  this->carriedVehicle = 0;
  this->vehicleThrown = false;
  this->targetPos = vector3df(0,0,0);

  // add and generate enemies
  this->enemies = new Enemies (metaTriSelector, this);
  this->enemies->generateObjects();



  /*** Setup User Interface (HUD) ***/

  // add the hud object
  this->hud = new Hud(this);



  /*** Setup Camera ***/

  // set key bindings (WASD=move, SPACE=jump) to camera
  SKeyMap keyMap[9];
  KeyBindings *keys = new KeyBindings(&keyMap[0]);
  keys->setKeys();
  // added: (remove if setKeys() becomes static)
  delete keys;

  // setup camera
  camera = smgr->addCameraSceneNodeFPS(
      0,						// parent (none)
      PLAYER_ROTATE_SPEED,	// rotate speed
      playerMoveSpeed,        // move speed
      IDFlag_IsPickable,		// ID
      keyMap,					// keymap
      9,						// keymap size
      noVerticalMovement,		// no vertical movement (true = up/down disabled)
      PLAYER_JUMP_SPEED		// jump speed
      );

  //TODO: read camera position from map file
  camera->setPosition(vector3df(2500, 1000, 4450));
  // set view distance
  camera->setFarValue(30000.0f);
  // hide cursor
  device->getCursorControl()->setVisible(false);

  // add automatic collision response to camera
  ISceneNodeAnimator* anim =
    smgr->createCollisionResponseAnimator(metaTriSelector, camera,
        core::vector3df(60, 150, 60), // radius
        core::vector3df(0, gravity, 0), // gravity (negative y = go down)
        core::vector3df(0, PLAYER_HEIGHT, 0), //radius offset
        0.1f); // sliding value TODO tweak as needed
  camera->addAnimator(anim);
  anim->drop();

  //create beatDown ray selector
  selector = new CastRay(smgr, camera);
  highlightedSceneNode = 0;

  //create objectCarrier for picking shit up
  objCarry = new ObjectCarrier(smgr, device, camera);
  //tell the mouse listener that right mouse isn't pressed to start with
  ((BorbiesEventReceiver *)receiver)->setRightMouse(false);

  /*** Add Hands ***/

  hands = new Hands(this);  

  /*** Add The Borbie ***/

  this->player = new Borbie(this); 	

  this->nextScoreEvent = 10000;

  // initialize world state to fabulous
  this->setWorldState(FABULOUS);
}
Ejemplo n.º 21
0
int main(int argc, char **argv) {

	// Help?
	if (argv[1] && argv[1][0] == '-') die(helpmsg);

	putenv((char *) "vblank_mode=0"); // No vsync for us, thanks.

	MyEventReceiver *r = new MyEventReceiver();
	IrrlichtDevice *dev = createDevice(EDT_OPENGL, core::dimension2d<u32>(1024,768), 32,
				false, false, false, r);
	if (!dev) die("Can't initialize Irrlicht");

	IVideoDriver *drv = dev->getVideoDriver();
	ISceneManager *smgr = dev->getSceneManager();
	IGPUProgrammingServices *gpu = drv->getGPUProgrammingServices();
	ICameraSceneNode *cam = NULL;
	ITexture *pic = NULL;
	IMeshSceneNode *ball = NULL;
	bool showpic = false;

	IReadFile *areamap = createMemoryReadFile(AreaMap33, sizeof(AreaMap33), "AreaMap33", false);
	if (!areamap) die("Failed to load areamap");
	ITexture *areamaptex = drv->getTexture(areamap);
	areamap->drop();

	// If there's an argument, assume it is a pic to load; otherwise, draw a sphere

	if (argv[1] && access(argv[1], R_OK) == 0) {
		showpic = true;
		pic = drv->getTexture(argv[1]);
		if (!pic) die("Can't load image");

		cam = smgr->addCameraSceneNode();
	} else {
		cam = smgr->addCameraSceneNodeMaya();
		cam->setTarget(vector3df(0, 0, 0));
		ball = smgr->addSphereSceneNode(40, 8);

		int ballshader = gpu->addHighLevelShaderMaterial(rnd,0,EVST_VS_1_1,0);
		ball->setMaterialType((E_MATERIAL_TYPE) ballshader);

		ISceneNodeAnimator *cool = smgr->createRotationAnimator(vector3df(-0.1, 0.1, -0.1));
		ball->addAnimator(cool);
		cool->drop();
	}

	// Set up static defines, RTTs, quads
	dimension2d<u32> screensize = drv->getScreenSize();
	char defines[128];
	snprintf(defines, 128,
		"#define PIXEL_SIZE vec2(1.0f / %u.0, 1.0f / %u.0)\n"
		"#define MAX_SEARCH_STEPS 8.0\n#define MAX_DISTANCE 33.0\n",
		screensize.Width, screensize.Height);

	ITexture *rt1 = drv->addRenderTargetTexture(screensize, "rt1", ECF_A8R8G8B8);
	ITexture *rt2 = drv->addRenderTargetTexture(screensize, "rt2", ECF_A8R8G8B8);
	ITexture *rt3 = drv->addRenderTargetTexture(screensize, "rt3", ECF_A8R8G8B8);
	if (!rt1 || !rt2 || !rt3) die("No RTT");

	ScreenQuad *def = new ScreenQuad(drv);
	ScreenQuad *sq = new ScreenQuad(drv);
	ScreenQuad *sq2 = new ScreenQuad(drv);
	ScreenQuad *sq3 = new ScreenQuad(drv);
	ScreenQuad *norm = new ScreenQuad(drv);
	if (showpic) def->SetTexture(pic);
	sq->SetTexture(rt1);
	sq->GetMaterial().setFlag(EMF_BILINEAR_FILTER, false);
	norm->SetTexture(rt1);
	norm->GetMaterial().setFlag(EMF_BILINEAR_FILTER, false);

	sq2->SetTexture(rt2);
	sq2->SetTexture(rt2, 1);
	sq2->SetTexture(areamaptex, 2);
	sq2->GetMaterial().TextureLayer[2].BilinearFilter = false;

	sq3->SetTexture(rt3);
	sq3->GetMaterial().setFlag(EMF_BILINEAR_FILTER, false);
	sq3->SetTexture(rt1,1);
	state_t state = MLAA_OFF;

	stringc tmp1, tmp2;
	tmp1 = defines;
	tmp1 += offsetvs;
	tmp2 = defines;
	tmp2 += color1fs;

	// Load shaders
	int edge = gpu->addHighLevelShaderMaterial(tmp1.c_str(),0,EVST_VS_1_1,tmp2.c_str());
	sq->SetMaterialType((E_MATERIAL_TYPE) edge);

	tmp2 = defines;
	tmp2 += blend2fs;

	blendcb *bcb = new blendcb();
	edge = gpu->addHighLevelShaderMaterial(tmp1.c_str(),0,EVST_VS_1_1,tmp2.c_str(),0,EPST_PS_1_1,bcb);
	sq2->SetMaterialType((E_MATERIAL_TYPE) edge);

	tmp2 = defines;
	tmp2 += neigh3fs;

	neighcb *ncb = new neighcb();
	edge = gpu->addHighLevelShaderMaterial(tmp1.c_str(),0,EVST_VS_1_1,tmp2.c_str(),0,EPST_PS_1_1,ncb);
	sq3->SetMaterialType((E_MATERIAL_TYPE) edge);

	// Record start time
	int lastfps = -1, minfps = 10000;
	unsigned long long total_frames = 0, fxtimer = 0, tmplong, onframes = 0;
	struct timeval starttime, tick1, tick2;
	float glsltime = 0;
	gettimeofday(&starttime, NULL);
	wchar_t cap[20];
	glEnable(GL_STENCIL_TEST);
	unsigned char firstrun = 1; // To avoid the glsl compiler in the timing

	// Main loop
	while (dev->run()) {

		gettimeofday(&tick1, NULL);
		drv->beginScene();

		switch (state) {
			case MLAA_OFF:
				if (showpic) def->Render(false);
				else smgr->drawAll();
			break;
			case MLAA_ON:
				if (showpic) def->Render(rt1);
				else {
					drv->setRenderTarget(rt1);
					smgr->drawAll();
				}


				glClear(GL_STENCIL_BUFFER_BIT);
				glStencilFunc(GL_ALWAYS, 1, ~0);
				glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
				sq->Render(rt2);

				glStencilFunc(GL_EQUAL, 1, ~0);
				glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
				sq2->Render(rt3);
				drv->setRenderTarget(rt1, false, false);

				// Overlay the smoothed edges on the initial image
				sq3->Render(false);

				// Blit the final image to the framebuffer
				glStencilFunc(GL_ALWAYS, 1, ~0);
				norm->Render();

			break;
		}

		drv->endScene();

		if (state == MLAA_ON) {
			gettimeofday(&tick2, NULL);
			if (!firstrun) {
				tmplong = (tick2.tv_sec - tick1.tv_sec) * 10000;
				tmplong += (tick2.tv_usec - tick1.tv_usec) / 100;
				fxtimer += tmplong;

				onframes++;
			} else {
				firstrun = 0;

				glsltime = tick2.tv_sec - tick1.tv_sec;
				glsltime += (tick2.tv_usec - tick1.tv_usec) / 1000000.0;
			}
		}

		int fps = drv->getFPS();
		if (minfps > fps) minfps = fps;
		if (lastfps != fps) {
			swprintf(cap, 20, L"%d fps, MLAA %s", fps, state == MLAA_ON ? "on" : "off");
			dev->setWindowCaption(cap);
			lastfps = fps;
		}

		if (r->IsKeyDown(KEY_KEY_M)) {
			if (state == MLAA_ON) state = MLAA_OFF;
			else state = MLAA_ON;

			lastfps++;
		}

		usleep(1); // 16?
		total_frames++;
	}

	dev->drop();
	delete ncb;
	delete bcb;
	delete def;
	delete sq;
	delete sq2;
	delete sq3;
	delete norm;
	delete r;

	struct timeval endtime;
	gettimeofday(&endtime, NULL);
	float sec = endtime.tv_sec - starttime.tv_sec;
	sec += ((float) endtime.tv_usec - starttime.tv_usec) / 1000000;
	printf("\nRan %.3fs, ", sec);
	sec -= glsltime;

	printf("average fps %.2f, min %d\n", (float) total_frames/sec, minfps);

	if (onframes) {
		printf("\nAverage on fps %.2f, average off fps %.2f\n\n", (float) onframes/(fxtimer/10000.0),
					(float) (total_frames - onframes)/(sec - (fxtimer/10000.0)));

//		printf("MLAA took on average %.1fms\n", (float) (fxtimer / onframes) / 10.0);
	}

	return 0;
}
Ejemplo n.º 22
0
int main(int argc, char* argv[])
{
	// ask user for driver
	video::E_DRIVER_TYPE driverType=driverChoiceConsole();
	if (driverType==video::EDT_COUNT)
		return 1;

	MyEventReceiver receiver;
	IrrlichtDevice* device = createDevice(driverType,
			core::dimension2du(800, 600), 32, false, false, false,
			&receiver);

	if(device == 0)
		return 1;

	IVideoDriver *driver = device->getVideoDriver();
	ISceneManager *smgr = device->getSceneManager();
	device->setWindowCaption(L"Irrlicht Example for SMesh usage.");

	/*
	Create the custom mesh and initialize with a heightmap
	*/
	TMesh mesh;
	HeightMap hm = HeightMap(255, 255);
	hm.generate(eggbox);
	mesh.init(hm, 50.f, grey, driver);

	// Add the mesh to the scene graph
	IMeshSceneNode* meshnode = smgr -> addMeshSceneNode(mesh.Mesh);
	meshnode->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);

	// light is just for nice effects
	ILightSceneNode *node = smgr->addLightSceneNode(0, vector3df(0,100,0),
		SColorf(1.0f, 0.6f, 0.7f, 1.0f), 500.0f);
	if (node)
	{
		node->getLightData().Attenuation.set(0.f, 1.f/500.f, 0.f);
		ISceneNodeAnimator* anim = smgr->createFlyCircleAnimator(vector3df(0,150,0),250.0f);
		if (anim)
		{
			node->addAnimator(anim);
			anim->drop();
		}
	}

	ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
	if (camera)
	{
		camera->setPosition(vector3df(-20.f, 150.f, -20.f));
		camera->setTarget(vector3df(200.f, -80.f, 150.f));
		camera->setFarValue(20000.0f);
	}

	/*
	Just a usual render loop with event handling. The custom mesh is
	a usual part of the scene graph which gets rendered by drawAll.
	*/
	while(device->run())
	{
		if(!device->isWindowActive())
		{
			device->sleep(100);
			continue;
		}

		if(receiver.IsKeyDown(irr::KEY_KEY_W))
		{
			meshnode->setMaterialFlag(video::EMF_WIREFRAME, !meshnode->getMaterial(0).Wireframe);
		}
		else if(receiver.IsKeyDown(irr::KEY_KEY_1))
		{
			hm.generate(eggbox);
			mesh.init(hm, 50.f, grey, driver);
		}
		else if(receiver.IsKeyDown(irr::KEY_KEY_2))
		{
			hm.generate(moresine);
			mesh.init(hm, 50.f, yellow, driver);
		}
		else if(receiver.IsKeyDown(irr::KEY_KEY_3))
		{
			hm.generate(justexp);
			mesh.init(hm, 50.f, yellow, driver);
		}

		driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0xff000000));
		smgr->drawAll();
		driver->endScene();
	}

	device->drop();

	return 0;
}