glLookAt in Irrlicht
glLookAt in Irrlicht
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)??
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)??
How about the methods of ICameraSceneNode? Specifically setTarget(), setUpVector() and setPosition().
Travis
Travis
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.
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.
-
Dark_Kilauea
- Posts: 368
- Joined: Tue Aug 21, 2007 1:43 am
- Location: The Middle of Nowhere
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.
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.
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???
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???
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;
}
