3D Person Camera??? I need Help!!

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.
Nikolino

3D Person Camera??? I need Help!!

Post by Nikolino »

Hy at first,

i know however this read knows that my englisch is very bad but I have a big problem!!

In my game I need an 3rd Person Camera. Hte Camera must follow the Modell who is the player!

but i don't know!

is der any on how can help me??

oh yes i must remmember I only coding in C, sorry guys but I must!!!

If there is annyone how can help me pleas send me an email!

nikokoop@web.de

thx! :D
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

Well the addCameraFPS didnt help me very much, so I decided to write my own 3rd person camera that follows my player. Here is the code I used, I hope it helps:

Code: Select all

vector3df CCharacter::getRelativeCameraPosition(){
	double rotationToCamera;
	double distanceToCamera;
	vector3df cameraPosition;

	rotationToCamera = vRotation.Y - 180;
	distanceToCamera = DISTANCE_TO_CAMERA;

	cameraPosition.X = vPosition.X - sin(rotationToCamera*PI/180)*distanceToCamera;
	cameraPosition.Z = vPosition.Z + cos(rotationToCamera*PI/180)*distanceToCamera;
	cameraPosition.Y = vPosition.Y + distanceToCamera;

	return cameraPosition;
}
What my code does is to first take the character position. I take the character's rotation (where he is looking at) and subtract 180 (because I want to use the angle directly behind the character as the base angle for where the camera is to be positioned). Then I have a distanceToCamera which is how far the camera must be positioned. Then using sin and cosine I figure out where the camera is positioned in the 3D world relative to the character.

So pretty much the variables mean:
- vPosition: Character Position
- rotationToCamera: where relative to the character the camera should be positioned (degrees in polar coordinates)
- distanceToCamera: how far along that rotation the camera should be positioned

If you need any clarification please ask.
Guest

Post by Guest »

Can you show me a little bit of an Code from you wehre you use it?? I can not imagine it!?!?!?!?!? :(

thx
Nikolino

Post by Nikolino »

Yes can you do it??
Nikolino

Post by Nikolino »

Yes can you do it??
Nikolino

Post by Nikolino »

Yes can you do it???? please!
Guest

Post by Guest »

stop spamming the boards and do a search it has been answered about 50 times at least.. failing that check the wiki.
Guest

Post by Guest »

yes, and if you are to stupid to do that just leave and quit programming!
Nikolino

Post by Nikolino »

Tja dann kann ich dir ja in deutsch sagen was ich will! Ich will mir nur angucken wie ihr das macht weil ich aus den Tutorials von Niko nicht schlau werde!!! Und die Dokumentation von Irrlicht, da hätte ich geren mehr beispiele zu den einzelnen Methoden gehabt!!!


Nur mal so was an dich nicht weil ich jetzt dur das beispiel nicht durch blicke heißt das nicht das ich es nicht lernen kann (Es ist noch kein Meister vom Himmel gefallen)
Maize
Posts: 163
Joined: Sat Oct 29, 2005 12:12 am
Location: In a cave...
Contact:

Post by Maize »

Oh man, you sure showed us.
Guest

Post by Guest »

Nikolino wrote:Tja dann kann ich dir ja in deutsch sagen was ich will! Ich will mir nur angucken wie ihr das macht weil ich aus den Tutorials von Niko nicht schlau werde!!! Und die Dokumentation von Irrlicht, da hätte ich geren mehr beispiele zu den einzelnen Methoden gehabt!!!


Nur mal so was an dich nicht weil ich jetzt dur das beispiel nicht durch blicke heißt das nicht das ich es nicht lernen kann (Es ist noch kein Meister vom Himmel gefallen)
A pity you are not as fluent in the language of C++ as you are in that stuff :)
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

Well Nikolino I am not sure what you mean code of where I use it. If you mean my call to the function then it is here:

Code: Select all

void update(){
	if(cCamera->isActive()){			//If avatar cam is active, change its Target to be Avatars Target
		//cCamera->updateLookAt(cCharacter->getRelativeCameraPosition());
		//cCamera->updateLookAt(vector3df(118,51,33));
		cCamera->updateLookAt(cCharacter->getLookAt());
		//pTest->setPosition(cCharacter->getLookAt());
		//pTest->setPosition(cCharacter->getRelativeCameraPosition());
		cCamera->setPosition(cCharacter->getRelativeCameraPosition());
	}
}


The update function is in my main.cpp file and is continuously called in the main loop.

P.S I know these guys sometimes get a bit annoying when they insult you on the forum, but this has been posted about before and using the search function would have helped. Please keep that in mind. GFXstyler is really nice once you get to know him ^_^
Nikolino

Post by Nikolino »

oh at fist I can write code in C++ but I must write my game in C because I show it an part of my class and thy can only C, for they understanding I must write my game in C, you understand? and if I use C++ I must explan that and I didn't wont that!!!!!!!!!!!!!!!!!


But my problem is that in Irrlicht no 3rd person Cameras incuded so i need your help for do that! and it's very hard vor me to read any about them in English, you can see that my English is like an Noob!! and if anyone have an tutorial in german say it me!


If no one have any toturial in german, an english tutorial do it too!!

and now to the pro who mean thy were the master i know its terrible to read so stupid questions in an forum but the noob (like me) want answers of there questions and no insults for them. I didn't want to spam the forum but on the day i wrote my text your database turn off and I didn't know about them that she nevertheless worte my text in this thread!so I'm sorry !

So can me anyone show an source in C who use an 3rd person Camera??

thx in front!
SenVa
Posts: 38
Joined: Fri Oct 14, 2005 1:00 pm
Location: Mi

Post by SenVa »

I dont know enough german to read what you wrote up there but i can say

Code: Select all

Es ist Nackt uhr.
and i guess that is what this thread is really about...

Ok i hope this helps you
add a non FPS camera
use krama757's code to stay with your model.
try downloading a few third person games and looking at that code, but i think it will be hard to find a game in pure C.
Xaron
Posts: 310
Joined: Sun Oct 16, 2005 7:39 am
Location: Germany
Contact:

Post by Xaron »

SenVa wrote:

Code: Select all

Es ist Nackt uhr.
:shock: That doesn't make any sense. :lol:

"Nackt" means naked. ;)

Do you mean it is night time and noone would answer so fast? That would be:

Code: Select all

Es ist Nacht.
or

Code: Select all

Es ist Nachtzeit.
But rather noone would use the second form. ;)

@Nikolino: Check this, especially the makeCockpit() function which will be almost the same for a 3rd person game:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?p=38347

Regards - Xaron
Post Reply