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
scene node setTarget
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
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
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.
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.
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!!!
tons of ideas have been generated in my mind.....sorry for not helping, but very interesting.
Tyn: thnx for elaborating!!!

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: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
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;
}