allways look at camera

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
VarmVaffel
Posts: 2
Joined: Mon Jul 26, 2004 11:39 am
Location: Norway
Contact:

allways look at camera

Post by VarmVaffel »

How do I make an IAnimatedMeshSceneNode* to allways look in the direction of (look at) an ICameraSceneNode*?

edit: Like the ICameraSceneNode setTarget() function
Last edited by VarmVaffel on Mon Jul 26, 2004 3:54 pm, edited 1 time in total.
Nothing is impossible, just highly unrealistic
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Re: allways look at camera

Post by bal »

VarmVaffel wrote:How do I make an IAnimatedMeshSceneNode* to allways look in the direction of (look at) an ICameraSceneNode*?
If it is 2d, then you can use a billboard. Else you'll have to update the Mesh' position each frame.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
VarmVaffel
Posts: 2
Joined: Mon Jul 26, 2004 11:39 am
Location: Norway
Contact:

Re: allways look at camera

Post by VarmVaffel »

bal wrote: Else you'll have to update the Mesh' position each frame.
I know I have to do that, but _how_ do I make the model look in my direction?
Nothing is impossible, just highly unrealistic
Mazer
Posts: 16
Joined: Sat Jun 19, 2004 12:21 pm

Post by Mazer »

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.

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
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.
Post Reply