bool testTransparentVertexAlphaMore(E_DRIVER_TYPE driverType)
{
	IrrlichtDevice *device = createDevice(driverType, dimension2d<u32>(160, 120));
	if (!device)
		return true;

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

	if (driver->getColorFormat() != video::ECF_A8R8G8B8)
	{
		device->closeDevice();
		device->run();
		device->drop();
		return true;
	}

	logTestString("Testing driver %ls\n", driver->getName());

	IAnimatedMesh* mesh = smgr->getMesh("../media/sydney.md2");
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
	IMeshSceneNode* cube = smgr->addCubeSceneNode(10.0f,0,-1,vector3df(-5,3,-15));

	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setFrameLoop(0, 310);
		node->setMaterialTexture( 0, driver->getTexture("../media/sydney.bmp") );
	}
	if (cube)
	{
		cube->getMaterial(0).MaterialType = EMT_TRANSPARENT_VERTEX_ALPHA;
		cube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
		cube->setMaterialFlag(EMF_LIGHTING, false);
		smgr->getMeshManipulator()->setVertexColorAlpha(cube->getMesh(),128);
	}
	// second cube without texture
	cube = smgr->addCubeSceneNode(10.0f,0,-1,vector3df(5,3,-15));
	if (cube)
	{
		cube->getMaterial(0).MaterialType = EMT_TRANSPARENT_VERTEX_ALPHA;
		cube->setMaterialFlag(EMF_LIGHTING, false);
		smgr->getMeshManipulator()->setVertexColorAlpha(cube->getMesh(),128);
	}

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

	driver->beginScene(true, true, SColor(0,200,200,200));
	smgr->drawAll();
	driver->endScene();

	bool result = takeScreenshotAndCompareAgainstReference(driver, "-transparentVertexAlphaChannelMore.png", 99.18f);

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

	return result;
}
Example #2
0
void Editor::LoadScene()
{
	IVideoDriver *driver = device->getVideoDriver();
	ISceneManager *smgr = device->getSceneManager();

	// Calculate Projection Matrix
	matrix4 projMat;
	irr::f32 orth_w = (float)(driver->getScreenSize().Width - 256) / (float)driver->getScreenSize().Height;
	orth_w = 3 * orth_w;
	projMat.buildProjectionMatrixOrthoLH(orth_w, 3, 1, 100);

	// Create target
	target = smgr->addEmptySceneNode(0, 200);
	target->setPosition(vector3df(0, 0, 0));

	// Add rotational camera
	pivot = smgr->addEmptySceneNode(target, 199);
	camera[0] = smgr->addCameraSceneNode(NULL, vector3df(0, 0, -2), vector3df(0, 0, 0));
	camera[0]->setParent(pivot);
	pivot->setRotation(vector3df(25, -45, 0));

	// Add Topdown camera
	camera[1] = smgr->addCameraSceneNode(target, vector3df(0, 2, -0.01), vector3df(0, 0, 0));
	camera[1]->setProjectionMatrix(projMat, true);

	// Add front camera
	camera[2] = smgr->addCameraSceneNode(target, vector3df(0, 0, -5), vector3df(0, 0, 0));
	camera[2]->setProjectionMatrix(projMat, true);

	// Add side camera
	camera[3] = smgr->addCameraSceneNode(target, vector3df(5, 0, 0), vector3df(0, 0, 0));
	camera[3]->setProjectionMatrix(projMat, true);

	// Add Light
	ILightSceneNode* light = smgr->addLightSceneNode(target, vector3df(25, 50, 0));
	light->setLightType(ELT_POINT);
	light->setRadius(2000);

	// Add Plane
	IMeshSceneNode* plane = smgr->addCubeSceneNode(1, 0, -1,
			vector3df(0.5, -5.5, 0.5), vector3df(0, 0, 0),
			vector3df(10, 10, 10));
	plane->setMaterialTexture(0, driver->getTexture("media/texture_terrain.png"));
	plane->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
	plane->getMaterial(0).getTextureMatrix(0).setTextureScale(10, 10);

	// Add sky box
	scene::IMeshSceneNode* skybox = smgr->addCubeSceneNode(50);
	skybox->setMaterialTexture(0, driver->getTexture("media/sky.jpg"));
	skybox->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
	skybox->setMaterialFlag(video::EMF_LIGHTING, false);
	smgr->getMeshManipulator()->flipSurfaces(skybox->getMesh());
	state->plane_tri = smgr->createOctreeTriangleSelector(skybox->getMesh(), skybox);
}
Example #3
0
/** Tests the Burning Video driver */
bool burningsVideo(void)
{
    IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO,
										core::dimension2di(160,120), 32);
    if (!device)
        return false;

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

    smgr->addCubeSceneNode(10.f, 0, -1, core::vector3df(0.f, 0.f, 20.f));
    smgr->addCameraSceneNode();
    // Test that ambient lighting works when there are no other lights in the scene
    smgr->setAmbientLight(video::SColorf(.7f, .1f, .1f, 1.f));

    bool result = false;
    device->run();
	if (driver->beginScene(true, true, video::SColor(0, 80, 80, 80)))
	{
		smgr->drawAll();
		driver->endScene();
		result = takeScreenshotAndCompareAgainstReference(driver, "-ambient-lighting.png", 100);
	}

    device->drop();

    return result;
}
Example #4
0
int main(int argc, char** argv)
{
    IrrlichtDevice* device = createDevice(video::EDT_OPENGL, dimension2d<u32>(800, 600), 16, false, false, false, 0);
    
    if (!device) {
        return 1;
    }
    
    
    device->setWindowCaption(L"boxes");
    
    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    
    IMeshSceneNode* cube = smgr->addCubeSceneNode();
    
    smgr->addCameraSceneNode(0);
    
    while (device->run()) {
        driver->beginScene();
        
        smgr->drawAll();
        
        driver->endScene();
    }
    
    return 0;
}
Example #5
0
static bool runTestWithDriver(E_DRIVER_TYPE driverType)
{
	IrrlichtDevice *device = createDevice( driverType, dimension2d<s32>(640, 480));
	if (!device)
		return true; // Treat a failure to create a driver as benign; this saves a lot of #ifdefs
	
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager * smgr = device->getSceneManager();
	
	// Draw a cube to check that the pixels' alpha is working.
	ISceneNode * cube = smgr->addCubeSceneNode(50.f, 0, -1, vector3df(0, 0, 60));
	cube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
	cube->setMaterialFlag(video::EMF_LIGHTING, false);
	(void)smgr->addCameraSceneNode();

	driver->beginScene(true, true, SColor(255,100,101,140));
	smgr->drawAll();

	// Test for offscreen values as well as onscreen.
	for(s32 x = -10; x < 650; ++x)
	{
		s32 y = 480 * x / 640;
		driver->drawPixel((u32)x, (u32)y, SColor(255, 255 * x / 640, 255 * (640 - x) / 640, 0));
		y = 480 - y;
		driver->drawPixel((u32)x, (u32)y, SColor(255 * x / 640, 0, 255, 255));
	}

	driver->endScene();

	bool result = takeScreenshotAndCompareAgainstReference(driver, "-drawPixel.jpg");

	device->drop();

	return result;
}
Example #6
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;
	}
}
Example #7
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 #8
0
void Editor::LoadScene()
{
	IVideoDriver *driver = device->getVideoDriver();
	ISceneManager *smgr = device->getSceneManager();

	// Create target
	target = smgr->addEmptySceneNode(0, 200);
	target->setPosition(vector3df(0, 0, 0));

	// Create cameras
	pivot = smgr->addEmptySceneNode(target, 199);
	pivot->setRotation(vector3df(25, -45, 0));
	recreateCameras();

	// Add Light
	ILightSceneNode* light = smgr->addLightSceneNode(target, vector3df(25, 50, 0));
	light->setLightType(ELT_POINT);
	light->setRadius(2000);

	// Add Plane
	plane = smgr->addCubeSceneNode(1, 0, -1,
			vector3df(0.5, -5.5, 0.5), vector3df(0, 0, 0),
			vector3df(10, 10, 10));
	plane->setMaterialTexture(0, driver->getTexture("media/texture_terrain.png"));
	plane->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
	plane->setMaterialFlag(video::EMF_LIGHTING, false);
	plane->setMaterialFlag(video::EMF_BACK_FACE_CULLING, true);
	plane->getMaterial(0).getTextureMatrix(0).setTextureScale(10, 10);

	// Add sky box
	scene::IMeshSceneNode* skybox = smgr->addCubeSceneNode(50);
	skybox->setMaterialTexture(0, driver->getTexture("media/sky.jpg"));
	skybox->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
	skybox->setMaterialFlag(video::EMF_LIGHTING, false);
	smgr->getMeshManipulator()->flipSurfaces(skybox->getMesh());
	state->plane_tri = smgr->createOctreeTriangleSelector(skybox->getMesh(), skybox);
}
/** Test the behaviour of makeColorKeyTexture() using both 16 bit (software)
	and 32 bit (Burning) textures, with the new behaviour and the legacy
	behaviour. */
