Irrlicht Example#007 (C++ Question)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
irrcode
Posts: 17
Joined: Thu Jun 21, 2012 9:45 pm

Irrlicht Example#007 (C++ Question)

Post by irrcode »

On line 264 of example #7,

Code: Select all

ray.end = ray.start + (camera->getTarget() - ray.start).normalize() * 1000.0f;
who owns the ".normalize()" ? I have not yet seen a function called in this way before. Is there a term for this type of method calling?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Irrlicht Example#007 (C++ Question)

Post by CuteAlien »

camera->getTarget() and ray.start are both vector3df which when subtracted from each other result in another vector3df. That result exists temporarily on the stack for this calculation. And while it exists all the usual member functions of vector3d can be called for it.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
irrcode
Posts: 17
Joined: Thu Jun 21, 2012 9:45 pm

Re: Irrlicht Example#007 (C++ Question)

Post by irrcode »

Ah, ok. That's kind of what I was guessing, but why do that in a mainloop? Aren't those stack operations (allocation and release) costly if repeated that much?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Irrlicht Example#007 (C++ Question)

Post by CuteAlien »

No, stack is super cheap - only heap allocations are expensive. All that's needed for the stack to grow or shrink is that the stack-pointer is moved up/down by the size of the object. Heap allocations (new/delete or malloc/free) on the other hand are very expensive as they have to find free memory and have to mark it as used (I don't know specifics on a modern OS, there is probably even additional checks and paging and stuff going on).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
irrcode
Posts: 17
Joined: Thu Jun 21, 2012 9:45 pm

Re: Irrlicht Example#007 (C++ Question)

Post by irrcode »

got it. thanks!
Post Reply