Creating a cube

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
zapakitul
Posts: 9
Joined: Sun Mar 22, 2009 7:04 pm

Creating a cube

Post by zapakitul »

Hey guys, i went over some Irrlicht tutorials and decided to try and write a small app that displays a cube on the screen. The code i have written compiles but the cube isn't displayed, and even though i tried changing it's position the screen goes eighter black, or stays blue.... Any idea where the problem could be?

Code: Select all

 #include <Irrlicht.h> 
#pragma comment(lib, "Irrlicht.lib"); 


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


int main()
{

 IrrlichtDevice *device = createDevice(EDT_OPENGL);
 IVideoDriver* video = device->getVideoDriver();
 ISceneManager* smgr = device->getSceneManager();

 ISceneNode* cube = smgr->addCubeSceneNode();
 cube->setPosition(vector3df(0,0,0));
 

 while(device->run() && device)
 {
  video->beginScene(true, true, video::SColor(255,0,0,255));
  smgr->drawAll();
  video->endScene();
 }

} 


Also, i have just moved to Irrlicht from DarkGDK and i am eager to port my project. Right now i am trying to get a hand on the basics and then work on it. My first question would be, how do i get an object position on the X, Y or Z scale? In GDK it was

Code: Select all

dbGetObjectPositionX(objectNumber);
in Irrlicht i position the object using cube->setPosition(vector3d(x,y,z)), but how do i get it's position? Thank you.
Alpha Omega
Posts: 288
Joined: Wed Oct 29, 2008 12:07 pm

Post by Alpha Omega »

You are not seeing the cube in your window because you have not created a camera to look at your cube.

Also to get position you do it exactly like you set...

Code: Select all

vector3df cubepos = cube->getPosition();
then to set the position based on what you got...

Code: Select all

cube->setPosition(cubepos);
zapakitul
Posts: 9
Joined: Sun Mar 22, 2009 7:04 pm

Post by zapakitul »

Ups silly me, forgot the camera!
Btw what if i want to get the X position, and then position the cube like
Cube Position X+1, cube Position Y, Cube Position Z?
Alpha Omega
Posts: 288
Joined: Wed Oct 29, 2008 12:07 pm

Post by Alpha Omega »

Remember that Vector3df is a class containing 3 arguments so to specify either the X, Y, or Z you can access the subclass by using the

Code: Select all

campos.X
for the X coordinate and so forth


Code: Select all

vector3df cubepos=getPosition();
cube->setPosition(vector3df(cubepos.X+1, cubepos.Y,cubepos.Z));
zapakitul
Posts: 9
Joined: Sun Mar 22, 2009 7:04 pm

Post by zapakitul »

thank you alpha.
Post Reply