Hello,
I created a camera like this:
camera = smgr->addCameraSceneNode(0, core::vector3df(0, 0, -300), core::vector3df(0, 0, 0));
camera->addAnimator(smgr->createFlyCircleAnimator(core::vector3df(0, -120, 0), 70, 0.002, core::vector3df(0.01f, 0.01f, 0.01f)));
I tried to put a scene node as child of it, but it doesn't move along with the camera. I would like it to be in front of the camera, no matter other objects move.
Can someone help me to do that? Any example code?
I was able to do that with position:
myNode->setPosition(camera->getPosition() + (camera->getTarget()-camera->getPosition())/2 );
But it rotates as camera moves.
Any help would be very appreciated.
[]s
3d in front of camera
When you set a node as a child to another node it's position is relative to its parent, not to the world coordinates.
So if you parent a node to your camera and your camera is at 100,0,0 and you set your node's position to 100,0,0 you may think that they'd be on top of each other but actually the node will end up at 200,0,0.
I'm not clear on what your problem is, it's early and i've just got into work so indulge me with a clearer explanation. How do you want the node to behave and how does it actually behave? Crummy MS Paint drawings might help
So if you parent a node to your camera and your camera is at 100,0,0 and you set your node's position to 100,0,0 you may think that they'd be on top of each other but actually the node will end up at 200,0,0.
I'm not clear on what your problem is, it's early and i've just got into work so indulge me with a clearer explanation. How do you want the node to behave and how does it actually behave? Crummy MS Paint drawings might help
JP,
Thanks for replying my message. and Thank you for saying it wasn't clear, I need to keep improving my english and any feedback is good for me!
What I want is really have my object in a position relative to my camera. If my camera is at world screen coordinates 100,100,100 and my object have coordinates 100,100,100, I would expect it to be distant from my camera and not on top of it.
When I use a FPS camera, it just works the way I want. However, when camera is not fps, it doesn't work. I tried to put an object as child from a camera and added an animator to the camera... The object just stay at the same position in world coordinates, it doesn't follow the camera.
Here is a piece of the code I have used:
//get scene manager
scene::ISceneManager* smgr = VRSystem::getInstance()->getSceneManager();
//add camera
camera = smgr->addCameraSceneNode(0, core::vector3df(0, 0, -300), core::vector3df(0, 0, 0));
//adds custom scene node
myNode = new SceneNode(smgr->getRootSceneNode(), smgr, 666);
//myNode->setPosition(core::vector3df(70.0f, 0, 0));
myNode->drop();
scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator(core::vector3df(1.0f, 0.1f, 0.1f));
camera->addAnimator(anim);
anim->drop();
camera->addChild(myNode);
Thanks for replying my message. and Thank you for saying it wasn't clear, I need to keep improving my english and any feedback is good for me!
What I want is really have my object in a position relative to my camera. If my camera is at world screen coordinates 100,100,100 and my object have coordinates 100,100,100, I would expect it to be distant from my camera and not on top of it.
When I use a FPS camera, it just works the way I want. However, when camera is not fps, it doesn't work. I tried to put an object as child from a camera and added an animator to the camera... The object just stay at the same position in world coordinates, it doesn't follow the camera.
Here is a piece of the code I have used:
//get scene manager
scene::ISceneManager* smgr = VRSystem::getInstance()->getSceneManager();
//add camera
camera = smgr->addCameraSceneNode(0, core::vector3df(0, 0, -300), core::vector3df(0, 0, 0));
//adds custom scene node
myNode = new SceneNode(smgr->getRootSceneNode(), smgr, 666);
//myNode->setPosition(core::vector3df(70.0f, 0, 0));
myNode->drop();
scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator(core::vector3df(1.0f, 0.1f, 0.1f));
camera->addAnimator(anim);
anim->drop();
camera->addChild(myNode);
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Apologies if I'm misunderstanding your requirements. I'm still not entirely clear on what you want to see happening. I'm going on the basis of your second example.
This animator rotates the camera scene node. The child node is moving in world space, in a circle around the camera's position.
However, in Irrlicht, a camera's look-at direction is independent of its scene node rotation. This has advantages and disadvantages.
The advantage is if you expect it and want it, that it's more flexible. The disadvantage is that it's rarely what people expect. Adding a fixed point of reference helps to demonstrate what's going on.
Now, if your goal is to have the camera's look-at target rotate, and the scene node to stay centered in the camera's view, then handily enough, you can just set the camera to look at the scene node. Just uncomment this line:
The problem may be that this doesn't do what you might expect.mvalle wrote:Code: Select all
scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator(core::vector3df(1.0f, 0.1f, 0.1f)); camera->addAnimator(anim); anim->drop();
This animator rotates the camera scene node. The child node is moving in world space, in a circle around the camera's position.
However, in Irrlicht, a camera's look-at direction is independent of its scene node rotation. This has advantages and disadvantages.
The advantage is if you expect it and want it, that it's more flexible. The disadvantage is that it's rarely what people expect. Adding a fixed point of reference helps to demonstrate what's going on.
Code: Select all
#include <irrlicht.h>
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
int main()
{
IrrlichtDevice *device =
createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480), 32, false);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
scene::ICameraSceneNode * camera = smgr->addCameraSceneNodeFPS();
// Created a fixed point of reference.
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
smgr->addSkyBoxSceneNode(
driver->getTexture("../../media/irrlicht2_up.jpg"),
driver->getTexture("../../media/irrlicht2_dn.jpg"),
driver->getTexture("../../media/irrlicht2_lf.jpg"),
driver->getTexture("../../media/irrlicht2_rt.jpg"),
driver->getTexture("../../media/irrlicht2_ft.jpg"),
driver->getTexture("../../media/irrlicht2_bk.jpg"));
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
// Create a node that will be made a child of the camera.
scene::IBillboardSceneNode * node = smgr->addBillboardSceneNode(smgr->getRootSceneNode());
node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
node->setMaterialTexture(0, driver->getTexture("../../media/particle.bmp"));
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setPosition(core::vector3df(0, 0, 50));
// This will cause the camera scene node to rotate. The billboard node will rotate in
// world space around it. However, this will NOT cause the camera's look-at target to
// rotate!
scene::ISceneNodeAnimator * anim = smgr->createRotationAnimator(core::vector3df(0, 1, 0));
camera->addAnimator(anim);
anim->drop();
camera->addChild(node);
while(device->run())
{
driver->beginScene(true, true, video::SColor(0,100,100,100));
// camera->setTarget(node->getAbsolutePosition()); // deliberately commented out - see below
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
Code: Select all
// camera->setTarget(node->getAbsolutePosition()); // deliberately commented out - see below
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
rogerborg,
Thanks a lot, that was exactly what I needed to know! I set the camera's target up and now it works the way I want, but...
when I run your sample app with that line uncommented (and the same happens to my app), the node kind of flickers on the scene... It is not really stopped (from the camera point of view), sometimes it is draw a bit to the left or to the right... Does the same happen to you? The calculus seems correct, the matter now is why is it being draw incorrectly...
I tried to set up video options, like enabling vsync, but still it doesn't work... I am using irrlitch 1.4 using eclipse CDT + cygwin as IDE... May that be the problem?
Sorry for the amount of questions, but it is helping me a lot. I am a newbie on irrlitch yet, but I am trying to be a quick learner.
Thanks a lot, that was exactly what I needed to know! I set the camera's target up and now it works the way I want, but...
when I run your sample app with that line uncommented (and the same happens to my app), the node kind of flickers on the scene... It is not really stopped (from the camera point of view), sometimes it is draw a bit to the left or to the right... Does the same happen to you? The calculus seems correct, the matter now is why is it being draw incorrectly...
I tried to set up video options, like enabling vsync, but still it doesn't work... I am using irrlitch 1.4 using eclipse CDT + cygwin as IDE... May that be the problem?
Sorry for the amount of questions, but it is helping me a lot. I am a newbie on irrlitch yet, but I am trying to be a quick learner.
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
That's due to it being a FPS camera; the FPS controls are fighting with the setTarget(). Sorry, I should have made it a basic camera.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
No, it happens to basic cameras as well...
I will try to compile it with visual studio and on linux later, to see it that still happens, but it's weird... It seems the screen is being draw at the same time the coordinates are being updated.
Here is the full code I have used:
#include <irrlicht.h>
using namespace irr;
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif
int main()
{
IrrlichtDevice *device =
createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480), 32, false);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
scene::ICameraSceneNode * camera
//= smgr->addCameraSceneNodeFPS();
= smgr->addCameraSceneNode(0, core::vector3df(0, 0, -300), core::vector3df(0, 0, 0));
// Created a fixed point of reference.
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
smgr->addSkyBoxSceneNode(
driver->getTexture("../media/irrlicht2_up.jpg"),
driver->getTexture("../media/irrlicht2_dn.jpg"),
driver->getTexture("../media/irrlicht2_lf.jpg"),
driver->getTexture("../media/irrlicht2_rt.jpg"),
driver->getTexture("../media/irrlicht2_ft.jpg"),
driver->getTexture("../media/irrlicht2_bk.jpg"));
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
// Create a node that will be made a child of the camera.
scene::IBillboardSceneNode * node = smgr->addBillboardSceneNode(smgr->getRootSceneNode());
node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
node->setMaterialTexture(0, driver->getTexture("../media/particle.bmp"));
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setPosition(core::vector3df(0, 0, 50));
// This will cause the camera scene node to rotate. The billboard node will rotate in
// world space around it. However, this will NOT cause the camera's look-at target to
// rotate!
scene::ISceneNodeAnimator * anim = smgr->createRotationAnimator(core::vector3df(0, 0.3f, 0));
camera->addAnimator(anim);
anim->drop();
camera->addChild(node);
while(device->run())
{
driver->beginScene(true, true, video::SColor(0,100,100,100));
camera->setTarget(node->getAbsolutePosition());
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
I will try to compile it with visual studio and on linux later, to see it that still happens, but it's weird... It seems the screen is being draw at the same time the coordinates are being updated.
Here is the full code I have used:
#include <irrlicht.h>
using namespace irr;
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif
int main()
{
IrrlichtDevice *device =
createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480), 32, false);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
scene::ICameraSceneNode * camera
//= smgr->addCameraSceneNodeFPS();
= smgr->addCameraSceneNode(0, core::vector3df(0, 0, -300), core::vector3df(0, 0, 0));
// Created a fixed point of reference.
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
smgr->addSkyBoxSceneNode(
driver->getTexture("../media/irrlicht2_up.jpg"),
driver->getTexture("../media/irrlicht2_dn.jpg"),
driver->getTexture("../media/irrlicht2_lf.jpg"),
driver->getTexture("../media/irrlicht2_rt.jpg"),
driver->getTexture("../media/irrlicht2_ft.jpg"),
driver->getTexture("../media/irrlicht2_bk.jpg"));
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
// Create a node that will be made a child of the camera.
scene::IBillboardSceneNode * node = smgr->addBillboardSceneNode(smgr->getRootSceneNode());
node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
node->setMaterialTexture(0, driver->getTexture("../media/particle.bmp"));
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setPosition(core::vector3df(0, 0, 50));
// This will cause the camera scene node to rotate. The billboard node will rotate in
// world space around it. However, this will NOT cause the camera's look-at target to
// rotate!
scene::ISceneNodeAnimator * anim = smgr->createRotationAnimator(core::vector3df(0, 0.3f, 0));
camera->addAnimator(anim);
anim->drop();
camera->addChild(node);
while(device->run())
{
driver->beginScene(true, true, video::SColor(0,100,100,100));
camera->setTarget(node->getAbsolutePosition());
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}