Page 1 of 1
Changes to camera methods
Posted: Mon May 16, 2011 12:16 am
by cjpaver
I need to change the way that a camera created with ICameraSceneNode rotates.
I've been able to successfully overwrite the methods in the IEventReceiver from the other posts and tutorials to create my own event handler.
I run into a problem when I try to do this the same way for the camera.
If I:
Code: Select all
class DiffCamera : public ICameraSceneNode
{
public:
void setRotation(const core::vector3df& rotation)
{
//something different
}
};
it will only call setRotation if I am creating an instance of DiffCamera. However, I cannot seem to create an instance of DiffCamera unless I overwrite the ISceneManager with something like:
Code: Select all
class DiffSceneManager : public ISceneManager
{
public:
virtual DiffCamera* addCameraSceneNode(ISceneNode* parent = 0,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& lookat = core::vector3df(0,0,100),
s32 id=-1, bool makeActive=true) = 0;
};
since the standard ISceneManager will not add a camera of my type. But if I do that, then the IrrlichtDevice won't return my scene manager type unless I override that one as well.
Creating a variation of IrrlichtDevice isn't working. What can I do so that I may change that single function to do my own thing?
Posted: Mon May 16, 2011 12:22 am
by Radikalizm
Just use the new keyword to create an instance of your camera
Posted: Tue May 17, 2011 12:23 am
by cjpaver
I'm sorry, I don't understand how that helps. Using the new keyword creates an instance of a camera that Irrlicht still doesn't know how to use.
Code: Select all
int main()
{
IrrlichtDevice *device;
device = createDevice( EDT_DIRECT3D9, dimension2d<u32>(800, 600), 16, false, false, false, &receiver);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* env = device->getGUIEnvironment();
ICameraSceneNode * camera = smgr->addCameraSceneNode(0,core::vector3df(0,10,0), core::vector3df(0,6,15));
camera->bindTargetAndRotation(true);
while(device->run())
{
driver->beginScene(true, true, Color(255,100,101,140));
smgr->drawAll();
env->drawAll();
driver->endScene();
env->clear();
}
device->drop();
return 0;
}
Using what was in my original post, how would I use the
new operator in this snippet to replace the
ICameraSceneNode so that
DiffCamera can be used with the existing
ISceneManager smgr?
Posted: Tue May 17, 2011 12:33 am
by Radikalizm
The scene manager doesn't have to create the node to be able to use it in your application, it'd be pretty stupid if you had to modify the engine each time you wanted to add a custom scene node
Why are you intent on replacing the existing camera creation method anyway?
Posted: Tue May 17, 2011 3:37 am
by cjpaver
I want to overwrite it for an assignment to write my own calculations. I know they exist already in Irrlicht, but it's about the coding experience, I guess.
So, in tutorial 003 I found:
Code: Select all
class DiffCamera : public scene::ICameraSceneNode
{
public:
DiffCamera (scene::ICameraSceneNode* parent, scene::ISceneManager* mgr, s32 id,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::vector3df& scale = core::vector3df(1.0f,1.0f,1.0f))
: ICameraSceneNode(parent, mgr, id, position, rotation, scale) {}
void setRotation(const core::vector3df& rotation)
{
std::cout << "This is a test" << std::endl;
}
};
and attempted to alter it to fit my needs. Like I said before, I am trying to overwrite just that setRotation() so I want to use the rest of it. It doesn't give me any syntax errors before running with this ^ section, but inside main() I have another problem.
Code: Select all
int main()
{
...
...
DiffCamera * kcam = new DiffCamera(smgr->getRootSceneNode(), smgr, 666, camPos, camRot, CamSca);
...
...
}
as it was done in the tutorial, gives an error of "object of abstract class type DiffCamera is not allowed." Is this because of the way something is declared in ICameraSceneNode or something that I can simply fix with what I have already done? What's got to get done differently to get
new DiffCamera(...) to work?
Posted: Tue May 17, 2011 4:36 am
by ChaiRuiPeng
that means you didn't define some pure virtual functions. since you are deriving from the camera scene node.
i think this is covered in oop tuts.
Posted: Tue May 17, 2011 5:37 am
by agamemnus
ChaiRuiPeng wrote:i think this is covered in oop tuts.
Even when you preface that with some explanation, this sounds like:
"[to a 9th grader] No, you did it wrong. I think it's covered in 3rd grade."
A good way to end a conversation, tough.

Posted: Tue May 17, 2011 7:38 am
by hybrid
Well, this half-complete implementation is even not enough for any scene node, but especially not for a camera scene node. You must implement all pure virtual methods of the interfaces you use.
Posted: Tue May 17, 2011 1:53 pm
by ChaiRuiPeng
agamemnus wrote:ChaiRuiPeng wrote:i think this is covered in oop tuts.
Even when you preface that with some explanation, this sounds like:
"[to a 9th grader] No, you did it wrong. I think it's covered in 3rd grade."
A good way to end a conversation, tough.

what? anyways, the error you are getting should tell you that you are not implementing all the pure virtual methods of the inherited classes. That is if you read some c++ tutorials maybe!!?! We're frank, but we are giving you the solution, no need to get upset.
Posted: Tue May 17, 2011 6:32 pm
by cjpaver
hybrid wrote:Well, this half-complete implementation is even not enough for any scene node, but especially not for a camera scene node. You must implement all pure virtual methods of the interfaces you use.
Thanks, I didn't know that I had to do all of the pure virtuals. I thought I only had to alter the one I wanted done differently, and the others would carry over as normal. This was the explanation I was looking for.
ChaiRuiPeng wrote:what? anyways, the error you are getting should tell you that you are not implementing all the pure virtual methods of the inherited classes. That is if you read some c++ tutorials maybe!!?! We're frank, but we are giving you the solution, no need to get upset.
He didn't ask the question you helped to answer, I did. Some things come from experience, and that may be where you got this understanding. Anything I've ever seen hasn't stated that each virtual had to be implemented. Unfortunately, I didn't know enough to know what I didn't know and needed to look up.
Posted: Tue May 17, 2011 7:02 pm
by serengeor
cjpaver wrote:hybrid wrote:Well, this half-complete implementation is even not enough for any scene node, but especially not for a camera scene node. You must implement all pure virtual methods of the interfaces you use.
Thanks, I didn't know that I had to do all of the pure virtuals. I thought I only had to alter the one I wanted done differently, and the others would carry over as normal. This was the explanation I was looking for.
They don't carry over simply because theres nothing to carry over, they are pure virtual without any 'function body'.
Posted: Tue May 17, 2011 8:02 pm
by aanderse
I think what the original poster is missing is that ICameraSceneNode is simply an interface, not an implementation.
The ICameraSceneNode class does almost nothing... it is the CCameraSceneNode class (a PRIVATE implementation which you do not have access to) that you are interested in copying+modifying.
Posted: Tue May 17, 2011 9:11 pm
by blAaarg
Using what was in my original post, how would I use the new operator in this snippet to replace the ICameraSceneNode so that DiffCamera can be used with the existing ISceneManager smgr?
Also, after putting the copied/modified CCameraSceneNode in a place where your compiler can find it, to use it you'll need to addSceneNode() and setActiveCamera() after creating the MyCameraSceneNode with
new.