Rotate Camera
-
- Posts: 15
- Joined: Fri Aug 04, 2006 11:36 am
Rotate Camera
Hi!
I want to rotate my camera 90 degrees left or right, but I can't find how to do that, setRotation doesn't seem to work.
Any help?
Cheers
I want to rotate my camera 90 degrees left or right, but I can't find how to do that, setRotation doesn't seem to work.
Any help?
Cheers
-
- Posts: 15
- Joined: Fri Aug 04, 2006 11:36 am
-
- Posts: 15
- Joined: Fri Aug 04, 2006 11:36 am
mmm
Well I think I'm doing it right:
then
then
(In fact even the setTarget here doesn't work. setPosition does though
And finnaly in my EventReceiver:
Well I think I'm doing it right:
Code: Select all
ICameraSceneNode *camera;
Code: Select all
camera = smgr->addCameraSceneNode();
Code: Select all
gameCore.camera->setPosition(vector3df(0,500,-250));
gameCore.camera->setTarget(vector3df(0,0,0));
And finnaly in my EventReceiver:
Code: Select all
case EGET_BUTTON_CLICKED:
if(id == 101)
{
camera->setRotation(vector3df(0,90,0));
}
-
- Posts: 10
- Joined: Fri May 05, 2006 10:38 am
- Location: Australia
Code: Select all
camera = smgr->addCameraSceneNode();
How would you know if setTarget(vector3df(0,0,0)) is working or not?
I thought that was the default heading of a camera???,
try setTarget(vector3df(100,500,-250));
I was told setRotation() is only for smgr->addCameraSceneNodeFPS()
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=13080
Actually the default target of the camera is (0, 0, 100) - according to the docs anyways:
Code: Select all
addCameraSceneNode (ISceneNode *parent=0, const core::vector3df &position=core::vector3df(0, 0, 0), const core::vector3df &lookat=core::vector3df(0, 0, 100), s32 id=-1)=0
Call me Wice, Miami Wice!
-
- Posts: 15
- Joined: Fri Aug 04, 2006 11:36 am
Are you absolutly 100 % sure that it isnt working?? Cuz sometimes it just seems like it, since "the code works in mysterius way", and sometimes actually does work!
Try debug and check that the values are indeed not changing. Dont just trust your eye on this one!
Anyways, maybe if you could show us your code it would help a bit understanding what you posibly could be doing wrong.
Try pasting you code here: http://pastebin.co.uk/
Then link us with code.
Try debug and check that the values are indeed not changing. Dont just trust your eye on this one!
Anyways, maybe if you could show us your code it would help a bit understanding what you posibly could be doing wrong.
Try pasting you code here: http://pastebin.co.uk/
Then link us with code.
Call me Wice, Miami Wice!
-
- Posts: 15
- Joined: Fri Aug 04, 2006 11:36 am
I can't manage to see their anti spam image so I'll just post it here:
Main:
CGameCore.h
GameCore.cpp
Any help?
Thanks a lot
Main:
Code: Select all
#include "CGameCore.h"
int main()
{
CGameCore gameCore;
if (!gameCore.GameInit())
{
return 0;
}
IAnimatedMesh* mesh;
ISceneNode* node;
gameCore.guienv = gameCore.device->getGUIEnvironment();
mesh = gameCore.smgr->getMesh("test.3ds");
node = gameCore.smgr->addAnimatedMeshSceneNode(mesh);
gameCore.device->setEventReceiver(&gameCore);
node->setScale(vector3df(2.0f,0.8f,2.0f));
node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
node->setMaterialFlag(video::EMF_LIGHTING, false);
IGUIImage *map;
IGUITabControl* tabctrl = gameCore.guienv->addTabControl(core::rect<int>(0,320,640,480),0, true, true);
IGUITab* optTab = tabctrl->addTab(L"Info");
IGUITab* aboutTab = tabctrl->addTab(L"Construction");
map = gameCore.guienv->addImage(gameCore.driver->getTexture("minimap.tga"),position2d<s32>(500,5),true,optTab);
IGUIButton* button1 = gameCore.guienv->addButton(rect<s32>(30,30,60,60),optTab,101,L"Rotate");
gameCore.camera->setPosition(vector3df(0,500,-250));
gameCore.camera->setTarget(vector3df(100,500,-250));
while (gameCore.GameLoop())
{
gameCore.CameraUpdate();
gameCore.Render();
}
return 0;
}
Code: Select all
#ifndef __CGameCore_h__
#define __CGameCore_h__
#include <irrlicht.h>
#include <iostream>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
struct Screen
{
int X;
int Y;
};
class CGameCore : public IEventReceiver
{
public:
IrrlichtDevice *device;
IVideoDriver *driver;
ISceneManager *smgr;
ICameraSceneNode *camera;
IGUIEnvironment *guienv;
Screen screen;
CGameCore();
virtual ~CGameCore(void);
bool GameInit();
void Destroy();
void Render();
bool GameLoop();
void CameraUpdate();
bool fullscreen;
int bitdepth;
virtual bool OnEvent(SEvent event);
private:
int cursx;
int cursy;
vector3df camerapos;
};
#endif
Code: Select all
#include "CGameCore.h"
CGameCore::CGameCore()
{
fullscreen = true;
bitdepth = 32;
}
CGameCore::~CGameCore()
{
Destroy();
}
bool CGameCore::GameInit()
{
screen.X=640;
screen.Y=480;
device = createDevice(EDT_OPENGL, dimension2d<s32>(screen.X, screen.Y),bitdepth,fullscreen,true,true,0);
if (device == 0) return false;
driver = device->getVideoDriver();
smgr = device->getSceneManager();
camera = smgr->addCameraSceneNode();
guienv = device->getGUIEnvironment();
quit = false;
return true;
}
void CGameCore::Destroy()
{
if (device)
{
device->closeDevice();
}
}
void CGameCore::Render()
{
if (!device->isWindowActive()) return;
driver->beginScene(true, true, 0);
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
bool CGameCore::GameLoop()
{
if (!device->run())
{
return false;
}
return true;
}
bool CGameCore::OnEvent(SEvent event)
{
if(event.EventType==EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
guienv = device->getGUIEnvironment();
switch(event.GUIEvent.EventType)
{
case EGET_BUTTON_CLICKED:
if(id == 101)
{
camera->setRotation(vector3df(0,90,0));
return false;
}
break;
}
}
return false;
}
void CGameCore::CameraUpdate()
{
camerapos = camera->getPosition();
camerapos.Z += 2;
camerapos.Y -= 2;
camera->setTarget(camerapos);
cursx = device->getCursorControl()->getPosition().X;
cursy = device->getCursorControl()->getPosition().Y;
float distance = 5.0;
if (cursx > (screen.X - 40))
{
camerapos = camera->getPosition();
camerapos.X += distance;
camera->setPosition(camerapos);
}
else if (cursx < 40)
{
camerapos = camera->getPosition();
camerapos.X -= distance;
camera->setPosition(camerapos);
}
if (cursy < 40)
{
camerapos = camera->getPosition();
camerapos.Z += distance;
camera->setPosition(camerapos);
}
else if (cursy > (screen.Y - 40))
{
camerapos = camera->getPosition();
camerapos.Z -= distance;
camera->setPosition(camerapos);
}
}
Thanks a lot
mhm.. Do you think this might have someting to do with your problem:
yes?
Code: Select all
void CGameCore::CameraUpdate()
{
camerapos = camera->getPosition();
camerapos.Z += 2;
camerapos.Y -= 2;
camera->setTarget(camerapos);
...
}
Call me Wice, Miami Wice!
-
- Posts: 15
- Joined: Fri Aug 04, 2006 11:36 am