How to Store Cam Position in vector3df

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
Schranz0r_23
Posts: 4
Joined: Sun Nov 02, 2008 8:50 am

How to Store Cam Position in vector3df

Post by Schranz0r_23 »

Hi there guys!

I have a little Problem.

I want to print out the current Cam Postion
on the Screen. Therefore i thought i could
store the current position into a vector 3df var.

Currently my Code looks like this.

Code: Select all

vector3df camPos;
float camX = 1.0f;
float camY = 1.0f;
float camZ = 1.0f;
..while () ... // main loop

Code: Select all

camPos.set(camX,camY,camZ);
//camPos.getAs4Values(smgr->getActiveCamera()->getPosition(),0); // error!
camX = camPos.getVectorX();
camY = camPos.getVectorY();
camZ = camPos.getVectorZ();
i modified the vector3d.h a little bit (Added 3 new Methods)

Code: Select all

// Just the first Method to get the X coord.
float getVectorX() const
{
return X;
}
And now in my main loop i want to print out
the Position like this >

Code: Select all

stringw cstr = L"Current: ";
cstr += smgr->getActiveCamera()->getName();
cstr += " ";
cstr += "Position-X: ";
cstr += camX; // Prints out 1.0f
I thought the method "getAs4Values" would return all
of the coords (X,Y,Z) as an array (type vector3df).
Wheres my error??

Im out of any ideas.

Many thanks for every help!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

This doesn't make much sense... You can access the X,Y,Z values of a vector3df just by name: myvector.X
The getAs4Values returns the content of the vector into a pre-allocated memory area of 4 floats, so this will naturally lead to a crash if you pass 0 as target :lol:
Just read a little more in the tutorials, and study the API a little bit (assuming your C++ knowledge is advanced enough to cope with 3d engines), then everything should become much clearer.
Eigen
Competition winner
Posts: 375
Joined: Fri Jan 27, 2006 2:01 pm
Location: Estonia
Contact:

Post by Eigen »

Yes, a simple

Code: Select all

vector3df camPos = smgr->getActiveCamera()->getPosition();

someFloat = camPos.X ..

would suffice. You're reinventing the wheel.
Schranz0r_23
Posts: 4
Joined: Sun Nov 02, 2008 8:50 am

Post by Schranz0r_23 »

Thanks guys !

I now got an answer : - )

It was .. pretty 2 simple

Code: Select all

camX = smgr->getActiveCamera()->getAbsolutePosition().X;
Thanks in advance!
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

Schranz0r_23 wrote:Thanks guys !

I now got an answer : - )

It was .. pretty 2 simple

Code: Select all

camX = smgr->getActiveCamera()->getAbsolutePosition().X;
Thanks in advance!
Why not just use
camPos = smgr->getActiveCamera()->getAbsolutePosition();


you wont need this then
camX = camPos.getVectorX();
camY = camPos.getVectorY();
camZ = camPos.getVectorZ();
Schranz0r_23
Posts: 4
Joined: Sun Nov 02, 2008 8:50 am

Post by Schranz0r_23 »

Well, the reason were these Error Messages:
(Remember i want to print out the current cam Pos on the Screen).
So the values must be at least int or string.

Code: Select all

// ERROR: can't convert vector3df in float
//float camPosTest = smgr->getActiveCamera()->getAbsolutePosition();

vector3df camPosTest = smgr->getActiveCamera()->getAbsolutePosition();

stringw cstr = L"Current: ";
cstr += smgr->getActiveCamera()->getName();
cstr += " ";
cstr += "Position-X: ";
cstr += camX;
cstr += "Position-Y: ";
cstr += camY;
cstr += "Position-Z: ";
cstr += camZ;
// ERROR 
//cstr += " ";
//cstr += camPosTest;


font->draw(cstr.c_str(),
rect<s32>(10,10,80,80),
SColor(255,255,255,255));
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

Code: Select all

// ERROR: can't convert vector3df in float
//float camPosTest = smgr->getActiveCamera()->getAbsolutePosition();

vector3df camPosTest = smgr->getActiveCamera()->getAbsolutePosition();

stringw cstr = L"Current: ";
cstr += smgr->getActiveCamera()->getName();
cstr += " ";
cstr += "Position-X: ";
cstr += camPosTest.X;
cstr += "Position-Y: ";
cstr += camPosTest.Y;
cstr += "Position-Z: ";
cstr += camPosTest.Z;
// ERROR
//cstr += " ";
//cstr += camPosTest;


font->draw(cstr.c_str(),
rect<s32>(10,10,80,80),
SColor(255,255,255,255)); 
easy right? :P
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Schranz0r_23 wrote:So the values must be at least int or string.
for what reason ??? :shock:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Schranz0r_23
Posts: 4
Joined: Sun Nov 02, 2008 8:50 am

Post by Schranz0r_23 »

@B@z:
omgosh :shock: sometimes it's too simple

@Achki

I thought that it must be at least an int or string because of
my error messages i got a few builds before. but it could be
that i made another mistake ; therefore nvm :oops:

many thanks !
Post Reply