What are the World / View / Projection / Texture transforms?

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
WindScar
Posts: 7
Joined: Wed Sep 01, 2010 10:38 pm

What are the World / View / Projection / Texture transforms?

Post by WindScar »

I've spent hours trying to do a simple program that draws a 3d cube (1,1,0,2,2,1) from a camera at pos (0,0,0) facing towards (1,0,0) in a LH coordinate system where Z faces upwards, without using the scene manager, but I can't figure out how to do it. My last attempt:

Code: Select all

core::matrix4 mat = core::matrix4().buildCameraLookAtMatrixRH(core::vector3df(0,0,0),core::vector3df(1,0,0),core::vector3df(0,0,1));
      driver->setTransform(video::ETS_PROJECTION, mat);
      driver->setTransform(video::ETS_VIEW, mat);
      driver->setTransform(video::ETS_WORLD, mat);
      driver->draw3DBox(core::aabbox3df(1,1,0,2,2,1),video::SColor(255,0,0,0));
Nothing works. Please enlighten me.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The matrix that you are building is just the view matrix. The view matrix controls the position and orientation of the virtual camera. The projection matrix controls how objects are projected from a 3d environment onto a 2d surface, and the world transformation describes where the object is oriented in 3d space.

Of course this would all be much simpler if you just used the existing camera and cube scene nodes.

Travis
WindScar
Posts: 7
Joined: Wed Sep 01, 2010 10:38 pm

Post by WindScar »

But if I call the video 3d drawing functions will it use the camera scene node? I'm really confused. I've tryed this:

Code: Select all

int main()
{
	video::E_DRIVER_TYPE driverType=video::EDT_OPENGL;
	IrrlichtDevice *device = createDevice(driverType,
      core::dimension2d<u32>(512, 384));
	if (device == 0) return 1;
	device->setWindowCaption(L"Tests...");
	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();

	scene::IMeshSceneNode* cube = smgr->addCubeSceneNode(3);
  cube->setPosition(core::vector3df(10,0,-10));
  scene::IMeshSceneNode* cube2 = smgr->addCubeSceneNode(3);
  cube2->setPosition(core::vector3df(18,0,-10));
  scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS();
	cam->setTarget(core::vector3df(0,0,-1));
	//cam->setUpVector(core::vector3df(0,0,1));


	while(device->run() && driver && !Controller::key_status(VK_ESCAPE))
	{
			driver->beginScene(true, true, video::SColor(255,255,255,255));
      if (Controller::key_status(VK_SPACE)) { cam->setTarget(core::vector3df(10,0,-10)); }

      driver->draw3DLine(
          core::vector3df(cube->getPosition().X,cube->getPosition().Y,cube->getPosition().Z),
          core::vector3df(cube2->getPosition().X,cube2->getPosition().Y,cube2->getPosition().Z),
          video::SColor(255,0,0,0));


      smgr->drawAll();

			driver->endScene();
	}

	device->drop();
	return 0;
}
But the line isn't going from a cube to another as expected, it is appearing in a different place.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

If you are calling the driver draw*() methods directly, you have to remember to set the world transform (and the material) first. The Irrlicht scene nodes all do this automatically. This has been covered many times on these forums. A simple search for setTransform() or drawVertexPrimitiveList() would probably show you the things you need to know.

The camera scene node takes care of the view and projection matrices automatically.

Another thing to think about is that the camera updates the view and projection matrices in the smgr->drawAll() call. If you render things before smgr->drawAll() they will be rendered using the view and projection matrices from the previous frame.

Irrlicht is a lot easier to use if you just follow the model that it uses. If you want to do render something special (other than the provided Irrlicht scene nodes), it will be simplest if you write your own derived scene nodes. There are other advantages to using scene nodes.

Travis
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

WindScar wrote: LH coordinate system where Z faces upwards
Why?
Post Reply