Example #1
0
int main()
{

   IrrlichtDevice *device =
      createDevice( video::EDT_OPENGL, dimension2d<u32>(800, 600));


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

        smgr->addCameraSceneNode(0, vector3df(0,10,-10), vector3df(0,5,0));

        IAnimatedMesh* mesh = smgr->getMesh("ninja.b3d");
   IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
   node->setMaterialFlag(EMF_LIGHTING, false);
   node->setMaterialTexture( 0, driver->getTexture("nskinrd.jpg") );
        node->setRotation(vector3df(0,180,0)); // let ninja be in front to us

        node->setJointMode(EJUOR_CONTROL); // tell irrlicht that you want to control joint positions

        IBoneSceneNode* bone = node->getJointNode("Joint10"); // create IBoneSceneNode and select the desired bone

   while(device->run()) {
            bone->setRotation(bone->getRotation() + vector3df(1,0,0)); // rotate bone

            driver->beginScene();
            smgr->drawAll();
            driver->endScene();
   }


   device->drop();

   return 0;
}
Example #2
0
ISceneNode* Render::createNode(bool isMD2, IAnimatedMesh* mesh, ITexture* texture, bool light,core::vector3df scale, core::vector3df pos, core::vector3df rotation)
{
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh, NULL, IDFlag_IsPickable);
	
	if(node)
	{
		pos.Y += -node->getBoundingBox().MinEdge.Y * scale.Y;
		node->setPosition(pos);
		node->setRotation(rotation);
		node->setScale(scale);
		node->setAnimationSpeed(20.f);
		scene::ITriangleSelector* selector = 0;
		selector = smgr->createTriangleSelector(node);
		node->setTriangleSelector(selector);
		selector->drop();
		
		//Autoscale
		//f32 scale = 0.25f;
		node->setScale(scale);
		
		if (texture)
		{
			//node->setMaterialFlag(EMF_LIGHTING, false);
			node->setMaterialTexture(0, texture);
		}

		node->setMD2Animation(EMAT_STAND);
	}

	return node;
}
Example #3
0
void Game::setupHud(){
  IAnimatedMesh* gunmesh = smgr->getMesh("resources/models/weapons/test.obj");
  IAnimatedMeshSceneNode* gunnode;
  if(gunmesh)
  {
             gunnode = smgr->addAnimatedMeshSceneNode(gunmesh, gunnode);
             gunnode->setParent(camera);
             gunnode->setPosition(vector3df(50, 0, 1000));
             gunnode->setRotation(vector3df(0, 0, 1000));
             gunnode->updateAbsolutePosition();
             std::cout << gunnode->getAbsolutePosition().X << ", " << gunnode->getAbsolutePosition().Y << ", "
            << gunnode->getAbsolutePosition().Z;
             //gunnode->setScale(vector3df(1, 1, 1));
  }
}
IAnimatedMeshSceneNode* MyIrrlichtComposition::mLoadMesh(vector3df pos,vector3df rot,vector3df scale, std::string name1, std::string name2)
{
	IAnimatedMeshSceneNode* obj = smgr->addAnimatedMeshSceneNode(smgr->getMesh(name1.c_str()));
	if(obj)
	{
		obj->setPosition(pos);
		obj->setMD2Animation(scene::EMAT_RUN);
		obj->setRotation(rot); 
		obj->setScale(scale);
		obj->setMaterialTexture(0, driver->getTexture(name2.c_str()));
		obj->addShadowVolumeSceneNode();
		return obj;
	}
	else 
		exit(2);
}
Example #5
0
int main()
{
	eventReceiver receiver;
	IrrlichtDevice *device = createDevice( video::EDT_OPENGL, dimension2d<u32>(1366, 768), 16,true, false, false,&receiver);
	device->setWindowCaption(L"(WhizGeek || Mclightning).com");
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();

	scene::ICameraSceneNode* kam= smgr->addCameraSceneNode(NULL,vector3df(0,0,200),vector3df(0,0,0));
	
	//kam->setPosition(vector3df(0,0,200));

	ISceneNode* kutu=smgr->addCubeSceneNode(50,0,2,vector3df(50,0,0));
	ISceneNode* kutu2=smgr->addCubeSceneNode(50,0,2,vector3df(-50,0,0));
	ITexture *duvar=driver->getTexture("wall.jpg");
	kutu->setMaterialTexture(0,duvar);
	kutu->setMaterialFlag(video::EMF_LIGHTING, false);
	kutu2->setMaterialTexture(0,duvar);
	kutu2->setMaterialFlag(video::EMF_LIGHTING, false);

		IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
		IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation(scene::EMAT_STAND);
		node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
		node->setRotation(vector3df(0,270,0));
		
	irFinder ir("test",true,230,255);
	CvPoint in;
	while(device->run())
	{		
		if(receiver.IsKeyDown(KEY_ESCAPE))
		{
			device->drop();
			return 0;
		}
		driver->beginScene(true, true, SColor(255,0,0,255));
		in=ir.yenile();
		//node->setPosition(vector3df(30*in.x/320,30*(240-in.y)/240,0));
		kam->setPosition(vector3df(in.x-160,(240-in.y),200));
		smgr->drawAll();
		driver->endScene();
	}
	device->drop();
}
Example #6
0
void Game::addCheckPoint(const vector3df& position, const vector3df& rotation)
{
	string<char> str = "checkpoint" + checkpoint->size();
	IAnimatedMesh *cp1 = smgr->addHillPlaneMesh(str.c_str(), dimension2d<f32>(1000,1000), dimension2d<u32>(1,1));
	IAnimatedMeshSceneNode *c = smgr->addAnimatedMeshSceneNode(cp1);
	c->setRotation(rotation);
	c->setPosition(position);
	//c->setDebugDataVisible(EDS_BBOX);
	checkpoint->push_back(c);
	
	if (checkpoint->size() == 1)
	{
		first_checkpoint = c;
	}
	
	c->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
	//c->setMaterialFlag(EMF_BACK_FACE_CULLING, false);
}
void PhysicsSim::drawVector(Vector3D init, Vector3D end, Color c)
{
	Vector3D vec = end-init;
	float length = vec.getLength();

	stringw meshname("ArrowMesh");
	meshname += (int)arrows.size();
	IAnimatedMesh* arrow = smgr->addArrowMesh (meshname, c, c, 4, 8, length, (length - 0.4 < 0.0) ? length*0.4 : (length-0.4));
	IAnimatedMeshSceneNode *arrownode =	smgr->addAnimatedMeshSceneNode(arrow);

	arrownode->setPosition(init);

	//arrownode->setScale(vector3df(1.0, length, 1.0));

	vec.normalize();
	quaternion q;
	q.rotationFromTo(vector3df(0,1,0), vec);
	vector3df rot;
	q.toEuler(rot);

	arrownode->setRotation(vector3df(rot.X*180.0/M_PI, rot.Y*180.0/M_PI, rot.Z*180.0/M_PI));

	arrows.push_back(arrownode);
}
Example #8
0
void AnnyFactory::produce(int x,int y,int z){
	std::string sydneyMesh = "monkey.obj";
	std::string sydneyMaterial = "unwrappedPainted.png";//"monkey.bmp";
	IAnimatedMesh* mesh = sceneManager->getMesh((RESOURCES+sydneyMesh).c_str());
	if (!mesh)
	{
		exit(1);
	}
	IAnimatedMeshSceneNode* node = sceneManager->addAnimatedMeshSceneNode( mesh );

	const wchar_t* name = L"Monkey head";
	objectList->addObject(name);

	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation(scene::EMAT_RUN);
		node->setMaterialTexture( 0, driver->getTexture((RESOURCES+sydneyMaterial).c_str()) );
		node->setName(name);
		node->setPosition(core::vector3df(x,y,z));
		node->setScale(core::vector3df(10,10,10));
		node->setRotation(core::vector3df(0,200,0));
	}
}
void CCharacterExample::runExample()
{
    for(s32 i=0; i<KEY_KEY_CODES_COUNT; i++)
        KeyIsDown[i] = false;

    debugDraw = true;
    drawProperties = true;
    drawWireFrame = false;

    rows = 10;
	columns = 10;

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


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

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


    device->getSceneManager()->addLightSceneNode(0, vector3df(20, 40, -50), SColorf(1.0f, 1.0f, 1.0f), 4000.0f);


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

    world->setDebugMode(EPDM_DrawAabb |
            EPDM_DrawContactPoints);

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


    camera = device->getSceneManager()->addCameraSceneNodeMaya();
	camera->setPosition(vector3df(50,15,200));
	camera->bindTargetAndRotation(true);


	createGround();
	createBoxes();

	IKinematicCharacterController* character = new IKinematicCharacterController(world);

	IAnimatedMeshSceneNode* sydney = device->getSceneManager()->addAnimatedMeshSceneNode(device->getSceneManager()->getMesh("sydney.md2"));
	sydney->setScale(vector3df(0.14,0.14,0.14));
	sydney->getMaterial(0).setTexture(0, device->getVideoDriver()->getTexture("sydney.bmp"));
	sydney->setMD2Animation(scene::EMAT_STAND);


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

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


		/*sydney->setPosition(character->getWorldTransform().getTranslation()+vector3df(0,-((sydney->getBoundingBox().MaxEdge.Y-sydney->getBoundingBox().MinEdge.Y)*0.1*0.5f),0));
        vector3df dir = camera->getAbsolutePosition()-sydney->getAbsolutePosition();
        dir.normalize();
        dir.Y = 0;
        dir *= -1;

        character->setWalkDirection(dir*0.3f);*/

        if(IsKeyDown(KEY_KEY_W))
        {
            DirZ = -1.0f;
        }

        else if(IsKeyDown(KEY_KEY_S))
        {
            DirZ = 1.0f;
        }

        else
        {
            DirZ = 0.0f;
        }

        if(IsKeyDown(KEY_KEY_A))
        {
            DirX = 1.0f;
        }

        else if(IsKeyDown(KEY_KEY_D))
        {
            DirX = -1.0f;
        }

        else
        {
            DirX = 0.0f;
        }

        if(IsKeyDown(KEY_SPACE))
        {
            character->jump();
            jump = true;
        }

        if(DirZ != 0 || DirX != 0)
            newAnimation = EMAT_RUN;

        else
            newAnimation = EMAT_STAND;

        if(!character->isOnGround())
        {
            newAnimation = jump ? EMAT_JUMP:EMAT_CROUCH_STAND;
        }

        else
            jump = false;


        if(animation != newAnimation)
        {
            animation = newAnimation;
            sydney->setMD2Animation(animation);
        }


        sydney->setPosition(character->getWorldTransform().getTranslation());

        vector3df rot(0, camera->getRotation().Y-90.0f, 0);
        sydney->setRotation(rot);


        vector3df direction(DirX, 0.0f, DirZ);

        irr::core::matrix4 m;

        m.setRotationDegrees(vector3df(0, camera->getRotation().Y-180.0f, 0));

        m.transformVect(direction);

        character->setPositionIncrementPerSimulatorStep(direction*0.3f);

        camera->setTarget(sydney->getPosition());

		// Step the simulation with our delta time
        world->stepSimulation(DeltaTime*0.001f, 120);


        world->debugDrawWorld(debugDraw);

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


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

        device->getVideoDriver()->endScene();
    }

    delete character;

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

    if(device)
        device->drop();
}
        unsigned prioq_idx;
        int owner_family;
        union in_addr_union owner_address;
        LIST_FIELDS(DnsCacheItem, by_key);
};

