Moving and zooming using an orthogonal camera [SOLVED]

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
bilygates
Posts: 13
Joined: Tue Feb 23, 2010 10:35 pm

Moving and zooming using an orthogonal camera [SOLVED]

Post by bilygates »

Hello,

I've created an orthogonal camera using the following code:

Code: Select all

    ICameraSceneNode * camera = smgr->addCameraSceneNode();
    matrix4 ortho;
    ortho.buildProjectionMatrixOrthoLH(800, 600, 1, 500);
    camera->setProjectionMatrix(ortho, true);
    camera->setPosition(vector3df(0, 0, 0));
    camera->updateAbsolutePosition();
I was wondering if it is possible to move the camera around the X and Y axis, maybe even zooming or rotating it? Basically, if I want to move around the world, I could move the camera instead of moving every Scene Node. Likewise for zooming and rotating.

I have tried this:

Code: Select all

camera->setPosition(vector3df(150, 0, 0));
But that just distorts the image in a way that I do not quite understand.

Thanks in advance. :)
Last edited by bilygates on Thu Mar 04, 2010 1:05 pm, edited 1 time in total.
Bear_130278
Posts: 237
Joined: Mon Jan 16, 2006 1:18 pm
Location: Odessa,Russian Federation

Post by Bear_130278 »

I'm using the ortho camera... look

Code: Select all

//Camera
		Core.Ortho.buildProjectionMatrixOrthoLH  (Core.ZoomX,Core.ZoomZ,0.0f,6000.0f);
		Core.cam->setProjectionMatrix(Core.Ortho,true);
		Core.cam->setTarget(vector3df((float)Core.X,0.0f,(float)Core.Z));
		Core.cam->setPosition(vector3df((float)Core.X+Core.d_RX,Core.Elevation/*1.75*/*2000.0f,Core.d_RZ+(float)Core.Z));
		Core.cam->updateAbsolutePosition() ;	
Some description
X,Z - Camera target;
ZoomX,ZoomZ - Distance from the camera to the target
ZoomX/ZoomZ=4/3;(in my case)
d_RX,d_RZ - Rotation vars (i calc the rotation, and get the new positions of the camera based on the rotations)
Rotation calc:

Code: Select all

	vector3df t_pos=Core.cam->getTarget();
	vector3df c_pos=Core.cam->getAbsolutePosition();
	c_pos.rotateXZBy(15, t_pos);
	c_pos-=t_pos;
	Core.d_RX=c_pos.X;
	Core.d_RZ=c_pos.Z;
Here i rotate the camera around the target for +15 degrees;

Elevation - represents the angle between Y and Z axis.....

Hope it helps a little 8)))
Do you like VODKA???
Image
Image
bilygates
Posts: 13
Joined: Tue Feb 23, 2010 10:35 pm

Post by bilygates »

Thank you! :D I've managed to move the camera and zoom in. Yay! I couldn't get the camera to rotate, though. I get a blank screen without any objects.

Just to be sure I've made myself clear, this is how I would like to rotate the camera:

Image

I've also tried things like this but without any luck:

Code: Select all

currentPosition = camera->getPosition();
currentPosition.rotateXZBy(15);
camera->setPosition(currentPosition);
Bear_130278
Posts: 237
Joined: Mon Jan 16, 2006 1:18 pm
Location: Odessa,Russian Federation

Post by Bear_130278 »

Ah.... but here you just need to :

Code: Select all

ICameraSceneNode::setRotation  ( const core::vector3df &  rotation  ) 
rotation.X,Y,Z - rotations in degrees for each axis, you need something like this:

Code: Select all

setRotation  (vector3df(0,0,45))
.... i guess
Do you like VODKA???
Image
Image
bilygates
Posts: 13
Joined: Tue Feb 23, 2010 10:35 pm

Post by bilygates »

I have tried that but it doesn't do anything.

Here is my project so far:

Code: Select all

#include "irrlicht.h"
#include <math.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;

