Exemple #1
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 );
}
Exemple #2
0
ISceneNode* AddNeptune()
{
	ISceneNode *neptune = smgr->addSphereSceneNode(16.0f, 32, 0, -1, vector3df(0, 0, 0), vector3df(0, 0, 0), vector3df(1.0, 1.0, 1.0));
	SSRotationAnimator *animNeptuneRot = new SSRotationAnimator(vector3df(0, 5.0f / 0.63f, 0), &koeffSpeed, &IsActiveRotating);
	SSFlyEllipceAnimator *animNeptune = new SSFlyEllipceAnimator(sun->getPosition(), 0, 6.4f, 5.4f, &koeffSpeed, 1800.0f, 1750.0f, &koeffOfDist, &IsActiveMoving);
	if (neptune)
	{
		neptune->setMaterialFlag(EMF_LIGHTING, false);
		neptune->setMaterialTexture(0, driver->getTexture(std::string(TexturesPath + "Neptune/Neptune.jpg").c_str()));
		neptune->addAnimator(animNeptune);
		neptune->addAnimator(animNeptuneRot);
		neptune->setRotation(vector3df(0.0f, 29.0f, 29.0f));
	}

	Planets.push_back(neptune);

	return neptune;
}
Exemple #3
0
ISceneNode* AddUranus()
{
	ISceneNode *uranus = smgr->addSphereSceneNode(15.4f, 32, 0, -1, vector3df(0, 0, 0), vector3df(0, 0, 0), vector3df(1.0, 1.0, 1.0));
	SSRotationAnimator *animUranusRot = new SSRotationAnimator(vector3df(0, 5.0f / 0.45f, 0), &koeffSpeed, &IsActiveRotating);
	SSFlyEllipceAnimator *animUranus = new SSFlyEllipceAnimator(sun->getPosition(), 0, 6.48f, 6.8f, &koeffSpeed, 1400.0f, 1200.0f, &koeffOfDist, &IsActiveMoving);
	if (uranus)
	{
		uranus->setMaterialFlag(EMF_LIGHTING, false);
		uranus->setMaterialTexture(0, driver->getTexture(std::string(TexturesPath + "Uranus/Uranus.jpg").c_str()));
		uranus->addAnimator(animUranus);
		uranus->addAnimator(animUranusRot);
		uranus->setRotation(vector3df(0.0f, 82.0f, 82.0f));
	}

	Planets.push_back(uranus);

	return uranus;
}
Exemple #4
0
ISceneNode* AddMars()
{
	ISceneNode *mars = smgr->addSphereSceneNode(2.0f, 32, 0, -1, vector3df(0, 0, 0), vector3df(0, 0, 0), vector3df(1.0, 1.0, 1.0));
	SSRotationAnimator *animMarsRot = new SSRotationAnimator(vector3df(0, 5.0f / 1.0f, 0), &koeffSpeed, &IsActiveRotating);
	SSFlyEllipceAnimator *animMars = new SSFlyEllipceAnimator(sun->getPosition(), 0, 5.65f, 24.1f, &koeffSpeed, 491.0f, 420.0f, &koeffOfDist, &IsActiveMoving);
	if (mars)
	{
		mars->setMaterialFlag(EMF_LIGHTING, false);
		mars->setMaterialTexture(0, driver->getTexture(std::string(TexturesPath + "Mars/Mars.jpg").c_str()));
		mars->addAnimator(animMars);
		mars->addAnimator(animMarsRot);
		mars->setRotation(vector3df(0.0f, 25.0f, 25.0f));
	}

	Planets.push_back(mars);

	return mars;
}
Exemple #5
0
ISceneNode* AddEarth()
{
	ISceneNode *earth = smgr->addSphereSceneNode(4.0f, 32, 0, -1, vector3df(0, 0, 0), vector3df(0, 0, 0), vector3df(1.0, 1.0, 1.0));
	SSRotationAnimator *animEarthRot = new SSRotationAnimator(vector3df(0, 5.0f / 1.0f, 0), &koeffSpeed, &IsActiveRotating);
	SSFlyEllipceAnimator *animEarth = new SSFlyEllipceAnimator(sun->getPosition(), 0, 7.25f, 29.0f, &koeffSpeed, 300.0f, 280.0f, &koeffOfDist, &IsActiveMoving);
	if (earth)
	{
		earth->setMaterialFlag(EMF_LIGHTING, false);
		earth->setMaterialTexture(0, driver->getTexture(std::string(TexturesPath + "Earth/Earth.png").c_str()));
		earth->addAnimator(animEarth);
		earth->addAnimator(animEarthRot);
		earth->setRotation(vector3df(0.0f, 23.0f, 23.0f));
	}

	Planets.push_back(earth);

	return earth;
}
Exemple #6
0
	int Java_zte_irrlib_scene_SceneNode_nativeAddDeleteAnimator(
		JNIEnv *env, jobject defaultObj, jint ms, jint id)
	{
		ISceneNode* node = smgr->getSceneNodeFromId(id);
		if (!node) 
		{
			WARN_NODE_NOT_FOUND(id, AddDeleteAnimator);
			return -1;
		}				
		ISceneNodeAnimator* anim = smgr->createDeleteAnimator(ms);
		node->addAnimator(anim);
		anim->drop();
		return 0;
	}