static void dns_cache_item_free(DnsCacheItem *i) {
        if (!i)
                return;

        dns_resource_record_unref(i->rr);
        dns_resource_key_unref(i->key);
        free(i);
}

DEFINE_TRIVIAL_CLEANUP_FUNC(DnsCacheItem*, dns_cache_item_free);

static void dns_cache_item_remove_and_free(DnsCache *c, DnsCacheItem *i) {
        DnsCacheItem *first;

        assert(c);

        if (!i)
                return;

        first = hashmap_get(c->by_key, i->key);
        LIST_REMOVE(by_key, first, i);

        if (first)
                assert_se(hashmap_replace(c->by_key, first->key, first) >= 0);
        else
                hashmap_remove(c->by_key, i->key);

        prioq_remove(c->by_expiry, i, &i->prioq_idx);

        dns_cache_item_free(i);
}

void dns_cache_flush(DnsCache *c) {
        DnsCacheItem *i;

        assert(c);

        while ((i = hashmap_first(c->by_key)))
                dns_cache_item_remove_and_free(c, i);

        assert(hashmap_size(c->by_key) == 0);
        assert(prioq_size(c->by_expiry) == 0);

        hashmap_free(c->by_key);
        c->by_key = NULL;

        prioq_free(c->by_expiry);
        c->by_expiry = NULL;
}