static bool doTestWith(E_DRIVER_TYPE driverType,
						bool zeroTexels)
{
	IrrlichtDevice *device = createDevice( driverType,
											dimension2d<u32>(160, 120), 32);
	if (!device)
		return false;

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

	// Draw a cube background so that we can check that the keying is working.
	ISceneNode * cube = smgr->addCubeSceneNode(50.f, 0, -1, vector3df(0, 0, 60));
	cube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
	cube->setMaterialFlag(video::EMF_LIGHTING, false);

	ITexture * Texture = device->getVideoDriver()->getTexture("../media/portal2.bmp");

	device->getVideoDriver()->makeColorKeyTexture(Texture,
												  position2d<s32>(64,64),
												  zeroTexels);
	device->getVideoDriver()->makeColorKeyTexture(Texture,
												  position2d<s32>(64,64),
												  zeroTexels);
	(void)smgr->addCameraSceneNode();

	driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(255,100,101,140));
	smgr->drawAll();

	driver->draw2DImage(Texture,
						position2di(40, 40),
						rect<s32>(0, 0, Texture->getSize().Width, Texture->getSize().Height),
						0,
						SColor(255,255,255,255),
						true);
	driver->endScene();

	char screenshotName[256];
	(void)snprintf_irr(screenshotName, 256, "-makeColorKeyTexture-%s.png",
		zeroTexels? "old" : "new");

	bool result = takeScreenshotAndCompareAgainstReference(driver, screenshotName);

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

	return result;
}
ISceneNode* Background::generateSingleCube(vector3df Size, vector3df Position, bool Transparency, char* TexturePath, irr::f32 SpeedHorizontal, irr::f32 SpeedInwards, IrrlichtDevice* Device, Level Lvl)
{
	IVideoDriver* driver = Device->getVideoDriver();
	ISceneManager* smgr = Device->getSceneManager();

	ISceneNode* cube = smgr->addCubeSceneNode();
	cube->setScale(Size);
	cube->setPosition(Position);

	cube->setMaterialTexture(0,driver->getTexture(TexturePath));
	cube->setMaterialFlag(video::EMF_LIGHTING, false);
	if(Transparency) cube->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);

	return cube;
}
BgMovableObject::BgMovableObject(Level* L, Point position, Point scale, char* TexturePath, int t, Point mov){

	movement=mov;
	type = t;
	IVideoDriver* driver = L->driver;
	ISceneManager* smgr = L->smgr;

	graphic_model= smgr->addCubeSceneNode();
	graphic_model->setMaterialFlag(video::EMF_LIGHTING, true);
	graphic_model->setMaterialTexture(0, driver->getTexture(TexturePath));
	graphic_model->setMaterialFlag(video::EMF_LIGHTING, false);
		
	graphic_model->setPosition(core::vector3df(position.position_x, position.position_y, position.layer));
	graphic_model->setScale(core::vector3df(scale.position_x, scale.position_y, scale.layer));
	graphic_model->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
}
Example #12
0
/** The result should be as follows: We have three times the same image, a billboard with a cube and the text in front.
They are replicated three times, one centered in the screen without viewport, one in the upper left (qurter screen) and
one on the right (half screen). The latter is stretched due to the changed aspect ratio.
The two viewport scenes get the texture drawn over the center as well, using draw2dimage. This should mark the proper
image position with the top left corner of the texture.
Finally, each scene has a checkbox drawn at the left side, vertically centered. This will show whether GUI elements adhere
to viewports as well. */
static bool viewPortText(E_DRIVER_TYPE driverType)
{
	IrrlichtDevice *device = createDevice( driverType, dimension2d<u32>(160, 120), 32);
	if (!device)
		return true; // Treat a failure to create a driver as benign; this saves a lot of #ifdefs

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

	stabilizeScreenBackground(driver);

	env->addCheckBox(true, core::recti(10,60,28,82));

	logTestString("Testing driver %ls\n", driver->getName());

	IBillboardSceneNode * bnode = smgr->addBillboardSceneNode(0,dimension2d<f32>(32,32),core::vector3df(0,0,10));
	bnode->setMaterialFlag(video::EMF_LIGHTING, false);
	bnode->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
	bnode->setMaterialTexture(0, driver->getTexture("../media/fire.bmp"));

	smgr->addTextSceneNode(device->getGUIEnvironment()->getBuiltInFont(), L"TEST", video::SColor(255,255,255,255), 0);
	smgr->addCubeSceneNode();
	smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

	driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(255,100,101,140));
	smgr->drawAll();
	env->drawAll();
	driver->setViewPort(rect<s32>(0,0,160/2,120/2));
	smgr->drawAll();
	env->drawAll();
	driver->draw2DImage(driver->getTexture("../media/fire.bmp"), core::vector2di(160/2,120/2));
	driver->setViewPort(rect<s32>(160/2,0,160,120));
	smgr->drawAll();
	env->drawAll();
	driver->draw2DImage(driver->getTexture("../media/fire.bmp"), core::vector2di(160/2,120/2));
	driver->endScene(); 

	bool result = takeScreenshotAndCompareAgainstReference(driver, "-viewPortText.png", 98.71f);

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

	return result;
}
Example #13
0
void Player::Init(UnitObject* pUnit,ITriangleSelector* pTerrain)
{
    Irrdevice* pDevice 	= Irrdevice::GetInstance();
    m_pUnitObject		= pUnit;

    ISceneManager* pSmgr = pDevice->GetSceneManager();

    SKeyMap aKeyMap[5];
    aKeyMap[0].Action = EKA_MOVE_FORWARD;
    aKeyMap[0].KeyCode = KEY_KEY_W;
    aKeyMap[1].Action = EKA_MOVE_BACKWARD;
    aKeyMap[1].KeyCode = KEY_KEY_S;
    aKeyMap[2].Action = EKA_STRAFE_LEFT;
    aKeyMap[2].KeyCode = KEY_KEY_A;
    aKeyMap[3].Action = EKA_STRAFE_RIGHT;
    aKeyMap[3].KeyCode = KEY_KEY_D;
    aKeyMap[4].Action = EKA_JUMP_UP;
    aKeyMap[4].KeyCode = KEY_SPACE;

    //각 유닛마다 카메라 생성
    m_pCamera = pSmgr->addCameraSceneNodeFPS(0,100.0f,0.5f,-1,aKeyMap,9,false,0,false,false);
    m_pCollisionAnimator = static_cast<ISceneNodeAnimatorCameraFPS*>(*(m_pCamera->getAnimators().begin()));	//카메라가 가지고 있는 FPS 카메라 애니메이션 을 가지온다. 이것은 줌 확대 기능 등!!


    //카메라 따라댕기는 유닉 오브젝트... 방향에 대한것도 설정해줘야함... 이것은 일단 나중에 테스트를 위하여
    m_pUnitObject->GetAnimatedNode()->setParent(m_pCamera);


    IMeshSceneNode* pNode = pSmgr->addCubeSceneNode(10,m_pCamera);
    m_pCamera->addChild(pUnit->GetAnimatedNode());

    pNode->setVisible(true);

    m_pMyTriangle = pSmgr->createTriangleSelector(pNode->getMesh(),pNode);

    m_pMetaTriangle = pSmgr->createMetaTriangleSelector();
    m_pMetaTriangle->addTriangleSelector(pTerrain);

    //역시 스크립트 적용 안할 수가 없다... 파일을 읽어와서 적용하던지.... 아우
    ISceneNodeAnimatorCollisionResponse * pani = pSmgr->createCollisionResponseAnimator(m_pMetaTriangle,m_pCamera);
    m_pCamera->addAnimator(pani);
    pani->drop();

}
Example #14
0
int main()
{
	MyEventReceiver receiver;

    IrrlichtDevice* device = createDevice(video::EDT_OPENGL,
            core::dimension2d<u32>(640, 480), 16, false, false, false, &receiver);
	IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
	smgr->addLightSceneNode(0,vector3df(50,50,50));
	ICameraSceneNode *camera = smgr->addCameraSceneNode();

	IMeshSceneNode *node = smgr->addCubeSceneNode();
	
	node->setPosition(vector3df(0,75,0));

	camera->setTarget(vector3df(0,1,0));

	
	smgr->getMeshManipulator()->setVertexColors(node->getMesh(), SColor(0,0,255,255));
	smgr->addLightSceneNode();

	while(device->run()){

		if(receiver.IsKeyDown(irr::KEY_LEFT)){
			node->setPosition(node->getPosition()+vector3df(0,0,-0.1));
		}
		else if(receiver.IsKeyDown(irr::KEY_RIGHT)){
			node->setPosition(node->getPosition()+vector3df(0,0,0.1));
		}
		else if(receiver.IsKeyDown(irr::KEY_SPACE)){
			
		}
		driver->beginScene(true, true, SColor(123,100,100,100));
        smgr->drawAll();
		driver->endScene();
	}



	return 0;
}
Example #15
0
/** Expect to see two diagonal lines overlaying a wall texture cube.
	One line should run from green at the top left to red at the bottom right.
	The other should run from cyan 100% transparent at the bottom left to
	cyan 100% opaque at the top right. */