Exemple #7
0
	int Java_zte_irrlib_scene_SceneNode_nativeAddRotationAnimator(
		JNIEnv*  env, jobject defaultObj, jdouble x, jdouble y, jdouble z,
		jint id)
	{
		ISceneNode* node = smgr->getSceneNodeFromId(id);
		if (!node) 
		{
			WARN_NODE_NOT_FOUND(id, AddRotationAnimator);
			return -1;
		}
		ISceneNodeAnimator* anim = smgr->createRotationAnimator(vector3df(x,y,z));
		node->addAnimator(anim);
		anim->drop();
		return 0;
	}
Exemple #8
0
	int Java_zte_irrlib_scene_SceneNode_nativeAddCollisionResponseAnimator(
		JNIEnv *env, jobject defaultObj, jint selId, jobject jradius, jboolean bbox, jboolean octree, jint id)
	{
		ISceneNode* selNode = smgr->getSceneNodeFromId(selId);
		if (!selNode)
		{
			WARN_NODE_NOT_FOUND(selId, AddCollisionResponseAnimator);
			return -1;
		}
		
		ISceneNode* node = smgr->getSceneNodeFromId(id);
		if (!node)
		{
			WARN_NODE_NOT_FOUND(id, AddCollisionResponseAnimator);
			return -1;
		}
		
		ITriangleSelector* selector = 0;
		if (bbox) selector = smgr->createTriangleSelectorFromBoundingBox(selNode);
		else if (!octree) selector = smgr->createTriangleSelector(((IMeshSceneNode*)selNode)->getMesh(), selNode);
		else selector = smgr->createTriangleSelector(((IMeshSceneNode*)selNode)->getMesh(), selNode);
		
		node->updateAbsolutePosition();
		const aabbox3d<f32>& box = node->getTransformedBoundingBox();
		
		vector3df radius;
		if (jradius == 0)
			radius = box.MaxEdge-box.getCenter();
		else radius = utils->createvector3dfFromVector3d(env, jradius);
		
		vector3df translation = -(box.getCenter() - node->getAbsolutePosition());
		
		//LOGD("max, %f, %f, %f", box.MaxEdge.X, box.MaxEdge.Y, box.MaxEdge.Z);
		//LOGD("min, %f, %f, %f", box.MinEdge.X, box.MinEdge.Y, box.MinEdge.Z);
		//LOGD("trans, %f, %f, %f", translation.X, translation.Y, translation.Z);
		ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(selector, node,
			radius,
			vector3df(),/*gravity*/
			translation,
			0.0005f
		);
		selector->drop();
		node->addAnimator(anim);
		anim->drop();
	}
Exemple #9
0
	int Java_zte_irrlib_scene_SceneNode_nativeAddFlyCircleAnimator(
		JNIEnv*  env, jobject defaultObj, jdouble cx, jdouble cy, jdouble cz,
		jdouble radius, jdouble speed, jdouble ax, jdouble ay, jdouble az, 
		jdouble startPosition, jdouble radiusEllipsoid, jint id)
	{
		ISceneNode* node = smgr->getSceneNodeFromId(id);
		if (!node) 
		{
			WARN_NODE_NOT_FOUND(id, AddFlyCircleAnimator);
			return -1;
		}		
		
		ISceneNodeAnimator* anim = 
			smgr->createFlyCircleAnimator(vector3df(cx,cy,cz),radius,speed,vector3df(ax, ay, az), startPosition, radiusEllipsoid);
		node->addAnimator(anim);
		anim->drop();
		return 0;
	}
Exemple #10
0
	int Java_zte_irrlib_scene_SceneNode_nativeAddFlyStraightAnimator(
		JNIEnv*  env, jobject defaultObj, jdouble sx, jdouble sy, jdouble sz,
		jdouble dx, jdouble dy, jdouble dz, jdouble time, 
		jboolean loop, jboolean pingpong, jint id)
	{
		ISceneNode* node = smgr->getSceneNodeFromId(id);
		if (!node) 
		{
			WARN_NODE_NOT_FOUND(id, AddFlyStraightAnimator);
			return -1;
		}			
		vector3df start(sx,sy,sz);
		vector3df end(dx, dy, dz);
		
		ISceneNodeAnimator* anim = smgr->createFlyStraightAnimator (start, end, time, loop, pingpong);
		node->addAnimator(anim);
		anim->drop();
		return 0;
	}
Exemple #11
0
void load_map() {
	IAnimatedMesh* mesh = smgr->getMesh("resources/nodes/maps/room.3ds");

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

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

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

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

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

	node->setMaterialType(video::EMT_REFLECTION_2_LAYER);

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

	// attach billboard to light
	node = smgr->addBillboardSceneNode(node, dimension2d<f32>(50, 50));
	node->setMaterialFlag(EMF_LIGHTING, false);
	node->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
	node->setMaterialTexture(0,	driver->getTexture("resources/textures/particles/particlewhite.bmp"));
}
/** 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;
}
/** 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;
}