scene node setTarget

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
jikbar
Posts: 62
Joined: Wed Aug 25, 2004 4:48 pm
Location: Canada
Contact:

scene node setTarget

Post by jikbar »

i need to know how o make a normal scene node look at a point in space like the setTarget() function. setTarget() only works for cameras.

setTarget() should be a function in every type of scene node, not just cameras
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

how about setRotation

it makes any node rotate in any direction in 3d space, including making a node "look" in a specific direction.

dunno if that's what you need but the origin-target stuff is camera-only related, pretty much like how you create a camera in a 3d package.
Image
jikbar
Posts: 62
Joined: Wed Aug 25, 2004 4:48 pm
Location: Canada
Contact:

Post by jikbar »

nope, thats not what i mean

setTarget() takes a 3D position and translates it into a rotation so the camera is facing that point. i want to do the same thing, take a point in 3D space and rotate my model so it faces that point.

if i send 0,0,0 as the position of my model into a function, and send 50,50,50 as the "look at" target of that model, the function should return a rotation of 45,45,0 (in degrees) which would be the rotation that faces the target.

i need this so the enemy in my game can aim at the player
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

What he is saying is that the setTarget in the camera class is not the same setTarget that you want, it is to do with how the view is calculated.

What you actually want is a faceTarget() function. It's around the forums somewhere, I remember a discussion a couple of months back about it. You basically use trig to work out the rotation angle between the two points, you should be able to get that from a maths book I think.
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

oh, I see, prolly helpful when using a crosshair, or if you had an automated turret gun that needs to follow a player or something. Setting the target to get snapped to another node set up in space at a different location and having your source node rotate in such target direction.... interesting.


tons of ideas have been generated in my mind.....sorry for not helping, but very interesting.

Tyn: thnx for elaborating!!! :D
Image
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

I am sure there are other ways, probably including matrix math but this works fine too. I made this function to get rotation around Y and X axis to face target:

Code: Select all

core::vector3df getYXangle(core::vector3df r)
{
   vector3df angle;
   
   angle.Y = atan2 (r.X, r.Z);
   angle.Y *= (180 / PI);
   
   if(angle.Y < 0) angle.Y += 360;
   if(angle.Y >= 360) angle.Y -= 360;
   
   float z1;
   z1 = sqrt( r.X * r.X   +   r.Z * r.Z );
   
   angle.X = atan2 (z1, r.Y);
   angle.X *= (180 / PI);
   angle.X -= 90;
   
   if(angle.X < 0) angle.X += 360;
   if(angle.X >= 360) angle.X -= 360;

   return angle;
}
core::vector3df r which is passed in to the function is relative position of target to object you want to turn. You calculate it by substracting position of object from position of target: r = target pos - node pos
jikbar
Posts: 62
Joined: Wed Aug 25, 2004 4:48 pm
Location: Canada
Contact:

Post by jikbar »

thx arras

i already had the Y angle part of that code but my relative target position and XYZ were messed up. it appears that math/physics books only cover the 2D version of the calculation :)
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

great function Arras, helped me out a lot!

Gonna add this to the line3d class in NX++ :)
Image
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

You are welcome ;)
Post Reply