static void dns_cache_remove(DnsCache *c, DnsResourceKey *key) {
        DnsCacheItem *i;

        assert(c);
        assert(key);

        while ((i = hashmap_get(c->by_key, key)))
                dns_cache_item_remove_and_free(c, i);
}

static void dns_cache_make_space(DnsCache *c, unsigned add) {
        assert(c);
void dns_cache_prune(DnsCache *c) {
        usec_t t = 0;

        assert(c);

        /* Remove all entries that are past their TTL */

        for (;;) {
                _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
                DnsCacheItem *i;

                i = prioq_peek(c->by_expiry);
                if (!i)
                        break;

                if (t <= 0)
                        t = now(CLOCK_BOOTTIME);

                if (i->until > t)
                        break;

                /* Take an extra reference to the key so that it
                 * doesn't go away in the middle of the remove call */
                key = dns_resource_key_ref(i->key);
                dns_cache_remove(c, key);
        }
}

static int dns_cache_item_prioq_compare_func(const void *a, const void *b) {
        const DnsCacheItem *x = a, *y = b;

        if (x->until < y->until)
                return -1;
        if (x->until > y->until)
                return 1;
        return 0;
}

static int dns_cache_init(DnsCache *c) {
        int r;

        assert(c);

        r = prioq_ensure_allocated(&c->by_expiry, dns_cache_item_prioq_compare_func);
        if (r < 0)
                return r;

        r = hashmap_ensure_allocated(&c->by_key, &dns_resource_key_hash_ops);
        if (r < 0)
                return r;

        return r;
}

static int dns_cache_link_item(DnsCache *c, DnsCacheItem *i) {
        DnsCacheItem *first;
        int r;

        assert(c);
        assert(i);

        r = prioq_put(c->by_expiry, i, &i->prioq_idx);
        if (r < 0)
                return r;

        first = hashmap_get(c->by_key, i->key);
        if (first) {
                LIST_PREPEND(by_key, first, i);
                assert_se(hashmap_replace(c->by_key, first->key, first) >= 0);
        } else {
                r = hashmap_put(c->by_key, i->key, i);
                if (r < 0) {
                        prioq_remove(c->by_expiry, i, &i->prioq_idx);
                        return r;
                }
        }

        return 0;
}

static DnsCacheItem* dns_cache_get(DnsCache *c, DnsResourceRecord *rr) {
        DnsCacheItem *i;

        assert(c);
        assert(rr);

        LIST_FOREACH(by_key, i, hashmap_get(c->by_key, rr->key))
                if (i->rr && dns_resource_record_equal(i->rr, rr) > 0)
                        return i;

        return NULL;
}

static void dns_cache_item_update_positive(DnsCache *c, DnsCacheItem *i, DnsResourceRecord *rr, usec_t timestamp) {
        assert(c);
        assert(i);
        assert(rr);

        i->type = DNS_CACHE_POSITIVE;

        if (!i->by_key_prev) {
                /* We are the first item in the list, we need to
                 * update the key used in the hashmap */

                assert_se(hashmap_replace(c->by_key, rr->key, i) >= 0);
        }

        dns_resource_record_ref(rr);
        dns_resource_record_unref(i->rr);
        i->rr = rr;

        dns_resource_key_unref(i->key);
        i->key = dns_resource_key_ref(rr->key);

        i->until = timestamp + MIN(rr->ttl * USEC_PER_SEC, CACHE_TTL_MAX_USEC);

        prioq_reshuffle(c->by_expiry, i, &i->prioq_idx);
}

static int dns_cache_put_positive(
                DnsCache *c,
                DnsResourceRecord *rr,
                usec_t timestamp,
                int owner_family,
                const union in_addr_union *owner_address) {

        _cleanup_(dns_cache_item_freep) DnsCacheItem *i = NULL;
        DnsCacheItem *existing;
        int r;

        assert(c);
        assert(rr);
        assert(owner_address);

        /* New TTL is 0? Delete the entry... */
        if (rr->ttl <= 0) {
                dns_cache_remove(c, rr->key);
                return 0;
        }

        if (rr->key->class == DNS_CLASS_ANY)
                return 0;
        if (rr->key->type == DNS_TYPE_ANY)
                return 0;

        /* Entry exists already? Update TTL and timestamp */
        existing = dns_cache_get(c, rr);
        if (existing) {
                dns_cache_item_update_positive(c, existing, rr, timestamp);
                return 0;
        }

        /* Otherwise, add the new RR */
        r = dns_cache_init(c);
        if (r < 0)
                return r;

        dns_cache_make_space(c, 1);

        i = new0(DnsCacheItem, 1);
        if (!i)
                return -ENOMEM;

        i->type = DNS_CACHE_POSITIVE;
        i->key = dns_resource_key_ref(rr->key);
        i->rr = dns_resource_record_ref(rr);
        i->until = timestamp + MIN(i->rr->ttl * USEC_PER_SEC, CACHE_TTL_MAX_USEC);
        i->prioq_idx = PRIOQ_IDX_NULL;
        i->owner_family = owner_family;
        i->owner_address = *owner_address;

        r = dns_cache_link_item(c, i);
        if (r < 0)
                return r;

        i = NULL;
        return 0;
}

static int dns_cache_put_negative(
                DnsCache *c,
                DnsResourceKey *key,
                int rcode,
                usec_t timestamp,
                uint32_t soa_ttl,
                int owner_family,
                const union in_addr_union *owner_address) {

        _cleanup_(dns_cache_item_freep) DnsCacheItem *i = NULL;
        int r;

        assert(c);
        assert(key);
        assert(owner_address);

        dns_cache_remove(c, key);

        if (key->class == DNS_CLASS_ANY)
                return 0;
        if (key->type == DNS_TYPE_ANY)
                return 0;
        if (soa_ttl <= 0)
                return 0;

        if (!IN_SET(rcode, DNS_RCODE_SUCCESS, DNS_RCODE_NXDOMAIN))
                return 0;

        r = dns_cache_init(c);
        if (r < 0)
                return r;

        dns_cache_make_space(c, 1);

        i = new0(DnsCacheItem, 1);
        if (!i)
                return -ENOMEM;

        i->type = rcode == DNS_RCODE_SUCCESS ? DNS_CACHE_NODATA : DNS_CACHE_NXDOMAIN;
        i->key = dns_resource_key_ref(key);
        i->until = timestamp + MIN(soa_ttl * USEC_PER_SEC, CACHE_TTL_MAX_USEC);
        i->prioq_idx = PRIOQ_IDX_NULL;
        i->owner_family = owner_family;
        i->owner_address = *owner_address;

        r = dns_cache_link_item(c, i);
        if (r < 0)
                return r;

        i = NULL;
        return 0;
}

int dns_cache_put(
                DnsCache *c,
                DnsQuestion *q,
                int rcode,
                DnsAnswer *answer,
                unsigned max_rrs,
                usec_t timestamp,
                int owner_family,
                const union in_addr_union *owner_address) {

        unsigned i;
        int r;

        assert(c);
        assert(q);
///////////////////////////////////////////函数实现////////////////////////////////////////////////
bool LoadModels(ISceneNode* m_ICamera,std::map<std::string,IAnimatedMeshSceneNode*>& myNode)
{
	_finddata_t file; 
	long longf;   
  
    //读取文件夹下文件名字 
    if((longf = _findfirst("..\\model\\*.3ds", &file))==-1l)   
    {   
        std::cout<<"没有找到模型!\n";   
    }   
    else  
    {   
        std::cout<<"\n加载模型\n";   
		std::string tempName;
		tempName = "";   
        tempName = file.name;
		m_vecStrModelName.push_back(tempName);//加载第一个模型名字
        while( _findnext( longf, &file ) == 0 )   
        {     
			tempName = "";   
            tempName = file.name; 
            if (tempName == "..")   
            {   
                continue;   
            }   
			m_vecStrModelName.push_back(tempName);
        }   
    }   
  
    _findclose(longf); 

	//模型库模型节点的ID(从1000开始)
	int storeModelID=1000;
	//加载模型创建场景节点
   auto iter(m_vecStrModelName.begin());
   while(iter!=m_vecStrModelName.end())
   {
	   std::string myPath=*iter;
	   myPath="..\\model\\"+myPath;
	   scene::IAnimatedMesh* mesh = m_IrrSmgr->getMesh((char*)myPath.c_str());

	   //模型设为摄像头的子节点
       IAnimatedMeshSceneNode* modelNode = m_IrrSmgr->addAnimatedMeshSceneNode(mesh,m_ICamera);

	   // 设置自发光强度大小(即镜面渲染中的亮度大小)
       modelNode->getMaterial(0).Shininess = 20.0f; 

	   modelNode->setMaterialFlag(EMF_LIGHTING, true);

	   modelNode->setRotation(vector3df(90, 0, 0));
	   modelNode->setPosition(vector3df(90, 0, 0));

	   //创建三角选择器
	   m_ItriElector = m_IrrSmgr->createTriangleSelector(modelNode);
	   modelNode->setTriangleSelector(m_ItriElector);
	   m_ItriElector->drop(); // We're done with this m_ItriElector, so drop it now.

	   myNode[(*iter)]=modelNode;//插入模型名字和模型库结点对
	   iter++;
	   //设置模型为不可见
	   modelNode->setVisible(false);

	   //设置模型库模型ID
	   modelNode->setID(storeModelID);
	   ++storeModelID;
   }

   //计算模型库的页数(三个模型一页)
   m_iTotalPageNumber=m_vecStrModelName.size()/m_iPageModelCount;
   if(m_vecStrModelName.size()%m_iPageModelCount!=0)
   {
	   m_iTotalPageNumber+=1;
   }

   //添加翻页标志模型
   for(int i=0;i<2;i++)
   {
	   scene::IAnimatedMesh* mesh;
	   if(0==i)
	   {
		   mesh = m_IrrSmgr->getMesh("left.3ds");
	   }
	   else
	   {
		   mesh = m_IrrSmgr->getMesh("right.3ds");
	   }
	   //模型设为摄像头的子节点
		IAnimatedMeshSceneNode* modelNode = m_IrrSmgr->addAnimatedMeshSceneNode(mesh,m_ICamera);

		// 设置自发光强度大小(即镜面渲染中的亮度大小)
		modelNode->getMaterial(0).Shininess = 20.0f; 

		modelNode->setMaterialFlag(EMF_LIGHTING, true);

		modelNode->setRotation(vector3df(90, 0, 0));

		//创建三角选择器
		m_ItriElector = m_IrrSmgr->createTriangleSelector(modelNode);
		modelNode->setTriangleSelector(m_ItriElector);
		m_ItriElector->drop(); // We're done with this m_ItriElector, so drop it now.

		//设置模型为不可见
		modelNode->setVisible(false);

		//设置模型库模型ID
		if(0==i)
		{
			modelNode->setID(2000);
		}
		else
		{
			modelNode->setID(2001);
		}
   }
   
   return true;
}
Example #13
0
int main()
{
	
	order_map<S3DVertex, int> map;
	S3DVertex s = S3DVertex(Vector3(23, 12, 14), Vector3(231, 33, 22), ColourValue::getColourValue(255,255,255,255), Vector2(12, 34));
	map.insert(s, 1);
	order_map<S3DVertex, int>::Node* nofe = map.find(s);
	int i = nofe->getValue();
	

	/*
	The most important function of the engine is the createDevice()
	function. The IrrlichtDevice is created by it, which is the root
	object for doing anything with the engine. createDevice() has 7
	parameters:

	- deviceType: Type of the device. This can currently be the Null-device,
	one of the two software renderers, D3D8, D3D9, or OpenGL. In this
	example we use EDT_SOFTWARE, but to try out, you might want to
	change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8,
	EDT_DIRECT3D9, or EDT_OPENGL.

	- windowSize: Size of the Window or screen in FullScreenMode to be
	created. In this example we use 640x480.

	- bits: Amount of color bits per pixel. This should be 16 or 32. The
	parameter is often ignored when running in windowed mode.

	- fullscreen: Specifies if we want the device to run in fullscreen mode
	or not.

	- stencilbuffer: Specifies if we want to use the stencil buffer (for
	drawing shadows).

	- vsync: Specifies if we want to have vsync enabled, this is only useful
	in fullscreen mode.

	- eventReceiver: An object to receive events. We do not want to use this
	parameter here, and set it to 0.

	Always check the return value to cope with unsupported drivers,
	dimensions, etc.
	*/
	Device *device =
		createDevice(EDT_OPENGL, dimension2d<Sapphire::UINT32>(1920, 1080), 32,
		false, false, false, 0);

	if (!device)
		return 1;
	
	/*
	Set the caption of the window to some nice text. Note that there is an
	'L' in front of the string. The Irrlicht Engine uses wide character
	strings when displaying text.
	*/
	device->setWindowCaption(L"HELLO WORLD!");

	/*
	Get a pointer to the VideoDriver, the SceneManager and the graphical
	user interface environment, so that we do not always have to write
	device->getVideoDriver(), device->getSceneManager(), or
	device->getGUIEnvironment().
	*/
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();

	/*
	We add a hello world label to the window, using the GUI environment.
	The text is placed at the position (10,10) as top left corner and
	(260,22) as lower right corner.
	*/
	guienv->addStaticText(L"Hello World!",
		rect<SINT32>(10, 10, 260, 22), true);

	/*
	To show something interesting, we load a Quake 2 model and display it.
	We only have to get the Mesh from the Scene Manager with getMesh() and add
	a SceneNode to display the mesh with addAnimatedMeshSceneNode(). We
	check the return value of getMesh() to become aware of loading problems
	and other errors.

	Instead of writing the filename sydney.md2, it would also be possible
	to load a Maya object file (.obj), a complete Quake3 map (.bsp) or any
	other supported file format. By the way, that cool Quake 2 model
	called sydney was modelled by Brian Collins.
	*/
	//IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
	//IAnimatedMesh* mesh = smgr->getMesh("media/q2mdl-wham/tris.md2");
	//IAnimatedMesh* mesh = smgr->getMesh("media/sydney.md2");
	IAnimatedMesh* mesh = smgr->getMesh("media/kokoro/kokoro.obj");
	if (!mesh)
	{
		device->drop();
		return 1;
	}
	
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
	//node->setDebugDataVisible(EDS_BBOX );
	/*
	To let the mesh look a little bit nicer, we change its material. We
	disable lighting because we do not have a dynamic light in here, and
	the mesh would be totally black otherwise. Then we set the frame loop,
	such that the predefined STAND animation is used. And last, we apply a
	texture to the mesh. Without it the mesh would be drawn using only a
	color.
	*/
	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
	//	node->setMD2Animation(EMAT_STAND);
		//node->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp"));
		
		//node->setMaterialTexture(0, driver->getTexture("media/sydney.bmp"));
	    // node->setMaterialTexture(0, driver->getTexture("media/q2mdl-wham/tundra.bmp"));
		//node->setMaterialTexture(0, driver->getTexture("media/kokoro/kok_face_d.tga"));
		//node->setMaterialTexture(0, driver->getTexture("media/kokoro/kok_acc1_d.tga"));
		//node->setMaterialTexture(0, driver->getTexture("media/kokoro/kok_body_d.tga"));
		//node->setMaterialTexture(0, driver->getTexture("media/kokoro/kok_body_d.tga"));
		//node->setMaterialTexture(0, driver->getTexture("media/kokoro/kok_hairback_s.tga"));
		node->setPosition(Vector3(1, 29, -39));
	    node->setRotation(Vector3(Math::DegreesToRadians(45), 0, 0));
		node->setRotation(Vector3(0, Math::DegreesToRadians(180), 0));
		
	}

	/*
	To look at the mesh, we place a camera into 3d space at the position
	(0, 30, -40). The camera looks from there to (0,5,0), which is
	approximately the place where our md2 model is.
	*/
	//smgr->addCameraSceneNode(0, Vector3(0, 30, -40), Vector3(0, 5, 0));
	ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 50.0f, 0.01f);
	camera->setTarget(Vector3(5, 10, 0));
	camera->setPosition(Vector3(0, 30, -40));

	/*
	Ok, now we have set up the scene, lets draw everything: We run the
	device in a while() loop, until the device does not want to run any
	more. This would be when the user closes the window or presses ALT+F4
	(or whatever keycode closes a window).
	*/
	while (device->run())
	{
		/*
		Anything can be drawn between a beginScene() and an endScene()
		call. The beginScene() call clears the screen with a color and
		the depth buffer, if desired. Then we let the Scene Manager and
		the GUI Environment draw their content. With the endScene()
		call everything is presented on the screen.
		*/
		driver->beginScene(true, true, ColourValue::getColourValue(255, 100, 101, 140));

 		smgr->drawAll();
		guienv->drawAll();

		driver->endScene();
	}

	/*
	After we are done with the render loop, we have to delete the Irrlicht 
	Device created before with createDevice(). In the Irrlicht Engine, you
	have to delete all objects you created with a method or function which
	starts with 'create'. The object is simply deleted by calling ->drop().
	See the documentation at irr::IReferenceCounted::drop() for more
	information.
	*/
	device->drop();

	return 0;
	return 0;
}
Example #14
0
int main()
{
	// create device
    EventHandler receiver;
	Init();
	Output();
	ISceneNode* objects [MAX_OBJECTS];



	 IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<u32>(ResX, ResY), 32, fullscreen, false, vsync, &receiver); 
	 
	 receiver.device = device; 

    if (!device)
        return 1;

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

	HMDDescriptor HMD;
	// Parameters from the Oculus Rift DK1
	HMD.hResolution = ResX;
	HMD.vResolution = ResY;
	HMD.hScreenSize = 0.14976;
	HMD.vScreenSize = 0.0936;
	HMD.interpupillaryDistance = 0.064;
	HMD.lensSeparationDistance = 0.064;
	HMD.eyeToScreenDistance = 0.041;
	HMD.distortionK[0] = 1.0;
	HMD.distortionK[1] = 0.22;
	HMD.distortionK[2] = 0.24;
	HMD.distortionK[3] = 0.0;

	HMDStereoRender renderer(device, HMD, 10); 


	#ifdef OCCULUS
		ICameraSceneNode* camera = smgr->addCameraSceneNode();
		camera->bindTargetAndRotation(false);
		camera->setTarget(vector3df(1,0,0));
	#else	
		ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
	#endif	

	
    device->getCursorControl()->setVisible(false); 


	// load a faerie 
	IAnimatedMesh* faerie = smgr->getMesh("media/faerie.md2");
	IAnimatedMeshSceneNode* faerieNode = smgr->addAnimatedMeshSceneNode(faerie);
	faerieNode->setMaterialTexture(0, driver->getTexture("media/faerie2.bmp"));
	faerieNode->setMaterialFlag(EMF_LIGHTING, false);
	faerieNode->setPosition(vector3df(40,190,-1030));
	faerieNode->setRotation(vector3df(0,-90,0));
	faerieNode->setMD2Animation(EMAT_SALUTE);

	// load a dwarf
	IAnimatedMesh* dwarf = smgr->getMesh("media/dwarf.x");
	IAnimatedMeshSceneNode* dwarfNode = smgr->addAnimatedMeshSceneNode(dwarf);
	dwarfNode->setPosition(vector3df(40,-25,20));
	  
	
	Level currentLevel(device);
	currentLevel.makeLevel(0);

	smgr->setAmbientLight(video::SColorf(0.1,0.1,0.1,1));
	ILightSceneNode* light1 = smgr->addLightSceneNode( camera , vector3df(0,0,0), video::SColorf(0.3f,0.4f,0.4f), 80.0f, 1 );


	vector3df pos = vector3df(0,0,0);

	//naplníme tunel pøekážkama

	 srand (time(NULL));
	/* generate secret number between 1 and 10: */
	
	for(int i = 0; i < MAX_OBJECTS; i++){
		objects[i] = smgr->addCubeSceneNode(2);
		objects[i]->setMaterialFlag(EMF_LIGHTING, false);
		objects[i]->setPosition( vector3df( (rand() % 30) - 5, (rand() % 30) - 5, rand() % 80) );
	}

	//device->setInputReceivingSceneManager(smgr);
	
	//použivane pro 
	vector3df tempRot; 
	irr::core::quaternion tempQ;
	irr::core::matrix4 tempM;

	float round = 0;

    while(device->run())
    {
		round += 0.01;
        driver->beginScene(true, true, SColor(255,100,101,140));
		
		for(int i = 0; i < MAX_OBJECTS; i++){
			vector3df tmpPos = objects[i]->getPosition();
			if(tmpPos.Z > pos.Z) continue;
			
			objects[i]->setPosition( vector3df( (rand() % 30) - 15, (rand() % 30) - 15, rand() % 80 + pos.Z) );
		}
		
	#ifndef OCCULUS
			tempM.setRotationDegrees(vector3df(sin(round*0.5)*360-180, sin(round)*360-180, cos(round*0.8)*360-180));
			
			// transform forward vector of camera
			irr::core::vector3df frv = irr::core::vector3df (0.0f, 0.0f, 1.0f);
			tempM.transformVect(frv);
    
			// transform upvector of camera
		    irr::core::vector3df upv = irr::core::vector3df (0.0f, 1.0f, 0.0f);
			tempM.transformVect(upv);

		    camera->setUpVector(upv); //set up vector of camera
			camera->setTarget(frv); //set target of camera (look at point) (thx Zeuss for correcting it)

	#endif

		
		if(pSensor){
			Quatf quaternion = FusionResult.GetOrientation();

		   ICameraSceneNode* camera = smgr->getActiveCamera();
   
		   tempQ.set(-quaternion.z,quaternion.y,-quaternion.x, quaternion.w);
		   tempQ.normalize();
		   tempQ.toEuler(tempRot);
    
		   
			tempM.setRotationDegrees(tempRot);

			// transform forward vector of camera
			irr::core::vector3df frv = irr::core::vector3df (0.0f, 0.0f, 1.0f);
			tempM.transformVect(frv);
    
			// transform upvector of camera
		    irr::core::vector3df upv = irr::core::vector3df (0.0f, 1.0f, 0.0f);
			tempM.transformVect(upv);

		    camera->setUpVector(upv); //set up vector of camera
			camera->setTarget(frv); //set target of camera (look at point) (thx Zeuss for correcting it)

			// update absolute position
			camera->updateAbsolutePosition();



			float yaw, pitch, roll;
			quaternion.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(&yaw, &pitch, &roll);
			camera->getParent()->setRotation( vector3df(RadToDegree(pitch),RadToDegree(yaw),RadToDegree(roll)));
			//camera->setRotation( vector3df(RadToDegree(-pitch),RadToDegree(-yaw),RadToDegree(roll)));
			//camera->setProjectionMatrix(ToMatrix(quaternion));
			cout << " Yaw: " << RadToDegree(yaw) << 
				", Pitch: " << RadToDegree(pitch) << 
				", Roll: " << RadToDegree(roll) << endl;
		
			if (_kbhit()) exit(0);
		}

		#ifdef OCCULUS
			renderer.drawAll(smgr); 
		#else
			smgr->drawAll();
		#endif

        guienv->drawAll();

        driver->endScene();
    }


    device->drop();
	Clear();
    return 0;
}