int main()
{
    SIrrlichtCreationParameters deviceParameter;
        deviceParameter.DriverType = EDT_OPENGL;
        deviceParameter.AntiAlias = 4;
        deviceParameter.Bits = 32;
        deviceParameter.Fullscreen = false;
        deviceParameter.Vsync = false;
        deviceParameter.WindowSize = dimension2d<s32>(800, 600);

    IrrlichtDevice *device = createDeviceEx(deviceParameter);
    ISceneManager* smgr  = device->getSceneManager();
    IVideoDriver* driver = device->getVideoDriver();

    ICameraSceneNode * camera = smgr->addCameraSceneNode();
    matrix4 ortho;
    ortho.buildProjectionMatrixOrthoLH(800, 600, -1, 500);
    camera->setProjectionMatrix(ortho, true);
    camera->setPosition(vector3df(0, 0, 0));
    camera->setTarget(vector3df(0, 0, 1));
    camera->setRotation(vector3df(0, 0, 45));
    camera->updateAbsolutePosition();


    video::S3DVertex Vertices[4];
    Vertices[0] = video::S3DVertex(-25,25,0, 0,0,1, video::SColor(255,255,0,0), 0, 0);
    Vertices[1] = video::S3DVertex(25,25,0, 0,1,1, video::SColor(255,0,255,0), 1, 0);
    Vertices[2] = video::S3DVertex(25,-25,0, 1,0,0, video::SColor(255,0,0,255), 1, 1);
    Vertices[3] = video::S3DVertex(-25,-25,0, 0,0,1, video::SColor(255,255,255,255),0, 1);

    u16 indices[] = {0,1,2, 2,3,0};

    SMaterial myMaterial;
    myMaterial.Lighting = false;

    SMeshBuffer *buffer = new SMeshBuffer();
    buffer->append(Vertices, 4, indices, 6);

    SMesh *cubeMesh = new SMesh();
    cubeMesh->addMeshBuffer(buffer);

    ISceneNode *cubeSceneNode = smgr->addMeshSceneNode(cubeMesh);
    cubeSceneNode->getMaterial(0) = myMaterial;

    while (device->run())
    {
        driver->beginScene(true, true, video::SColor(0,100,100,100));
        smgr->drawAll();
        driver->endScene();
    }
}
This doesn't change anything:

Code: Select all

camera->setRotation(vector3df(0, 0, 45));
The square should appear rotated by 45 degrees, but it doesn't. I bet the solution is something extremely simple but I just can't figure it out. I'm using Irrlicht 1.7.1, by the way.
Bear_130278
Posts: 237
Joined: Mon Jan 16, 2006 1:18 pm
Location: Odessa,Russian Federation

Post by Bear_130278 »

Just in case 8)))
Check if your image node IS NOT a child of the camera node 8)))
Because in this case the image rotates with the camera 8)))
Do you like VODKA???
Image
Image
blAaarg
Posts: 94
Joined: Tue Mar 02, 2010 9:11 pm
Location: SoCal

Post by blAaarg »

Cameras are strange because rotating them doesn't do anything (except rotate their children, if they have any) unless you first call:

Code: Select all

ICameraSceneNode::bindTargetAndRotation  ( bool  bound   )


Also, I think rotation vectors are in radians by default so you might need to change your rotation to:

Code: Select all

camera->setRotation(vector3df(0, 0, core::DEGTORAD * 45)


If that doesn't work then you should look into:

Code: Select all

ICameraSceneNode::setUpVector (...)
"Computers don't make mistakes! What they do they do on purpose!!"

-Dale Gribble
bilygates
Posts: 13
Joined: Tue Feb 23, 2010 10:35 pm

Post by bilygates »

Finally, this worked:

Code: Select all

camera->setUpVector(vector3df(cos(DEGTORAD * angle), sin(DEGTORAD * angle), 0));
I knew it was something extremely simple. Thank you blAaarg and Bear_130278 for your help. :D
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

setRotation takes degrees, otherwise Radians is explicitly mentioned in the function name. Only exception are quaternions IIRC, but the API should tell you which values to insert.
Post Reply