Please Explain

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
trixs
Posts: 26
Joined: Fri Jan 11, 2008 5:19 am
Location: Georgia
Contact:

Please Explain

Post by trixs »

I have been trying to get a basic camera to work for a week now and finally tried this on something I saw posted from 03.. To my surprise it actually works. The camera will move in whatever direction it is facing.. Ok great!

How does it work??

Edit: Nevermind.. Works in space find but you apply an animator to it and it goes nutty when contacts ground. I really dont think I will ever understand how to actually create a camera that is smoth.

Code: Select all

i = (whatever speed)

core::vector3df movedir = camera->getTarget() - camera->getPosition();
movedir.normalize();

core::vector3df pos = camera->getPosition();
	
camera->setPosition(pos + movedir * i);
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Please Explain

Post by CuteAlien »

trixs wrote: Edit: Nevermind.. Works in space find but you apply an animator to it and it goes nutty when contacts ground. I really dont think I will ever understand how to actually create a camera that is smoth.
Don't give up to soon. Coding a camera is hard and for many professional games the programmers also had to spend weeks until they got it right. At the moment you find a line from where the camera is to the place where it looks at. And then you move the camera along that line, so it gets on each step closer to the target at which it looks. So after a while your camera should reach the target. If you step once more the camera should turn and if you reach the target exactly it can no longer move, because the line does no longer have a direction.

I suppose you use some camera like the fps-cam or the maya-cam as basis, otherwise you would not be able to look in any direction as the target would always be at the same place. Those cameras already do translate key- and mouseinput into camera movement and camera target placement. It might be worth to check the code of those to find out how they are doing that. Once you want to add stuff to those it's mostly easier to use a very basic camera and code everything for it yourself.

It helps if you know really exactly what you want to be able to do with your camera. As player you don't notice it that much - all 3rd person cam's look the same. But as programmer you learn that there are actually a lot of differences. You need to know at which target it has to look all the time and at which position the camera should be and also if it might need to be rotated in some way additionally (like beeing upside-down or just a little tilted).

And then you have to translate that in math. Which means usually learning more about vectors and matrices. But if you know exactly what you want and you can describe it good enough you can also ask for help here :-)
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
trixs
Posts: 26
Joined: Fri Jan 11, 2008 5:19 am
Location: Georgia
Contact:

Post by trixs »

CuteAlien,

Basically I went about writing my own FPS camera for two reasons:

1. To help learn
2. I cant stand the way user input is not separated from the included cameras.

Anyway, I can get a basic camera moving around but you attach to a collision response animator and it simply goes nutty whenever comes near the ground. Now this is only for a ground that has a heigh aspect to it. Something like a flat plane and it works fine.

IT comes down to I wish there was a good example(COMMENTED) and tutorial on cameras. Ive looked through these forums at everything I could find and it is always the same. People ask questions but get no answers. People where asking for a tutorial back in 03 for cameras and there still isn't one. If I ever figure it out I know what I will be doing lol
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Yeah, I also wont be able to write some cool camera tutorial in my sparetime. That needs just more time than I do have. But on concrete problems I try to help. Though even that is often not trivial.

For example I'm not sure what an collision animator will do to a cameranode. A camera has no mesh and shouldn't have a collision area, so I don't know what would collide there. Maybe colliding an (invisible) mesh which you set at the same place than the camera and using the resulting values would work better.

But then I'm also not sure if a collision animator will even get what you want. I guess you use it, because you want to avoid that the camera ever gets behind a wall. Probably I would write that collision myself and use a sphere around the camera for it.

The next thing is collision reaction. It's not enough to get outside the collision, but you also have to be careful to keep smooth movements. Maybe for a start it would be easier to switch the camera completely to a new position (another cameraangle) whenever it collides. Define a few defaultangles and each time one collides switch to the next one.

But even that won't be enough. When walking around a corner you might have for example a place where your camera is not colliding, your playerobject is not colliding, but still a wall is in between. So you will probably need additional tracelines and you must think what the camera does in such a situation. For example getting closer to the player until the traceline does no longer collide.
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
Post Reply