Rotation works in DX, doesn't in GL. What?

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
Felipe
Posts: 25
Joined: Thu Jun 10, 2004 9:13 pm
Location: Rio de Janeiro

Rotation works in DX, doesn't in GL. What?

Post by Felipe »

Hi all.
I've downloaded+installed Irrlicht 0.6 about 2 or 3 weeks ago, and I've been messing around with it. I've tried not to post any questions here as newbies tend to asking the same thing. So far, most of my questions have met answers from the Search link. :)

The problem I'm having is rotating a node to face another one. I've seen the thread by Gorgon Zola, but I don't understand anything in it. :oops:
I'm trying to get the angle a node needs to rotate towards, but without actually rotating it. Now, I'm better with trig than matrix math, so I re-wrote Gorgon Zola's function completely. Here's what I got:

Code: Select all

float DTR=(180.0f/3.14159265358979323f);
float faceTarget(ISceneNode *hero, ISceneNode *target){
	vector3df hp;
	hp=target->getPosition()-hero->getPosition();
	return 180+atanf(hp.Z/hp.X)*DTR;
}
Aparently, this is working well. Since I only need to rotate the Y axis, it's all I need.

Now, the game I'm working on currently has over 1,150 lines of code, so I'll just extract a small peice:

Code: Select all

reg[0]=(int) faceTarget(RID->playerN, player[reg[0]].playerN);
.
.
.
RID->playerN->setRotation(vector3df(0,(float) reg[0], 0));
This is used to control a few bots, and it does it pretty well, as long as I'm using Direct X. When I change into OpenGL or software, the bots walk in a line to the right (270deg). :shock:
In DirectX they find the nearest other bot and walk towards it.
Last edited by Felipe on Wed Jun 30, 2004 4:28 pm, edited 1 time in total.
Felipe
Posts: 25
Joined: Thu Jun 10, 2004 9:13 pm
Location: Rio de Janeiro

Post by Felipe »

after some more testing, I found that my faceTarget function doesn't really work either. Now I'm completly lost. :(
Felipe
Posts: 25
Joined: Thu Jun 10, 2004 9:13 pm
Location: Rio de Janeiro

Post by Felipe »

YAY! It's working!
I figured I wasn't using the atanf function correctly so I decided to take a look at the MSDN website. After hitting my head on the desk all day yesterday and till now, I found the atan2() function. Just what I needed.

The function is now like this:

Code: Select all

float faceTarget(scene::ISceneNode *obj, scene::ISceneNode *target){
	core::vector3df hp;
	hp=obj->getPosition()-target->getPosition();
	return (float) atan2(hp.Z,hp.X)*DTR;
} 
Now can someone please say if there's any difference (performance-wise) between this function and Gorgon Zola's? I know atan is supposed to be slow, but it doesn't seem to be hurting performance at all on my PC. I have 5 bots chasing each other at 200 fps, which is all my graphics card can take anyway.
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Nice that you found it out yourself :)
Felipe
Posts: 25
Joined: Thu Jun 10, 2004 9:13 pm
Location: Rio de Janeiro

Post by Felipe »

yeah. And it only took me a day and a half too. :P
What a way to spend my vacations. When classes start again, my teacher will probably ask "what did you do with all the spare time?". Everyone will probably say something like going to the beach. "Umm... I messed with trig all day." :shock:
Hoff
Posts: 13
Joined: Sun Jun 27, 2004 5:59 pm

Post by Hoff »

Felipe wrote:yeah. And it only took me a day and a half too. :P
What a way to spend my vacations. When classes start again, my teacher will probably ask "what did you do with all the spare time?". Everyone will probably say something like going to the beach. "Umm... I messed with trig all day." :shock:
For future reference, messing with trig is far cooler than going to the beach.

-- John
Post Reply