glLookAt in Irrlicht

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
mcbart
Posts: 19
Joined: Thu Aug 07, 2008 11:36 am

glLookAt in Irrlicht

Post by mcbart »

Hi there!
I have one question with concerning glLookAt function. I exactly mean if i can somehow use this function in irrlicht program or if there is any other function which works in similar way like this(or even in the same)??
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

How about the methods of ICameraSceneNode? Specifically setTarget(), setUpVector() and setPosition().

Travis
mcbart
Posts: 19
Joined: Thu Aug 07, 2008 11:36 am

Post by mcbart »

Thanks but i wanna create set of function which make camera move. Some thing like 3rd person camera.
void PrzesunPrzod(float distance)
{
vector3df przodTmp(przod.X, 0, przod.Z);
poz = poz +przodTmp*distance;


}
void UpDate()
{
camera->setPosition(poz);


}
That functions i used to make camera move but there's one problem. In a moment when it moves suddenly it turn around and goes back. I mean when i press and hold W it moves forward and suddenly it turn around and goes back.
Last edited by mcbart on Wed Jan 14, 2009 11:01 am, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You have to update the target as well, in order to keep it looking into the desired direction.
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Look at the FPS camera animator for an example, or check out one of the numerous Third Person Cameras posted on the forums.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
mcbart
Posts: 19
Joined: Thu Aug 07, 2008 11:36 am

Post by mcbart »

hybrid wrote:You have to update the target as well, in order to keep it looking into the desired direction.
What should be target for this camera and how to do this??
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

ICameraSceneNode::setTarget(vector3df)

You just give it a position in 3D space at which you want the camera to look... It should be fairly clear what it should be set to...

If you're just moving the camera forward then you add to the target the same vector you added to the camera's position to make it go forward.
Image Image Image
mcbart
Posts: 19
Joined: Thu Aug 07, 2008 11:36 am

Post by mcbart »

ok i did it what you said.
I set mesh in front of camera to check if camera moves and used this code
camera->setTarget(przodTmp)
and result is that mesh dissepear.
I even used something like this
camera->setTarget(suma)
suma=przodTmp*distance
and it doesnt works too. What is wrong with this code. Or maybe i have done something wrong???
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Maybe you should search the forum for the large number of other 3rd person style cameras which have been posted...? Or look at the source code for the FPS camera which might give you some hints.
Image Image Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

What is przod, why do you think that not taking into account the rotation will help, and how do you create the whole setup for testing?
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

It would help if you post your code of us to check.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
mcbart
Posts: 19
Joined: Thu Aug 07, 2008 11:36 am

Post by mcbart »

That's full code of application.
----------------------------------------------------------

Code: Select all

#include <irrlicht.h>
#include <stdio.h>




using namespace irr;


using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")

scene::ICameraSceneNode* camera ;

bool key_W;
bool key_S;




static vector3df przod;//forward
 static     vector3df prawo;//right
  
 static     vector3df poz;
 
      
     vector3df przodTmp(przod.X, 0, przod.Z);
 static     vector3df suma;

      	
      	
     
 
void PrzesunPrzod(float distance)//moving forward
{
	
	poz = poz + przodTmp*distance;
	suma=przodTmp*distance;

	
	
}

void PrzesunPrawoLewo(float distance)//moving in left and right
{
	poz = poz + prawo*distance;
}
void intZmienne()
{
             przod = vector3df(0, 0, -1);
	prawo = vector3df(1, 0, 0);
	gora = vector3df(0, 1, 0);
	//obiekt na który ma patrzeć
	cel = vector3df(0, 0, 0);
	//pozycja kamery
	poz = vector3df(0,30,-40);
	//kąty
	pitch = roll = yaw = 0;

}

void UpDate()
{


camera->setPosition(poz);
camera->setTarget(suma);
}
class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{ if ( event.EventType == irr::EET_KEY_INPUT_EVENT)
{
if(event.KeyInput.Key== KEY_KEY_W )
		{
			key_W=event.KeyInput.PressedDown;
		}
	 
		 if(event.KeyInput.Key== KEY_KEY_S)
		 {
			 key_S=event.KeyInput.PressedDown;
		 }
      }
     


	
return false;	
	} 
 };
int main()
{MyEventReceiver receiver;
	

	IrrlichtDevice *device =
		createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 16,
			false, false, false, &receiver);


	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");


	IVideoDriver* driver = device->getVideoDriver();
	
	IGUIEnvironment* guienv = device->getGUIEnvironment();
	
ISceneManager* smgr = device->getSceneManager();
camera = smgr->addCameraSceneNode(0,vector3df(0,30,-40), vector3df(0,5,0)); 
   

	guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
		rect<int>(10,10,260,22), true);
		
		
		device->getFileSystem()->addZipFileArchive      ("media/map-20kdm2.pk3");

	
	scene::IAnimatedMesh* q3levelmesh = smgr->getMesh("20kdm2.bsp");
	scene::ISceneNode* q3node = 0;
 	IAnimatedMesh* mesh = smgr->getMesh("media/sydney.md2");IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
if (node){	node->setMaterialFlag(EMF_LIGHTING, false);	node->setFrameLoop(0, 310);		node->setMaterialTexture( 0, driver->getTexture("media/sydney.bmp") );}

		


 




		

	
	

	
	while(device->run())
	{   UpDate();
if(key_W==true)
{
               PrzesunPrzod(1);
               }
          
		driver->beginScene(true, true, SColor(255,100,101,140));
     
		smgr->drawAll();
		guienv->drawAll();

		driver->endScene();
	}

	device->drop();

	return 0;
}
Post Reply