Page 1 of 2

Light in Game

Posted: Wed Jan 18, 2006 10:09 am
by Yoann
Hello! I seek to make a sun in mouvemement in my video game. I did that:


scene::ISceneManager* smgr = device->getSceneManager();
scene::ISceneNodeAnimator* anim = 0;
anim = smgr->createFlyCircleAnimator (core::vector3df(10,15,10),300.0f);
node->addAnimator(anim);

node = smgr->addBillboardSceneNode(node, core::dimension2d<f32>(50,50));
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
node->setMaterialTexture(0, driver->getTexture("F:/Ancien D/irrlicht-0.12.0/media/lumiere.bmp"));


The circle does not turn around good vector... How to make? Thank you in advance! Yoann

Posted: Wed Jan 18, 2006 7:41 pm
by xtheagonyscenex
not sure i understand but add a light by adddynamiclightscenenode
and parent it to the mesh that moves and it will affect all objects along the way and fake the look of the sun everywhere this is done battlefield 2. hope it helps! :D

Posted: Wed Jan 18, 2006 8:57 pm
by Yoann
Yes, but my problem is that Light turn around axis Y, avec I want turn it arount axis X .... You understand ?

Thank you !

Yoann

Rotation of the sun

Posted: Thu Jan 19, 2006 12:36 am
by Xandar
I had similiar problem. I solved it using sin and cos. I calculated the 24 points
and used fly straight animator to move the light from point to point.

a better solution... i work on it

Posted: Thu Jan 19, 2006 11:55 am
by sdi2001
a better solution is to use the animation function but with an rotation and translation of the layer. i work on it but im not a mathematician....
:D

better solution... =)

Posted: Fri Jan 20, 2006 9:00 am
by sdi2001
hi here is the solution with the layer rotation to make the rotation animator flexibly .

change the function declaration in "ISceneManager.h" to

Code: Select all

virtual ISceneNodeAnimator* createFlyCircleAnimator(const core::vector3df& center,  f32 radius, f32 speed=0.001f, const core::vector3df &direction = core::vector3df(0.0f, 0.0f, 0.0f)) = 0;
then change the function declaration in "CSceneManager.h" to

Code: Select all

virtual ISceneNodeAnimator* createFlyCircleAnimator(const core::vector3df& normal, f32 radius, f32 speed, const core::vector3df &direction);
then change the function "createFlyCircleAnimator" in "CSceneManager.cpp" to

Code: Select all

ISceneNodeAnimator* CSceneManager::createFlyCircleAnimator(const core::vector3df& normal, f32 radius, f32 speed, const core::vector3df &direction)
{
	ISceneNodeAnimator* anim = new CSceneNodeAnimatorFlyCircle(os::Timer::getTime(), normal, direction,
			radius, speed);
	return anim;
}
then change the constructor declaration of the flyingcircle animator "CSceneNodeAnimatorFlyCircle.h" to

Code: Select all

CSceneNodeAnimatorFlyCircle(u32 time, const core::vector3df& center, const core::vector3df& direction, f32 radius, f32 speed);
then the constructor in "CSceneNodeAnimatorFlyCircle.cpp" to

Code: Select all

CSceneNodeAnimatorFlyCircle::CSceneNodeAnimatorFlyCircle(u32 time, const core::vector3df& center, const core::vector3df& direction, f32 radius, f32 speed)
: Radius(radius), Center(center), Speed(speed), StartTime(time), Direction(direction)
{
	#ifdef _DEBUG
	setDebugName("CSceneNodeAnimatorFlyCircle");
	#endif
}
and the last change in the "CSceneNodeAnimatorFlyCircle.cpp" is the function
"animateNode"

Code: Select all

