示例#1
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);
}
示例#2
0
// newDocument
// new 3d scene document
void CDocument::newDocument()
{		
	ISceneManager *smgr = getIView()->getSceneMgr();
	IrrlichtDevice *device = getIView()->getDevice();

	// clear all history
	CHistoryManager::getInstance()->clearAll();

	// create design camera
	m_designCamera = new CGameCamera();
	m_designCamera->setName( L"Design camera" );
	m_designCamera->setTarget(core::vector3df(300,100,300));
	m_designCamera->setPosition( core::vector3df(0, 200, 0) );	
	getIView()->setActiveCamera( m_designCamera );
		
	// add oxyz plane node
	CGameOxyzSceneNode *oxyPlane = new CGameOxyzSceneNode( smgr->getRootSceneNode(), smgr, 1 );
	m_gridNode = oxyPlane;

	// add light
	ISceneNode* pNode = smgr->addEmptySceneNode();

	// default light
	smgr->setAmbientLight( video::SColorf(0.2f, 0.2f, 0.2f ,1.0f) );
	//ILightSceneNode *light = smgr->addLightSceneNode( pNode, core::vector3df(0, 0, 0) );
	//light->setLightType( video::ELT_DIRECTIONAL );

	// reset file path
	m_filePath = L"";

	// begin id
	CGameObject::s_objectID = 1;

	// add root
	const WCHAR *lpRootName = L"level";
	uiTreeView *pTreeview = getIView()->getDocumentTreeView();
	m_treeViewRoot = pTreeview->addItem( (WCHAR*)lpRootName );	

	// create a zone
	CZone *pZone = (CZone*)createZone();
	getIView()->setCurrentZone( pZone );
	getIView()->setObjectProperty( pZone );

	m_treeViewRoot->expandChild( true );

	// register draw all template obj
	if ( s_isFirstDocument == true )
	{
		CObjTemplateFactory::registerDrawAllTemplateObject();
		s_isFirstDocument = false;
	}

	// have 1 zone
	m_totalObjects = 1;
}
示例#3
0
ISceneNode* MySceneManager::addRunWaySceneNode( const core::vector3df& position /*= core::vector3df( 0 )*/,
	f32 interval /*= 200*/, f32 width /*= 300*/,
	const core::vector3df& colorFrom /*= core::vector3df( 0, 63, 255 )*/, const core::vector3df& colorTo /*= core::vector3df( 255, 255, 0 )*/,
	s32 numOfArrows /*= 15 */ )
{
	MyIrrlichtEngine* pEngine = MyIrrlichtEngine::GetEngine();
	ISceneManager* smgr = pEngine->GetSceneManager();
	IVideoDriver* driver = pEngine->GetVideoDriver();
	u32 TimeMs = pEngine->GetDevice()->getTimer()->getTime();
	f32 delay = 100;

	// 跑道根节点
	ISceneNode* runWay = smgr->addEmptySceneNode();
	runWay->setPosition( position );
	// 供复制的节点
	ISceneNode* node = smgr->addMeshSceneNode( smgr->getMesh( "../media/UnitModel/UnitPlane.obj" ), runWay );
	node->setScale( vector3df( 90, 176, 1 ) );
	node->setRotation( vector3df( 0, 45, 0 ) );
	node->setMaterialTexture( 0, driver->getTexture( "../media/UIResource/Game/arrow.png" ) );
	node->setMaterialFlag( EMF_BACK_FACE_CULLING, false );
	// 节点临时变量
	ISceneNode* copy;
	// Shader
	SceneNodeShader shader;
	// 色彩偏移量
	vector3df colorOffset = ( colorTo - colorFrom ) / (f32)numOfArrows;
	// 右跑道
	for( int i=0; i<numOfArrows; i++ )
	{
		copy = node->clone();
		copy->setPosition( vector3df( width / 2.f, 0, interval * i ) );
		RunWayBlink* ani = new RunWayBlink( (u32)(delay * i), (f32)i, colorFrom, colorOffset );
		copy->addAnimator( ani );
		ani->drop();
	}
	node->setRotation( vector3df( 0, 45, 180 ) );
	// 左跑道
	for( int i=0; i<numOfArrows; i++ )
	{
		copy = node->clone();
		copy->setPosition( vector3df( -width / 2.f, 0, interval * i ) );
		RunWayBlink* ani = new RunWayBlink( (u32)(delay * i), (f32)i, colorFrom, colorOffset );
		copy->addAnimator( ani );
		ani->drop();
	}
	node->setVisible( false );

	return runWay;
	//return CreateRunWay( position, interval, width, colorFrom, colorTo, numOfArrows );
}
示例#4
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);
}
示例#5
0
ActionManager::ActionManager(IrrlichtDevice* dev, ISceneNode* root, Craft* f, SETTINGS_STRUCT* set) 
	: device(dev), rootNode(root), SETTINGS(set) {
	//if(!scene) log << "NULL cout" << endl;
	leftShotTime = 0;
	rightShotTime = 0;
	currentTime = 0;
	gameOverTime = 0;
	currentScore = 0;
	delay = 5;
	inGame = true;
	leftPressed = false;
	rightPressed = false;

	ISceneManager* scene = device->getSceneManager();

	fighter = scene->getSceneNodeFromId(NEWGAME_ELEMENT::NEWGAME_FIGHTER);
	//fighter->setDebugDataVisible(scene::EDS_BBOX);
	craftPool.push_back(f);

	enemyRoot = scene->addEmptySceneNode(rootNode); //scene node that contains all enemy crafts

	//open sound effects
	rocketSound = OpenSoundEffect(audioDevice, "../res/sound/rocket.wav", MULTIPLE);
	rocketSound->setPan(0);       // 0 Left, 1 Right
	rocketSound->setPitchShift(1.5);

	explosionSound = OpenSoundEffect(audioDevice, "../res/sound/explosion.wav", MULTIPLE);
	explosionSound->setPan(0);       // 0 Left, 1 Right
	explosionSound->setPitchShift(2.0);

	IGUIFont* font = device->getGUIEnvironment()->getFont("button_font.xml");
	score = scene->addTextSceneNode(font, L"", SColor(100,255,255, 255), rootNode, vector3df(0,SH_SF - 20,0));
	updateScore();

	/*
	ISceneNode* sphere_1 = scene->addSphereSceneNode();
	sphere_1->setPosition(vector3df(0,0,0));

	ISceneNode* sphere_2 = scene->addSphereSceneNode();
	sphere_2->setPosition(vector3df(-10,-10,0));
	*/
	
	enemyGenerator = new EnemyGenerator(SETTINGS->gameMode, device, enemyRoot, craftPool);
}
示例#6
0
void CIrrWindow::initScene()
{
	IVideoDriver* driver = m_driver;
	IrrlichtDevice* device = m_device;
	ISceneManager* smgr = m_smgr;

	// create texture manager
	CTextureManager::createGetInstance();

	// create design camera
	m_designCamera = new CGameCamera();
	m_designCamera->setName( L"Design camera" );
	m_designCamera->setTarget(core::vector3df(0,0,0));
	m_designCamera->setPosition( core::vector3df(-400, 200, -400) );


	// set active camera
	getIView()->setActiveCamera( m_designCamera );



	// add oxyz plane node
	CGameOxyzSceneNode *oxyPlane = new CGameOxyzSceneNode( smgr->getRootSceneNode(), smgr, 1 );	
	oxyPlane->drop();

	// add light
	ISceneNode* pNode = smgr->addEmptySceneNode();

	// default light	
	ILightSceneNode *light = smgr->addLightSceneNode( pNode, core::vector3df(0, 0, 0) );
	light->setLightType( video::ELT_DIRECTIONAL );


	// add demo particle
	m_particleObject = new CGameObject();
	CParticleComponent *particleComp = new CParticleComponent(m_particleObject);
	particleComp->initParticle();
	m_particleObject->m_components.push_back( particleComp );

}
/** Test that a custom animator can remove itself cleanly from an ISceneNode during its
 *  own animateNode() loop. 
 * http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=32271 */
