How do I make an IAnimatedMeshSceneNode* to allways look in the direction of (look at) an ICameraSceneNode*?
edit: Like the ICameraSceneNode setTarget() function
allways look at camera
-
- Posts: 2
- Joined: Mon Jul 26, 2004 11:39 am
- Location: Norway
- Contact:
allways look at camera
Last edited by VarmVaffel on Mon Jul 26, 2004 3:54 pm, edited 1 time in total.
Nothing is impossible, just highly unrealistic
Re: allways look at camera
If it is 2d, then you can use a billboard. Else you'll have to update the Mesh' position each frame.VarmVaffel wrote:How do I make an IAnimatedMeshSceneNode* to allways look in the direction of (look at) an ICameraSceneNode*?
-
- Posts: 2
- Joined: Mon Jul 26, 2004 11:39 am
- Location: Norway
- Contact:
Re: allways look at camera
I know I have to do that, but _how_ do I make the model look in my direction?bal wrote: Else you'll have to update the Mesh' position each frame.
Nothing is impossible, just highly unrealistic
I assume you'd have to get the position of the object and the camera and then call a function like the following in order to get the angle to which you should rotate the object.
Now, that's some old code I had for a language called Turing. Again, it's old and it was made for a 2D game. You'll have to change it anyways for whatever language you are using, but that's the basic idea. Don't forget to take the Z coords into consideration so you can get another angle of rotation. There may have been a better way of doing it, but I hope this helps you.
Code: Select all
function trueAngles (x1, y1, x2, y2 : int) : real % result an angle between 0 and 360 degrees
if x1 not= x2 then
if x1 < x2 and y1 < y2 then
result (arctand ((y1 - y2) / (x1 - x2)))
elsif x1 < x2 and y1 > y2 then
result (arctand ((y1 - y2) / (x1 - x2)) + 360)
elsif x1 > x2 and y1 < y2 then
result (arctand ((y1 - y2) / (x1 - x2)) + 180)
elsif x1 > x2 and y1 > y2 then
result (arctand ((y1 - y2) / (x1 - x2)) + 180)
elsif y1 = y2 then
if x1 < x2 then
result 0
else
result 180
end if
end if
else
if y1 > y2 then
result 270
elsif y1 < y2 then
result 90
else
result 0
end if
end if
end trueAngles