Light in Game
Light in Game
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
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
-
- Posts: 131
- Joined: Fri Jun 03, 2005 7:26 pm
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!
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!
"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."
"How quickly I forget that this is meaningless."
Rotation of the sun
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.
and used fly straight animator to move the light from point to point.
a better solution... i work on it
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....
better solution... =)
hi here is the solution with the layer rotation to make the rotation animator flexibly .
change the function declaration in "ISceneManager.h" to
then change the function declaration in "CSceneManager.h" to
then change the function "createFlyCircleAnimator" in "CSceneManager.cpp" to
then change the constructor declaration of the flyingcircle animator "CSceneNodeAnimatorFlyCircle.h" to
then the constructor in "CSceneNodeAnimatorFlyCircle.cpp" to
and the last change in the "CSceneNodeAnimatorFlyCircle.cpp" is the function
"animateNode"
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. =)
is this is what u want?
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;
Code: Select all
virtual ISceneNodeAnimator* createFlyCircleAnimator(const core::vector3df& normal, f32 radius, f32 speed, const core::vector3df &direction);
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;
}
Code: Select all
CSceneNodeAnimatorFlyCircle(u32 time, const core::vector3df& center, const core::vector3df& direction, f32 radius, f32 speed);
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
}
"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);
}
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));
oups...
the function "animateNode" must be change to...
i have forgot the back to the old position translate =)
now it works right
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);
}
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.
Hope that helps a bit.
Code: Select all
Irrlicht includes=Irrlichts includes
Irrlicht lib= YOUR lib
Irrlicht.dll- YOUR Irrlicht.dll
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
Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
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
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