static bool lineRender(E_DRIVER_TYPE driverType)
{
	IrrlichtDevice *device = createDevice( driverType, dimension2d<u32>(160, 120), 32);
	if (!device)
		return true; // Treat a failure to create a driver as benign; this saves a lot of #ifdefs

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

	stabilizeScreenBackground(driver);

	logTestString("Testing driver %ls\n", driver->getName());

	// Draw a cube background so that we can check that the pixels' alpha is working.
	ISceneNode * cube = smgr->addCubeSceneNode(50.f, 0, -1, vector3df(0, 0, 60));
	cube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
	cube->setMaterialFlag(video::EMF_LIGHTING, false);
	(void)smgr->addCameraSceneNode();

	driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(255,100,101,140));
	smgr->drawAll();

	// Test for benign handling of offscreen pixel values as well as onscreen ones.
	for(s32 x = -10; x < 170; ++x)
	{
		s32 y = 120 * x / 160;
		driver->drawPixel((u32)x, (u32)y, SColor(255, 255 * x / 640, 255 * (640 - x) / 640, 0));
		y = 120 - y;
		driver->drawPixel((u32)x, (u32)y, SColor(255 * x / 640, 0, 255, 255));
	}

	driver->endScene();

	bool result = takeScreenshotAndCompareAgainstReference(driver, "-drawPixel.png", 98.81f);

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

	return result;
}
Example #16
0
// Tests B3D animations.
bool b3dAnimation(void)
{
	// Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
	IrrlichtDevice *device = createDevice( EDT_BURNINGSVIDEO, dimension2d<u32>(160, 120), 32);
	assert(device);
	if (!device)
		return false;

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

	ISkinnedMesh* mesh = (ISkinnedMesh*)smgr->getMesh("../media/ninja.b3d");
	assert(mesh);

	bool result = false;
	if (!mesh)
		return false;

	IAnimatedMeshSceneNode* node1 = smgr->addAnimatedMeshSceneNode(mesh);
	assert(node1);

	/** Verify that two skinned animated mesh scene nodes can use different frames of the skinned mesh */
	if(node1)
	{
		node1->setPosition(vector3df(-3, -3, 10));
		node1->setMaterialFlag(EMF_LIGHTING, false);
		node1->setAnimationSpeed(0.f);
		node1->setCurrentFrame(10.f);
		node1->setDebugDataVisible(irr::scene::EDS_BBOX_BUFFERS);
	}

	IAnimatedMeshSceneNode* node2 = smgr->addAnimatedMeshSceneNode(mesh);
	assert(node2);
	if(node2)
	{
		node2->setPosition(vector3df(3, -3, 10));
		node2->setMaterialFlag(EMF_LIGHTING, false);
		node2->setAnimationSpeed(0.f);
		node2->setCurrentFrame(62.f);
		node2->setDebugDataVisible(irr::scene::EDS_BBOX_BUFFERS);
	}

	(void)smgr->addCameraSceneNode();

	// Just jump to the last frame since that's all we're interested in.
	device->run();
	driver->beginScene(true, true, SColor(255, 60, 60, 60));
	smgr->drawAll();
	driver->endScene();

	result = takeScreenshotAndCompareAgainstReference(driver, "-b3dAnimation.png");
	if (node2)
		node2->remove();

	/** Now test if bones are correctly positioned. */
	node1->setDebugDataVisible(scene::EDS_SKELETON);
	node1->setPosition(vector3df(1, -5, 8));
	node1->setRotation(core::vector3df(0,180,0));
	node1->updateAbsolutePosition();
	for (u32 i=0; i<node1->getJointCount(); ++i)
	{
		smgr->addCubeSceneNode(1.f,0,-1,node1->getJointNode(i)->getAbsolutePosition());
//		smgr->addCubeSceneNode(1.f,node1->getJointNode(i));
	}

	// Simple render call
	device->run();
	driver->beginScene(true, true, SColor(255, 60, 60, 60));
	smgr->drawAll();
	driver->endScene();

	result &= takeScreenshotAndCompareAgainstReference(driver, "-b3dJointPosition.png");

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

	return result;
}
Example #17
0
int main(int argc, char **argv) {
    BSPdungeon dun(50,50,5);
    
   IrrlichtDevice *device =createDevice( video::EDT_OPENGL, dimension2d<u32>(1280,720), 16,false, false, false, 0);

	if (!device)
		return 1;

	device->setWindowCaption(L"Pangolin Kwest");

	
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();
	
	smgr->setAmbientLight(video::SColorf(0.1,0.1,0.1,1));
	
	ILightSceneNode* mylight1 = smgr->addLightSceneNode( 0, core::vector3df(00,00,00), video::SColorf(0.3f,0.3f,0.3f), 30.0f, 1 ); 
	
	//IGUIFont* myfont=guienv->getFont("./myfont.xml");
	//if(myfont==0)exit(93);
	
	//guienv->addMessageBox(L"Alertz!",L"You pangolin are been createrized. You totalleh ready to bash monstaz etc.!");
	
	mylight1->enableCastShadow(true);
	
	//guienv->addStaticText(L"Pangolin Kwest 3D",rect<s32>(10,10,260,22), true);
	//-------------------------------------------	
	
	int x,y,z;
	for(x=0;x<50;x++){
		for(y=0;y<50;y++){
		  if(dun.map[x][y]==NIL){
		    for(z=0;z<3;z++){
		      ISceneNode* cueb=smgr->addCubeSceneNode(10);
		      cueb->setMaterialFlag(EMF_LIGHTING, true);
		      cueb->setMaterialTexture( 0, driver->getTexture("media/stdwall.jpg") );
		     // cueb->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.25,0.5);
		     // cueb->getMaterial(0).getTextureMatrix(0).setTextureScale(0.0625,0.0625);
		      cueb->setPosition(vector3df(x*10,z*10,y*10));
		    }
		  }
// 		   ISceneNode* cueb=smgr->addCubeSceneNode(10);
// 		   cueb->setMaterialFlag(EMF_LIGHTING, true);
// 		   cueb->setMaterialTexture( 0, driver->getTexture("media/stdfloor.jpg") );
// 		   cueb->setPosition(vector3df(x*10,-10,y*10));
		   
		   ISceneNode* cueb=smgr->addCubeSceneNode(10);
		   cueb->setMaterialFlag(EMF_LIGHTING, true);
		   cueb->setMaterialTexture( 0, driver->getTexture("media/stdup.jpg") );
		   cueb->setPosition(vector3df(x*10,30,y*10));
		   
		}
	}	

	
	
	ISceneNode* cueb=smgr->addCubeSceneNode(500);
	cueb->setMaterialFlag(EMF_LIGHTING, true);
	cueb->setMaterialTexture( 0, driver->getTexture("media/stdfloor.jpg") );
	cueb->setPosition(vector3df(250,-255,250));
	//cueb->getMaterial(0).getTextureMatrix(0).setTextureTranslate(0.25,0.5);
	cueb->getMaterial(0).getTextureMatrix(0).setTextureScale(50,50);
	//cueb->setScale(vector3df(0,-5,0));
	 //cueb->addshadowVolumeSceneNode();



	//-------------------------------------------	

	int lastFPS;

	//smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
	ICameraSceneNode* mycam;
	mycam=smgr->addCameraSceneNodeFPS(0,100.0f,0.025f);
	mycam->setFOV(45);
	mylight1->setParent(mycam);
	while(device->run())
	{
		//mylight1->setPosition();
		//mylight1->
		driver->beginScene(true, true, SColor(255,100,101,140));
  
		smgr->drawAll();
		guienv->drawAll();

		driver->endScene();
		
		int fps = driver->getFPS();

                if (lastFPS != fps)
                {
                        core::stringw str = L"Pangolin Kwest 3D [";
                        str += driver->getName();
                        str += "] FPS:";
                        str += fps;

                        device->setWindowCaption(str.c_str());
                        lastFPS = fps;
                }
		
	}

	
	device->drop();

    
    
    
    
    
    
    return 0;
}
/** Test that collision response animator will reset itself when removed from a
	scene node, so that the scene node can then be moved without the animator
	jumping it back again. */