void CSceneNodeAnimatorFlyCircle::animateNode(ISceneNode* node, u32 timeMs)
{	
	core::matrix4 mat;
	core::vector3df l_newCenter = Center;
	core::vector3df l_newPos;

	f32 t = (timeMs-StartTime) * Speed;
	
	core::vector3df circle(Radius * (f32)sin(t), 0, Radius * (f32)cos(t));
	
	l_newPos = circle;

	//back to the orgin
	mat.setInverseTranslation(Center);
	mat.translateVect(l_newCenter);
	mat.translateVect(l_newPos);

	mat.makeIdentity();

	mat.setRotationRadians(Direction);
	mat.rotateVect(l_newCenter);
	mat.rotateVect(l_newPos);

	node->setPosition(l_newCenter + l_newPos);
	//node->setPosition(Center + circle);
}
recompile the irrlicht engine and you can use the animator with rotation in any direction =)

now you can use the function with a direction to rotate. =)

Code: Select all

ISceneNodeAnimator *anim = smgr->createFlyCircleAnimator(core::vector3df(0,0,0), 20, 0.001f, core::vector3df(90.0f, 0.0f, 0.0f));
is this is what u want? :D

oups...

Posted: Fri Jan 20, 2006 9:08 am
by sdi2001
the function "animateNode" must be change to...
i have forgot the back to the old position translate =)

Code: Select all

void CSceneNodeAnimatorFlyCircle::animateNode(ISceneNode* node, u32 timeMs)
{	
	core::matrix4 mat;
	core::vector3df l_newCenter = Center;
	core::vector3df l_newPos;

	f32 t = (timeMs-StartTime) * Speed;
	
	core::vector3df circle(Radius * (f32)sin(t), 0, Radius * (f32)cos(t));
	
	l_newPos = circle;

	//back to the orgin
	mat.setInverseTranslation(Center);
	mat.translateVect(l_newCenter);
	mat.translateVect(l_newPos);

	mat.makeIdentity();

	mat.setRotationRadians(Direction);
	mat.rotateVect(l_newCenter);
	mat.rotateVect(l_newPos);

       //back to the old pos
	mat.setTranslation(Center);
	mat.translateVect(l_newCenter);
	mat.translateVect(l_newPos);

	node->setPosition(l_newCenter + l_newPos);
	//node->setPosition(Center + circle);
}
now it works right

Posted: Sun Jan 22, 2006 2:32 pm
by Yoann
It's a great idea ! Thank you very much !

I will try !

Yo.

Posted: Sun Jan 22, 2006 2:41 pm
by Yoann
I can't built Irrlicht , I have the error :
"Compiling Irrlicht with Visual Studio 6.0, support for DX9 is disabled."

I don't know what I can do ....

Posted: Sun Jan 22, 2006 4:21 pm
by Yoann
I built Irrlicht without problem , but now , I don't knwo how to use it with my project ....

What I must replace in the file Irrlicht where I have média, include .... etc

Thank you !

Yoann

Posted: Sun Jan 22, 2006 5:08 pm
by MikeR
In your lib linker, just change the lib file link from the original to your lib file, and add your dll to your project. The includes folder is the same one as before.

Code: Select all

Irrlicht includes=Irrlichts includes
Irrlicht lib= YOUR lib
Irrlicht.dll- YOUR Irrlicht.dll
Hope that helps a bit.

Posted: Mon Jan 23, 2006 5:14 pm
by Yoann
Yes ... but how can I make MY lib , and MY DLL with Visual C++ 6.0 ... I don't know how to do ....

Thank You !


Yo.

Posted: Tue Jan 24, 2006 9:35 am
by sdi2000
what do you mean with your lib???
i could not understand!?!?! :shock:

Posted: Tue Jan 24, 2006 5:46 pm
by Yoann
MikeR has said :

" In your lib linker, just change the lib file link from the original to your lib file, and add your dll to your project. The includes folder is the same one as before. "

And I don't how to make MY lib file, and MY dll with Visual C++ ....


Yo.

Posted: Tue Jan 24, 2006 6:25 pm
by sdi2000
Mike means: change the lib path in your visual studio or whatever you use to compile your own project. Use the pathes of your builded irrlicht engine.
Note do not use the old include folder. Use the Include folder in the source folder of irrlicht, because with the code sniped of the new rotation animator we have changed the interface. Without the new interfache declaration we became a compile error.
good luck
:D