bool removeCustomAnimator(void)
{
	IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2du(160, 120));
	assert(device);
	if(!device)
		return false;

	ISceneManager * smgr = device->getSceneManager();

	ISceneNode * node = smgr->addEmptySceneNode();
	CustomAnimator * instantlyElapsing1 = new CustomAnimator();
	CustomAnimator * instantlyElapsing2 = new CustomAnimator();
	node->addAnimator(instantlyElapsing1);
	node->addAnimator(instantlyElapsing2);

	// This should result in both custom animators being removed and
	// deleted cleanly, without a crash.
	node->OnAnimate(0);
	
	device->drop();

	// If we didn't crash, then the test passed.
	return true;
}
示例#8
0
	/*!
		Constructs button as a plane node and text node with shared root node.
		@param game Game instance.
		@param config Configuration (texture, size, etc).
		@param index Index of the button (from 0 to count - 1).
	*/
	Button(Game* game, const MenuConfig& config, s32 index)
	{
		ISceneManager* scene = game->getDevice()->getSceneManager();
		Root = scene->addEmptySceneNode();

		scene->addTextSceneNode(
			config.Font,
			config.Buttons[index].Text.c_str(),
			config.FontColor,
			Root)->setPosition(vector3df(0, 10, 0));

		SMaterial material;

		material.MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL;
		material.setTexture(0, config.ButtonTextures.Default);

		Plane = scene->addMeshSceneNode(
			scene->getGeometryCreator()->createPlaneMesh(
				dimension2df(
					(f32) config.ButtonSize.Width, 
					(f32) config.ButtonSize.Height),
				dimension2du(1, 1), &material, dimension2df(1, 1)
			), Root);
	};
/** 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;
}
示例#10
0
/** Test functionality of the ISceneNodeAnimator implementations. */
bool sceneNodeAnimator(void)
{
	IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(160, 120));
	assert_log(device);
	if(!device)
		return false;

	ISceneManager * smgr = device->getSceneManager();

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

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

	ISceneNodeAnimator* flyCircleAnimator = smgr->createFlyCircleAnimator();

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

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

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

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

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

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

	bool result = true;

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

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

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

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

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

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

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

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

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

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

	return result;
}