bool collisionResponseAnimator(void)
{
	IrrlichtDevice * device = irr::createDevice(video::EDT_NULL);
	assert(device);
	if(!device)
		return false;

	ISceneManager * smgr = device->getSceneManager();

	// Create 2 nodes to the left of a "wall"
	ISceneNode * testNode1 = smgr->addEmptySceneNode();
	ISceneNode * testNode2 = smgr->addEmptySceneNode();
	testNode1->setPosition(vector3df(-50, 0,0));
	testNode2->setPosition(vector3df(-50, 0,0));

	// Create a "wall" node, and collision response animators for each test node.
	IMeshSceneNode * wallNode = smgr->addCubeSceneNode(10.f);

	ITriangleSelector * wallSelector = smgr->createTriangleSelectorFromBoundingBox(wallNode);
	ISceneNodeAnimatorCollisionResponse * collisionAnimator1 =
		smgr->createCollisionResponseAnimator(wallSelector,
												testNode1,
												vector3df(10,10,10),
												vector3df(0, 0, 0));
	testNode1->addAnimator(collisionAnimator1);

	CMyCollisionCallback collisionCallback;
	collisionAnimator1->setCollisionCallback(&collisionCallback);

	collisionAnimator1->drop();
	collisionAnimator1 = 0;

	ISceneNodeAnimatorCollisionResponse * collisionAnimator2 =
		smgr->createCollisionResponseAnimator(wallSelector,
												testNode2,
												vector3df(10,10,10),
												vector3df(0, 0, 0));
	testNode2->addAnimator(collisionAnimator2);
	collisionAnimator2->setCollisionCallback(&collisionCallback);

	wallSelector->drop();
	// Don't drop() collisionAnimator2 since we're going to use it.

	// Get the system in a good state
	device->run();
	smgr->drawAll();

	// Try to move both nodes to the right of the wall.
	// This one should be stopped by its animator.
	testNode1->setPosition(vector3df(50, 0,0));
	collisionCallback.setNextExpectedCollision(testNode1,
												vector3df(-5.005f, 0, 0),
												vector3df(-15.005f, 0, 0),
												false);

	// Whereas this one, by forcing the animator to update its target node, should be
	// able to pass through the wall. (In <=1.6 it was stopped by the wall even if
	// the animator was removed and later re-added);
	testNode2->setPosition(vector3df(50, 0,0));
	collisionAnimator2->setTargetNode(testNode2);
	collisionAnimator2->drop(); // We're done using this now.

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

	bool result = true;

	if(testNode1->getAbsolutePosition().X > -15.f)
	{
		logTestString("collisionResponseAnimator test node 1 wasn't stopped from moving.\n");
		assert(false);
		result = false;
	}

	if(testNode2->getAbsolutePosition().X < 50.f)
	{
		logTestString("collisionResponseAnimator test node 2 was stopped from moving.\n");
		assert(false);
		result = false;
	}

	// Now try to move the second node back through the wall again. Now it should be
	// stopped by the wall.
	testNode2->setPosition(vector3df(-50, 0, 0));

	// We'll consume this collision, so the node will actually move all the way through.
	collisionCallback.setNextExpectedCollision(testNode2,
												vector3df(5.005f, 0, 0),
												vector3df(15.005f, 0, 0),
												true);

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

	if(testNode2->getAbsolutePosition().X != -50.f)
	{
		logTestString("collisionResponseAnimator test node 2 was stopped from moving.\n");
		assert(false);
		result = false;
	}

	// Now we'll try to move it back to the right and allow it to be stopped.
	collisionCallback.setNextExpectedCollision(testNode2,
												vector3df(-5.005f, 0, 0),
												vector3df(-15.005f, 0, 0),
												false);
	testNode2->setPosition(vector3df(50, 0, 0));

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

	if(testNode2->getAbsolutePosition().X > -15.f)
	{
		logTestString("collisionResponseAnimator test node 2 moved too far.\n");
		assert(false);
		result = false;
	}


	device->drop();

	result &= expectedCollisionCallbackPositions;
	return result;
}
Example #19
0
//! Tests IVideoDriver::writeImageToFile() using IWriteFile
bool writeImageToFile(void)
{
	IrrlichtDevice *device = createDevice( EDT_BURNINGSVIDEO, dimension2d<u32>(160, 120), 32);
	if (!device)
		return true; // Treat a failure to create a driver as benign; this saves a lot of #ifdefs

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

	// Draw a cube background so that we can check that the pixels' alpha is working.
	ISceneNode * cube = smgr->addCubeSceneNode(50.f, 0, -1, vector3df(0, 0, 60));
	cube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
	cube->setMaterialFlag(video::EMF_LIGHTING, false);
	(void)smgr->addCameraSceneNode();

	driver->beginScene(true, true, SColor(255,100,101,140));
	smgr->drawAll();

	// Test for benign handling of offscreen pixel values as well as onscreen ones.
	for(s32 x = -10; x < 170; ++x)
	{
		s32 y = 120 * x / 160;
		driver->drawPixel((u32)x, (u32)y, SColor(255, 255 * x / 640, 255 * (640 - x) / 640, 0));
		y = 120 - y;
		driver->drawPixel((u32)x, (u32)y, SColor(255 * x / 640, 0, 255, 255));
	}

	driver->endScene();

	bool result = false;
	IWriteFile * writtenFile = 0;
	IWriteFile * memoryFile = 0;
	const char * writtenFilename = 0;
	const u32 BUFFER_SIZE = 160 * 120 * 4;
	c8 * buffer = 0;
	const char * referenceFilename = 0;
	video::ECOLOR_FORMAT format;

	irr::video::IImage * screenshot = driver->createScreenShot();
	if(!screenshot)
	{
		logTestString("Failed to take screenshot\n");
		assert(false);
		goto cleanup;
	}

	format = screenshot->getColorFormat();
	if(format != video::ECF_R8G8B8)
	{
		irr::video::IImage * fixedScreenshot = driver->createImage(video::ECF_R8G8B8, screenshot);
		screenshot->drop();

		if(!fixedScreenshot)
		{
			logTestString("Failed to convert screenshot to ECF_A8R8G8B8\n");
			assert(false);
			goto cleanup;
		}

		screenshot = fixedScreenshot;
	}

	buffer = new c8[BUFFER_SIZE];
	writtenFilename = "results" DIR_SEP_STRING "Burning's Video-drawPixel.png";
	memoryFile = device->getFileSystem()->createMemoryWriteFile(buffer, BUFFER_SIZE, writtenFilename, false);
	if(!driver->writeImageToFile(screenshot, memoryFile))
	{
		logTestString("Failed to write png to memory file\n");
		assert(false);
		goto cleanup;
	}

	writtenFile = device->getFileSystem()->createAndWriteFile(memoryFile->getFileName());
	if(!writtenFile)
	{
		logTestString("Can't open %s for writing.\n", writtenFilename);
		assert(false);
		goto cleanup;
	}

	if(memoryFile->getPos() != writtenFile->write(buffer, memoryFile->getPos()))
	{
		logTestString("Error while writing to %s.\n", writtenFilename);
		assert(false);
		goto cleanup;
	}

	writtenFile->drop();
	writtenFile = 0;

	referenceFilename = "media" DIR_SEP_STRING "Burning's Video-drawPixel.png";
	if(!binaryCompareFiles(writtenFilename, referenceFilename))
	{
		logTestString("File written from memory is not the same as the reference file.\n");
		assert(false);
		goto cleanup;
	}

	result = true;

cleanup:
	if(writtenFile)
		writtenFile->drop();

	if(memoryFile)
		memoryFile->drop();

	delete [] buffer;

	device->drop();

	return result;
}
Example #20
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;
}
Example #21
0
int main()
{
    const int nRobots = 2;
    //given robot numbers will be controlled by humans
    vector<int> humanBrainIds; 
    //humanBrainIds.push_back(1);
    //humanBrainIds.push_back(0);

//-- device ------------------------------------------------------------//

    IrrlichtDevice* device;

    device = createDevice(
        EDT_OPENGL, //driverType
        windowSize,
        16,  //bits
        false,
        false, //stencilbuffer
        false, //vsync
        NULL //receiver
    );
    //advanced device params
        //SIrrlichtCreationParameters params;
        //params.DeviceType = EIDT_CONSOLE;
        //params.DriverType = EDT_OPENGL;
        //params.WindowSize = windowSize;
        //device = createDeviceEx(params);

    if (device == 0)
        return EXIT_FAILURE; // could not create selected driver.

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

//-- lights ------------------------------------------------------------//

    //ambient light
    //smgr->setAmbientLight( SColorf(1.0f,1.0f,1.0f,1.0f) );
        //smgr->setAmbientLight( SColorf(.3f,.3f,.3f,1.0f) );

    //diffusive light
        SLight light_data;
        light_data.AmbientColor = SColorf(.3,.3,.3);
        //light_data.Attenuation = vector3df(.3,.3,.3); //Attenuation cte, linear quadratic TODO ??
        light_data.DiffuseColor = SColorf(.0,.0,.0);
        light_data.SpecularColor = SColorf(.0,.0,.0);
        light_data.CastShadows = true;
        light_data.Radius = 100.0f;
        light_data.Type = ELT_DIRECTIONAL;
            //ELT_POINT 	point light, it has a position in space and radiates light in all directions
            //ELT_SPOT    spot light, it has a position in space, a direction, and a limited cone of influence
            //ELT_DIRECTIONAL 	directional light, coming from a direction from an infinite distance 
            
        ILightSceneNode* light = smgr->addLightSceneNode(0, core::vector3df(.5f,.0f,.5f));
        light->setLightData(light_data);

//-- objects ------------------------------------------------------------//

    IMesh* mesh;
    ISceneNode * node;
    float HEIGHT=1000.f, WIDTH=1.f;
    //height between center/sky == height bottom/center
    //large so that scene looks 2d on interactive test mode.
    //on automatic mode, only middle pixel row is taken, so this does not matter

    //outter boundary
        
        //square
            node = smgr->addCubeSceneNode(
                2.f*WIDTH,  // width
                0,      // parent
                -1,     // id
                vector3df(0, 0, 0),               // center
                vector3df(0, 0, 0),               // rotation
                vector3df(1.0f, HEIGHT, 1.0f)*-1.f    // scale. *-1 turns it inside out. to use both faces make two cubes.
            );

        //circle
            //mesh = smgr->getGeometryCreator()->createCylinderMesh(
                //1.f,    //radius
                //1.,     //length
                //50,     //tesselation
                //SColor(0,0,0,255),     //color
                //false,                 //closeTop
                //0.f                    //oblique
            //);
            //node = smgr->addMeshSceneNode(
                //mesh,
                //0,     //ISceneNode * parent
                //-1,    //s32 id
                //vector3df(0, -HEIGHT, 0),            //const core::vector3df & position
                //vector3df(0, 0, 0),                     //const core::vector3df & rotation
                //vector3df(1.0f, 2.f*HEIGHT, 1.0f)      //const core::vector3df & scale
            //);

        node->getMaterial(0).AmbientColor.set(0,0,0,0);
        node->getMaterial(0).DiffuseColor.set(0,0,0,0);
        //node->getMaterial(0).SpecularColor.set(255,255,255,255);
        //node->getMaterial(0).Shininess = 20.0f;
        //node->getMaterial(0).EmissiveColor.set(0,0,0,0);
        //node->setMaterialFlag(EMF_WIREFRAME,true); //wireframe only

    //left cube
        node = smgr->addCubeSceneNode(
            0.2,    // width
            0,      // parent
            -1,     // id
            vector3df(-.3, 0, 0),       // center
            vector3df(0, 0, 0),           // rotation
            vector3df(1.0f, HEIGHT, 1.0f)   // scale
        );
        node->getMaterial(0).AmbientColor.set(0,255,0,0);
        node->getMaterial(0).DiffuseColor.set(0,255,0,0);

    //right cube
        node = smgr->addCubeSceneNode(
            .2f,    // width
            0,      // parent
            -1,     // id
            vector3df(.3, 0, 0),        // center
            vector3df(0, 0, 0),           // rotation
            vector3df(1.0f, HEIGHT, 1.0f)   // scale
        );
        node->getMaterial(0).AmbientColor.set(0,0,255,0);
        node->getMaterial(0).DiffuseColor.set(0,0,255,0);

    //cylinder
        //mesh = smgr->getGeometryCreator()->createCylinderMesh(
            //.1f,    //radius
            //1.,     //length
            //50,     //tesselation
            //SColor(),              //color
            //false,                 //closeTop
            //0.f                    //oblique
        //);
        //node = smgr->addMeshSceneNode(
            //mesh,
            //0,     //ISceneNode * parent
            //-1,    //s32 id
            //vector3df(0, -HEIGHT, 0),            //const core::vector3df & position
            //vector3df(0, 0, 0),                  //const core::vector3df & rotation
            //vector3df(1.0f, 2.*HEIGHT, 1.0f)     //const core::vector3df & scale
        //);
        //node->getMaterial(0).AmbientColor.set(0,0,0,255);
        //node->getMaterial(0).DiffuseColor.set(0,0,0,255);

    //sphere
        //node = smgr->addSphereSceneNode(
            //0.1,     // radius
            //50,     // poly count
            //0,      // parent
            //FruitID,     // id
            //vector3df(0, 0, 0),         // center
            //vector3df(0, 0, 0),           // rotation
            //vector3df(1.0f, 1.0f, 1.0f)   // scale
        //);
        //node->getMaterial(0).AmbientColor.set(0,0,0,255);
        //node->getMaterial(0).DiffuseColor.set(0,0,0,255);
        //node->getMaterial(0).Lighting = true;

//-- collision ------------------------------------------------------------//

    /* Put everything we want to do collision checking with inside the meta selector. */
    IMetaTriangleSelector * meta = smgr->createMetaTriangleSelector();
    array<ISceneNode *> nodes;
    smgr->getSceneNodesFromType(ESNT_ANY, nodes); // Find all nodes

    for (u32 i=0; i < nodes.size(); ++i)
    {
        ISceneNode * node = nodes[i];
        ITriangleSelector * selector = 0;

        switch(node->getType())
        {
            case ESNT_CUBE:
            case ESNT_ANIMATED_MESH:
            // Because the selector won't animate with the mesh,
            // and is only being used for camera collision, we'll just use an approximate
            // bounding box instead of ((IAnimatedMeshSceneNode*)node)->getMesh(0)
            selector = smgr->createTriangleSelectorFromBoundingBox(node);
            break;

            case ESNT_MESH:
            case ESNT_SPHERE: // Derived from IMeshSceneNode
            selector = smgr->createTriangleSelector(((IMeshSceneNode*)node)->getMesh(), node);
            break;

            case ESNT_TERRAIN:
            selector = smgr->createTerrainTriangleSelector((ITerrainSceneNode*)node);
            break;

            case ESNT_OCTREE:
            selector = smgr->createOctreeTriangleSelector(((IMeshSceneNode*)node)->getMesh(), node);
            break;

            default:
            // Don't create a selector for this node type
            break;
        }

        if(selector)
        {
            // Add it to the meta selector, which will take a reference to it
            meta->addTriangleSelector(selector);
            // And drop my reference to it, so that the meta selector owns it.
            selector->drop();
        }
    }

//-- robots ------------------------------------------------------------//

    //create robots
    Fly2D::Brain* brains[nRobots];


    //all to a default type
    //for ( int i=0; i<nRobots; i++ )
    //{
        //brains[i] = new Fly2D::BrainForward;
        ////brains[i] = new Fly2D::BrainCircle();
    //}

    brains[0] = new Fly2D::BrainForward;
    brains[1] = new Fly2D::BrainForward;

    //decide human control
        vector<Fly2D::BrainHuman*> hBrains;
        for (
            vector<int>::iterator i = humanBrainIds.begin();
            i != humanBrainIds.end();
            ++i
        )
        {
            if ( *i > nRobots )
            {
                cerr << "no such robot: " << *i << endl;
                exit(EXIT_FAILURE);
            }
            delete brains[*i];
            Fly2D::BrainHuman* hBrain = new Fly2D::BrainHuman;
            brains[*i] = hBrain;
            hBrains.push_back(hBrain);
        }
        Fly2D::ReceiverHuman hReceiver = Fly2D::ReceiverHuman( hBrains );
        device->setEventReceiver( &hReceiver );

    Robot* robots[nRobots];
    robots[0] = new Fly2D::Robot( *device, *meta, *brains[0], vector3df(0,0,-0.5f), vector3df(0,0, 0.5f),  0.01 );
    robots[1] = new Fly2D::Robot( *device, *meta, *brains[1], vector3df(0,0,0.5f),  vector3df(0,0, -0.5f), 0.01 );

    meta->drop(); // As soon as we're done with the selector, drop it.

//-- run ------------------------------------------------------------//
    //TEST
    vector3df oldpos, oldtarget;
    //END TEST
    
    int nFrames = 0;
    ITimer* timer = device->getTimer();
    int t0 = timer->getTime();
    int w = driver->getScreenSize().Width;
    int h = driver->getScreenSize().Height;
    int dh = h/nRobots;
    int observeRobot = 0;

	while(device->run())
	{
        //if (device->isWindowActive()) //only work if window has focus.

        //draw

        driver->setViewPort(rect<s32>(0,0,w,h));
        driver->beginScene(true,true,0);
        for(int i=0; i<nRobots; i++)
        {
            driver->setViewPort(rect<s32>(0,dh*i,w,dh*(i+1)));
            //only part of window gets drawn into

            smgr->setActiveCamera(robots[i]->camera);

            smgr->drawAll(); 
            //draws on window scene of active camera
 
            robots[i]->update();
        }
        driver->endScene();

        //TEST
        //if
        //(
            //robots[observeRobot].getPosition() != oldpos
            //|| robots[observeRobot].getTarget() != oldtarget
        //)
        //oldpos = robots[observeRobot].getPosition();
        //oldtarget = robots[observeRobot].getTarget();

        cout << robots[observeRobot]->str();

        //FPS info
            //cout << "frame no:" << endl << nFrames << endl;;
            //cout << "average fps:" << endl << 1000*nFrames/(float)(timer->getTime()-t0) << endl;
            //nFrames++;
            cout << "fps:" << endl << driver->getFPS() << endl;
        //END TEST
	}
	device->drop();
	return 0;
}
Example #22
0
// Tests mesh transformations via mesh manipulator.
bool meshTransform(void)
{
	// Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
	IrrlichtDevice *device = createDevice(EDT_BURNINGSVIDEO, dimension2d<u32>(160, 120), 32);
	assert_log(device);
	if (!device)
		return false;

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

	IMeshSceneNode* node1 = smgr->addCubeSceneNode(50);
	IAnimatedMesh* amesh = smgr->getMesh("../media/sydney.md2");
	IAnimatedMesh* smesh = smgr->getMesh("../media/ninja.b3d");
	assert_log(node1 && amesh && smesh);

	bool result = false;
	if (!node1 || !amesh || !smesh)
		return false;

//	node1->setPosition(core::vector3df(-60,0,150));
	node1->setDebugDataVisible(scene::EDS_BBOX_ALL);

	IMeshSceneNode* node2 = smgr->addMeshSceneNode(amesh->getMesh(10));
	assert_log(node2);

	if (!node2)
		return false;

//	node2->setPosition(core::vector3df(30,10,150));
	node2->setDebugDataVisible(scene::EDS_BBOX_ALL);
	node2->setMaterialFlag(EMF_LIGHTING, false);

	IMeshSceneNode* node3 = smgr->addMeshSceneNode(smesh->getMesh(10));
	assert_log(node3);

	if (!node3)
		return false;

//	node3->setPosition(core::vector3df(10,0,0));
	node3->setDebugDataVisible(scene::EDS_BBOX_ALL);
	node3->setMaterialFlag(EMF_LIGHTING, false);

	smgr->addCameraSceneNode()->setPosition(core::vector3df(0,0,-20));

	// Just jump to the last frame since that's all we're interested in.
	device->run();
	driver->beginScene(true, true, SColor(255, 60, 60, 60));
	smgr->drawAll();
	driver->endScene();

	core::matrix4 mat;
	mat.setTranslation(core::vector3df(-60,0,150));
	driver->getMeshManipulator()->transform(node1->getMesh(), mat);

	mat.setTranslation(core::vector3df(30,10,150));
	driver->getMeshManipulator()->transform(node2->getMesh(), mat);

	mat.setTranslation(core::vector3df(10,0,0));
	driver->getMeshManipulator()->transform(node3->getMesh(), mat);

	// Just jump to the last frame since that's all we're interested in.
	device->run();
	driver->beginScene(true, true, SColor(255, 60, 60, 60));
	smgr->drawAll();
	driver->endScene();

	result = takeScreenshotAndCompareAgainstReference(driver, "-meshTransform.png");

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

	return result;
}
Example #23
0
int main()
{

    MyEventReceiver receiver;

    IrrlichtDevice *device =
        createDevice( video::EDT_OPENGL, dimension2d<u32>(1280, 800), 16,
        false, false, false, &receiver);

    if (!device)
        return 1;

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

    scene::ISceneNode* o = smgr->addSphereSceneNode(20);
    //o->setMaterialFlag(video::EMF_LIGHTING, false);
    o->setPosition(core::vector3df(0,0,0));
    SMaterial &m = o->getMaterial(0);
    m.EmissiveColor = SColor(255, 255, 0, 0);


    vector3df sssPos(0, 60, 0);

    scene::ISceneNode* sss = smgr->addCubeSceneNode(30);
    sss->setMaterialFlag(video::EMF_LIGHTING, true);
    //sss->setMaterialTexture(0, driver->getTexture("wall.bmp"));
    sss->setPosition(sssPos);
    SMaterial &sssm = sss->getMaterial(0);
    sssm.EmissiveColor = SColor(100, 255, 255, 255);


    scene::ISceneNode*  hp = smgr->addSphereSceneNode(10);
    SMaterial &hpm = hp->getMaterial(0);
    hpm.EmissiveColor = SColor(255, 0, 0, 255);
    scene::ISceneNode*  hd = smgr->addSphereSceneNode(10);
    SMaterial &hdm = hd->getMaterial(0);
    hdm.EmissiveColor = SColor(255, 0, 0, 100);


    scene::ISceneNode* node[10];
    for (int i = 0; i < 10; ++i)
    {
        node[i] = smgr->addSphereSceneNode(5);
        //node[i]->setMaterialFlag(video::EMF_LIGHTING, false);
        node[i]->setVisible(false);
        SMaterial &m = node[i]->getMaterial(0);
        m.EmissiveColor = SColor(255, 255, 0, 0);
    }

    scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS();

    vector3df camPos(0,0,200);
    vector3df camshift(0,0,0);

    cam->setPosition(camPos);
    cam->setTarget(core::vector3df(0,0,0));

    u32 then = device->getTimer()->getTime();
    const f32 MOVEMENT_SPEED = 50.f;



    irr::video::S3DVertex m_cPlaneVertices[4];
    irr::u16 m_iPlaneIndices[6];

    m_cPlaneVertices[0] = irr::video::S3DVertex(-100.0f, -100.0f, -100.0f,1,1,0, irr::video::SColor(255,255,255,255), 0.0f, 0.0f);
    m_cPlaneVertices[1] = irr::video::S3DVertex(-100.0f,  100.0f, -100.0f,1,1,0, irr::video::SColor(255,255,255,255), 0.0f, 1.0f);
    m_cPlaneVertices[2] = irr::video::S3DVertex( 100.0f,  100.0f, -100.0f,1,1,0, irr::video::SColor(255,255,255,255), 1.0f, 1.0f);
    m_cPlaneVertices[3] = irr::video::S3DVertex( 100.0f, -100.0f, -100.0f,1,1,0, irr::video::SColor(255,255,255,255), 1.0f, 0.0f);

    m_iPlaneIndices[0] = 0;
    m_iPlaneIndices[1] = 2;
    m_iPlaneIndices[2] = 1;
    m_iPlaneIndices[3] = 0;
    m_iPlaneIndices[4] = 3;
    m_iPlaneIndices[5] = 2;


    SMaterial m_cRenderMaterial;
    m_cRenderMaterial.Wireframe = false;
    m_cRenderMaterial.Lighting = false;
    m_cRenderMaterial.TextureLayer[0].TextureWrapU = irr::video::ETC_CLAMP;
    m_cRenderMaterial.TextureLayer[0].TextureWrapV = irr::video::ETC_CLAMP;
    
    ITexture      *m_pRenderTexture = 0;

    CvCapture *capture;
    IplImage *frame;
    char AviFileName[]="Accel World.mp4";
    capture = cvCaptureFromAVI(AviFileName);

    if (driver->queryFeature(irr::video::EVDF_RENDER_TO_TARGET))
    {
        m_pRenderTexture = driver->addRenderTargetTexture(irr::core::dimension2d<irr::u32>((irr::u32)(720), (irr::u32)(480)));
        m_cRenderMaterial.setTexture(0, m_pRenderTexture);
    }

//     m_pRenderTexture = driver->getTexture("wall.bmp");
//     m_cRenderMaterial.setTexture(0, m_pRenderTexture);

    while(device->run())
    {
        const u32 now = device->getTimer()->getTime();
        const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
        then = now;

        if(receiver.IsKeyDown(irr::KEY_KEY_W))
            camshift.Z -= MOVEMENT_SPEED * frameDeltaTime;
        else if(receiver.IsKeyDown(irr::KEY_KEY_S))
            camshift.Z += MOVEMENT_SPEED * frameDeltaTime;

        if(receiver.IsKeyDown(irr::KEY_KEY_A))
            camshift.X -= MOVEMENT_SPEED * frameDeltaTime;
        else if(receiver.IsKeyDown(irr::KEY_KEY_D))
            camshift.X += MOVEMENT_SPEED * frameDeltaTime;

        if(receiver.IsKeyDown(irr::KEY_KEY_X))
            camshift.Y -= MOVEMENT_SPEED * frameDeltaTime;
        else if(receiver.IsKeyDown(irr::KEY_SPACE))
            camshift.Y += MOVEMENT_SPEED * frameDeltaTime;

        cam->setPosition(camPos + camshift);


        driver->beginScene(true, true, SColor(255,0,0,0));




        driver->setRenderTarget(m_pRenderTexture, true, true, irr::video::SColor(0,0,0,0));
        
        if(cvGrabFrame(capture))
        {
            frame=cvRetrieveFrame(capture);

            void* pBits = m_pRenderTexture->lock();
            u32  Pitch = m_pRenderTexture->getPitch();  

            int wmin= Pitch;
//             for(int h=0; h< 100; h++) 
//                 memcpy((char*)pBits+((h)*wmin),(char*)frame->imageDataOrigin + h * wmin, wmin);

            char* tmp = new char[frame->imageSize + 720 * 480];
            for (int i = 0; i < 480; ++i)
            {
                for (int j = 0; j < 720; ++j)
                {
                    tmp[(i * 720 + j) * 4] = frame->imageDataOrigin[(i * 720 + j) * 3];
                    tmp[(i * 720 + j) * 4 + 1] = frame->imageDataOrigin[(i * 720 + j) * 3 + 1];
                    tmp[(i * 720 + j) * 4 + 2] = frame->imageDataOrigin[(i * 720 + j) * 3 + 2];
                    tmp[(i * 720 + j) * 4 + 3] = 255;
                }
            }

            memcpy(pBits,tmp, frame->imageSize + 720 * 480);

            delete []tmp;

            m_pRenderTexture->unlock();

        }

        driver->setRenderTarget(0, false, false, irr::video::SColor(0,100,100,100));

        //driver->setTransform(video::ETS_VIEW, core::matrix4());
        driver->setTransform(video::ETS_WORLD, core::matrix4());
        //driver->setTransform(video::ETS_PROJECTION, core::matrix4());

        driver->setMaterial(m_cRenderMaterial);
        driver->drawIndexedTriangleList(m_cPlaneVertices, 4, m_iPlaneIndices, 2);

        



        smgr->drawAll();

        driver->endScene();
    }

    //controller.removeListener(listener);
    device->drop();

    return 0;
}
Example #24
0
int main()
{



	IrrlichtDevice *device = createDevice( video::EDT_OPENGL, dimension2d<u32>(1024, 768), 32, false, false, true, 0);
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();

	smgr->addCameraSceneNodeFPS();

    const s32 randLength = 1024;
    srand(device->getTimer()->getRealTime());


    //Creating the grid for unit measure, etc
    u32 tileNumber = 128;
	IAnimatedMesh* groundMesh = smgr->addHillPlaneMesh("", dimension2d<float>(8,8),dimension2d<u32>(tileNumber,tileNumber),0,0.0f,dimension2df(0,0),dimension2df(tileNumber,tileNumber));
    IAnimatedMeshSceneNode * groundNode = smgr->addAnimatedMeshSceneNode(groundMesh);
    groundNode->setMaterialTexture(0,driver->getTexture("../media/grid2.png"));
    groundNode->setMaterialFlag(EMF_LIGHTING,false);
    groundNode->setPosition(vector3df(0,-2,0));


    //obstacles for stuff
    EntityGroup obstacles;

    for(int i = 0; i < 20; i++)
    {
        ISceneNode* s = smgr->addSphereSceneNode(20);
        IrrlichtBaseEntity * e = new IrrlichtBaseEntity(s);
        s->setPosition(vector3df(rand()%randLength - (randLength/2),0,rand()%randLength - (randLength/2)));
        obstacles.push_back(e);
    }

    //Nodes for vehicles
    ISceneNode * cube = smgr->addCubeSceneNode(4);
    ISceneNode * cube2 = smgr->addCubeSceneNode(4);
    cube->setMaterialFlag(EMF_LIGHTING,false);
    cube->setMaterialTexture(0,driver->getTexture("../media/v1-solid.png"));
    cube2->setMaterialFlag(EMF_LIGHTING,false);
    cube2->setMaterialTexture(0,driver->getTexture("../media/v2-solid.png"));

    //Creating the actual vehicles
    IrrlichtMobileEntity * Entity1 = new IrrlichtMobileEntity(cube ,vector3df(0,0,0), 1, 90, 40);
    IrrlichtMobileEntity * Entity2 = new IrrlichtMobileEntity(cube2,vector3df(0,0,300), 1, 100, 50);

    //Creating the steering conrollers, constructor also sets steering on entity
    SimpleSteeringController* Entity1Steering = new SimpleSteeringController(Entity1);
    SimpleSteeringController * Entity2Steering = new SimpleSteeringController(Entity2);

    //Setting up other params for behaviors
    Entity1Steering->SetObstacles(obstacles);
    Entity1Steering->SetHideTarget(Entity2);
    Entity1Steering->SetBehaviorFlag(EBF_HIDE,true);
    Entity1Steering->SetBehaviorFlag(EBF_AVOID,true);

    Entity2Steering->SetObstacles(obstacles);
    Entity2Steering->SetPursuitTarget(Entity1);
    Entity2Steering->SetBehaviorFlag(EBF_PURSUIT,true);
    Entity2Steering->SetBehaviorFlag(EBF_AVOID,true);

    //vars for tracking time between frames. This allows framerate independent motion state updates.
    u32 then = device->getTimer()->getTime();
    float timeUpdate = 0;

    while(device->run())
	{
	    const u32 now = device->getTimer()->getTime();
        const float frameDeltaTime = (float)(now - then) / 1000.f; // Time in seconds
        then = now;
        timeUpdate += frameDeltaTime;

        if(timeUpdate > 1)
        {
            core::stringw str = L"desteer v0.0.1  FPS: ";
            str += (s32)driver->getFPS();
			device->setWindowCaption(str.c_str());
			timeUpdate = 0;
		}

        //Do behavior updates before the rendering.
        Entity1->Update(frameDeltaTime);
        Entity2->Update(frameDeltaTime);

        driver->beginScene(true, true, SColor(255,100,101,140));
            smgr->drawAll();
		driver->endScene();
	}
    //Clean up irrlicht.
	device->drop();

	return 0;
}