Page 1 of 1

Help needed , WIP included

Posted: Tue Sep 06, 2005 8:10 pm
by gershon
http://rapidsharing.com/show.php/570_new.zip
(DLL not included)

hey all,
new to irrlicht, but going along pretty good 10x to this forum!
been fiddling with this for a few days now..

my camera needs a lot of work, if any1 could recommend one of the cameras on this forum...

hmmm... physics not fully implement...

see the stupid arrow? its my biggest problem right now.
i want this to be some sort of navigational gizmo in the upper middle of the screen,
i thought i'd just child it to the camera, and make it point to a target.

doest work! :x maybe its my camera code..
any alternative? 10x.

Posted: Tue Sep 06, 2005 9:31 pm
by omaremad
why not look at thsi function(do some reasearch before posting plz)


core::vector3df getTargetAngle(core::vector3df v, core::vector3df r)
{
#define PI 3.14159265358979323846
//v -position
//r -target

core::vector3df angle;
float x,y,z;
x = r.X - v.X;
y = r.Y - v.Y;
z = r.Z - v.Z;

//angle in X-Z plane
angle.Y = atan2 (x, z);
angle.Y *= (180 / PI); //converting from rad to degrees

//angle.Y-=90;
//just making sure angle is somewhere between 0-360 degrees
if(angle.Y < 0) angle.Y += 360;
if(angle.Y >= 360) angle.Y -= 360;

//angle in Y-Z plane while Z and X axes are already rotated around Y
float z1 = sqrt(x*x + z*z);

angle.X = atan2 (z1, y);
angle.X *= (180 / PI); //converting from rad to degrees

//angle.X -= 90;
//just making sure angle is somewhere between 0-360 degrees
if(angle.X < 0) angle.X += 360;
if(angle.X >= 360) angle.X -= 360;


return angle;

}

Posted: Thu Sep 08, 2005 8:48 pm
by gershon
i'm sorry, didnt get it...
and where could i research?
10x

Posted: Thu Sep 08, 2005 9:10 pm
by Guest
You can utlise the search function or look in the faq section or the wiki

Posted: Thu Sep 08, 2005 9:38 pm
by omaremad
if u dont get this function learn more C++

v=cammera pos r=target pos

apply the rotation angle to the arrow thing

core::vector3df getTargetAngle(core::vector3df v, core::vector3df r)

Posted: Thu Sep 08, 2005 9:43 pm
by gershon
hmm... yeah... i think i googled before :?

anyway, i thought maybe buildCameraLookAtMatrixRH() could help me here but i'm still lost...


HELP!

Posted: Thu Sep 08, 2005 9:47 pm
by omaremad_guest
Use the function i gave you.

vector3df arrowangle=core::vector3df getTargetAngle(camera->getAbsolutePosition(), camera->getAbsolutePosition());

arrow->setRotation(arrowangle);

put in update loop

Posted: Thu Sep 08, 2005 9:48 pm
by Guest
i meant this

vector3df arrowangle=core::vector3df getTargetAngle(camera->getAbsolutePosition(), target->getAbsolutePosition());

arrow->setRotation(arrowangle);

Posted: Thu Sep 08, 2005 10:01 pm
by gershon
but what about its position?

Posted: Tue Sep 13, 2005 8:08 pm
by gershon
well, kinda solved I guess...

i used the above function to set camera rotation, which being targeted has'nt got any of its own, hence the arrow was just sitting still.

took me while...

so:

cam->setRotation ( getTargetAngle(cam->getPosition(), cam->getTarget() );


just keep in mind that now if you arrow->setPosition(), it will translate with camera's orientation.

hope this made sense.