Light in Game

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Yoann

Light in Game

Post 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
xtheagonyscenex
Posts: 131
Joined: Fri Jun 03, 2005 7:26 pm

Post 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
"Held in Your arms but too far from my heart." "These thoughts will carry me through the darkest nights...while your eyes rest in mine."
"How quickly I forget that this is meaningless."
Yoann

Post 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
Xandar
Posts: 16
Joined: Mon Nov 28, 2005 9:17 pm
Contact:

Rotation of the sun

Post 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.
sdi2001

a better solution... i work on it

Post 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
sdi2001

better solution... =)

Post 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
sdi2001

oups...

Post 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
Yoann

Post by Yoann »

It's a great idea ! Thank you very much !

I will try !

Yo.
Yoann

Post 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 ....
Yoann

Post 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
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Post 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.
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
Yoann

Post 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.
sdi2000
Posts: 129
Joined: Thu Aug 25, 2005 12:19 pm
Location: Berlin, DE
Contact:

Post by sdi2000 »

what do you mean with your lib???
i could not understand!?!?! :shock:
Yoann

Post 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.
sdi2000
Posts: 129
Joined: Thu Aug 25, 2005 12:19 pm
Location: Berlin, DE
Contact:

Post 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
Post Reply