trying to use m_driver->setTransform()

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
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

trying to use m_driver->setTransform()

Post by keless »

I am trying to draw a series of 2D rectangles (colored, not textured).

in OGL, I would simply do:
glPushMatrix();
glTranslatef(0, 100, 0);
//draw blocks
glPopMatrix();

looking at CustomSceneNode, you dont seem to have any PushMatrix stuff.. So I assume each 'node' has a built in equivilent of PushMatrix()? I havent yet tried to build a CSN yet though, I'm just writing raw drawing code for now.

Currently my code does this in its render stage (between m_driver->start and end functions):

Code: Select all

    irr::core::matrix4 pilePos;  //pilePos.makeIdentity(); unneccesary
    pilePos.setTranslation(irr::core::vector3df(0, 100, 0));
    m_driver->setTransform(irr::video::TS_WORLD, pilePos);
    for(int i=0; i<TS_PILEBLOB_H-10 ;i++) {
     for(int j=0; j<TS_PILEBLOB_W-10 ;j++) {
          m_driver->draw2DRectangle(obj->rows[i][j], 
                    irr::core::rect<irr::s32>( 44*j, 44*i, 44 + 44*j, 44 + 44*i));
     }
    }
The 2D rectangles draw, but in the same position as if I had not called m_driver->setTranslation(); Because of this I assume the translation matrix only work on 3D calls?

Should I be drawing my blocks as 3D Quads to try to take advantage of this? The reason I want to do this is because your origin is TopLeft, but my Tetris_BlockBlob code assumes an origin of BottomLeft. So my Tetris_RenderBlob code needs to translate to the bottom left and then rotate 180degs around the X-Axis so the Y-axis points upwards.

Any advice?
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

Yes, the transform matrix only works on 3d objects, but the driver->draw2DRectangle() does not draw in 3d. It is meant for GUI objects and so uses absolute screen coordinates rather then 3d space coordinates.

If you want to use the driver->setTransform() to set position, you will have to use 3D Quads.
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

okay, I'm now trying to use driver->draw3DTriangle.. but its crashing.

Code: Select all

void tetris_PileBlobRenderer::DrawRect(irr::video::SColor color, irr::core::rect<irr::s32> pos)
{
    if(!m_driver) return;
    irr::core::vector3df tl, tr, bl, br;
    tl.set((irr::f32)pos.UpperLeftCorner.X, (irr::f32)pos.UpperLeftCorner.Y, 0 );
    tr.set((irr::f32)pos.LowerRightCorner.X, (irr::f32)pos.UpperLeftCorner.Y, 0 );
    br.set((irr::f32)pos.LowerRightCorner.X, (irr::f32)pos.LowerRightCorner.Y, 0 );
    bl.set((irr::f32)pos.UpperLeftCorner.X, (irr::f32)pos.LowerRightCorner.Y, 0 );
    irr::core::triangle3df up, rht;
    up.set( tr, tl, bl );
    rht.set( bl, br, tr );
    m_driver->draw3DTriangle(up, color); 
    //m_driver->draw3DTriangle(rht, color);
}
If i change pos to a f32 rect, it still crashes.

If I comment out the m_driver->draw3DTriangle(..);s it does not crash (though of course it doesnt draw anything). If I use 2DRectangle() it works properly. Am I forgetting to set something, or is there a type conflict or soemthing?
Post Reply